From patchwork Tue Oct 23 12:04:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 149443 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp609993ljp; Tue, 23 Oct 2018 05:08:08 -0700 (PDT) X-Google-Smtp-Source: AJdET5cej03/RXwpRAOnvsQobAY0ZrRxq/CXLkvPHfbm80+MogYkNkPB0OFc9SLPMmnVXQJG4Rjg X-Received: by 2002:ac8:5191:: with SMTP id c17-v6mr7764203qtn.250.1540296488126; Tue, 23 Oct 2018 05:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540296488; cv=none; d=google.com; s=arc-20160816; b=qa4lQ6h0XyeO6K1eIzYvakEFB4PA4h2xR7n63OoFZo3g8pPNSBFBtIC01NnDUBeLtv opxsCciiqijHJMV71VVmEf+9jJbCSpD7bhxxMZJiAnv30/wWUfdMhuPDdhxcliz6aefZ Mp8bl6yO33cWnTVtNlyNECfOZGWzKG5yhIRS+hsvBHRQpcklWca+OgVuOshoAOj0kMLA u4OI0pROk4HliH/XY5/w+7mWcpEjnsSkaJ+gh0YXqDIFKCty6lsuW85WG6Hs8FW51A2k vgDrkTr5SU8zglR3oWLyeiXnh17OgK7/beuItw4Uv8p8yECFa2EO1lEgMg9qpiEWAGpI r9Mg== 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=jQBNHOxP5RFDCTW/z3zDYbak/5FAp8OPVY3+8AdbzF8=; b=PMUJOcnIFDcRt6BkY8UeJ1EszIXefvPE/bdDrCNGexFNeRq8n2dSarYH7UdHLiq9/l NTpjYc0DPbx6VbaP1uswEtE87oW8R+iOkgHpDhJszmIXkdwHGSyfFTygCpPLH/iceVCq ZvY40/X1dQVwPS6I86rHELoHw7Qsxux4D5umsTN2mkVBPpAWsMOu5xamtjea/twY5Gg3 X7R1Rl8Kc4EdHXTM0PxzLI+G8lAwmHJvJe8oD5jdJM9CI06xtLtqMwyXX1Rxr1o+Y8E2 s65wU9xL5eNa9GDzHyXmDHZQ5kQTlRTpe7sv8qwYqsxkeeCWVTQmDChApMX1p6glupoM 7WXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hBZuvJZI; 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 r16si837667qvm.160.2018.10.23.05.08.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 23 Oct 2018 05:08:08 -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=hBZuvJZI; 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]:40714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEvTj-0001XJ-IN for patch@linaro.org; Tue, 23 Oct 2018 08:08:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEvQq-0005X2-N7 for qemu-devel@nongnu.org; Tue, 23 Oct 2018 08:05:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gEvQn-0007Vj-Et for qemu-devel@nongnu.org; Tue, 23 Oct 2018 08:05:08 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40403) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gEvQn-0007Uw-6m for qemu-devel@nongnu.org; Tue, 23 Oct 2018 08:05:05 -0400 Received: by mail-wm1-x342.google.com with SMTP id b203-v6so1507315wme.5 for ; Tue, 23 Oct 2018 05:05:05 -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=jQBNHOxP5RFDCTW/z3zDYbak/5FAp8OPVY3+8AdbzF8=; b=hBZuvJZIcbvcgS4i1o9JJSZbNfYvbJn3Nwv6sAfh9QUqvJAB7D9LC9Njojc/hTRxYh IbpifBX6rsOzWCJssXx0HI1qnQIg+VTmDCW4G98lIQqaJTewRQovHj+P4BhRUNwplXI9 3qxhFL9KrijhQRpOFXHSSC987kUH+H3azist8= 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=jQBNHOxP5RFDCTW/z3zDYbak/5FAp8OPVY3+8AdbzF8=; b=nF0WqnnfBj3bFDKOMWoQmHQdGVdRy/AH+o00BgLRwK4s1qkJwt64tjVoELnTZNeI6o ONUjdjcr1D4geypTKbY99T4c0BVT33/1KmldmQPsaMWjy02sQEAe8IfAdL4pLGWOCzrN 3aabuf+9V15wiIZPQaiBlxAHsbNwOBMHf8rvadlhGzvaK9vIBbWLnpMZz3VQbKsSAqR3 jcMfDCwuqnQul2DID7d+J0muXtUNYunrmdgVppQnpkCu2dRuOR+xrY4w8o+wAK7aTEjF TU5eKhNm2Uig1gt8HmxqK9miYUa6Bj4kssMtmSYwXjDN8BNZxYQ5pP7sQn683fZbTY7W G10Q== X-Gm-Message-State: ABuFfojgb7W594DTaTPeWUBBVuiS+rh1tF54Vtd0kY8R/A4qu1YGZXoa tW44CDfzPPD+vxlpMuYdC1zSckJoOrM= X-Received: by 2002:a1c:4889:: with SMTP id v131-v6mr19937083wma.87.1540296303816; Tue, 23 Oct 2018 05:05:03 -0700 (PDT) Received: from cloudburst.twiddle.net.net ([185.7.230.213]) by smtp.gmail.com with ESMTPSA id a1-v6sm1009200wrt.79.2018.10.23.05.05.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 05:05:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 23 Oct 2018 13:04:48 +0100 Message-Id: <20181023120454.28553-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181023120454.28553-1-richard.henderson@linaro.org> References: <20181023120454.28553-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::342 Subject: [Qemu-devel] [PATCH 1/7] 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: sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, palmer@sifive.com, peer.adelt@hni.uni-paderborn.de, Alistair.Francis@wdc.com, mjc@sifive.com 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 have unique names. Signed-off-by: Richard Henderson --- scripts/decodetree.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) -- 2.17.2 Reviewed-by: Bastian Koppelmann Reviewed-by: Philippe Mathieu-Daudé diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 277f9a9bba..a9b10452ef 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 @@ -169,6 +172,7 @@ input_file = '' output_file = None output_fd = None insntype = 'uint32_t' +decode_function = 'decode' re_ident = '[a-zA-Z][a-zA-Z0-9_]*' @@ -394,8 +398,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): @@ -405,10 +410,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 @@ -542,7 +548,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: @@ -551,7 +561,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 @@ -575,13 +585,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 @@ -589,6 +600,7 @@ def infer_argument_set(flds): def infer_format(arg, fieldmask, flds): global arguments global formats + global decode_function const_flds = {} var_flds = {} @@ -608,7 +620,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) @@ -973,8 +985,8 @@ def main(): global insnwidth global insntype global insnmask + global decode_function - decode_function = 'decode' decode_scope = 'static ' long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']