File: syscall_defs_gen.py

package info (click to toggle)
vuos 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,616 kB
  • sloc: ansic: 22,155; python: 284; makefile: 28; sh: 4
file content (56 lines) | stat: -rwxr-xr-x 1,587 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
import sys
import os.path

if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]):
	print(f"{sys.argv[0]}: the input should be 'vu_syscalls.conf'")
	sys.exit(1)

# Parse and output

code = '''#ifndef __VU_SYSCALL_DEFS__
#define __VU_SYSCALL_DEFS__

/* Arch independent definitions */

'''
vu_syscall_max_namelen = 0
vvu_syscall_max_namelen = 0

with open(sys.argv[1]) as f:
	counter = 0
	vcounter = 1
	mcounter = 0
	for line in f:
		line = line.strip()
		if line == "BUILTIN":
			mcounter = counter
		elif not line.startswith('#'):
			syscall_line = line.split(':')
			if len(syscall_line) > 1:
				syscall = syscall_line[0].strip()
				if len(syscall) > 1:
					syscall = syscall.split(',')[0].strip()
				syscall = syscall.split('/')[0]
				if syscall.startswith('-'):
					syscall = syscall[1:].strip()
					syscall_len = len(syscall)
					if syscall_len > vvu_syscall_max_namelen:
							vvu_syscall_max_namelen = syscall_len
					code += f"#define __VVU_{syscall} {-vcounter}\n"
					vcounter += 1
				else:
					syscall_len = len(syscall)
					if syscall_len > vu_syscall_max_namelen:
							vu_syscall_max_namelen = syscall_len
					code += f"#define __VU_{syscall} {counter}\n"
					counter += 1
if mcounter == 0:
	mcounter = counter
code += f"\n#define VU_NR_SYSCALLS {counter}"
code += f"\n#define VU_NR_MODULE_SYSCALLS {mcounter}"
code += f"\n#define VVU_NR_SYSCALLS {vcounter}"
code += f"\n#define VU_SYSCALL_MAX_NAMELEN {vu_syscall_max_namelen}"
code += f"\n#define VVU_SYSCALL_MAX_NAMELEN {vvu_syscall_max_namelen}"
code += "\n\n#endif"
print(code)