tcg_h.py (2747B)
1# -*- coding: utf-8 -*- 2 3""" 4Generate .h file for TCG code generation. 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, Arguments 16import tracetool.vcpu 17 18 19def vcpu_transform_args(args): 20 assert len(args) == 1 21 return Arguments([ 22 args, 23 # NOTE: this name must be kept in sync with the one in "tcg_h" 24 # NOTE: Current helper code uses TCGv_env (CPUArchState*) 25 ("TCGv_env", "__tcg_" + args.names()[0]), 26 ]) 27 28 29def generate(events, backend, group): 30 if group == "root": 31 header = "trace/trace-root.h" 32 else: 33 header = "trace.h" 34 35 out('/* This file is autogenerated by tracetool, do not edit. */', 36 '/* You must include this file after the inclusion of helper.h */', 37 '', 38 '#ifndef TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(), 39 '#define TRACE_%s_GENERATED_TCG_TRACERS_H' % group.upper(), 40 '', 41 '#include "exec/helper-proto.h"', 42 '#include "%s"' % header, 43 '', 44 ) 45 46 for e in events: 47 # just keep one of them 48 if "tcg-exec" not in e.properties: 49 continue 50 51 out('static inline void %(name_tcg)s(%(args)s)', 52 '{', 53 name_tcg=e.original.api(e.QEMU_TRACE_TCG), 54 args=tracetool.vcpu.transform_args("tcg_h", e.original)) 55 56 if "disable" not in e.properties: 57 args_trans = e.original.event_trans.args 58 args_exec = tracetool.vcpu.transform_args( 59 "tcg_helper_c", e.original.event_exec, "wrapper") 60 if "vcpu" in e.properties: 61 trace_cpu = e.args.names()[0] 62 cond = "trace_event_get_vcpu_state(%(cpu)s,"\ 63 " TRACE_%(id)s)"\ 64 % dict( 65 cpu=trace_cpu, 66 id=e.original.event_exec.name.upper()) 67 else: 68 cond = "true" 69 70 out(' %(name_trans)s(%(argnames_trans)s);', 71 ' if (%(cond)s) {', 72 ' gen_helper_%(name_exec)s(%(argnames_exec)s);', 73 ' }', 74 name_trans=e.original.event_trans.api(e.QEMU_TRACE), 75 name_exec=e.original.event_exec.api(e.QEMU_TRACE), 76 argnames_trans=", ".join(args_trans.names()), 77 argnames_exec=", ".join(args_exec.names()), 78 cond=cond) 79 80 out('}') 81 82 out('', 83 '#endif /* TRACE_%s_GENERATED_TCG_TRACERS_H */' % group.upper())