util: add helper APIs for dealing with inotify in portable manner
[qemu/ar7.git] / scripts / tracetool / format / tcg_h.py
blob1651cc3f7199675e5abcfbe946c5fda996816b98
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 Generate .h file for TCG code generation.
6 """
8 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
10 __license__ = "GPL version 2 or (at your option) any later version"
12 __maintainer__ = "Stefan Hajnoczi"
13 __email__ = "stefanha@linux.vnet.ibm.com"
16 from tracetool import out, Arguments
17 import tracetool.vcpu
20 def vcpu_transform_args(args):
21 assert len(args) == 1
22 return Arguments([
23 args,
24 # NOTE: this name must be kept in sync with the one in "tcg_h"
25 # NOTE: Current helper code uses TCGv_env (CPUArchState*)
26 ("TCGv_env", "__tcg_" + args.names()[0]),
30 def generate(events, backend, group):
31 if group == "root":
32 header = "trace-root.h"
33 else:
34 header = "trace.h"
36 out('/* This file is autogenerated by tracetool, do not edit. */',
37 '/* You must include this file after the inclusion of helper.h */',
38 '',
39 '#ifndef TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(),
40 '#define TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(),
41 '',
42 '#include "exec/helper-proto.h"',
43 '#include "%s"' % header,
44 '',
47 for e in events:
48 # just keep one of them
49 if "tcg-exec" not in e.properties:
50 continue
52 out('static inline void %(name_tcg)s(%(args)s)',
53 '{',
54 name_tcg=e.original.api(e.QEMU_TRACE_TCG),
55 args=tracetool.vcpu.transform_args("tcg_h", e.original))
57 if "disable" not in e.properties:
58 args_trans = e.original.event_trans.args
59 args_exec = tracetool.vcpu.transform_args(
60 "tcg_helper_c", e.original.event_exec, "wrapper")
61 if "vcpu" in e.properties:
62 trace_cpu = e.args.names()[0]
63 cond = "trace_event_get_vcpu_state(%(cpu)s,"\
64 " TRACE_%(id)s)"\
65 % dict(
66 cpu=trace_cpu,
67 id=e.original.event_exec.name.upper())
68 else:
69 cond = "true"
71 out(' %(name_trans)s(%(argnames_trans)s);',
72 ' if (%(cond)s) {',
73 ' gen_helper_%(name_exec)s(%(argnames_exec)s);',
74 ' }',
75 name_trans=e.original.event_trans.api(e.QEMU_TRACE),
76 name_exec=e.original.event_exec.api(e.QEMU_TRACE),
77 argnames_trans=", ".join(args_trans.names()),
78 argnames_exec=", ".join(args_exec.names()),
79 cond=cond)
81 out('}')
83 out('',
84 '#endif /* TRACE_%s_GENERATED_TCG_TRACERS_H */' % group.upper())