configure: Force the C standard to gnu99
[qemu/ar7.git] / scripts / tracetool / format / h.py
blobe06f0f27c52e875f56736c8246de9c13b828032f
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 trace/generated-tracers.h
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
19 def generate(events, backend, group):
20 out('/* This file is autogenerated by tracetool, do not edit. */',
21 '',
22 '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
23 '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
24 '',
25 '#include "qemu-common.h"',
26 '#include "trace/control.h"',
27 '')
29 for e in events:
30 out('extern TraceEvent %(event)s;',
31 event = e.api(e.QEMU_EVENT))
33 for e in events:
34 out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
36 # static state
37 for e in events:
38 if 'disable' in e.properties:
39 enabled = 0
40 else:
41 enabled = 1
42 if "tcg-exec" in e.properties:
43 # a single define for the two "sub-events"
44 out('#define TRACE_%(name)s_ENABLED %(enabled)d',
45 name=e.original.name.upper(),
46 enabled=enabled)
47 out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
49 backend.generate_begin(events, group)
51 for e in events:
52 # tracer-specific dstate
53 out('',
54 '#define %(api)s() ( \\',
55 api=e.api(e.QEMU_BACKEND_DSTATE))
57 if "disable" not in e.properties:
58 backend.generate_backend_dstate(e, group)
60 out(' false)')
62 # tracer without checks
63 out('',
64 'static inline void %(api)s(%(args)s)',
65 '{',
66 api=e.api(e.QEMU_TRACE_NOCHECK),
67 args=e.args)
69 if "disable" not in e.properties:
70 backend.generate(e, group)
72 out('}')
74 # tracer wrapper with checks (per-vCPU tracing)
75 if "vcpu" in e.properties:
76 trace_cpu = next(iter(e.args))[1]
77 cond = "trace_event_get_vcpu_state(%(cpu)s,"\
78 " TRACE_%(id)s)"\
79 % dict(
80 cpu=trace_cpu,
81 id=e.name.upper())
82 else:
83 cond = "true"
85 out('',
86 'static inline void %(api)s(%(args)s)',
87 '{',
88 ' if (%(cond)s) {',
89 ' %(api_nocheck)s(%(names)s);',
90 ' }',
91 '}',
92 api=e.api(),
93 api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
94 args=e.args,
95 names=", ".join(e.args.names()),
96 cond=cond)
98 backend.generate_end(events, group)
100 out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())