From nobody Sat May 18 12:05:07 2024 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=1684843559; cv=none; d=zohomail.com; s=zohoarc; b=cFeSYmCH6CPoRtygt7BluIFK3BFN2kSWaKX+uonXu6IL8xXv1EseT3fSSpvwBv6Tt0XIgK1CRcvZVi13Pb51nexfN9j8NhtbUwxuCm+lVWbLPGPKCudguEpi1fiQyM/e1QAlckpGLJvcJATi+5RYwnU3PMJqjcWHAkPQ3pbXvJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684843559; h=Content-Transfer-Encoding:Cc: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=4CXmvCi8lTzgvgYiHwHs7/x5DBl5UXEByr1AFvDiIAo=; b=cVj9M6xZdN0XXhGmZpsZo49mIPTwQ02T2eCZOUhhJ5h4s+TWjtrtu2wiP1QCHQzXSjxhrzdOVsBLkqYn3gE+jOmmr3HAweHLQ5j7Y9lKk+VonwOKFEu3Pmoxly3NUawty5/2E5jf0TNCpeWwJ2XlPc+TvmYdQZhXcjZbgPtagPc= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16848435594876.15650010616082; Tue, 23 May 2023 05:05:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Ql4-0002P1-G5; Tue, 23 May 2023 08:04:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Ql3-0002OS-Df for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:53 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1Ql0-0008QE-PE for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:52 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f607839b89so13828295e9.3 for ; Tue, 23 May 2023 05:04:50 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l17-20020adfe591000000b003079c402762sm10848778wrm.19.2023.05.23.05.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 05:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684843489; x=1687435489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4CXmvCi8lTzgvgYiHwHs7/x5DBl5UXEByr1AFvDiIAo=; b=OS3lzeLTnpH/aYUTfXiTSb0ZAjNBmr7IEIWWNV8Uh3IkjgAWpW0/riGxLXJ9I4O1J2 vMGKWY5m98ySsYoZQ9adK4vDRBMehxz+yK+uEaGIyhS+EYSBkIDyqKg9N3B9UJ1Lzgiv +hrj/mXdSF4VoQkxRigjpw5unaL/dvRP3mDwoGUv2pMJ/qwMKBH3ZvHYjtv2zXfTrfcF rsYxgUdivHzn/DGq3OEAxzzoMeYj4LYuI/NCraZlQUL/jJ2a0A1ngKLmw95JUk0OfV74 6J+JZJloddo8Kv5v4KFHcEGXLeB/0HrYrZLQtPuEiDIlKkj36KSMqnOP23KDMgjNpBXM Du3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843489; x=1687435489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4CXmvCi8lTzgvgYiHwHs7/x5DBl5UXEByr1AFvDiIAo=; b=cDoTXRCspQV/wh7bnB4/aKNZZyJKj2igzRN6drsKn6NujhjN+gbNw0obCnBkZECbTS 0uelOy48fJOt4m0mfw1niDuRKzgshfHoZnTuF00jSX7pCPdImmc5mlN9YmUt0zR6Xd/K SSEjtDbBs6O6eU4oYpLJNvz+GZzUPdvoXQUONgu27ksSlnCDtNvYbiyS+QQKocX2Is6+ zpu8O5jFXVS2Pf190hpyO7L6GWEuIGLYRYm+mUMRRYexpL+CdmyIDCWE2TDcpyB2dP2N DcYCzVRYhqEezI+KtOcCg0NrtF66iN9jZS4NniJn1koqY0fbRmtpL7macVGOAvFLIpCJ uDoA== X-Gm-Message-State: AC+VfDziqObIADYvCTwgTfD2K1JNaz59fnJJe0eWnqnjXZ2GCf5uTP01 D3qTLoysEVvpVgN2Pss0fgmqHC2KQ0IEHICvhVI= X-Google-Smtp-Source: ACHHUZ4C87Sy0Pc+31i+2bKb7l8J1EGQvfkgTXICDXawGcH7cPZ1hV8YOjYPs1S/6+rTKzqcOcNCTw== X-Received: by 2002:a7b:c044:0:b0:3f4:e853:6a1 with SMTP id u4-20020a7bc044000000b003f4e85306a1mr9465077wmc.38.1684843489467; Tue, 23 May 2023 05:04:49 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 1/6] tests/decodetree/check.sh: Exit failure for all failures Date: Tue, 23 May 2023 13:04:42 +0100 Message-Id: <20230523120447.728365-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230523120447.728365-1-peter.maydell@linaro.org> References: <20230523120447.728365-1-peter.maydell@linaro.org> MIME-Version: 1.0 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::334; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x334.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1684843561503100007 Content-Type: text/plain; charset="utf-8" The check.sh script doesn't set its exit status to 1 for failures in the succ_* (should-pass) tests, only for the err_* (should-error) tests. This means that even on a test failure meson will report that the test suite passed. Set the exit status for all failures. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- In an ideal world we'd tell meson how to run each test, so that we got per-test pass/fail/log information, I suppose. --- tests/decode/check.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/decode/check.sh b/tests/decode/check.sh index 95445a01155..4b5a47fbbf2 100755 --- a/tests/decode/check.sh +++ b/tests/decode/check.sh @@ -18,6 +18,7 @@ done for i in succ_*.decode; do if ! $PYTHON $DECODETREE $i > /dev/null 2> /dev/null; then echo FAIL:$i 1>&2 + E=3D1 fi done =20 --=20 2.34.1 From nobody Sat May 18 12:05:07 2024 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=1684843541; cv=none; d=zohomail.com; s=zohoarc; b=BYhFIa295I6oO4DidSdv/iBya6sO9gZWvZL/Go1YyyX6JpgtIxoT42NjBuPNxshl6wKZqwmiSzP8fFufUmvDB+nfPrSkgYFQ7iRriixw1EDGgdda/tYyjNaZJjzY7UATYVbNmGFZSG1PQDwWwN+9kco/DKeBL/gIRD57uKm1xsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684843541; h=Content-Transfer-Encoding:Cc: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=BdpkvDlA4UmVXiobxDu+YLmGZsz0CGX9FJr5LiiDCI0=; b=ZFf2C45U4pKjfLj3ej0VgOs40fwGSPkVTan7hz+zokGpb4R3+4HxIkLKRGXcr6ZutOeEstz/GFDZYxvWtXhdNivYUlxaI4crUghrVTpzrO1B6+Rk6nvybHcnJ2KutuEi/BYgLJ7aBO/leE5qAxTSrHDLtcPLfJBPvwGq27oBBds= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684843541022138.34627147774177; Tue, 23 May 2023 05:05:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Ql6-0002QK-4R; Tue, 23 May 2023 08:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Ql3-0002Oa-PE for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:53 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1Ql1-0008QP-N0 for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:53 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-306dbad5182so4831567f8f.1 for ; Tue, 23 May 2023 05:04:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l17-20020adfe591000000b003079c402762sm10848778wrm.19.2023.05.23.05.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 05:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684843490; x=1687435490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BdpkvDlA4UmVXiobxDu+YLmGZsz0CGX9FJr5LiiDCI0=; b=BoxleB2f7RstIIcpPHNcsvRnHU8L1GFuE1Al8cFMs94kTlJF5SUvWSUaeklvXVMrVR YXFEFDFlxrYSn2dIsA2bZSk6Y9avndyIKCielqXpXoTXnu7P3lO+VzvB8D63QujxU9V3 nzB1bC7UGRoD1cci8/E4tnSBUQMJrmIJ+3fFsY4qNiVpyeIb0Rv6+ATcDpmmIVp9lfx1 TJWjf3uOQSWBURWt4rGXli8R8qBkaap5TqEmqXXHn54vEEsthKCgmvUQtv2tm+hXSrd7 RLTAeBr2KTgnVZrfUZPr6TMdsvxrxM9ErM88uXPTeZoc2oCtPhekPbMwmyCDg7Gim2S4 Syrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843490; x=1687435490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BdpkvDlA4UmVXiobxDu+YLmGZsz0CGX9FJr5LiiDCI0=; b=fj8z2SIhi8Y4FdLQgQ5DLpf/fAPq9AE08/Bt58O0L7Myp6+YxeD02R0vmkQXqsZcaD nO59fLNhsbYPq04bVqXm6Rkgo8+73LPOv+aIaPRGoVNTb3WGyIYoCSq6K25guUY0+9xO cRAIaW2CrM7qjGB1nSlDiICwaA8mQ980GIihX7bq3aePcA/7xDnXvqMC2Hlmc5JO+DiE v3l/ynqSK9bH5dU8tRY3APWAO0EmRp6Jr6kIfCuR4bKhnYrf12Tyfb5GH94QkkmNFA2+ 1dSFDfLPeypmEuSaZcPbpFE5BUeOGppu1nhpm8ah4pYDebwLc3rCkwjC0baubRvLiIEw 2G7A== X-Gm-Message-State: AC+VfDxRKS+q3pina0uoEL6obA9jG4DF7E/9MqfCDoJwLJAYmwzHnVKg HV4kxrNgqHJyIFwvMxIK+jvOp0yJrSSZODf4ZIU= X-Google-Smtp-Source: ACHHUZ5ZK1lDkOho+A3gbtZGDhv7L7hv+ZXAO/6krdbnXAQ9+VjWRCFXbHU7snz95PCiVGXrMr/iQg== X-Received: by 2002:a05:6000:1285:b0:307:a58f:5f7b with SMTP id f5-20020a056000128500b00307a58f5f7bmr10123157wrx.64.1684843489899; Tue, 23 May 2023 05:04:49 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 2/6] docs: Document decodetree named field syntax Date: Tue, 23 May 2023 13:04:43 +0100 Message-Id: <20230523120447.728365-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230523120447.728365-1-peter.maydell@linaro.org> References: <20230523120447.728365-1-peter.maydell@linaro.org> MIME-Version: 1.0 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::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1684843542523100001 Content-Type: text/plain; charset="utf-8" Document the named field syntax that we want to implement for the decodetree script. This allows a field to be defined in terms of some other field that the instruction pattern has already set, for example: %sz_imm 10:3 sz:3 !function=3Dexpand_sz_imm to allow a function to be passed both an immediate field from the instruction and also a sz value which might have been specified by the instruction pattern directly (sz=3D1, etc) rather than being a simple field within the instruction. Note that the restriction on not having the format referring to the pattern and the pattern referring to the format simultaneously is a restriction of the decoder generator rather than inherently being a silly thing to do. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- docs/devel/decodetree.rst | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/devel/decodetree.rst b/docs/devel/decodetree.rst index 49ea50c2a7f..e3392aa7057 100644 --- a/docs/devel/decodetree.rst +++ b/docs/devel/decodetree.rst @@ -23,22 +23,42 @@ Fields =20 Syntax:: =20 - field_def :=3D '%' identifier ( unnamed_field )* ( !function=3Dident= ifier )? + field_def :=3D '%' identifier ( field )* ( !function=3Didentifier )? + field :=3D unnamed_field | named_field unnamed_field :=3D number ':' ( 's' ) number + named_field :=3D identifier ':' ( 's' ) number =20 For *unnamed_field*, the first number is the least-significant bit position of the field and the second number is the length of the field. If the 's'= is -present, the field is considered signed. If multiple ``unnamed_fields`` a= re -present, they are concatenated. In this way one can define disjoint field= s. +present, the field is considered signed. + +A *named_field* refers to some other field in the instruction pattern +or format. Regardless of the length of the other field where it is +defined, it will be inserted into this field with the specified +signedness and bit width. + +Field definitions that involve loops (i.e. where a field is defined +directly or indirectly in terms of itself) are errors. + +A format can include fields that refer to named fields that are +defined in the instruction pattern(s) that use the format. +Conversely, an instruction pattern can include fields that refer to +named fields that are defined in the format it uses. However you +cannot currently do both at once (i.e. pattern P uses format F; F has +a field A that refers to a named field B that is defined in P, and P +has a field C that refers to a named field D that is defined in F). + +If multiple ``fields`` are present, they are concatenated. +In this way one can define disjoint fields. =20 If ``!function`` is specified, the concatenated result is passed through t= he named function, taking and returning an integral value. =20 -One may use ``!function`` with zero ``unnamed_fields``. This case is call= ed +One may use ``!function`` with zero ``fields``. This case is called a *parameter*, and the named function is only passed the ``DisasContext`` and returns an integral value extracted from there. =20 -A field with no ``unnamed_fields`` and no ``!function`` is in error. +A field with no ``fields`` and no ``!function`` is in error. =20 Field examples: =20 @@ -56,6 +76,9 @@ Field examples: | %shimm8 5:s8 13:1 | expand_shimm8(sextract(i, 5, 8) << 1 | | | !function=3Dexpand_shimm8 | extract(i, 13, 1)) = | +---------------------------+---------------------------------------------+ +| %sz_imm 10:2 sz:3 | expand_sz_imm(extract(i, 10, 2) << 3 | | +| !function=3Dexpand_sz_imm | extract(a->sz, 0, 3)) = | ++---------------------------+---------------------------------------------+ =20 Argument Sets =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 2.34.1 From nobody Sat May 18 12:05:07 2024 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=1684843590; cv=none; d=zohomail.com; s=zohoarc; b=CnN52Mb5bo9kZr/SZ6jitIez9jFYaanOPYtEUST0xclZlfzvAgJQyFdTLLVQvxHMuP50VD5/Z5pofTOdcEguvGTW4VRIuI6gb7okAPtDj3QGM3ArwKMQKx9r3qesHpRKL/AaEE4WBjnKeKY5c2g2KTTJdJDGJBeiKnKcvLO9ftY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684843590; h=Content-Transfer-Encoding:Cc: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=xbN6BYbhg9Tc9GAYch8/jujIr0chTMGn9JipZlla0d0=; b=CvOUEfqmLeyep7D8a1dMMbluUK7RRDWZCqLezu+o82zEKR6e+iUayp3KKXU5B+g9IotQXkqCBNdbRjhQSil8g9IyKLhDXjcTxIYfH27b1jV/eHmOjQe5GmbBij8iCAr0a1M8J3CECYR9K6GATfLfkZBrdQA25AA/hSrtRXjluMw= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684843590363120.99347014464479; Tue, 23 May 2023 05:06:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Ql5-0002Pa-73; Tue, 23 May 2023 08:04:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Ql4-0002On-BZ for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:54 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1Ql2-0008QY-1o for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:54 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f41dceb93bso47512135e9.1 for ; Tue, 23 May 2023 05:04:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l17-20020adfe591000000b003079c402762sm10848778wrm.19.2023.05.23.05.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 05:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684843490; x=1687435490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xbN6BYbhg9Tc9GAYch8/jujIr0chTMGn9JipZlla0d0=; b=Qx3qIYWEErLGhZBj/GkloiSqv8yDf7Zclo7kTGmeddsHnwWysd9SDHZaK+ZJdqTR41 Mm42oDfMglQjrhgZXSDbuOuXg+uE27H01cUjS1OfQRdG5Ts9h6TtqBiGnFIqgiGLYY2d 35GmLoiJFT5WY46+y9T04mp59z0LBjup6jjOv8/JwE0ORe7PU6rYkb3pWtJ8d0kLpcvA FLvuryf2oUAagNpVIHcDakPf5qRvgRJrdzQHjhupCRM+N0dz7xt9BQoSVd40yl/eIY4v k/9Y1+IDC3U0d+JO/Kx6kXUdtmaDCS1JNR7yZLvq8Y+9OlcvATIxbMfhaj2NAi3O0maQ sc1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843490; x=1687435490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xbN6BYbhg9Tc9GAYch8/jujIr0chTMGn9JipZlla0d0=; b=l7iJfzhUuvzqiHkuG7K5QVolU5fnd2GDh7mdIY4JwIG4X5+vt+ylRYOKtYuaqj26HT kUQsiUDTYYrfv3KQ7wsNA60LqWJw9JWnDdXRG8jIg2Qrtu2Utr/d6+rGOFgKTouOdkfV 8Wg7nbTL+TJ6vsYyYz9+WMEDrBkv2ZZp7toTFccXL7Ii4DgdwhDPsUWW8xYznD3hlyug tUivRpIiwur9SX+efZiaDAkgoWeJz73qfF3cqVHccF2kGt4XzBZSS0gKA8rEipjASNMP MGw8Vce65o/VOFUNB54Q8XnXPU3LUpeiEKW7Ml/ArznJfu6UXETHg+8QjiFnITJZ0T7D M1Uw== X-Gm-Message-State: AC+VfDxPlSMcMa6nycRMZAejfpRZfY/wfRm4oZVSDnixWLaLDZ9fFWUM nImvgdCCcY1n6Bz+wSO0mlcKsXV4JCSTLgZFvo0= X-Google-Smtp-Source: ACHHUZ4+MOTjQgpghsERQnZtYPmfoUFU2xP6yyUy8Frp0fO0BeLRGCRDlFPcmiQAKCzXid9fby4W0A== X-Received: by 2002:a1c:6a09:0:b0:3f6:1e6:d5a2 with SMTP id f9-20020a1c6a09000000b003f601e6d5a2mr5789238wmc.4.1684843490616; Tue, 23 May 2023 05:04:50 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 3/6] scripts/decodetree: Pass lvalue-formatter function to str_extract() Date: Tue, 23 May 2023 13:04:44 +0100 Message-Id: <20230523120447.728365-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230523120447.728365-1-peter.maydell@linaro.org> References: <20230523120447.728365-1-peter.maydell@linaro.org> MIME-Version: 1.0 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::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1684843591657100001 Content-Type: text/plain; charset="utf-8" To support referring to other named fields in field definitions, we need to pass the str_extract() method a function which tells it how to emit the code for a previously initialized named field. (In Pattern::output_code() the other field will be "u.f_foo.field", and in Format::output_extract() it is "a->field".) Refactor the two callsites that currently do "output code to initialize each field", and have them pass a lambda that defines how to format the lvalue in each case. This is then used both in emitting the LHS of the assignment and also passed down to str_extract() as a new argument (unused at the moment, but will be used in the following patch). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- scripts/decodetree.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/decodetree.py b/scripts/decodetree.py index a03dc6b5e3e..33f4252b4ee 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -205,7 +205,7 @@ def __str__(self): s =3D '' return str(self.pos) + ':' + s + str(self.len) =20 - def str_extract(self): + def str_extract(self, lvalue_formatter): global bitop_width s =3D 's' if self.sign else '' return f'{s}extract{bitop_width}(insn, {self.pos}, {self.len})' @@ -228,12 +228,12 @@ def __init__(self, subs, mask): def __str__(self): return str(self.subs) =20 - def str_extract(self): + def str_extract(self, lvalue_formatter): global bitop_width ret =3D '0' pos =3D 0 for f in reversed(self.subs): - ext =3D f.str_extract() + ext =3D f.str_extract(lvalue_formatter) if pos =3D=3D 0: ret =3D ext else: @@ -264,7 +264,7 @@ def __init__(self, value): def __str__(self): return str(self.value) =20 - def str_extract(self): + def str_extract(self, lvalue_formatter): return str(self.value) =20 def __cmp__(self, other): @@ -283,8 +283,9 @@ def __init__(self, func, base): def __str__(self): return self.func + '(' + str(self.base) + ')' =20 - def str_extract(self): - return self.func + '(ctx, ' + self.base.str_extract() + ')' + def str_extract(self, lvalue_formatter): + return (self.func + '(ctx, ' + + self.base.str_extract(lvalue_formatter) + ')') =20 def __eq__(self, other): return self.func =3D=3D other.func and self.base =3D=3D other.base @@ -304,7 +305,7 @@ def __init__(self, func): def __str__(self): return self.func =20 - def str_extract(self): + def str_extract(self, lvalue_formatter): return self.func + '(ctx)' =20 def __eq__(self, other): @@ -357,6 +358,11 @@ def __str__(self): =20 def str1(self, i): return str_indent(i) + self.__str__() + + def output_fields(self, indent, lvalue_formatter): + for n, f in self.fields.items(): + output(indent, lvalue_formatter(n), ' =3D ', + f.str_extract(lvalue_formatter), ';\n') # end General =20 =20 @@ -370,8 +376,7 @@ def extract_name(self): def output_extract(self): output('static void ', self.extract_name(), '(DisasContext *ctx, ', self.base.struct_name(), ' *a, ', insntype, ' insn)\n{\n') - for n, f in self.fields.items(): - output(' a->', n, ' =3D ', f.str_extract(), ';\n') + self.output_fields(str_indent(4), lambda n: 'a->' + n) output('}\n\n') # end Format =20 @@ -395,8 +400,7 @@ def output_code(self, i, extracted, outerbits, outermas= k): if not extracted: output(ind, self.base.extract_name(), '(ctx, &u.f_', arg, ', insn);\n') - for n, f in self.fields.items(): - output(ind, 'u.f_', arg, '.', n, ' =3D ', f.str_extract(), ';\= n') + self.output_fields(ind, lambda n: 'u.f_' + arg + '.' + n) output(ind, 'if (', translate_prefix, '_', self.name, '(ctx, &u.f_', arg, ')) return true;\n') =20 --=20 2.34.1 From nobody Sat May 18 12:05:07 2024 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=1684843535; cv=none; d=zohomail.com; s=zohoarc; b=YLwT8jL7/OdYbp15FbY5K1vv1zNDRxfOsxjrobhMNHTZvbh1i7J0GMe/JADV5NTXioCKq5tSjD+zvi8oyA1ZDNTAMdRalNqvTWoE486+fdb6k/loY6iH8xUqXDEmyCDB3amvBKMsaGSAKj5+GMq6T/aF8ib2klak76hKfGI7QkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684843535; h=Content-Transfer-Encoding:Cc: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=CP4iW2arzPiOFlsv2K+bA4KJE/pPkFARYRAohYFYWwc=; b=Pb2W3RiHVuJ8yGp97lKbhVg9cea/wP5AHkSB45U67l35bt9tf/ucnDRFHkbKDmtXwfcQjybqxe5G/6M2U032qvVNC+JyDB6386YWYo4RxaDGT/WgH0kLxVJa/b5kLo+N0gByFFv1r14W7u5AV2j7fVSAktBoeYiqMsq/wt1fCew= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168484353539510.416470129500794; Tue, 23 May 2023 05:05:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Ql9-0002R9-JK; Tue, 23 May 2023 08:04:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Ql8-0002Ql-9T for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:58 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1Ql2-0008Qj-F2 for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:58 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30948709b3cso4009486f8f.3 for ; Tue, 23 May 2023 05:04:52 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l17-20020adfe591000000b003079c402762sm10848778wrm.19.2023.05.23.05.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 05:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684843491; x=1687435491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CP4iW2arzPiOFlsv2K+bA4KJE/pPkFARYRAohYFYWwc=; b=DfQW+/OP3KoNl5K+arAy3j2tf9Py0CE4MyMjxN8dBMdbvtyCN2DqZ7/1C2S9oZHsXN DxpB7md074AMUeF+2Jnq1a6K5q2wpc/qOjXuY1SiMcQGc0/ZPVKlZP7dnlT2rfw0KLfY B3ybDj2W3YHa0cSwZm02bTcZaxnERA8Y4/CNDHukibz//2esYkZsD0rIjccc+3GkcQy5 qEtDEJD/Xhz9BzO7r5sUKd5HAXigQn1EfnWq/8GHbOxW1cHLsDJCkNYrBj3yPiloe8wF EaM7Qi7h98U7VB8NkhtfGiY8yCIrRuXRsbR+psX3XOp5pn+usc6zzHoODYIG9Axuj48u LbmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843491; x=1687435491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CP4iW2arzPiOFlsv2K+bA4KJE/pPkFARYRAohYFYWwc=; b=OjeKUpsDQW3LGvSS2oxEU0g6kc9h+jUY3X/M7Irs+l3tubJuKnt01/evbiK5zNjLbx 809nXLYoITCS+gwv7NUHwuDhj7co6mUCLROY9mGwRl/7FpywiBQkwkNYz05tVUyIV7Ka KAiMc5D+mc+QwzBMgXCyFb+b8iVJkSrD/CDEkvHIKVm5WBrZ1ksE8QYrLby8y9Mo3lHx f/M3gjApW9LFLa9NVLbwDutmyB8gMPwgF/HoFoKEIA2MB2BOJqr8bbAyo/C/rc77xprE Hzt29JeNrC2OgN5kc4kIwC4qxhhlE/A04kxH119GXyHpGeZTKYCJjB/crLfLNOCe6wqB kl3g== X-Gm-Message-State: AC+VfDxKE3CKjjonz674GRcbMD+La9yn8qV5PCCYeYwovVFePaXkK+aV LZZSw8X4naLLO1rLh5KzDkhCEvBrP20hwJPzJYU= X-Google-Smtp-Source: ACHHUZ7TyKoAx1cYmWUIvgrjoDKMGz28slyKgMp90/8uKsyRvSUHNzjudrtdB539W5FEjBAKkEuskA== X-Received: by 2002:a5d:694e:0:b0:309:4227:6d1a with SMTP id r14-20020a5d694e000000b0030942276d1amr8761817wrw.70.1684843491185; Tue, 23 May 2023 05:04:51 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 4/6] scripts/decodetree: Implement a topological sort Date: Tue, 23 May 2023 13:04:45 +0100 Message-Id: <20230523120447.728365-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230523120447.728365-1-peter.maydell@linaro.org> References: <20230523120447.728365-1-peter.maydell@linaro.org> MIME-Version: 1.0 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::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1684843536584100005 Content-Type: text/plain; charset="utf-8" To support named fields, we will need to be able to do a topological sort (so that we ensure that we output the assignment to field A before the assignment to field B if field B refers to field A by name). The good news is that there is a tsort in the python standard library; the bad news is that it was only added in Python 3.9. To bridge the gap between our current minimum supported Python version and 3.9, provide a local implementation that has the same API as the stdlib version for the parts we care about. In future when QEMU's minimum Python version requirement reaches 3.9 we can delete this code and replace it with an 'import' line. The core of this implementation is based on https://code.activestate.com/recipes/578272-topological-sort/ which is MIT-licensed. Signed-off-by: Peter Maydell Acked-by: Richard Henderson --- scripts/decodetree.py | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 33f4252b4ee..e1fd995eaab 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -53,6 +53,80 @@ re_fmt_ident =3D '@[a-zA-Z0-9_]*' re_pat_ident =3D '[a-zA-Z0-9_]*' =20 +# Local implementation of a topological sort. We use the same API that +# the Python graphlib does, so that when QEMU moves forward to a +# baseline of Python 3.9 or newer this code can all be dropped and +# replaced with: +# from graphlib import TopologicalSorter, CycleError +# +# https://docs.python.org/3.9/library/graphlib.html#graphlib.TopologicalSo= rter +# +# We only implement the parts of TopologicalSorter we care about: +# ts =3D TopologicalSorter(graph=3DNone) +# create the sorter. graph is a dictionary whose keys are +# nodes and whose values are lists of the predecessors of that node. +# (That is, if graph contains "A" -> ["B", "C"] then we must output +# B and C before A.) +# ts.static_order() +# returns a list of all the nodes in sorted order, or raises CycleError +# CycleError +# exception raised if there are cycles in the graph. The second +# element in the args attribute is a list of nodes which form a +# cycle; the first and last element are the same, eg [a, b, c, a] +# (Our implementation doesn't give the order correctly.) +# +# For our purposes we can assume that the data set is always small +# (typically 10 nodes or less, actual links in the graph very rare), +# so we don't need to worry about efficiency of implementation. +# +# The core of this implementation is from +# https://code.activestate.com/recipes/578272-topological-sort/ +# (but updated to Python 3), and is under the MIT license. + +class CycleError(ValueError): + """Subclass of ValueError raised if cycles exist in the graph""" + pass + +class TopologicalSorter: + """Topologically sort a graph""" + def __init__(self, graph=3DNone): + self.graph =3D graph + + def static_order(self): + # We do the sort right here, unlike the stdlib version + from functools import reduce + data =3D {} + r =3D [] + + if not self.graph: + return [] + + # This code wants the values in the dict to be specifically sets + for k, v in self.graph.items(): + data[k] =3D set(v) + + # Find all items that don't depend on anything. + extra_items_in_deps =3D (reduce(set.union, data.values()) + - set(data.keys())) + # Add empty dependencies where needed + data.update({item:{} for item in extra_items_in_deps}) + while True: + ordered =3D set(item for item, dep in data.items() if not dep) + if not ordered: + break + r.extend(ordered) + data =3D {item: (dep - ordered) + for item, dep in data.items() + if item not in ordered} + if data: + # This doesn't give as nice results as the stdlib, which + # gives you the cycle by listing the nodes in order. Here + # we only know the nodes in the cycle but not their order. + raise CycleError(f'nodes are in a cycle', list(data.keys())) + + return r +# end TopologicalSorter + def error_with_file(file, lineno, *args): """Print an error message from file:line and args and exit.""" global output_file --=20 2.34.1 From nobody Sat May 18 12:05:07 2024 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=1684843572; cv=none; d=zohomail.com; s=zohoarc; b=fH1IHR+QyKocMUVXBlIYteFd2RhRlT83nQM8uM96pYmX57y+161OSr6kkQOglBsR1XDI+5RLEgR78bO/zoCDaJzmG+f33LKIybjMTYUgHO07vZspB9c5+RWsiCwPm+/5N/FyObSqplF/aY5dBmUE9lq5s2Iqo3mdqfZwN8rpOio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684843572; h=Content-Transfer-Encoding:Cc: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=FK0kwEu4kzUizKTcdb7b9atTVcQCpq+2RRFxmoaG+cE=; b=cy63ErYfQCoHGkp/bDQpnT2XhwwtfNy1oGUs3adeJVrQ+Qpqbtpu9YrHEZO9qSqLR3BRAlp1R0XoqWex4p+SyLHMMxZ4o5qYQBYYi6voM+na3kBWzrBxwjWNq2wOW5yG1pX05Nb4heHgxORcU5cnKUlMbaIHiKmiX5ZvYm7fM7k= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168484357255169.43870445986363; Tue, 23 May 2023 05:06:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Ql6-0002QV-U9; Tue, 23 May 2023 08:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Ql5-0002Pk-K0 for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:55 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1Ql3-0008Qv-7e for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:55 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f60ec45314so1659025e9.3 for ; Tue, 23 May 2023 05:04:52 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l17-20020adfe591000000b003079c402762sm10848778wrm.19.2023.05.23.05.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 05:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684843492; x=1687435492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FK0kwEu4kzUizKTcdb7b9atTVcQCpq+2RRFxmoaG+cE=; b=OmcTKVpOVUmpDvdSuuQxk0GxJN+kvscNCYn9/wUDjCKkB4TvSWlhF6hweCMNtLXd4M TfZUrE7UPIoWwAkgD2R5oxDdK6Q1CXuUPXAPagj0MFMxKgdXBYi8v9PzpPq5s84w72Lx i3JDY/iFF3W/TRyS7boB2tViQtF+xYoaK8YcFwFPrW8nsr1EM9OBKE8dYEJwf8j+DHYD 73ce2ltSLe/sZxDE1cQHZ4am/eHRlRC6CjzquALAqdPxInyTlkyEVJ7q8iRvqu7d3DXE /HJH5VWU/vWWGR8ud8q9hHZQMpiU4vrOvrEme5iZgigoC5B2ezzBjEEAa7PZcRo2BgcM l0fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843492; x=1687435492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FK0kwEu4kzUizKTcdb7b9atTVcQCpq+2RRFxmoaG+cE=; b=h2w0V6M0QnJO0TM9wshIMG0Illw3o/yEsPVV4iv/kGwKUQt6J5G2l5eVwhgrI5RN5X pnagZ/XUud5MUaof6U7duXQ+cVfT4+vfIzdQjZZt4ld0cfpbu0c85Vv3vuTt4MpYWgIT nN9so3vWt169MJu0vFK96zN9MqcQr6mFc0s0F0WuoHcpYSVop8RPknu2hNtf+sWjioMJ Dd6h/qeLgIA9ff3Wy+QWVyrsd0nOG3YnpbvF/FHmef+gcEBF8xVOgd0S1RXb/8slKrt5 GkkQDlnhQ1mXhFH8SRQMc24tXZTBryc6FgHIV+eZTW6UwIY5HC4eTmY4CU2dvvxWOXkP mPyA== X-Gm-Message-State: AC+VfDxY5mvauKo/USrJ8XZrv3tyMCfxMCJcKMoTdh4MTNV9yq1/x03E wp0E8R7fOpLYFhiC6Crgvqa7noY+iwWxnJzHXm8= X-Google-Smtp-Source: ACHHUZ4fpN68I7rnfmZE/cK2Rq5pa5gCszbF7H4uNr5iIRRYLksDu2bVhLmvl23kjXAbwHsbpuwcJQ== X-Received: by 2002:a7b:c7cb:0:b0:3f5:d313:db68 with SMTP id z11-20020a7bc7cb000000b003f5d313db68mr9933647wmk.5.1684843491765; Tue, 23 May 2023 05:04:51 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 5/6] scripts/decodetree: Implement named field support Date: Tue, 23 May 2023 13:04:46 +0100 Message-Id: <20230523120447.728365-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230523120447.728365-1-peter.maydell@linaro.org> References: <20230523120447.728365-1-peter.maydell@linaro.org> MIME-Version: 1.0 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::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1684843574008100003 Content-Type: text/plain; charset="utf-8" Implement support for named fields, i.e. where one field is defined in terms of another, rather than directly in terms of bits extracted from the instruction. The new method referenced_fields() on all the Field classes returns a list of fields that this field references. This just passes through, except for the new NamedField class. We can then use referenced_fields() to: * construct a list of 'dangling references' for a format or pattern, which is the fields that the format/pattern uses but doesn't define itself * do a topological sort, so that we output "field =3D value" assignments in an order that means that we assign a field before we reference it in a subsequent assignment * check when we output the code for a pattern whether we need to fill in the format fields before or after the pattern fields, and do other error checking Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- scripts/decodetree.py | 145 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 6 deletions(-) diff --git a/scripts/decodetree.py b/scripts/decodetree.py index e1fd995eaab..70629b37646 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -284,6 +284,9 @@ def str_extract(self, lvalue_formatter): s =3D 's' if self.sign else '' return f'{s}extract{bitop_width}(insn, {self.pos}, {self.len})' =20 + def referenced_fields(self): + return [] + def __eq__(self, other): return self.sign =3D=3D other.sign and self.mask =3D=3D other.mask =20 @@ -315,6 +318,12 @@ def str_extract(self, lvalue_formatter): pos +=3D f.len return ret =20 + def referenced_fields(self): + l =3D [] + for f in self.subs: + l.extend(f.referenced_fields()) + return l + def __ne__(self, other): if len(self.subs) !=3D len(other.subs): return True @@ -341,6 +350,9 @@ def __str__(self): def str_extract(self, lvalue_formatter): return str(self.value) =20 + def referenced_fields(self): + return [] + def __cmp__(self, other): return self.value - other.value # end ConstField @@ -361,6 +373,9 @@ def str_extract(self, lvalue_formatter): return (self.func + '(ctx, ' + self.base.str_extract(lvalue_formatter) + ')') =20 + def referenced_fields(self): + return self.base.referenced_fields() + def __eq__(self, other): return self.func =3D=3D other.func and self.base =3D=3D other.base =20 @@ -382,6 +397,9 @@ def __str__(self): def str_extract(self, lvalue_formatter): return self.func + '(ctx)' =20 + def referenced_fields(self): + return [] + def __eq__(self, other): return self.func =3D=3D other.func =20 @@ -389,6 +407,32 @@ def __ne__(self, other): return not self.__eq__(other) # end ParameterField =20 +class NamedField: + """Class representing a field already named in the pattern""" + def __init__(self, name, sign, len): + self.mask =3D 0 + self.sign =3D sign + self.len =3D len + self.name =3D name + + def __str__(self): + return self.name + + def str_extract(self, lvalue_formatter): + global bitop_width + s =3D 's' if self.sign else '' + lvalue =3D lvalue_formatter(self.name) + return f'{s}extract{bitop_width}({lvalue}, 0, {self.len})' + + def referenced_fields(self): + return [self.name] + + def __eq__(self, other): + return self.name =3D=3D other.name + + def __ne__(self, other): + return not self.__eq__(other) +# end NamedField =20 class Arguments: """Class representing the extracted fields of a format""" @@ -412,7 +456,6 @@ def output_def(self): output('} ', self.struct_name(), ';\n\n') # end Arguments =20 - class General: """Common code between instruction formats and instruction patterns""" def __init__(self, name, lineno, base, fixb, fixm, udfm, fldm, flds, w= ): @@ -426,6 +469,7 @@ def __init__(self, name, lineno, base, fixb, fixm, udfm= , fldm, flds, w): self.fieldmask =3D fldm self.fields =3D flds self.width =3D w + self.dangling =3D None =20 def __str__(self): return self.name + ' ' + str_match_bits(self.fixedbits, self.fixed= mask) @@ -433,10 +477,51 @@ def __str__(self): def str1(self, i): return str_indent(i) + self.__str__() =20 + def dangling_references(self): + # Return a list of all named references which aren't satisfied + # directly by this format/pattern. This will be either: + # * a format referring to a field which is specified by the + # pattern(s) using it + # * a pattern referring to a field which is specified by the + # format it uses + # * a user error (referring to a field that doesn't exist at all) + if self.dangling is None: + # Compute this once and cache the answer + dangling =3D [] + for n, f in self.fields.items(): + for r in f.referenced_fields(): + if r not in self.fields: + dangling.append(r) + self.dangling =3D dangling + return self.dangling + def output_fields(self, indent, lvalue_formatter): + # We use a topological sort to ensure that any use of NamedField + # comes after the initialization of the field it is referencing. + graph =3D {} for n, f in self.fields.items(): - output(indent, lvalue_formatter(n), ' =3D ', - f.str_extract(lvalue_formatter), ';\n') + refs =3D f.referenced_fields() + graph[n] =3D refs + + try: + ts =3D TopologicalSorter(graph) + for n in ts.static_order(): + # We only want to emit assignments for the keys + # in our fields list, not for anything that ends up + # in the tsort graph only because it was referenced as + # a NamedField. + try: + f =3D self.fields[n] + output(indent, lvalue_formatter(n), ' =3D ', + f.str_extract(lvalue_formatter), ';\n') + except KeyError: + pass + except CycleError as e: + # The second element of args is a list of nodes which form + # a cycle (there might be others too, but only one is reported= ). + # Pretty-print it to tell the user. + cycle =3D ' =3D> '.join(e.args[1]) + error(self.lineno, 'field definitions form a cycle: ' + cycle) # end General =20 =20 @@ -471,10 +556,36 @@ def output_code(self, i, extracted, outerbits, outerm= ask): ind =3D str_indent(i) arg =3D self.base.base.name output(ind, '/* ', self.file, ':', str(self.lineno), ' */\n') + # We might have named references in the format that refer to fields + # in the pattern, or named references in the pattern that refer + # to fields in the format. This affects whether we extract the fie= lds + # for the format before or after the ones for the pattern. + # For simplicity we don't allow cross references in both direction= s. + # This is also where we catch the syntax error of referring to + # a nonexistent field. + fmt_refs =3D self.base.dangling_references() + for r in fmt_refs: + if r not in self.fields: + error(self.lineno, f'format refers to undefined field {r}') + pat_refs =3D self.dangling_references() + for r in pat_refs: + if r not in self.base.fields: + error(self.lineno, f'pattern refers to undefined field {r}= ') + if pat_refs and fmt_refs: + error(self.lineno, ('pattern that uses fields defined in forma= t ' + 'cannot use format that uses fields define= d ' + 'in pattern')) + if fmt_refs: + # pattern fields first + self.output_fields(ind, lambda n: 'u.f_' + arg + '.' + n) + assert not extracted, "dangling fmt refs but it was already ex= tracted" if not extracted: output(ind, self.base.extract_name(), '(ctx, &u.f_', arg, ', insn);\n') - self.output_fields(ind, lambda n: 'u.f_' + arg + '.' + n) + if not fmt_refs: + # pattern fields last + self.output_fields(ind, lambda n: 'u.f_' + arg + '.' + n) + output(ind, 'if (', translate_prefix, '_', self.name, '(ctx, &u.f_', arg, ')) return true;\n') =20 @@ -614,8 +725,10 @@ def output_code(self, i, extracted, outerbits, outerma= sk): ind =3D str_indent(i) =20 # If we identified all nodes below have the same format, - # extract the fields now. - if not extracted and self.base: + # extract the fields now. But don't do it if the format relies + # on named fields from the insn pattern, as those won't have + # been initialised at this point. + if not extracted and self.base and not self.base.dangling_referenc= es(): output(ind, self.base.extract_name(), '(ctx, &u.f_', self.base.base.name, ', insn);\n') extracted =3D True @@ -737,6 +850,7 @@ def parse_field(lineno, name, toks): """Parse one instruction field from TOKS at LINENO""" global fields global insnwidth + global re_C_ident =20 # A "simple" field will have only one entry; # a "multifield" will have several. @@ -751,6 +865,25 @@ def parse_field(lineno, name, toks): func =3D func[1] continue =20 + if re.fullmatch(re_C_ident + ':s[0-9]+', t): + # Signed named field + subtoks =3D t.split(':') + n =3D subtoks[0] + le =3D int(subtoks[1]) + f =3D NamedField(n, True, le) + subs.append(f) + width +=3D le + continue + if re.fullmatch(re_C_ident + ':[0-9]+', t): + # Unsigned named field + subtoks =3D t.split(':') + n =3D subtoks[0] + le =3D int(subtoks[1]) + f =3D NamedField(n, False, le) + subs.append(f) + width +=3D le + continue + if re.fullmatch('[0-9]+:s[0-9]+', t): # Signed field extract subtoks =3D t.split(':s') --=20 2.34.1 From nobody Sat May 18 12:05:07 2024 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=1684843559; cv=none; d=zohomail.com; s=zohoarc; b=M71o5yP0ca77z4/EnQ6MG8azfxqTCFG10fqNecSVmFp6vUC3wia/1D+e0m8M4bZ8kaoJSPqumnmIYYCUHB+wWeritAxsq194N6sfWFk+GFozS7ZKlzVBvJYMwcmAYTqTdZH7JyIIhGXlXRFRmy9XZ2pXN+KKp9UxH7EupNO79pM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684843559; h=Content-Transfer-Encoding:Cc: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=gB3R2llxQU+c9Ja3BYRkfIk0uQTzezpbeFI9jfQINrc=; b=la0dTLs63iKWq2tmabFTLsw5DWUPvqKKFAIUQGlGsZyiRPXJp/b/MYh2td+jgl3PojIY2kveJt4lmwRWEPjONkqvU4K/49jDEK+xVlfDeyI0g3sHlKZiLfOboFBRNIgxMuhBVlYGEtW28hkJ9ehz/gqdQMysKvolI/NHxXZe0JU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684843559004225.91468835058413; Tue, 23 May 2023 05:05:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Ql6-0002QN-91; Tue, 23 May 2023 08:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Ql5-0002Pe-FJ for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:55 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1Ql3-0008R6-Hm for qemu-devel@nongnu.org; Tue, 23 May 2023 08:04:55 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f50020e0f8so32223425e9.0 for ; Tue, 23 May 2023 05:04:53 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l17-20020adfe591000000b003079c402762sm10848778wrm.19.2023.05.23.05.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 05:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684843492; x=1687435492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gB3R2llxQU+c9Ja3BYRkfIk0uQTzezpbeFI9jfQINrc=; b=ESU/2A9Ff+jkff+xg9bmhoN5ahH5bp4o+8/fWF0xfLA17HhbVqKBRdeOx0GWFLsufP 4cHhC64Yild5ED5L0M12Ubv3hYyIl2ZiMRgPOM30seJkWCVV6lHP5FY3T45A3+ii/QiW 9ijVZYVtdxM/8xi3N77oEPf0qg1Ic8+aAxDqqywpMTKzm4CyirokL6cXfcOb6dZOm37r 9OsI84xQMEGX28gX2cOTQF+DULhCCkzhvl/XvhpYUVcQpK0Z+oppqZRNiAQFNG1ckOPM yaQf6K1/lnyyj8we8QFGyO2lkSlwHux/KFZNa9XpgdkdisyQJA2CrRw70mEvRhrKVFRf Kl4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843492; x=1687435492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gB3R2llxQU+c9Ja3BYRkfIk0uQTzezpbeFI9jfQINrc=; b=ampIbd1OZEBQ2+mKe/rotjBukJ1PimgrFHOCmpT9MemOZZpqjInkflRGoPmwSM5vnd rczbI4UHandSR1ZRNmEknHJtDl6awst+pOQkDWnIdycvzVyO6iNZkas8+v6uKMiSRxUU KdwD4vtD0epa1fFEICw9faOU3Tu4t7HRYTPMdI2Em5/36ittOUJzdzDxRNwOqTdXzBT0 9K5u+HI397wkBDr6f+HhYwq89nEJECpWs/QjKMRvbB0ZW0gF5OJ/vPnIJcsewZasxvr7 bQ350aJ1JkjQAs70S6+z2Hezcb0yqzMRIflL56TL/JrbcTrwfvN7T4i2WpaY6JQBBIkS Tm1A== X-Gm-Message-State: AC+VfDzkXge/KWZutVeLZYcgC8mlCYlEAy7JJC0gZXRwy9tlKS/LgEEf S+c4/6zTgO8K1Ps9hwey30HhLueQeZ1WKqW3RLM= X-Google-Smtp-Source: ACHHUZ6q483OuQhJyTMeAZyP6w0GCop9AkevoABookHkYXsMQOFlS1M2Ei6/6oDE9qcT2wjKjAAO7A== X-Received: by 2002:a05:600c:450c:b0:3f6:eb:20fc with SMTP id t12-20020a05600c450c00b003f600eb20fcmr6174873wmo.6.1684843492177; Tue, 23 May 2023 05:04:52 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 6/6] tests/decode: Add tests for various named-field cases Date: Tue, 23 May 2023 13:04:47 +0100 Message-Id: <20230523120447.728365-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230523120447.728365-1-peter.maydell@linaro.org> References: <20230523120447.728365-1-peter.maydell@linaro.org> MIME-Version: 1.0 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::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1684843559486100001 Content-Type: text/plain; charset="utf-8" Add some tests for various cases of named-field use, both ones that should work and ones that should be diagnosed as errors. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- tests/decode/err_field1.decode | 2 +- tests/decode/err_field10.decode | 7 +++++++ tests/decode/err_field7.decode | 7 +++++++ tests/decode/err_field8.decode | 8 ++++++++ tests/decode/err_field9.decode | 14 ++++++++++++++ tests/decode/succ_named_field.decode | 19 +++++++++++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/decode/err_field10.decode create mode 100644 tests/decode/err_field7.decode create mode 100644 tests/decode/err_field8.decode create mode 100644 tests/decode/err_field9.decode create mode 100644 tests/decode/succ_named_field.decode diff --git a/tests/decode/err_field1.decode b/tests/decode/err_field1.decode index e07a5a73e0e..85c3f326d07 100644 --- a/tests/decode/err_field1.decode +++ b/tests/decode/err_field1.decode @@ -2,4 +2,4 @@ # See the COPYING.LIB file in the top-level directory. =20 # Diagnose invalid field syntax -%field asdf +%field 1asdf diff --git a/tests/decode/err_field10.decode b/tests/decode/err_field10.dec= ode new file mode 100644 index 00000000000..3e672b7459e --- /dev/null +++ b/tests/decode/err_field10.decode @@ -0,0 +1,7 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose formats which refer to undefined fields +%field1 field2:3 +@fmt ........ ........ ........ ........ %field1 +insn 00000000 00000000 00000000 00000000 @fmt diff --git a/tests/decode/err_field7.decode b/tests/decode/err_field7.decode new file mode 100644 index 00000000000..51fad7cceaf --- /dev/null +++ b/tests/decode/err_field7.decode @@ -0,0 +1,7 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose fields whose definitions form a loop +%field1 field2:3 +%field2 field1:4 +insn 00000000 00000000 00000000 00000000 %field1 %field2 diff --git a/tests/decode/err_field8.decode b/tests/decode/err_field8.decode new file mode 100644 index 00000000000..cc47c08a459 --- /dev/null +++ b/tests/decode/err_field8.decode @@ -0,0 +1,8 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose patterns which refer to undefined fields +&f1 f1 a +%field1 field2:3 +@fmt ........ ........ ........ .... a:4 &f1 +insn 00000000 00000000 00000000 0000 .... @fmt f1=3D%field1 diff --git a/tests/decode/err_field9.decode b/tests/decode/err_field9.decode new file mode 100644 index 00000000000..e7361d521ba --- /dev/null +++ b/tests/decode/err_field9.decode @@ -0,0 +1,14 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose fields where the format refers to a field defined in the +# pattern and the pattern refers to a field defined in the format. +# This is theoretically not impossible to implement, but is not +# supported by the script at this time. +&abcd a b c d +%refa a:3 +%refc c:4 +# Format defines 'c' and sets 'b' to an indirect ref to 'a' +@fmt ........ ........ ........ c:8 &abcd b=3D%refa +# Pattern defines 'a' and sets 'd' to an indirect ref to 'c' +insn 00000000 00000000 00000000 ........ @fmt d=3D%refc a=3D6 diff --git a/tests/decode/succ_named_field.decode b/tests/decode/succ_named= _field.decode new file mode 100644 index 00000000000..e64b3f93568 --- /dev/null +++ b/tests/decode/succ_named_field.decode @@ -0,0 +1,19 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or late= r. +# See the COPYING.LIB file in the top-level directory. + +# field using a named_field +%imm_sz 8:8 sz:3 +insn 00000000 00000000 ........ 00000000 imm_sz=3D%imm_sz sz=3D1 + +# Ditto, via a format. Here a field in the format +# references a named field defined in the insn pattern: +&imm_a imm alpha +%foo 0:16 alpha:4 +@foo 00000001 ........ ........ ........ &imm_a imm=3D%foo +i1 ........ 00000000 ........ ........ @foo alpha=3D1 +i2 ........ 00000001 ........ ........ @foo alpha=3D2 + +# Here the named field is defined in the format and referenced +# from the insn pattern: +@bar 00000010 ........ ........ ........ &imm_a alpha=3D4 +i3 ........ 00000000 ........ ........ @bar imm=3D%foo --=20 2.34.1