xref: /openbmc/qemu/scripts/tracetool/format/h.py (revision 89aafcf2)
1# -*- coding: utf-8 -*-
2
3"""
4trace/generated-tracers.h
5"""
6
7__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
8__copyright__  = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
9__license__    = "GPL version 2 or (at your option) any later version"
10
11__maintainer__ = "Stefan Hajnoczi"
12__email__      = "stefanha@redhat.com"
13
14
15from tracetool import out
16
17
18def generate(events, backend, group):
19    if group == "root":
20        header = "trace/control-vcpu.h"
21    else:
22        header = "trace/control.h"
23
24    out('/* This file is autogenerated by tracetool, do not edit. */',
25        '',
26        '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
27        '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
28        '',
29        '#include "%s"' % header,
30        '')
31
32    for e in events:
33        out('extern TraceEvent %(event)s;',
34            event = e.api(e.QEMU_EVENT))
35
36    for e in events:
37        out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
38
39    # static state
40    for e in events:
41        if 'disable' in e.properties:
42            enabled = 0
43        else:
44            enabled = 1
45        if "tcg-exec" in e.properties:
46            # a single define for the two "sub-events"
47            out('#define TRACE_%(name)s_ENABLED %(enabled)d',
48                name=e.original.name.upper(),
49                enabled=enabled)
50        out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
51
52    backend.generate_begin(events, group)
53
54    for e in events:
55        # tracer-specific dstate
56        out('',
57            '#define %(api)s() ( \\',
58            api=e.api(e.QEMU_BACKEND_DSTATE))
59
60        if "disable" not in e.properties:
61            backend.generate_backend_dstate(e, group)
62
63        out('    false)')
64
65        # tracer without checks
66        out('',
67            'static inline void %(api)s(%(args)s)',
68            '{',
69            api=e.api(e.QEMU_TRACE_NOCHECK),
70            args=e.args)
71
72        if "disable" not in e.properties:
73            backend.generate(e, group)
74
75        out('}')
76
77        cond = "true"
78
79        out('',
80            'static inline void %(api)s(%(args)s)',
81            '{',
82            '    if (%(cond)s) {',
83            '        %(api_nocheck)s(%(names)s);',
84            '    }',
85            '}',
86            api=e.api(),
87            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
88            args=e.args,
89            names=", ".join(e.args.names()),
90            cond=cond)
91
92    backend.generate_end(events, group)
93
94    out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
95