]> git.proxmox.com Git - mirror_qemu.git/blame - scripts/qapi-gen.py
scripts/cocci: Patch to remove unnecessary memory_region_set_readonly()
[mirror_qemu.git] / scripts / qapi-gen.py
CommitLineData
3d004a37 1#!/usr/bin/env python3
fb0bc835
MA
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
e6c42b96 7
3b446a18
MA
8import argparse
9import re
fb0bc835 10import sys
e6c42b96 11
fb0bc835 12from qapi.commands import gen_commands
e6c42b96 13from qapi.doc import gen_doc
fb0bc835
MA
14from qapi.events import gen_events
15from qapi.introspect import gen_introspect
e6c42b96
MA
16from qapi.schema import QAPIError, QAPISchema
17from qapi.types import gen_types
18from qapi.visit import gen_visit
fb0bc835
MA
19
20
21def main(argv):
3b446a18
MA
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
181feaf3
MA
43 try:
44 schema = QAPISchema(args.schema)
45 except QAPIError as err:
46 print(err, file=sys.stderr)
47 exit(1)
3b446a18
MA
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)
fb0bc835
MA
55
56
57if __name__ == '__main__':
58 main(sys.argv)