aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi-event.py
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2015-05-15 17:51:20 +0100
committerPeter Maydell <peter.maydell@linaro.org>2015-05-15 17:51:20 +0100
commit385057cbec9b4a0eb6150330c572e875ed714965 (patch)
tree7adc24566bfe8afc56aee25128b2fc3bd5a6a9a5 /scripts/qapi-event.py
parent99e7627a70d1a23e30a514e5a4798005cf4eb3aa (diff)
parent4180978c9205c50acd2d6c385def9b3e81911696 (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2015-05-15' into staging
qapi: Fix qapi mangling of downstream names, and more # gpg: Signature made Fri May 15 17:41:31 2015 BST using RSA key ID EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" * remotes/armbru/tags/pull-qapi-2015-05-15: (26 commits) qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue() qapi: Drop pointless flush() before close() qapi: Factor open_output(), close_output() out of generators qapi: Turn generators' mandatory option -i into an argument qapi: Fix generators to report command line errors decently qapi: Factor parse_command_line() out of the generators qapi: qapi-commands.py option --type is unused, drop it qapi: qapi-event.py option -b does nothing, drop it tests: Add missing dependencies on $(qapi-py) qapi: Support downstream events and commands qapi: Support downstream alternates qapi: Support downstream flat unions qapi: Support downstream simple unions qapi: Support downstream structs qapi: Support downstream enums qapi: Make c_type() consistently convert qapi names qapi: Tidy c_type() logic qapi: Move camel_to_upper(), c_enum_const() to closely related code qapi: Use c_enum_const() in generate_alternate_qtypes() qapi: Simplify c_enum_const() ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts/qapi-event.py')
-rw-r--r--scripts/qapi-event.py125
1 files changed, 28 insertions, 97 deletions
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 47dc041805..56bc602a6d 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -11,23 +11,19 @@
from ordereddict import OrderedDict
from qapi import *
-import sys
-import os
-import getopt
-import errno
def _generate_event_api_name(event_name, params):
- api_name = "void qapi_event_send_%s(" % c_fun(event_name).lower();
+ api_name = "void qapi_event_send_%s(" % c_name(event_name).lower();
l = len(api_name)
if params:
for argname, argentry, optional in parse_args(params):
if optional:
- api_name += "bool has_%s,\n" % c_var(argname)
+ api_name += "bool has_%s,\n" % c_name(argname)
api_name += "".ljust(l)
api_name += "%s %s,\n" % (c_type(argentry, is_param=True),
- c_var(argname))
+ c_name(argname))
api_name += "".ljust(l)
api_name += "Error **errp)"
@@ -98,7 +94,7 @@ def generate_event_implement(api_name, event_name, params):
ret += mcgen("""
if (has_%(var)s) {
""",
- var = c_var(argname))
+ var = c_name(argname))
push_indent()
if argentry == "str":
@@ -113,7 +109,7 @@ def generate_event_implement(api_name, event_name, params):
}
""",
var_type = var_type,
- var = c_var(argname),
+ var = c_name(argname),
type = type_name(argentry),
name = argname)
@@ -177,7 +173,7 @@ typedef enum %(event_enum_name)s
event_enum_name = event_enum_name)
# append automatically generated _MAX value
- enum_max_value = generate_enum_full_value(event_enum_name, "MAX")
+ enum_max_value = c_enum_const(event_enum_name, "MAX")
enum_values = event_enum_values + [ enum_max_value ]
i = 0
@@ -216,67 +212,9 @@ const char *%(event_enum_name)s_lookup[] = {
''')
return ret
+(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
-# Start the real job
-
-try:
- opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
- ["source", "header", "builtins", "prefix=",
- "input-file=", "output-dir="])
-except getopt.GetoptError, err:
- print str(err)
- sys.exit(1)
-
-input_file = ""
-output_dir = ""
-prefix = ""
-c_file = 'qapi-event.c'
-h_file = 'qapi-event.h'
-
-do_c = False
-do_h = False
-do_builtins = False
-
-for o, a in opts:
- if o in ("-p", "--prefix"):
- prefix = a
- elif o in ("-i", "--input-file"):
- input_file = a
- elif o in ("-o", "--output-dir"):
- output_dir = a + "/"
- elif o in ("-c", "--source"):
- do_c = True
- elif o in ("-h", "--header"):
- do_h = True
- elif o in ("-b", "--builtins"):
- do_builtins = True
-
-if not do_c and not do_h:
- do_c = True
- do_h = True
-
-c_file = output_dir + prefix + c_file
-h_file = output_dir + prefix + h_file
-
-try:
- os.makedirs(output_dir)
-except os.error, e:
- if e.errno != errno.EEXIST:
- raise
-
-def maybe_open(really, name, opt):
- if really:
- return open(name, opt)
- else:
- import StringIO
- return StringIO.StringIO()
-
-fdef = maybe_open(do_c, c_file, 'w')
-fdecl = maybe_open(do_h, h_file, 'w')
-
-fdef.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+c_comment = '''
/*
* schema-defined QAPI event functions
*
@@ -289,19 +227,8 @@ fdef.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
-
-#include "qemu-common.h"
-#include "%(header)s"
-#include "%(prefix)sqapi-visit.h"
-#include "qapi/qmp-output-visitor.h"
-#include "qapi/qmp-event.h"
-
-''',
- prefix=prefix, header=basename(h_file)))
-
-fdecl.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+'''
+h_comment = '''
/*
* schema-defined QAPI event functions
*
@@ -314,16 +241,29 @@ fdecl.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
+'''
-#ifndef %(guard)s
-#define %(guard)s
+(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
+ 'qapi-event.c', 'qapi-event.h',
+ c_comment, h_comment)
+fdef.write(mcgen('''
+#include "qemu-common.h"
+#include "%(prefix)sqapi-event.h"
+#include "%(prefix)sqapi-visit.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp-event.h"
+
+''',
+ prefix=prefix))
+
+fdecl.write(mcgen('''
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix, guard=guardname(h_file)))
+ prefix=prefix))
exprs = parse_schema(input_file)
@@ -343,8 +283,7 @@ for expr in exprs:
fdecl.write(ret)
# We need an enum value per event
- event_enum_value = generate_enum_full_value(event_enum_name,
- event_name)
+ event_enum_value = c_enum_const(event_enum_name, event_name)
ret = generate_event_implement(api_name, event_name, params)
fdef.write(ret)
@@ -357,12 +296,4 @@ fdecl.write(ret)
ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
fdef.write(ret)
-fdecl.write('''
-#endif
-''')
-
-fdecl.flush()
-fdecl.close()
-
-fdef.flush()
-fdef.close()
+close_output(fdef, fdecl)