mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-05 19:35:34 +00:00
qapi: Factor open_output(), close_output() out of generators
Backports commit 12f8e1b9ff57e99dafbb13f89cd5a99ad5c28527 from qemu
This commit is contained in:
parent
d77e0dd040
commit
2c9ed3c379
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "unicorn/platform.h"
|
#include "unicorn/platform.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef QAPI_TYPES_BUILTIN_STRUCT_DECL_H
|
#ifndef QAPI_TYPES_BUILTIN_STRUCT_DECL_H
|
||||||
#define QAPI_TYPES_BUILTIN_STRUCT_DECL_H
|
#define QAPI_TYPES_BUILTIN_STRUCT_DECL_H
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* schema-defined QAPI visitor functions
|
* schema-defined QAPI visitor functions
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* schema-defined QAPI visitor functions
|
* schema-defined QAPI visitor functions
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
|
|
||||||
from ordereddict import OrderedDict
|
from ordereddict import OrderedDict
|
||||||
from qapi import *
|
from qapi import *
|
||||||
import os
|
|
||||||
import errno
|
|
||||||
|
|
||||||
def _generate_event_api_name(event_name, params):
|
def _generate_event_api_name(event_name, params):
|
||||||
api_name = "void qapi_event_send_%s(" % c_name(event_name).lower();
|
api_name = "void qapi_event_send_%s(" % c_name(event_name).lower();
|
||||||
|
@ -214,36 +212,9 @@ const char *%(event_enum_name)s_lookup[] = {
|
||||||
''')
|
''')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
# Start the real job
|
|
||||||
|
|
||||||
c_file = 'qapi-event.c'
|
|
||||||
h_file = 'qapi-event.h'
|
|
||||||
|
|
||||||
(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
|
(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
|
||||||
|
|
||||||
c_file = output_dir + prefix + c_file
|
c_comment = '''
|
||||||
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 */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* schema-defined QAPI event functions
|
* schema-defined QAPI event functions
|
||||||
*
|
*
|
||||||
|
@ -256,41 +227,42 @@ fdef.write(mcgen('''
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
'''
|
||||||
|
h_comment = '''
|
||||||
|
/*
|
||||||
|
* schema-defined QAPI event functions
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Wenchao Xia
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Wenchao Xia <wenchaoqemu@gmail.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
||||||
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
'''
|
||||||
|
|
||||||
|
(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 "qemu-common.h"
|
||||||
#include "%(header)s"
|
#include "%(prefix)sqapi-event.h"
|
||||||
#include "%(prefix)sqapi-visit.h"
|
#include "%(prefix)sqapi-visit.h"
|
||||||
#include "qapi/qmp-output-visitor.h"
|
#include "qapi/qmp-output-visitor.h"
|
||||||
#include "qapi/qmp-event.h"
|
#include "qapi/qmp-event.h"
|
||||||
|
|
||||||
''',
|
''',
|
||||||
prefix=prefix, header=basename(h_file)))
|
prefix=prefix))
|
||||||
|
|
||||||
fdecl.write(mcgen('''
|
fdecl.write(mcgen('''
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* schema-defined QAPI event functions
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 Wenchao Xia
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Wenchao Xia <wenchaoqemu@gmail.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef %(guard)s
|
|
||||||
#define %(guard)s
|
|
||||||
|
|
||||||
#include "qapi/error.h"
|
#include "qapi/error.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "%(prefix)sqapi-types.h"
|
#include "%(prefix)sqapi-types.h"
|
||||||
|
|
||||||
''',
|
''',
|
||||||
prefix=prefix, guard=guardname(h_file)))
|
prefix=prefix))
|
||||||
|
|
||||||
exprs = parse_schema(input_file)
|
exprs = parse_schema(input_file)
|
||||||
|
|
||||||
|
@ -323,12 +295,4 @@ fdecl.write(ret)
|
||||||
ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
|
ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
|
||||||
fdef.write(ret)
|
fdef.write(ret)
|
||||||
|
|
||||||
fdecl.write('''
|
close_output(fdef, fdecl)
|
||||||
#endif
|
|
||||||
''')
|
|
||||||
|
|
||||||
fdecl.flush()
|
|
||||||
fdecl.close()
|
|
||||||
|
|
||||||
fdef.flush()
|
|
||||||
fdef.close()
|
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
|
|
||||||
from ordereddict import OrderedDict
|
from ordereddict import OrderedDict
|
||||||
from qapi import *
|
from qapi import *
|
||||||
import os
|
|
||||||
import errno
|
|
||||||
|
|
||||||
def generate_fwd_struct(name, members, builtin_type=False):
|
def generate_fwd_struct(name, members, builtin_type=False):
|
||||||
if builtin_type:
|
if builtin_type:
|
||||||
|
@ -263,9 +261,6 @@ void qapi_free_%(name)s(%(c_type)s obj)
|
||||||
c_type=c_type(name), name=c_name(name))
|
c_type=c_type(name), name=c_name(name))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
c_file = 'qapi-types.c'
|
|
||||||
h_file = 'qapi-types.h'
|
|
||||||
|
|
||||||
do_builtins = False
|
do_builtins = False
|
||||||
|
|
||||||
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
||||||
|
@ -275,28 +270,7 @@ for o, a in opts:
|
||||||
if o in ("-b", "--builtins"):
|
if o in ("-b", "--builtins"):
|
||||||
do_builtins = True
|
do_builtins = True
|
||||||
|
|
||||||
c_file = output_dir + prefix + c_file
|
c_comment = '''
|
||||||
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('''
|
|
||||||
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* deallocation functions for schema-defined QAPI types
|
* deallocation functions for schema-defined QAPI types
|
||||||
*
|
*
|
||||||
|
@ -310,16 +284,8 @@ fdef.write(mcgen('''
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
'''
|
||||||
#include "qapi/dealloc-visitor.h"
|
h_comment = '''
|
||||||
#include "%(prefix)sqapi-types.h"
|
|
||||||
#include "%(prefix)sqapi-visit.h"
|
|
||||||
|
|
||||||
''', prefix=prefix))
|
|
||||||
|
|
||||||
fdecl.write(mcgen('''
|
|
||||||
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* schema-defined QAPI types
|
* schema-defined QAPI types
|
||||||
*
|
*
|
||||||
|
@ -332,14 +298,22 @@ fdecl.write(mcgen('''
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
'''
|
||||||
|
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
|
||||||
|
'qapi-types.c', 'qapi-types.h',
|
||||||
|
c_comment, h_comment)
|
||||||
|
|
||||||
#ifndef %(guard)s
|
fdef.write(mcgen('''
|
||||||
#define %(guard)s
|
#include "qapi/dealloc-visitor.h"
|
||||||
|
#include "%(prefix)sqapi-types.h"
|
||||||
#include "unicorn/platform.h"
|
#include "%(prefix)sqapi-visit.h"
|
||||||
|
|
||||||
''',
|
''',
|
||||||
guard=guardname(h_file)))
|
prefix=prefix))
|
||||||
|
|
||||||
|
fdecl.write(mcgen('''
|
||||||
|
#include "unicorn/platform.h"
|
||||||
|
'''))
|
||||||
|
|
||||||
exprs = parse_schema(input_file)
|
exprs = parse_schema(input_file)
|
||||||
exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
|
exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
|
||||||
|
@ -417,12 +391,4 @@ for expr in exprs:
|
||||||
continue
|
continue
|
||||||
fdecl.write(ret)
|
fdecl.write(ret)
|
||||||
|
|
||||||
fdecl.write('''
|
close_output(fdef, fdecl)
|
||||||
#endif
|
|
||||||
''')
|
|
||||||
|
|
||||||
fdecl.flush()
|
|
||||||
fdecl.close()
|
|
||||||
|
|
||||||
fdef.flush()
|
|
||||||
fdef.close()
|
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
from ordereddict import OrderedDict
|
from ordereddict import OrderedDict
|
||||||
from qapi import *
|
from qapi import *
|
||||||
import re
|
import re
|
||||||
import os
|
|
||||||
import errno
|
|
||||||
|
|
||||||
implicit_structs = []
|
implicit_structs = []
|
||||||
|
|
||||||
|
@ -376,9 +374,6 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **er
|
||||||
''',
|
''',
|
||||||
name=c_name(name))
|
name=c_name(name))
|
||||||
|
|
||||||
c_file = 'qapi-visit.c'
|
|
||||||
h_file = 'qapi-visit.h'
|
|
||||||
|
|
||||||
do_builtins = False
|
do_builtins = False
|
||||||
|
|
||||||
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
(input_file, output_dir, do_c, do_h, prefix, opts) = \
|
||||||
|
@ -388,70 +383,51 @@ for o, a in opts:
|
||||||
if o in ("-b", "--builtins"):
|
if o in ("-b", "--builtins"):
|
||||||
do_builtins = True
|
do_builtins = True
|
||||||
|
|
||||||
c_file = output_dir + prefix + c_file
|
c_comment = '''
|
||||||
h_file = output_dir + prefix + h_file
|
/*
|
||||||
|
* schema-defined QAPI visitor functions
|
||||||
|
*
|
||||||
|
* Copyright IBM, Corp. 2011
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anthony Liguori <aliguori@us.ibm.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
||||||
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
'''
|
||||||
|
h_comment = '''
|
||||||
|
/*
|
||||||
|
* schema-defined QAPI visitor functions
|
||||||
|
*
|
||||||
|
* Copyright IBM, Corp. 2011
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anthony Liguori <aliguori@us.ibm.com>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
||||||
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
'''
|
||||||
|
|
||||||
try:
|
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
|
||||||
os.makedirs(output_dir)
|
'qapi-visit.c', 'qapi-visit.h',
|
||||||
except os.error, e:
|
c_comment, h_comment)
|
||||||
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('''
|
fdef.write(mcgen('''
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* schema-defined QAPI visitor functions
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2011
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
#include "%(header)s"
|
#include "%(prefix)sqapi-visit.h"
|
||||||
''',
|
''',
|
||||||
header=basename(h_file)))
|
prefix = prefix))
|
||||||
|
|
||||||
fdecl.write(mcgen('''
|
fdecl.write(mcgen('''
|
||||||
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* schema-defined QAPI visitor functions
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2011
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
||||||
* See the COPYING.LIB file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef %(guard)s
|
|
||||||
#define %(guard)s
|
|
||||||
|
|
||||||
#include "qapi/visitor.h"
|
#include "qapi/visitor.h"
|
||||||
#include "%(prefix)sqapi-types.h"
|
#include "%(prefix)sqapi-types.h"
|
||||||
|
|
||||||
''',
|
''',
|
||||||
prefix=prefix, guard=guardname(h_file)))
|
prefix=prefix))
|
||||||
|
|
||||||
exprs = parse_schema(input_file)
|
exprs = parse_schema(input_file)
|
||||||
|
|
||||||
|
@ -507,12 +483,4 @@ for expr in exprs:
|
||||||
ret += generate_enum_declaration(expr['enum'], expr['data'])
|
ret += generate_enum_declaration(expr['enum'], expr['data'])
|
||||||
fdecl.write(ret)
|
fdecl.write(ret)
|
||||||
|
|
||||||
fdecl.write('''
|
close_output(fdef, fdecl)
|
||||||
#endif
|
|
||||||
''')
|
|
||||||
|
|
||||||
fdecl.flush()
|
|
||||||
fdecl.close()
|
|
||||||
|
|
||||||
fdef.flush()
|
|
||||||
fdef.close()
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from ordereddict import OrderedDict
|
from ordereddict import OrderedDict
|
||||||
|
import errno
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -1019,3 +1020,53 @@ def parse_command_line(extra_options = "", extra_long_options = []):
|
||||||
input_file = args[0]
|
input_file = args[0]
|
||||||
|
|
||||||
return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
|
return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
|
||||||
|
|
||||||
|
def open_output(output_dir, do_c, do_h, prefix, c_file, h_file,
|
||||||
|
c_comment, h_comment):
|
||||||
|
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('''
|
||||||
|
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
||||||
|
%(comment)s
|
||||||
|
''',
|
||||||
|
comment = c_comment))
|
||||||
|
|
||||||
|
fdecl.write(mcgen('''
|
||||||
|
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
|
||||||
|
%(comment)s
|
||||||
|
#ifndef %(guard)s
|
||||||
|
#define %(guard)s
|
||||||
|
|
||||||
|
''',
|
||||||
|
comment = h_comment, guard = guardname(h_file)))
|
||||||
|
|
||||||
|
return (fdef, fdecl)
|
||||||
|
|
||||||
|
def close_output(fdef, fdecl):
|
||||||
|
fdecl.write('''
|
||||||
|
#endif
|
||||||
|
''')
|
||||||
|
|
||||||
|
fdecl.flush()
|
||||||
|
fdecl.close()
|
||||||
|
|
||||||
|
fdef.flush()
|
||||||
|
fdef.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue