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 8import argparse 9import re 10import sys 11 12from qapi.commands import gen_commands 13from qapi.events import gen_events 14from qapi.introspect import gen_introspect 15from qapi.schema import QAPIError, QAPISchema 16from qapi.types import gen_types 17from qapi.visit import gen_visit 18 19 20def 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 55if __name__ == '__main__': 56 main(sys.argv) 57