fuzz: use qemu_get_exec_dir
[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.events import gen_events
14 from qapi.introspect import gen_introspect
15 from qapi.schema import QAPIError, QAPISchema
16 from qapi.types import gen_types
17 from qapi.visit import gen_visit
18
19
20 def main(argv):
21 parser = argparse.ArgumentParser(
22 description='Generate code from a QAPI schema')
23 parser.add_argument('-b', '--builtins', action='store_true',
24 help="generate code for built-in types")
25 parser.add_argument('-o', '--output-dir', action='store', default='',
26 help="write output to directory OUTPUT_DIR")
27 parser.add_argument('-p', '--prefix', action='store', default='',
28 help="prefix for symbols")
29 parser.add_argument('-u', '--unmask-non-abi-names', action='store_true',
30 dest='unmask',
31 help="expose non-ABI names in introspection")
32 parser.add_argument('schema', action='store')
33 args = parser.parse_args()
34
35 match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', args.prefix)
36 if match.end() != len(args.prefix):
37 print("%s: 'funny character '%s' in argument of --prefix"
38 % (sys.argv[0], args.prefix[match.end()]),
39 file=sys.stderr)
40 sys.exit(1)
41
42 try:
43 schema = QAPISchema(args.schema)
44 except QAPIError as err:
45 print(err, file=sys.stderr)
46 exit(1)
47
48 gen_types(schema, args.output_dir, args.prefix, args.builtins)
49 gen_visit(schema, args.output_dir, args.prefix, args.builtins)
50 gen_commands(schema, args.output_dir, args.prefix)
51 gen_events(schema, args.output_dir, args.prefix)
52 gen_introspect(schema, args.output_dir, args.prefix, args.unmask)
53
54
55 if __name__ == '__main__':
56 main(sys.argv)