tcg_h.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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-2016, 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. '',
  34. )
  35. for e in events:
  36. # just keep one of them
  37. if "tcg-trans" 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. out(' %(name_trans)s(%(argnames_trans)s);',
  48. ' gen_helper_%(name_exec)s(%(argnames_exec)s);',
  49. name_trans=e.original.event_trans.api(e.QEMU_TRACE),
  50. name_exec=e.original.event_exec.api(e.QEMU_TRACE),
  51. argnames_trans=", ".join(args_trans.names()),
  52. argnames_exec=", ".join(args_exec.names()))
  53. out('}')
  54. out('',
  55. '#endif /* TRACE_%s_GENERATED_TCG_TRACERS_H */' % group.upper())