2
0

tcg_helper_c.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Generate trace/generated-helpers.c.
  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 Arguments, out
  12. from tracetool.transform import *
  13. import tracetool.vcpu
  14. def vcpu_transform_args(args, mode):
  15. assert len(args) == 1
  16. # NOTE: this name must be kept in sync with the one in "tcg_h"
  17. args = Arguments([(args.types()[0], "__tcg_" + args.names()[0])])
  18. if mode == "code":
  19. return Arguments([
  20. # Does cast from helper requirements to tracing types
  21. ("CPUState *", "env_cpu(%s)" % args.names()[0]),
  22. ])
  23. else:
  24. args = Arguments([
  25. # NOTE: Current helper code uses TCGv_env (CPUArchState*)
  26. ("CPUArchState *", args.names()[0]),
  27. ])
  28. if mode == "header":
  29. return args
  30. elif mode == "wrapper":
  31. return args.transform(HOST_2_TCG)
  32. else:
  33. assert False
  34. def generate(events, backend, group):
  35. if group == "root":
  36. header = "trace-root.h"
  37. else:
  38. header = "trace.h"
  39. events = [e for e in events
  40. if "disable" not in e.properties]
  41. out('/* This file is autogenerated by tracetool, do not edit. */',
  42. '',
  43. '#include "qemu/osdep.h"',
  44. '#include "qemu-common.h"',
  45. '#include "cpu.h"',
  46. '#include "exec/helper-proto.h"',
  47. '#include "%s"' % header,
  48. '',
  49. )
  50. for e in events:
  51. if "tcg-exec" not in e.properties:
  52. continue
  53. e_args_api = tracetool.vcpu.transform_args(
  54. "tcg_helper_c", e.original, "header").transform(
  55. HOST_2_TCG_COMPAT, TCG_2_TCG_HELPER_DEF)
  56. e_args_call = tracetool.vcpu.transform_args(
  57. "tcg_helper_c", e, "code")
  58. out('void %(name_tcg)s(%(args_api)s)',
  59. '{',
  60. # NOTE: the check was already performed at TCG-generation time
  61. ' %(name)s(%(args_call)s);',
  62. '}',
  63. name_tcg="helper_%s_proxy" % e.api(),
  64. name=e.api(e.QEMU_TRACE_NOCHECK),
  65. args_api=e_args_api,
  66. args_call=", ".join(e_args_call.casted()),
  67. )