1*3d004a37SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2fb0bc835SMarkus Armbruster# QAPI generator 3fb0bc835SMarkus Armbruster# 4fb0bc835SMarkus Armbruster# This work is licensed under the terms of the GNU GPL, version 2 or later. 5fb0bc835SMarkus Armbruster# See the COPYING file in the top-level directory. 6fb0bc835SMarkus Armbruster 73b446a18SMarkus Armbrusterfrom __future__ import print_function 8e6c42b96SMarkus Armbruster 93b446a18SMarkus Armbrusterimport argparse 103b446a18SMarkus Armbrusterimport re 11fb0bc835SMarkus Armbrusterimport sys 12e6c42b96SMarkus Armbruster 13fb0bc835SMarkus Armbrusterfrom qapi.commands import gen_commands 14e6c42b96SMarkus Armbrusterfrom qapi.doc import gen_doc 15fb0bc835SMarkus Armbrusterfrom qapi.events import gen_events 16fb0bc835SMarkus Armbrusterfrom qapi.introspect import gen_introspect 17e6c42b96SMarkus Armbrusterfrom qapi.schema import QAPIError, QAPISchema 18e6c42b96SMarkus Armbrusterfrom qapi.types import gen_types 19e6c42b96SMarkus Armbrusterfrom qapi.visit import gen_visit 20fb0bc835SMarkus Armbruster 21fb0bc835SMarkus Armbruster 22fb0bc835SMarkus Armbrusterdef main(argv): 233b446a18SMarkus Armbruster parser = argparse.ArgumentParser( 243b446a18SMarkus Armbruster description='Generate code from a QAPI schema') 253b446a18SMarkus Armbruster parser.add_argument('-b', '--builtins', action='store_true', 263b446a18SMarkus Armbruster help="generate code for built-in types") 273b446a18SMarkus Armbruster parser.add_argument('-o', '--output-dir', action='store', default='', 283b446a18SMarkus Armbruster help="write output to directory OUTPUT_DIR") 293b446a18SMarkus Armbruster parser.add_argument('-p', '--prefix', action='store', default='', 303b446a18SMarkus Armbruster help="prefix for symbols") 313b446a18SMarkus Armbruster parser.add_argument('-u', '--unmask-non-abi-names', action='store_true', 323b446a18SMarkus Armbruster dest='unmask', 333b446a18SMarkus Armbruster help="expose non-ABI names in introspection") 343b446a18SMarkus Armbruster parser.add_argument('schema', action='store') 353b446a18SMarkus Armbruster args = parser.parse_args() 36fb0bc835SMarkus Armbruster 373b446a18SMarkus Armbruster match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', args.prefix) 383b446a18SMarkus Armbruster if match.end() != len(args.prefix): 393b446a18SMarkus Armbruster print("%s: 'funny character '%s' in argument of --prefix" 403b446a18SMarkus Armbruster % (sys.argv[0], args.prefix[match.end()]), 413b446a18SMarkus Armbruster file=sys.stderr) 423b446a18SMarkus Armbruster sys.exit(1) 43fb0bc835SMarkus Armbruster 44181feaf3SMarkus Armbruster try: 453b446a18SMarkus Armbruster schema = QAPISchema(args.schema) 46181feaf3SMarkus Armbruster except QAPIError as err: 47181feaf3SMarkus Armbruster print(err, file=sys.stderr) 48181feaf3SMarkus Armbruster exit(1) 49fb0bc835SMarkus Armbruster 503b446a18SMarkus Armbruster gen_types(schema, args.output_dir, args.prefix, args.builtins) 513b446a18SMarkus Armbruster gen_visit(schema, args.output_dir, args.prefix, args.builtins) 523b446a18SMarkus Armbruster gen_commands(schema, args.output_dir, args.prefix) 533b446a18SMarkus Armbruster gen_events(schema, args.output_dir, args.prefix) 543b446a18SMarkus Armbruster gen_introspect(schema, args.output_dir, args.prefix, args.unmask) 553b446a18SMarkus Armbruster gen_doc(schema, args.output_dir, args.prefix) 56fb0bc835SMarkus Armbruster 57fb0bc835SMarkus Armbruster 58fb0bc835SMarkus Armbrusterif __name__ == '__main__': 59fb0bc835SMarkus Armbruster main(sys.argv) 60