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