tcg_h.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- coding: utf-8 -*-
  2. """
  3. Generate .h file for TCG code generation.
  4. """
  5. __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
  6. __copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
  7. __license__ = "GPL version 2 or (at your option) any later version"
  8. __maintainer__ = "Stefan Hajnoczi"
  9. __email__ = "stefanha@redhat.com"
  10. from tracetool import out, Arguments
  11. import tracetool.vcpu
  12. def vcpu_transform_args(args):
  13. assert len(args) == 1
  14. return Arguments([
  15. args,
  16. # NOTE: this name must be kept in sync with the one in "tcg_h"
  17. # NOTE: Current helper code uses TCGv_env (CPUArchState*)
  18. ("TCGv_env", "__tcg_" + args.names()[0]),
  19. ])
  20. def generate(events, backend, group):
  21. if group == "root":
  22. header = "trace/trace-root.h"
  23. else:
  24. header = "trace.h"
  25. out('/* This file is autogenerated by tracetool, do not edit. */',
  26. '/* You must include this file after the inclusion of helper.h */',
  27. '',
  28. '#ifndef TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(),
  29. '#define TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(),
  30. '',
  31. '#include "exec/helper-proto.h"',
  32. '#include "%s"' % header,
  33. '',
  34. )
  35. for e in events:
  36. # just keep one of them
  37. if "tcg-exec" not in e.properties:
  38. continue
  39. out('static inline void %(name_tcg)s(%(args)s)',
  40. '{',
  41. name_tcg=e.original.api(e.QEMU_TRACE_TCG),
  42. args=tracetool.vcpu.transform_args("tcg_h", e.original))
  43. if "disable" not in e.properties:
  44. args_trans = e.original.event_trans.args
  45. args_exec = tracetool.vcpu.transform_args(
  46. "tcg_helper_c", e.original.event_exec, "wrapper")
  47. if "vcpu" in e.properties:
  48. trace_cpu = e.args.names()[0]
  49. cond = "trace_event_get_vcpu_state(%(cpu)s,"\
  50. " TRACE_%(id)s)"\
  51. % dict(
  52. cpu=trace_cpu,
  53. id=e.original.event_exec.name.upper())
  54. else:
  55. cond = "true"
  56. out(' %(name_trans)s(%(argnames_trans)s);',
  57. ' if (%(cond)s) {',
  58. ' gen_helper_%(name_exec)s(%(argnames_exec)s);',
  59. ' }',
  60. name_trans=e.original.event_trans.api(e.QEMU_TRACE),
  61. name_exec=e.original.event_exec.api(e.QEMU_TRACE),
  62. argnames_trans=", ".join(args_trans.names()),
  63. argnames_exec=", ".join(args_exec.names()),
  64. cond=cond)
  65. out('}')
  66. out('',
  67. '#endif /* TRACE_%s_GENERATED_TCG_TRACERS_H */' % group.upper())