From patchwork Wed Oct 31 12:14:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 149780 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6713074ljp; Wed, 31 Oct 2018 05:15:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5cCkj5H/Vixg3cBvmyIQIdryta+FLCiFlvvMZpEI6Sm6SrpC6KDaZ8xKtu1M+bGggXsAf3Z X-Received: by 2002:a0c:ab13:: with SMTP id h19mr2413726qvb.74.1540988123910; Wed, 31 Oct 2018 05:15:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540988123; cv=none; d=google.com; s=arc-20160816; b=wmrzuTtUCApVWqmGFv3duomnD4jnWWOVFWXSRrK6/LZ9wV31lV6f/fcB3eVRMjaFw2 K2puL5nVGGB3+ilolFCrtBDQtdU145pO8ZyfXnutPTacs0LOLio9y5SdVbCBbH0MXYJp RddXUpIIgwOPT6Dk+/gjJB6lPK/MWdYcguGUWJaqXe7S8BDy25NLz4Gu2xCoRH+xs29k /U41U90hhIZANDp+V8FYfyvHS6W/qUHmWxl1q9Xf7TGv6xYKlYqLItVRPCfvZsHY2WP7 JSZIIPKbMmbk10mX1UQdLT0F1HSj4yLN+Ng21Md3Bg8dJjiRx0zYuywpSWOF/NWAsP+k ziFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=g3gVRo2rWHd2Ivno5DMAZKrALo+n9kMvoQuaNgnC26o=; b=0du/3S0d8QhgyMjqwxLwfxGGbv1Q4DVlB/SKd6Vw2ornKE+0+Jum+g3EFpWfzd/Qbx hyaXoB+lpKlZJ/JJQw5hkUKMsBWT5C1RyyFmw1O0Zs0V8gc7/vcSAuyY4EuYo12gZsQe XLR8VnYFfVrM7TePnOnpLhU1GW3sDczBmLSBipBKny+DIN00XHcm1RphgNphB5kNkSn6 abuEq6miXypH/esK/RnV2NCrM7CnYHtVmubuoAieaHyIPK5El3d/wxFkDb391mkHfbkK bzukLJbCQEqyHu6cKwYG38BQxHAkJiygWcc0D0zQT9as2LzNKk7+etxoN3k0vCPjS8gn vb+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jCLG89++; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s3-v6si2381074qvb.138.2018.10.31.05.15.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 31 Oct 2018 05:15:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jCLG89++; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHpP9-000362-9k for patch@linaro.org; Wed, 31 Oct 2018 08:15:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHpOn-00034G-92 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 08:15:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHpOj-0002fb-6X for qemu-devel@nongnu.org; Wed, 31 Oct 2018 08:15:01 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:54403) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHpOf-0002Pb-Ed for qemu-devel@nongnu.org; Wed, 31 Oct 2018 08:14:55 -0400 Received: by mail-wm1-x331.google.com with SMTP id r63-v6so14918818wma.4 for ; Wed, 31 Oct 2018 05:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g3gVRo2rWHd2Ivno5DMAZKrALo+n9kMvoQuaNgnC26o=; b=jCLG89++EeSPJUIyqP1mikyBiKorUVz7B1KFXaSknC3TZ7Q6ufGqP71khA1Hiwnnia 9KgJK91pUb3eReGxjAv/stfH7Mebh9SEeLR2VFcdF5w2QhU/c08f+HsYPOl/K4RetA/h lfe8ZkRR3o8AxM6B0aj4iHLdst4e16p51nt8k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g3gVRo2rWHd2Ivno5DMAZKrALo+n9kMvoQuaNgnC26o=; b=H0NyZ2j1QOR/ZI1wg1nw2XZLJFNYGI9hkFZNaTDFy/44H0jl6eA9Bt8+Ru5LnSObNu orGxKHw+mbRglvdNgLm1RAYVNaAQ6Jr8nWk5Lu5L7+OC6PmmS4CDC/pBZ6IJlfiDrxFi 9T5ZcDhGDY/0e82BcA9/JwigyI/ySyZbCgSTZH6sDl2CfmYEk84H1FNVSEBhylJ0QT7y d6Wiq4cVLUX+GEucXDUdZBG6vZwNt1zGvO5s5EbzMBKtWVCmhmQl5kppEkBDYb/viOq0 NH66plU8R2E5OH/28TLhH/PiXRsWz7f2n9vLO0+tjeFeZGYQjoyRwrasnwBItypcPlqj KkBQ== X-Gm-Message-State: AGRZ1gLiUxKWpWclHuAImXDWAqCovBVgiFlbYEyqLrLcl2ZnFBE569iA Bh1wAj3tX9+QOFGdUdzuoazVruzhpBM= X-Received: by 2002:a1c:7203:: with SMTP id n3-v6mr2357302wmc.5.1540988086255; Wed, 31 Oct 2018 05:14:46 -0700 (PDT) Received: from cloudburst.twiddle.net.lan (79-69-241-110.dynamic.dsl.as9105.com. [79.69.241.110]) by smtp.gmail.com with ESMTPSA id l140-v6sm37008148wmb.24.2018.10.31.05.14.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 05:14:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 12:14:41 +0000 Message-Id: <20181031121443.605-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181031121443.605-1-richard.henderson@linaro.org> References: <20181031121443.605-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::331 Subject: [Qemu-devel] [PATCH v2 1/3] decodetree: Add !extern flag to argument sets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kbastian@mail.uni-paderborn.de Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Allow argument sets to be shared between two decoders by avoiding a re-declaration error. Make sure that anonymous argument sets and anonymous formats have unique names. Reviewed-by: Bastian Koppelmann Signed-off-by: Richard Henderson --- scripts/decodetree.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) -- 2.17.2 diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 457cffea90..28bbd4e3c1 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -63,13 +63,16 @@ # # *** Argument set syntax: # -# args_def := '&' identifier ( args_elt )+ +# args_def := '&' identifier ( args_elt )+ ( !extern )? # args_elt := identifier # # Each args_elt defines an argument within the argument set. # Each argument set will be rendered as a C structure "arg_$name" # with each of the fields being one of the member arguments. # +# If !extern is specified, the backing structure is assumed to +# have been already declared, typically via a second decoder. +# # Argument set examples: # # ®3 ra rb rc @@ -167,6 +170,7 @@ input_file = '' output_file = None output_fd = None insntype = 'uint32_t' +decode_function = 'decode' re_ident = '[a-zA-Z][a-zA-Z0-9_]*' @@ -392,8 +396,9 @@ class FunctionField: class Arguments: """Class representing the extracted fields of a format""" - def __init__(self, nm, flds): + def __init__(self, nm, flds, extern): self.name = nm + self.extern = extern self.fields = sorted(flds) def __str__(self): @@ -403,10 +408,11 @@ class Arguments: return 'arg_' + self.name def output_def(self): - output('typedef struct {\n') - for n in self.fields: - output(' int ', n, ';\n') - output('} ', self.struct_name(), ';\n\n') + if not self.extern: + output('typedef struct {\n') + for n in self.fields: + output(' int ', n, ';\n') + output('} ', self.struct_name(), ';\n\n') # end Arguments @@ -540,7 +546,11 @@ def parse_arguments(lineno, name, toks): global re_ident flds = [] + extern = False for t in toks: + if re_fullmatch('!extern', t): + extern = True + continue if not re_fullmatch(re_ident, t): error(lineno, 'invalid argument set token "{0}"'.format(t)) if t in flds: @@ -549,7 +559,7 @@ def parse_arguments(lineno, name, toks): if name in arguments: error(lineno, 'duplicate argument set', name) - arguments[name] = Arguments(name, flds) + arguments[name] = Arguments(name, flds, extern) # end parse_arguments @@ -573,13 +583,14 @@ def add_field_byname(lineno, flds, new_name, old_name): def infer_argument_set(flds): global arguments + global decode_function for arg in arguments.values(): if eq_fields_for_args(flds, arg.fields): return arg - name = str(len(arguments)) - arg = Arguments(name, flds.keys()) + name = decode_function + str(len(arguments)) + arg = Arguments(name, flds.keys(), False) arguments[name] = arg return arg @@ -587,6 +598,7 @@ def infer_argument_set(flds): def infer_format(arg, fieldmask, flds): global arguments global formats + global decode_function const_flds = {} var_flds = {} @@ -606,7 +618,7 @@ def infer_format(arg, fieldmask, flds): continue return (fmt, const_flds) - name = 'Fmt_' + str(len(formats)) + name = decode_function + '_Fmt_' + str(len(formats)) if not arg: arg = infer_argument_set(flds) @@ -971,8 +983,8 @@ def main(): global insnwidth global insntype global insnmask + global decode_function - decode_function = 'decode' decode_scope = 'static ' long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']