target/ppc: Remove msr_ir macro
[qemu.git] / scripts / modinfo-generate.py
blobf559eed0077a22bfd25a26a79c01fa995f501e9d
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
4 import os
5 import sys
7 def print_array(name, values):
8 if len(values) == 0:
9 return
10 list = ", ".join(values)
11 print(" .%s = ((const char*[]){ %s, NULL })," % (name, list))
13 def parse_line(line):
14 kind = ""
15 data = ""
16 get_kind = False
17 get_data = False
18 for item in line.split():
19 if item == "MODINFO_START":
20 get_kind = True
21 continue
22 if item.startswith("MODINFO_END"):
23 get_data = False
24 continue
25 if get_kind:
26 kind = item
27 get_kind = False
28 get_data = True
29 continue
30 if get_data:
31 data += " " + item
32 continue
33 return (kind, data)
35 def generate(name, lines):
36 arch = ""
37 objs = []
38 deps = []
39 opts = []
40 for line in lines:
41 if line.find("MODINFO_START") != -1:
42 (kind, data) = parse_line(line)
43 if kind == 'obj':
44 objs.append(data)
45 elif kind == 'dep':
46 deps.append(data)
47 elif kind == 'opts':
48 opts.append(data)
49 elif kind == 'arch':
50 arch = data;
51 else:
52 print("unknown:", kind)
53 exit(1)
55 print(" .name = \"%s\"," % name)
56 if arch != "":
57 print(" .arch = %s," % arch)
58 print_array("objs", objs)
59 print_array("deps", deps)
60 print_array("opts", opts)
61 print("},{");
62 return deps
64 def print_pre():
65 print("/* generated by scripts/modinfo-generate.py */")
66 print("#include \"qemu/osdep.h\"")
67 print("#include \"qemu/module.h\"")
68 print("const QemuModinfo qemu_modinfo[] = {{")
70 def print_post():
71 print(" /* end of list */")
72 print("}};")
74 def main(args):
75 deps = {}
76 print_pre()
77 for modinfo in args:
78 with open(modinfo) as f:
79 lines = f.readlines()
80 print(" /* %s */" % modinfo)
81 (basename, ext) = os.path.splitext(modinfo)
82 deps[basename] = generate(basename, lines)
83 print_post()
85 flattened_deps = {flat.strip('" ') for dep in deps.values() for flat in dep}
86 error = False
87 for dep in flattened_deps:
88 if dep not in deps.keys():
89 print("Dependency {} cannot be satisfied".format(dep),
90 file=sys.stderr)
91 error = True
93 if error:
94 exit(1)
96 if __name__ == "__main__":
97 main(sys.argv[1:])