tcg_h.py 2.7 KB

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