From nobody Thu Dec 18 19:38:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1600092472; cv=none; d=zohomail.com; s=zohoarc; b=hD80UAgcv/BJ9NtKGH18iBzg+TjXIAI+0TFCsWwtk5ylDrPKHCewVwy7W7qDEh8mC6WP/2WdYKxX1z8Vk+W4G8Vs3Wf+Om1XV0C8/W877AlWztTBdHxig6PCaNiqWmhKZ6VPFyoRDGMuKZ3J2m7mJebrvOd2tIOsAfjQJeQrR0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600092472; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z3+dVa+XKMSVJBjdjYmI3jiS50/vtSpLwi7l2pD3ZbU=; b=jTMMgVNQKus9b2iYaSQuBrR0FH24WHXGrFIbUl29P0xN6TkZV6crjj8DUlpT5wIwJ0Tud0q9q8eMkra4L03DCbT55anKHMiG0EeqQuEU/sQcuxX5iOZNa4hZbCpxyBnZt0DehOBavdscIwmTdu1SZtFwNes7p04RIEQn7u0U29g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600092472939287.5471131499238; Mon, 14 Sep 2020 07:07:52 -0700 (PDT) Received: from localhost ([::1]:54456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHp95-00041k-SO for importer@patchew.org; Mon, 14 Sep 2020 10:07:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHp89-000282-NJ for qemu-devel@nongnu.org; Mon, 14 Sep 2020 10:06:53 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:37004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHp87-0007Xp-La for qemu-devel@nongnu.org; Mon, 14 Sep 2020 10:06:53 -0400 Received: by mail-wm1-x32a.google.com with SMTP id a9so200258wmm.2 for ; Mon, 14 Sep 2020 07:06:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id x16sm20834041wrq.62.2020.09.14.07.06.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 07:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=z3+dVa+XKMSVJBjdjYmI3jiS50/vtSpLwi7l2pD3ZbU=; b=CyETJ6tG4l2WaL0ShSbjSeN6zvQeFzt2lLBwqPZw/eRFLACg2ZZ0Dy2necqHOZMQPL mr7IJ/NE/YI9NcqK2FwWtHMj7owa/vMvgg2x9Txrrd2zk1vWV0tG6qnGHYWTcOlqdKWA b9ZrKIpyi63IZq7+jR2DOCv7RuRfMJfDDW+KoA5yymmv25ugY4ivIQ1Vhdl43EgXL2gv lgIJKW3dkvvxaOtqIJiJvKwrxEK0XFMdKEhFEb4Rf5nrWaHs0sMmNvMK/qCzD07FfzBL eMgY5W7haZExlCCNkQo1oqULO93oGNpaozkiO2XQlNEc8yCEAQK/0sRvRAvw5fNqdayJ AYYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z3+dVa+XKMSVJBjdjYmI3jiS50/vtSpLwi7l2pD3ZbU=; b=CNjjeSfVwCSF1ac5KuyC1aIU3hiJeAKV3sLqAIBzXwCVY3vWR20rKbViouwAAecN15 m6EMnpw6spx04KcDAYGRIijI6PzPG18i6e28EIzE53Ce/eEzJWsjj09j8FX4+Eatd3nj AiKFNcknP5uD4EF3lcA1LwvNfQknleRswk5xktf5iaSjxFqnkMP3l1GNP+vJhyTEwWJn qcj9xu34j01P5ZDBiQmhY5cqOe2bPSp/1MATfWFYlLERWwouTE+XZiCEeuURCcvTTEcO NsZvdS9+yg0FtLjRzCL9S8/JPFgsAq+g9chezRsuxdLRIYJS834yD8yQ6QVuC4mVhA7e H3Tg== X-Gm-Message-State: AOAM533knmn/LrsqHt4EWC+MghpwTmUAuKK4pt0b+DyFQHb5t3/ID/qJ uFZraiZcX0QYav0Lj3909wRmPn11FkZ4/U4c X-Google-Smtp-Source: ABdhPJwURO2UDlj2k5AELrLZsa/xMzbM0Onoqm3h//l/wrVn21yTQ+iDl2FxPzIQL70ZjfN+gDOcjA== X-Received: by 2002:a1c:80d7:: with SMTP id b206mr15193802wmd.161.1600092409880; Mon, 14 Sep 2020 07:06:49 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 06/36] decodetree: Improve identifier matching Date: Mon, 14 Sep 2020 15:06:11 +0100 Message-Id: <20200914140641.21369-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200914140641.21369-1-peter.maydell@linaro.org> References: <20200914140641.21369-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) From: Richard Henderson Only argument set members have to be C identifiers, everything else gets prefixed during conversion to C. Some places just checked the leading character, and some places matched a leading character plus a C identifier. Convert everything to match full identifiers, including the [&%@&] prefix, and drop the full C identifier requirement. Reported-by: Peter Maydell Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20200903192334.1603773-1-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- tests/decode/succ_ident1.decode | 7 +++++ scripts/decodetree.py | 46 +++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 tests/decode/succ_ident1.decode diff --git a/tests/decode/succ_ident1.decode b/tests/decode/succ_ident1.dec= ode new file mode 100644 index 00000000000..f15cfbe1470 --- /dev/null +++ b/tests/decode/succ_ident1.decode @@ -0,0 +1,7 @@ +%1f 0:8 +%2f 8:8 +%3f 16:8 + +&3arg a b c +@3arg ........ ........ ........ ........ &3arg a=3D%1f b=3D%2f c=3D%3f +3insn 00000000 ........ ........ ........ @3arg diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 4cd1e109046..c02de9865b2 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -42,8 +42,14 @@ output_fd =3D None insntype =3D 'uint32_t' decode_function =3D 'decode' =20 -re_ident =3D '[a-zA-Z][a-zA-Z0-9_]*' +# An identifier for C. +re_C_ident =3D '[a-zA-Z][a-zA-Z0-9_]*' =20 +# Identifiers for Arguments, Fields, Formats and Patterns. +re_arg_ident =3D '&[a-zA-Z0-9_]*' +re_fld_ident =3D '%[a-zA-Z0-9_]*' +re_fmt_ident =3D '@[a-zA-Z0-9_]*' +re_pat_ident =3D '[a-zA-Z0-9_]*' =20 def error_with_file(file, lineno, *args): """Print an error message from file:line and args and exit.""" @@ -632,7 +638,6 @@ class ExcMultiPattern(MultiPattern): def parse_field(lineno, name, toks): """Parse one instruction field from TOKS at LINENO""" global fields - global re_ident global insnwidth =20 # A "simple" field will have only one entry; @@ -641,7 +646,7 @@ def parse_field(lineno, name, toks): width =3D 0 func =3D None for t in toks: - if re.fullmatch('!function=3D' + re_ident, t): + if re.match('^!function=3D', t): if func: error(lineno, 'duplicate function') func =3D t.split('=3D') @@ -695,7 +700,7 @@ def parse_field(lineno, name, toks): def parse_arguments(lineno, name, toks): """Parse one argument set from TOKS at LINENO""" global arguments - global re_ident + global re_C_ident global anyextern =20 flds =3D [] @@ -705,7 +710,7 @@ def parse_arguments(lineno, name, toks): extern =3D True anyextern =3D True continue - if not re.fullmatch(re_ident, t): + if not re.fullmatch(re_C_ident, t): error(lineno, 'invalid argument set token "{0}"'.format(t)) if t in flds: error(lineno, 'duplicate argument "{0}"'.format(t)) @@ -791,7 +796,10 @@ def parse_generic(lineno, parent_pat, name, toks): global arguments global formats global allpatterns - global re_ident + global re_arg_ident + global re_fld_ident + global re_fmt_ident + global re_C_ident global insnwidth global insnmask global variablewidth @@ -807,7 +815,7 @@ def parse_generic(lineno, parent_pat, name, toks): fmt =3D None for t in toks: # '&Foo' gives a format an explcit argument set. - if t[0] =3D=3D '&': + if re.fullmatch(re_arg_ident, t): tt =3D t[1:] if arg: error(lineno, 'multiple argument sets') @@ -818,7 +826,7 @@ def parse_generic(lineno, parent_pat, name, toks): continue =20 # '@Foo' gives a pattern an explicit format. - if t[0] =3D=3D '@': + if re.fullmatch(re_fmt_ident, t): tt =3D t[1:] if fmt: error(lineno, 'multiple formats') @@ -829,19 +837,19 @@ def parse_generic(lineno, parent_pat, name, toks): continue =20 # '%Foo' imports a field. - if t[0] =3D=3D '%': + if re.fullmatch(re_fld_ident, t): tt =3D t[1:] flds =3D add_field_byname(lineno, flds, tt, tt) continue =20 # 'Foo=3D%Bar' imports a field with a different name. - if re.fullmatch(re_ident + '=3D%' + re_ident, t): + if re.fullmatch(re_C_ident + '=3D' + re_fld_ident, t): (fname, iname) =3D t.split('=3D%') flds =3D add_field_byname(lineno, flds, fname, iname) continue =20 # 'Foo=3Dnumber' sets an argument field to a constant value - if re.fullmatch(re_ident + '=3D[+-]?[0-9]+', t): + if re.fullmatch(re_C_ident + '=3D[+-]?[0-9]+', t): (fname, value) =3D t.split('=3D') value =3D int(value) flds =3D add_field(lineno, flds, fname, ConstField(value)) @@ -866,7 +874,7 @@ def parse_generic(lineno, parent_pat, name, toks): fixedmask =3D (fixedmask << shift) | fms undefmask =3D (undefmask << shift) | ubm # Otherwise, fieldname:fieldwidth - elif re.fullmatch(re_ident + ':s?[0-9]+', t): + elif re.fullmatch(re_C_ident + ':s?[0-9]+', t): (fname, flen) =3D t.split(':') sign =3D False if flen[0] =3D=3D 's': @@ -971,6 +979,10 @@ def parse_generic(lineno, parent_pat, name, toks): =20 def parse_file(f, parent_pat): """Parse all of the patterns within a file""" + global re_arg_ident + global re_fld_ident + global re_fmt_ident + global re_pat_ident =20 # Read all of the lines of the file. Concatenate lines # ending in backslash; discard empty lines and comments. @@ -1063,14 +1075,16 @@ def parse_file(f, parent_pat): continue =20 # Determine the type of object needing to be parsed. - if name[0] =3D=3D '%': + if re.fullmatch(re_fld_ident, name): parse_field(start_lineno, name[1:], toks) - elif name[0] =3D=3D '&': + elif re.fullmatch(re_arg_ident, name): parse_arguments(start_lineno, name[1:], toks) - elif name[0] =3D=3D '@': + elif re.fullmatch(re_fmt_ident, name): parse_generic(start_lineno, None, name[1:], toks) - else: + elif re.fullmatch(re_pat_ident, name): parse_generic(start_lineno, parent_pat, name, toks) + else: + error(lineno, 'invalid token "{0}"'.format(name)) toks =3D [] =20 if nesting !=3D 0: --=20 2.20.1