target/rx: Emit all disassembly in one prt()
[qemu.git] / scripts / qapi-gen.py
1 #!/usr/bin/env python3
2 # QAPI generator
3 #
4 # This work is licensed under the terms of the GNU GPL, version 2 or later.
5 # See the COPYING file in the top-level directory.
6
7
8 import argparse
9 import re
10 import sys
11
12 from qapi.commands import gen_commands
13 from qapi.doc import gen_doc
14 from qapi.events import gen_events
15 from qapi.introspect import gen_introspect
16 from qapi.schema import QAPIError, QAPISchema
17 from qapi.types import gen_types
18 from qapi.visit import gen_visit
19
20
21 def main(argv):
22 parser = argparse.ArgumentParser(
23 description='Generate code from a QAPI schema')
24 parser.add_argument('-b', '--builtins', action='store_true',
25 help="generate code for built-in types")
26 parser.add_argument('-o', '--output-dir', action='store', default='',
27 help="write output to directory OUTPUT_DIR")
28 parser.add_argument('-p', '--prefix', action='store', default='',
29 help="prefix for symbols")
30 parser.add_argument('-u', '--unmask-non-abi-names', action='store_true',
31 dest='unmask',
32 help="expose non-ABI names in introspection")
33 parser.add_argument('schema', action='store')
34 args = parser.parse_args()
35
36 match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', args.prefix)
37 if match.end() != len(args.prefix):
38 print("%s: 'funny character '%s' in argument of --prefix"
39 % (sys.argv[0], args.prefix[match.end()]),
40 file=sys.stderr)
41 sys.exit(1)
42
43 try:
44 schema = QAPISchema(args.schema)
45 except QAPIError as err:
46 print(err, file=sys.stderr)
47 exit(1)
48
49 gen_types(schema, args.output_dir, args.prefix, args.builtins)
50 gen_visit(schema, args.output_dir, args.prefix, args.builtins)
51 gen_commands(schema, args.output_dir, args.prefix)
52 gen_events(schema, args.output_dir, args.prefix)
53 gen_introspect(schema, args.output_dir, args.prefix, args.unmask)
54 gen_doc(schema, args.output_dir, args.prefix)
55
56
57 if __name__ == '__main__':
58 main(sys.argv)