blob: 7d93d01ed2f7906ebc1217dce9d0918ede6543c9 [file] [log] [blame]
Michael Rothc17d9902011-07-19 14:50:42 -05001#
2# QAPI command marshaller generator
3#
4# Copyright IBM, Corp. 2011
Markus Armbruster297a3642014-05-07 09:53:54 +02005# Copyright (C) 2014 Red Hat, Inc.
Michael Rothc17d9902011-07-19 14:50:42 -05006#
7# Authors:
8# Anthony Liguori <aliguori@us.ibm.com>
9# Michael Roth <mdroth@linux.vnet.ibm.com>
Markus Armbruster297a3642014-05-07 09:53:54 +020010# Markus Armbruster <armbru@redhat.com>
Michael Rothc17d9902011-07-19 14:50:42 -050011#
Markus Armbruster678e48a2014-03-01 08:40:34 +010012# This work is licensed under the terms of the GNU GPL, version 2.
13# See the COPYING file in the top-level directory.
Michael Rothc17d9902011-07-19 14:50:42 -050014
15from ordereddict import OrderedDict
16from qapi import *
Markus Armbruster297a3642014-05-07 09:53:54 +020017import re
Michael Rothc17d9902011-07-19 14:50:42 -050018import sys
19import os
20import getopt
21import errno
22
Anthony Liguori15e43e62011-09-14 14:30:00 -050023def type_visitor(name):
24 if type(name) == list:
25 return 'visit_type_%sList' % name[0]
26 else:
27 return 'visit_type_%s' % name
28
Michael Rothc17d9902011-07-19 14:50:42 -050029def generate_command_decl(name, args, ret_type):
30 arglist=""
31 for argname, argtype, optional, structured in parse_args(args):
32 argtype = c_type(argtype)
33 if argtype == "char *":
34 argtype = "const char *"
35 if optional:
36 arglist += "bool has_%s, " % c_var(argname)
37 arglist += "%s %s, " % (argtype, c_var(argname))
38 return mcgen('''
39%(ret_type)s qmp_%(name)s(%(args)sError **errp);
40''',
Federico Simoncellic9da2282012-03-20 13:54:35 +000041 ret_type=c_type(ret_type), name=c_fun(name), args=arglist).strip()
Michael Rothc17d9902011-07-19 14:50:42 -050042
Markus Armbruster297a3642014-05-07 09:53:54 +020043def gen_err_check(errvar):
44 if errvar:
45 return mcgen('''
46if (local_err) {
47 goto out;
48}
49''')
50 return ''
51
Michael Rothc17d9902011-07-19 14:50:42 -050052def gen_sync_call(name, args, ret_type, indent=0):
53 ret = ""
54 arglist=""
55 retval=""
56 if ret_type:
57 retval = "retval = "
58 for argname, argtype, optional, structured in parse_args(args):
59 if optional:
60 arglist += "has_%s, " % c_var(argname)
61 arglist += "%s, " % (c_var(argname))
62 push_indent(indent)
63 ret = mcgen('''
Markus Armbruster297a3642014-05-07 09:53:54 +020064%(retval)sqmp_%(name)s(%(args)s&local_err);
Michael Rothc17d9902011-07-19 14:50:42 -050065
66''',
Federico Simoncellic9da2282012-03-20 13:54:35 +000067 name=c_fun(name), args=arglist, retval=retval).rstrip()
Michael Rothc17d9902011-07-19 14:50:42 -050068 if ret_type:
Markus Armbruster297a3642014-05-07 09:53:54 +020069 ret += "\n" + gen_err_check('local_err')
Michael Rothc17d9902011-07-19 14:50:42 -050070 ret += "\n" + mcgen(''''
Markus Armbruster297a3642014-05-07 09:53:54 +020071%(marshal_output_call)s
Michael Rothc17d9902011-07-19 14:50:42 -050072''',
73 marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip()
74 pop_indent(indent)
75 return ret.rstrip()
76
77
78def gen_marshal_output_call(name, ret_type):
79 if not ret_type:
80 return ""
Markus Armbruster297a3642014-05-07 09:53:54 +020081 return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_fun(name)
Michael Rothc17d9902011-07-19 14:50:42 -050082
Markus Armbrusterf9bee752014-05-07 09:53:44 +020083def gen_visitor_input_containers_decl(args, obj):
Michael Rothc17d9902011-07-19 14:50:42 -050084 ret = ""
85
86 push_indent()
87 if len(args) > 0:
88 ret += mcgen('''
Markus Armbrusterf9bee752014-05-07 09:53:44 +020089QmpInputVisitor *mi = qmp_input_visitor_new_strict(%(obj)s);
Michael Rothc17d9902011-07-19 14:50:42 -050090QapiDeallocVisitor *md;
91Visitor *v;
Markus Armbrusterf9bee752014-05-07 09:53:44 +020092''',
93 obj=obj)
Michael Rothc17d9902011-07-19 14:50:42 -050094 pop_indent()
95
96 return ret.rstrip()
97
98def gen_visitor_input_vars_decl(args):
99 ret = ""
100 push_indent()
101 for argname, argtype, optional, structured in parse_args(args):
102 if optional:
103 ret += mcgen('''
104bool has_%(argname)s = false;
105''',
106 argname=c_var(argname))
107 if c_type(argtype).endswith("*"):
108 ret += mcgen('''
109%(argtype)s %(argname)s = NULL;
110''',
111 argname=c_var(argname), argtype=c_type(argtype))
112 else:
113 ret += mcgen('''
Michael Rothfc13d932014-05-20 12:20:39 -0500114%(argtype)s %(argname)s = {0};
Michael Rothc17d9902011-07-19 14:50:42 -0500115''',
116 argname=c_var(argname), argtype=c_type(argtype))
117
118 pop_indent()
119 return ret.rstrip()
120
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200121def gen_visitor_input_block(args, dealloc=False):
Michael Rothc17d9902011-07-19 14:50:42 -0500122 ret = ""
Markus Armbruster297a3642014-05-07 09:53:54 +0200123 errparg = '&local_err'
124 errarg = 'local_err'
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400125
Michael Rothc17d9902011-07-19 14:50:42 -0500126 if len(args) == 0:
127 return ret
128
129 push_indent()
130
131 if dealloc:
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400132 errparg = 'NULL'
Markus Armbruster297a3642014-05-07 09:53:54 +0200133 errarg = None;
Michael Rothc17d9902011-07-19 14:50:42 -0500134 ret += mcgen('''
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200135qmp_input_visitor_cleanup(mi);
Michael Rothc17d9902011-07-19 14:50:42 -0500136md = qapi_dealloc_visitor_new();
137v = qapi_dealloc_get_visitor(md);
138''')
139 else:
140 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500141v = qmp_input_get_visitor(mi);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200142''')
Michael Rothc17d9902011-07-19 14:50:42 -0500143
144 for argname, argtype, optional, structured in parse_args(args):
145 if optional:
146 ret += mcgen('''
Markus Armbrustere2cd0f42014-05-07 09:53:46 +0200147visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500148''',
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400149 c_name=c_var(argname), name=argname, errp=errparg)
Markus Armbruster297a3642014-05-07 09:53:54 +0200150 ret += gen_err_check(errarg)
151 ret += mcgen('''
152if (has_%(c_name)s) {
153''',
154 c_name=c_var(argname))
Michael Rothc17d9902011-07-19 14:50:42 -0500155 push_indent()
156 ret += mcgen('''
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400157%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500158''',
Anthony Liguori15e43e62011-09-14 14:30:00 -0500159 c_name=c_var(argname), name=argname, argtype=argtype,
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400160 visitor=type_visitor(argtype), errp=errparg)
Markus Armbruster297a3642014-05-07 09:53:54 +0200161 ret += gen_err_check(errarg)
Michael Rothc17d9902011-07-19 14:50:42 -0500162 if optional:
163 pop_indent()
164 ret += mcgen('''
165}
Markus Armbrustere2cd0f42014-05-07 09:53:46 +0200166''')
Michael Rothc17d9902011-07-19 14:50:42 -0500167
168 if dealloc:
169 ret += mcgen('''
170qapi_dealloc_visitor_cleanup(md);
171''')
Michael Rothc17d9902011-07-19 14:50:42 -0500172 pop_indent()
173 return ret.rstrip()
174
Anthony Liguori776574d2011-09-02 12:34:46 -0500175def gen_marshal_output(name, args, ret_type, middle_mode):
Michael Rothc17d9902011-07-19 14:50:42 -0500176 if not ret_type:
177 return ""
Anthony Liguori776574d2011-09-02 12:34:46 -0500178
Michael Rothc17d9902011-07-19 14:50:42 -0500179 ret = mcgen('''
180static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_out, Error **errp)
181{
Markus Armbruster297a3642014-05-07 09:53:54 +0200182 Error *local_err = NULL;
Michael Rothc17d9902011-07-19 14:50:42 -0500183 QmpOutputVisitor *mo = qmp_output_visitor_new();
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200184 QapiDeallocVisitor *md;
Michael Rothc17d9902011-07-19 14:50:42 -0500185 Visitor *v;
186
187 v = qmp_output_get_visitor(mo);
Markus Armbruster297a3642014-05-07 09:53:54 +0200188 %(visitor)s(v, &ret_in, "unused", &local_err);
189 if (local_err) {
190 goto out;
Michael Rothc17d9902011-07-19 14:50:42 -0500191 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200192 *ret_out = qmp_output_get_qobject(mo);
193
194out:
195 error_propagate(errp, local_err);
Michael Rothc17d9902011-07-19 14:50:42 -0500196 qmp_output_visitor_cleanup(mo);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200197 md = qapi_dealloc_visitor_new();
Michael Rothc17d9902011-07-19 14:50:42 -0500198 v = qapi_dealloc_get_visitor(md);
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400199 %(visitor)s(v, &ret_in, "unused", NULL);
Michael Rothc17d9902011-07-19 14:50:42 -0500200 qapi_dealloc_visitor_cleanup(md);
201}
202''',
Federico Simoncellic9da2282012-03-20 13:54:35 +0000203 c_ret_type=c_type(ret_type), c_name=c_fun(name),
Anthony Liguori15e43e62011-09-14 14:30:00 -0500204 visitor=type_visitor(ret_type))
Michael Rothc17d9902011-07-19 14:50:42 -0500205
206 return ret
207
Anthony Liguori776574d2011-09-02 12:34:46 -0500208def gen_marshal_input_decl(name, args, ret_type, middle_mode):
209 if middle_mode:
Federico Simoncellic9da2282012-03-20 13:54:35 +0000210 return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_fun(name)
Anthony Liguori776574d2011-09-02 12:34:46 -0500211 else:
Federico Simoncellic9da2282012-03-20 13:54:35 +0000212 return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_fun(name)
Anthony Liguori776574d2011-09-02 12:34:46 -0500213
214
215
216def gen_marshal_input(name, args, ret_type, middle_mode):
217 hdr = gen_marshal_input_decl(name, args, ret_type, middle_mode)
218
Michael Rothc17d9902011-07-19 14:50:42 -0500219 ret = mcgen('''
Anthony Liguori776574d2011-09-02 12:34:46 -0500220%(header)s
Michael Rothc17d9902011-07-19 14:50:42 -0500221{
Markus Armbruster297a3642014-05-07 09:53:54 +0200222 Error *local_err = NULL;
Michael Rothc17d9902011-07-19 14:50:42 -0500223''',
Anthony Liguori776574d2011-09-02 12:34:46 -0500224 header=hdr)
225
226 if middle_mode:
227 ret += mcgen('''
Anthony Liguori776574d2011-09-02 12:34:46 -0500228 QDict *args = (QDict *)qdict;
229''')
Michael Rothc17d9902011-07-19 14:50:42 -0500230
231 if ret_type:
232 if c_type(ret_type).endswith("*"):
233 retval = " %s retval = NULL;" % c_type(ret_type)
234 else:
235 retval = " %s retval;" % c_type(ret_type)
236 ret += mcgen('''
237%(retval)s
238''',
239 retval=retval)
240
241 if len(args) > 0:
242 ret += mcgen('''
243%(visitor_input_containers_decl)s
244%(visitor_input_vars_decl)s
245
246%(visitor_input_block)s
247
248''',
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200249 visitor_input_containers_decl=gen_visitor_input_containers_decl(args, "QOBJECT(args)"),
Michael Rothc17d9902011-07-19 14:50:42 -0500250 visitor_input_vars_decl=gen_visitor_input_vars_decl(args),
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200251 visitor_input_block=gen_visitor_input_block(args))
Anthony Liguori776574d2011-09-02 12:34:46 -0500252 else:
253 ret += mcgen('''
Markus Armbruster297a3642014-05-07 09:53:54 +0200254
Anthony Liguori776574d2011-09-02 12:34:46 -0500255 (void)args;
256''')
Michael Rothc17d9902011-07-19 14:50:42 -0500257
258 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500259%(sync_call)s
260''',
261 sync_call=gen_sync_call(name, args, ret_type, indent=4))
Markus Armbruster297a3642014-05-07 09:53:54 +0200262 if re.search('^ *goto out\\;', ret, re.MULTILINE):
263 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500264
265out:
266''')
Markus Armbruster297a3642014-05-07 09:53:54 +0200267 if not middle_mode:
268 ret += mcgen('''
269 error_propagate(errp, local_err);
270''')
Michael Rothc17d9902011-07-19 14:50:42 -0500271 ret += mcgen('''
272%(visitor_input_block_cleanup)s
Michael Rothc17d9902011-07-19 14:50:42 -0500273''',
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200274 visitor_input_block_cleanup=gen_visitor_input_block(args,
Anthony Liguori776574d2011-09-02 12:34:46 -0500275 dealloc=True))
276
277 if middle_mode:
278 ret += mcgen('''
279
280 if (local_err) {
281 qerror_report_err(local_err);
282 error_free(local_err);
283 return -1;
284 }
285 return 0;
286''')
287 else:
288 ret += mcgen('''
289 return;
290''')
291
292 ret += mcgen('''
293}
294''')
295
Michael Rothc17d9902011-07-19 14:50:42 -0500296 return ret
297
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300298def option_value_matches(opt, val, cmd):
299 if opt in cmd and cmd[opt] == val:
300 return True
301 return False
302
Michael Rothc17d9902011-07-19 14:50:42 -0500303def gen_registry(commands):
304 registry=""
305 push_indent()
306 for cmd in commands:
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300307 options = 'QCO_NO_OPTIONS'
308 if option_value_matches('success-response', 'no', cmd):
309 options = 'QCO_NO_SUCCESS_RESP'
310
Michael Rothc17d9902011-07-19 14:50:42 -0500311 registry += mcgen('''
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300312qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500313''',
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300314 name=cmd['command'], c_name=c_fun(cmd['command']),
315 opts=options)
Michael Rothc17d9902011-07-19 14:50:42 -0500316 pop_indent()
317 ret = mcgen('''
318static void qmp_init_marshal(void)
319{
320%(registry)s
321}
322
323qapi_init(qmp_init_marshal);
324''',
325 registry=registry.rstrip())
326 return ret
327
328def gen_command_decl_prologue(header, guard, prefix=""):
329 ret = mcgen('''
330/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
331
332/*
333 * schema-defined QAPI function prototypes
334 *
335 * Copyright IBM, Corp. 2011
336 *
337 * Authors:
338 * Anthony Liguori <aliguori@us.ibm.com>
339 *
340 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
341 * See the COPYING.LIB file in the top-level directory.
342 *
343 */
344
345#ifndef %(guard)s
346#define %(guard)s
347
348#include "%(prefix)sqapi-types.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100349#include "qapi/qmp/qdict.h"
350#include "qapi/error.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500351
352''',
Anthony Liguori776574d2011-09-02 12:34:46 -0500353 header=basename(header), guard=guardname(header), prefix=prefix)
Michael Rothc17d9902011-07-19 14:50:42 -0500354 return ret
355
356def gen_command_def_prologue(prefix="", proxy=False):
357 ret = mcgen('''
358/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
359
360/*
361 * schema-defined QMP->QAPI command dispatch
362 *
363 * Copyright IBM, Corp. 2011
364 *
365 * Authors:
366 * Anthony Liguori <aliguori@us.ibm.com>
367 *
368 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
369 * See the COPYING.LIB file in the top-level directory.
370 *
371 */
372
Paolo Bonzini79ee7df2012-12-06 11:22:34 +0100373#include "qemu-common.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100374#include "qemu/module.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100375#include "qapi/qmp/qerror.h"
376#include "qapi/qmp/types.h"
377#include "qapi/qmp/dispatch.h"
378#include "qapi/visitor.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500379#include "qapi/qmp-output-visitor.h"
380#include "qapi/qmp-input-visitor.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100381#include "qapi/dealloc-visitor.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500382#include "%(prefix)sqapi-types.h"
383#include "%(prefix)sqapi-visit.h"
384
385''',
386 prefix=prefix)
387 if not proxy:
388 ret += '#include "%sqmp-commands.h"' % prefix
Anthony Liguori776574d2011-09-02 12:34:46 -0500389 return ret + "\n\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500390
391
392try:
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200393 opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
Avi Kivity8d3bc512011-12-27 16:02:16 +0200394 ["source", "header", "prefix=",
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200395 "input-file=", "output-dir=",
396 "type=", "middle"])
Michael Rothc17d9902011-07-19 14:50:42 -0500397except getopt.GetoptError, err:
398 print str(err)
399 sys.exit(1)
400
401output_dir = ""
402prefix = ""
403dispatch_type = "sync"
404c_file = 'qmp-marshal.c'
405h_file = 'qmp-commands.h'
Anthony Liguori776574d2011-09-02 12:34:46 -0500406middle_mode = False
Michael Rothc17d9902011-07-19 14:50:42 -0500407
Avi Kivity8d3bc512011-12-27 16:02:16 +0200408do_c = False
409do_h = False
410
Michael Rothc17d9902011-07-19 14:50:42 -0500411for o, a in opts:
412 if o in ("-p", "--prefix"):
413 prefix = a
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200414 elif o in ("-i", "--input-file"):
415 input_file = a
Michael Rothc17d9902011-07-19 14:50:42 -0500416 elif o in ("-o", "--output-dir"):
417 output_dir = a + "/"
418 elif o in ("-t", "--type"):
419 dispatch_type = a
Anthony Liguori776574d2011-09-02 12:34:46 -0500420 elif o in ("-m", "--middle"):
421 middle_mode = True
Avi Kivity8d3bc512011-12-27 16:02:16 +0200422 elif o in ("-c", "--source"):
Avi Kivity8d3bc512011-12-27 16:02:16 +0200423 do_c = True
Avi Kivity19bf7c82011-12-28 12:26:58 +0200424 elif o in ("-h", "--header"):
425 do_h = True
Avi Kivity8d3bc512011-12-27 16:02:16 +0200426
427if not do_c and not do_h:
428 do_c = True
429 do_h = True
Michael Rothc17d9902011-07-19 14:50:42 -0500430
431c_file = output_dir + prefix + c_file
432h_file = output_dir + prefix + h_file
433
Avi Kivity8d3bc512011-12-27 16:02:16 +0200434def maybe_open(really, name, opt):
Avi Kivity8d3bc512011-12-27 16:02:16 +0200435 if really:
436 return open(name, opt)
437 else:
Avi Kivity19bf7c82011-12-28 12:26:58 +0200438 import StringIO
439 return StringIO.StringIO()
Avi Kivity8d3bc512011-12-27 16:02:16 +0200440
Michael Rothc17d9902011-07-19 14:50:42 -0500441try:
442 os.makedirs(output_dir)
443except os.error, e:
444 if e.errno != errno.EEXIST:
445 raise
446
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200447exprs = parse_schema(input_file)
Michael Rothc17d9902011-07-19 14:50:42 -0500448commands = filter(lambda expr: expr.has_key('command'), exprs)
Anthony Liguori5dbee472011-12-12 14:29:33 -0600449commands = filter(lambda expr: not expr.has_key('gen'), commands)
Michael Rothc17d9902011-07-19 14:50:42 -0500450
451if dispatch_type == "sync":
Avi Kivity8d3bc512011-12-27 16:02:16 +0200452 fdecl = maybe_open(do_h, h_file, 'w')
453 fdef = maybe_open(do_c, c_file, 'w')
Michael Rothc17d9902011-07-19 14:50:42 -0500454 ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
455 fdecl.write(ret)
456 ret = gen_command_def_prologue(prefix=prefix)
457 fdef.write(ret)
458
459 for cmd in commands:
460 arglist = []
461 ret_type = None
462 if cmd.has_key('data'):
463 arglist = cmd['data']
464 if cmd.has_key('returns'):
465 ret_type = cmd['returns']
466 ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
467 fdecl.write(ret)
468 if ret_type:
Anthony Liguori776574d2011-09-02 12:34:46 -0500469 ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500470 fdef.write(ret)
Anthony Liguori776574d2011-09-02 12:34:46 -0500471
472 if middle_mode:
473 fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode))
474
475 ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500476 fdef.write(ret)
477
Michael Roth7534ba02011-08-10 13:10:51 -0500478 fdecl.write("\n#endif\n");
Anthony Liguori776574d2011-09-02 12:34:46 -0500479
480 if not middle_mode:
481 ret = gen_registry(commands)
482 fdef.write(ret)
Michael Rothc17d9902011-07-19 14:50:42 -0500483
484 fdef.flush()
485 fdef.close()
486 fdecl.flush()
487 fdecl.close()