1#!/usr/bin/env python 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 7from __future__ import print_function 8import argparse 9import re 10import sys 11from qapi.common import QAPIError, QAPISchema 12from qapi.types import gen_types 13from qapi.visit import gen_visit 14from qapi.commands import gen_commands 15from qapi.events import gen_events 16from qapi.introspect import gen_introspect 17from qapi.doc import gen_doc 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 gen_doc(schema, args.output_dir, args.prefix) 54 55 56if __name__ == '__main__': 57 main(sys.argv) 58