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.
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
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',
31 help="expose non-ABI names in introspection")
32 parser.add_argument('schema', action='store')
33 args = parser.parse_args()
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()]),
43 schema = QAPISchema(args.schema)
44 except QAPIError as err:
45 print(err, file=sys.stderr)
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)
55 if __name__ == '__main__':