xref: /openbmc/qemu/scripts/tracetool/format/h.py (revision e9206163)
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    header = "trace/control.h"
20
21    out('/* This file is autogenerated by tracetool, do not edit. */',
22        '',
23        '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
24        '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
25        '',
26        '#include "%s"' % header,
27        '')
28
29    for e in events:
30        out('extern TraceEvent %(event)s;',
31            event = e.api(e.QEMU_EVENT))
32
33    for e in events:
34        out('extern uint16_t %s;' % e.api(e.QEMU_DSTATE))
35
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))
48
49    backend.generate_begin(events, group)
50
51    for e in events:
52        # tracer-specific dstate
53        out('',
54            '#define %(api)s() ( \\',
55            api=e.api(e.QEMU_BACKEND_DSTATE))
56
57        if "disable" not in e.properties:
58            backend.generate_backend_dstate(e, group)
59
60        out('    false)')
61
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)
68
69        if "disable" not in e.properties:
70            backend.generate(e, group)
71
72        out('}')
73
74        cond = "true"
75
76        out('',
77            'static inline void %(api)s(%(args)s)',
78            '{',
79            '    if (%(cond)s) {',
80            '        %(api_nocheck)s(%(names)s);',
81            '    }',
82            '}',
83            api=e.api(),
84            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
85            args=e.args,
86            names=", ".join(e.args.names()),
87            cond=cond)
88
89    backend.generate_end(events, group)
90
91    out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
92