Received: from eggs.gnu.org ([2001:4830:134:3::10]:41488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W9Ger-0007yo-Dx for qemu-devel@nongnu.org; Fri, 31 Jan 2014 11:09:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W9Gek-0000pE-Jw for qemu-devel@nongnu.org; Fri, 31 Jan 2014 11:09:33 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:58454 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W9Gek-0000ow-8c for qemu-devel@nongnu.org; Fri, 31 Jan 2014 11:09:26 -0500 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Fri, 31 Jan 2014 17:09:25 +0100 Message-Id: <20140131160925.32741.23126.stgit@fimbulvetr.bsc.es> In-Reply-To: <20140131160902.32741.2680.stgit@fimbulvetr.bsc.es> References: <20140131160902.32741.2680.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 04/12] trace: [tracetool, tcg] Provide TCG-related type transformation rules List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Signed-off-by: Llu=C3=ADs Vilanova --- scripts/tracetool/transform.py | 157 ++++++++++++++++++++++++++++++++++= ++++++ 1 file changed, 157 insertions(+) create mode 100644 scripts/tracetool/transform.py diff --git a/scripts/tracetool/transform.py b/scripts/tracetool/transform= .py new file mode 100644 index 0000000..e5fbf92 --- /dev/null +++ b/scripts/tracetool/transform.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Type-transformation rules. +""" + +__author__ =3D "Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " +__license__ =3D "GPL version 2 or (at your option) any later version" + +__maintainer__ =3D "Stefan Hajnoczi" +__email__ =3D "stefanha@linux.vnet.ibm.com" + + +def _transform_type(type_, trans): + if isinstance(trans, str): + return trans + elif isinstance(trans, dict): + if type_ in trans: + return _transform_type(type_, trans[type_]) + elif None in trans: + return _transform_type(type_, trans[None]) + else: + return type_ + elif callable(trans): + return trans(type_) + else: + raise ValueError("Invalid type transformation rule: %s" % trans) + + +def transform_type(type_, *trans): + """Return a new type transformed according to the given rules. + + Applies each of the transformation rules in trans in order. + + If an element of trans is a string, return it. + + If an element of trans is a function, call it with type_ as its only + argument. + + If an element of trans is a dict, search type_ in its keys. If type_= is + a key, use the value as a transformation rule for type_. Otherwise, = if + None is a key use the value as a transformation rule for type_. + + Otherwise, return type_. + + Parameters + ---------- + type_ : str + Type to transform. + trans : list of function or dict + Type transformation rules. + """ + if len(trans) =3D=3D 0: + raise ValueError + res =3D type_ + for t in trans: + res =3D _transform_type(res, t) + return res + + +################################################## +# host/tcg -> host + +def TCG_2_HOST(backend): + """Return transformation rules for the given backend.""" + + def _tcg_2_host(type_): + if type_ =3D=3D "TCGv": + if backend =3D=3D "tcg": + return "target_ulong" + else: + # force a fixed-size type in trace.{h,c} + # (ideally would use a host-specific type) + return "uint64_t" + else: + return type_ + + dict_ =3D { + "TCGv_i32": "uint32_t", + "TCGv_i64": "uint64_t", + "TCGv_ptr": "void *", + None: _tcg_2_host, + } + + return dict_ + +################################################## +# host -> host compatible with tcg sizes + +HOST_2_TCG_COMPAT =3D { + "uint8_t": "uint32_t", + } + + +################################################## +# host/tcg -> tcg + +def _host_2_tcg(type_): + if type_.startswith("TCGv"): + return type_ + raise ValueError("Don't know how to translate '%s' into a TCG type\n= " % type_) + +HOST_2_TCG =3D { + "uint32_t": "TCGv_i32", + "uint64_t": "TCGv_i64", + "void *" : "TCGv_ptr", + None: _host_2_tcg, + } + + +################################################## +# tcg -> tcg helper declaration + +def _tcg_2_tcg_helper_decl_error(type_): + raise ValueError("Don't know how to translate type '%s' into a TCG h= elper declaration type\n" % type_) + +TCG_2_TCG_HELPER_DECL =3D { + "TCGv" : "tl", + "TCGv_ptr": "ptr", + "TCGv_i32": "i32", + "TCGv_i64": "i64", + None: _tcg_2_tcg_helper_decl_error, + } + + +################################################## +# host/tcg -> tcg temporal constant allocation + +def _host_2_tcg_tmp_new(type_): + if type_.startswith("TCGv"): + return "tcg_temp_new_nop" + raise ValueError("Don't know how to translate type '%s' into a TCG t= emporal allocation" % type_) + +HOST_2_TCG_TMP_NEW =3D { + "uint32_t": "tcg_const_i32", + "uint64_t": "tcg_const_i64", + "void *" : "tcg_const_ptr", + None: _host_2_tcg_tmp_new, + } + + +################################################## +# host/tcg -> tcg temporal constant deallocation + +def _host_2_tcg_tmp_free(type_): + if type_.startswith("TCGv"): + return "tcg_temp_free_nop" + raise ValueError("Don't know how to translate type '%s' into a TCG t= emporal deallocation" % type_) + +HOST_2_TCG_TMP_FREE =3D { + "uint32_t": "tcg_temp_free_i32", + "uint64_t": "tcg_temp_free_i64", + "void *" : "tcg_temp_free_ptr", + None: _host_2_tcg_tmp_free, + }