From patchwork Tue May 23 12:04:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 684899 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1674210wrt; Tue, 23 May 2023 05:05:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6HNabWo3MWN6CP7eBYwbWYw3eYT7gwQVFXkMyvRv+E7lCgQLqEz4JRJ9mRjsyOXeYWDAdK X-Received: by 2002:ac8:5ad5:0:b0:3f6:b1ad:97e with SMTP id d21-20020ac85ad5000000b003f6b1ad097emr7904023qtd.7.1684843558715; Tue, 23 May 2023 05:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843558; cv=none; d=google.com; s=arc-20160816; b=bm9zuy0Rc5DaVAxVISLfFzrgNJuERyHETSRZrNk/MSqOBTDl9xeJytylXUDXrTPdUv YnMJcIK+pF3n0pjYc96k2xUZTUtEYODvh4jQvxJACsWgs/PwKqzE6bRAJOxEdDD+NAE+ q8BIagWD/24TEgYuesHVpoLn/A/LskgN9szB/GWozmzz0bmTe9T5MlAF6Y0lUlyJxzYz nu37wRr7A5yrZyQc3a/7IVjVtnSP/98LcZRwD++M5AbYzN8OHqLnKobMR/VSD9bzfyrG 2WepkGx+Hz6lR6lV8eO56X/eeWSm4fqF1SVgfDiiXwxm60AbsFyZZmT1aeSEi5t7cCPG 9MwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4CXmvCi8lTzgvgYiHwHs7/x5DBl5UXEByr1AFvDiIAo=; b=GT6AQ+Ig39B5oimX6poJLlUW1Bb+CzjhpQ1FFX8OaQt4Zw/II3mJyo36TEqxvWUDxT xKmUtxaOF/Q0tZeJtypyG8YjgPflMDxgcZVaqRUvwxgC9aMtIpiIAEeW6rdOpQ6r/HCj TPFFa2o1evG0ZdhI7Ou0qj4EHbaX17ZUORVo83+eIVeYXcOOv22m7DM/kbvR3v+pGYnz xJ7hHkt/VRpxB4jUYY8ozwWkP/xi+xVQeG6BzhRcOvcQLLlByPpTToPw4PWCje4ZiV1y 8WWCm6qd53anlJBTkKqfnTRwmJolXM/ln72zppHNYtmNA5fB31lXsx0IsvZ6Tmevyh6Q hc5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OS3lzeLT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s29-20020a05620a031d00b0074df91a6741si4646235qkm.437.2023.05.23.05.05.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 05:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OS3lzeLT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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=1 fi done From patchwork Tue May 23 12:04:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 684898 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1674048wrt; Tue, 23 May 2023 05:05:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60MzcICO8CMtwgldCIhtotFZZgjncx/EcWouF4ZNgFyTMLIVnHFC76/u74ts2fGE1SpWM+ X-Received: by 2002:a05:620a:6017:b0:75b:23a1:831a with SMTP id dw23-20020a05620a601700b0075b23a1831amr4089744qkb.21.1684843540653; Tue, 23 May 2023 05:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843540; cv=none; d=google.com; s=arc-20160816; b=qfdZd+/q1aTx3cziM+25H9tjpfLVF84n7zOXt8w5CZw1a5XIrIR5PGpLyjv9zxi554 B75PNToR3V+nsrFxYpuZ7NsDVY/Iutdlgu6ho32FrmNdpQ81cspGEKI9Gi6L18xLu44V 8BURwQdR10eYfsv/mDEl30Ldj45H8feIXmAPjdaJjZiIZ4dkLt18kkSL9zwgXcUpUHo8 PX0ujw+u3RPlMowdyI1jIuF2+3PZfdFv0vLn/pEISwg0yfp2uW2YwHhBnRyzAxMqc16y U7Spxn+3Z7ZDww2sHpQOjFc719Lx8UnczaE24jknvmXKShGagFLtIKhKstZejOy8LsJd aqIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BdpkvDlA4UmVXiobxDu+YLmGZsz0CGX9FJr5LiiDCI0=; b=O4y8nbGLDRkzXqx6vgLn9tw9XfEZFWcvCb6MdF8HcUHZujCv2srsUPpsapcMwOplyM yI2pKJrERNYuDSLYRbnRioPLlB7YAUqAcN/meK9VjtQX3K6/gLbE7EWg5ByjKz0oIYy3 487eI8TzTvVuyBg5vhRrBCeiEXEAk6suGDAGnXZYm+4mrYjbowS76ZIvcu2EAQkB/E5n SIbVAo3V7UCjkjs5IHhNLVepK1jdb3kzwiSOPVr3RpHOBeFgoJiwyBfd8lgdWrc/K2Hy N7bS4XwvwruIe54tz30b6xkSQn03hGY7JonOIC0WgtmB6EnD0HeyKE5YcnhbPENmAbxc FDDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BoxleB2f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z24-20020ae9c118000000b007577bd16a23si4610695qki.434.2023.05.23.05.05.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 05:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BoxleB2f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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=expand_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=1, 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 Syntax:: - field_def := '%' identifier ( unnamed_field )* ( !function=identifier )? + field_def := '%' identifier ( field )* ( !function=identifier )? + field := unnamed_field | named_field unnamed_field := number ':' ( 's' ) number + named_field := identifier ':' ( 's' ) number 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`` are -present, they are concatenated. In this way one can define disjoint fields. +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. If ``!function`` is specified, the concatenated result is passed through the named function, taking and returning an integral value. -One may use ``!function`` with zero ``unnamed_fields``. This case is called +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. -A field with no ``unnamed_fields`` and no ``!function`` is in error. +A field with no ``fields`` and no ``!function`` is in error. Field examples: @@ -56,6 +76,9 @@ Field examples: | %shimm8 5:s8 13:1 | expand_shimm8(sextract(i, 5, 8) << 1 | | | !function=expand_shimm8 | extract(i, 13, 1)) | +---------------------------+---------------------------------------------+ +| %sz_imm 10:2 sz:3 | expand_sz_imm(extract(i, 10, 2) << 3 | | +| !function=expand_sz_imm | extract(a->sz, 0, 3)) | ++---------------------------+---------------------------------------------+ Argument Sets ============= From patchwork Tue May 23 12:04:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 684902 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1674500wrt; Tue, 23 May 2023 05:06:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6fDeJfZ0Gp+DeomJ9xaWpnB4p8TeDQoOq2+DSbxRZC/DVpkWHcivb5qSO7+54myPr9ixrR X-Received: by 2002:a05:620a:27c5:b0:75b:23a1:d848 with SMTP id i5-20020a05620a27c500b0075b23a1d848mr4527037qkp.10.1684843588334; Tue, 23 May 2023 05:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843588; cv=none; d=google.com; s=arc-20160816; b=ReC1wdto9dSxUuSFyfa5lRP9sGbSIlwJP1nt19hp7BQTFikKjLfZd0HEkznBEGePS+ 9uRBgeqWH5lvS/ZVx7UQ374InlnX9h2PJLeu5eHiq/xvA+kvnTnu4MNavIt1FgcjKnz6 F0rr5xo7Enu9wx+Yxy7Lfp721mbqahzsXRmKSmodT5p+M/1Xxd6UIy/WYVlv8lujiHS/ KESFx+qI+HD8xxOZk8WEMDJ4xoS1PFmouYi7W4LT4qYQrNXATql5FzyT0zqJ0gZIamnq Yabnnx7vcSJWP3mqI5zVUs4OZlDlPqeBcL0QwRBhi2MCKS59CXXEq1jUhpH+YeDenX9u yjFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xbN6BYbhg9Tc9GAYch8/jujIr0chTMGn9JipZlla0d0=; b=zglV7H46Rezhh9B2Nm0YALS3P/1kMou6eBSDhzdwYUR8IwbCXMfan2E0zaKvYSR0JA qTXVvMoAyj8w8w2fGxppJ6fePFLRIP1E5BCihDXx/v6eWxMfgfhVkuOaL9Xyn9MKcPIi whHFvDr5jYKj2dEfUOm1sdLxC204r79FC9qFM/2lu7PPyboXBt/1vD+0UjqbkjSywh+v PetzxipQruw4nDoDGMQCTdHH3ZUInKToKfbWQxhbzZTIlmnnwOqGHacukQOYXlIlfDDy weXoUv7AI5/T2aijRe58Usx79p1v/KkmJ4gaZdUyE4TySvaCBSTbSe+j4NUFB60lAJTR qX1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qx3qIYWE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a5-20020a05620a102500b007591e1168cbsi4485424qkk.72.2023.05.23.05.06.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 05:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qx3qIYWE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 = '' return str(self.pos) + ':' + s + str(self.len) - def str_extract(self): + def str_extract(self, lvalue_formatter): global bitop_width s = '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) - def str_extract(self): + def str_extract(self, lvalue_formatter): global bitop_width ret = '0' pos = 0 for f in reversed(self.subs): - ext = f.str_extract() + ext = f.str_extract(lvalue_formatter) if pos == 0: ret = ext else: @@ -264,7 +264,7 @@ def __init__(self, value): def __str__(self): return str(self.value) - def str_extract(self): + def str_extract(self, lvalue_formatter): return str(self.value) def __cmp__(self, other): @@ -283,8 +283,9 @@ def __init__(self, func, base): def __str__(self): return self.func + '(' + str(self.base) + ')' - 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) + ')') def __eq__(self, other): return self.func == other.func and self.base == other.base @@ -304,7 +305,7 @@ def __init__(self, func): def __str__(self): return self.func - def str_extract(self): + def str_extract(self, lvalue_formatter): return self.func + '(ctx)' def __eq__(self, other): @@ -357,6 +358,11 @@ def __str__(self): 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), ' = ', + f.str_extract(lvalue_formatter), ';\n') # end General @@ -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, ' = ', f.str_extract(), ';\n') + self.output_fields(str_indent(4), lambda n: 'a->' + n) output('}\n\n') # end Format @@ -395,8 +400,7 @@ def output_code(self, i, extracted, outerbits, outermask): 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, ' = ', 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') From patchwork Tue May 23 12:04:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 684897 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1674002wrt; Tue, 23 May 2023 05:05:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XP5jrRFrYHoyijxhsBiIVY/aeiNzH8pDWkHbMKS2iTfX4h9Ftd0FYouzzVc6ijJpjAxC1 X-Received: by 2002:a37:7c6:0:b0:75b:23a1:8e73 with SMTP id 189-20020a3707c6000000b0075b23a18e73mr3519835qkh.68.1684843534961; Tue, 23 May 2023 05:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843534; cv=none; d=google.com; s=arc-20160816; b=m43I5QoZrcJO8GCScT04ue49leOyRFf/nkCJPXM4okZ4Agj72JSQDwvy10C2yeeYZB W9sauwFouBaBBaBNv7xl3TcPUFnQbZBp4C29Gmz6DnNUeQA+R7E+pFQ7qqGpvhL6ylMP RT6qrh6few/pAAzXXmBOTsS+Ry7Tz+CZ4+poDSotLEsQEFL9OtynCgM0Cn7BdBYwUfiJ aHS8k7y0WHkONfqKHcZzN7pLRuUeosBuK4UwEhnVBCTCYhVbkcvEvnNWcgkA5559FrDU zgvLy0/eJbNKfVvBb92+lyon08qC6nepHBn8kNsEZk3Nx1mGZmfmJYWuSgSgDtHC5ffx yVdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CP4iW2arzPiOFlsv2K+bA4KJE/pPkFARYRAohYFYWwc=; b=vVii5qJf0D3IaioTHhoL6brwl2stuvSLl/c3a8FgzFElyS6fSxPZacTUVdvXfm16ZO hTyaOgkjTBNMCqyEtHHibFqN3Fx2LqLt5idNFZka1JBG3PgsFNLY42U/P9a1DU0Uekde 6HVLhu/Izov7Hv1PNS72UnC7Ud7NWjp3ZlJ1ZIk5mVk258/rjImzN2PmxXc9zQkqeRcj Lk7qUClnL82W0OWQRHNhJ4q5+NSFR2+5VedxQLysUuxOkpoLNzhyC6azLrVbNrSMe/At 3h71dhGcWwdBU/5aT9GrydqZjT4AsLOfDQaM6OazrZpJLZ/tFog1CQJe2WB7OKoVvIeK aH2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="DfQW+/OP"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c2-20020a05620a134200b0075b0f1e7505si2914933qkl.26.2023.05.23.05.05.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 05:05:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="DfQW+/OP"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 = '@[a-zA-Z0-9_]*' re_pat_ident = '[a-zA-Z0-9_]*' +# 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.TopologicalSorter +# +# We only implement the parts of TopologicalSorter we care about: +# ts = TopologicalSorter(graph=None) +# 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=None): + self.graph = graph + + def static_order(self): + # We do the sort right here, unlike the stdlib version + from functools import reduce + data = {} + r = [] + + 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] = set(v) + + # Find all items that don't depend on anything. + extra_items_in_deps = (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 = set(item for item, dep in data.items() if not dep) + if not ordered: + break + r.extend(ordered) + data = {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 From patchwork Tue May 23 12:04:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 684901 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1674344wrt; Tue, 23 May 2023 05:06:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63jac/ClXv9ZvokzTXRqIYIgf7KOIBxBivO2bY3xexWCzPYKUBsyPiFLY0iS4/3Ei9CI7W X-Received: by 2002:a05:620a:8297:b0:75b:23a1:830a with SMTP id ox23-20020a05620a829700b0075b23a1830amr3524706qkn.5.1684843571909; Tue, 23 May 2023 05:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843571; cv=none; d=google.com; s=arc-20160816; b=sC1VnlijRPa11jragJZ0a0PvTyFHy6mSoh5OgdaLSK1RUdDa5Gq0ZsW9UrgEoRemWd 0pkRZnLv4yjz9KS+0XOQWmoczsVDNQBBnbwbuLcCre66TXdYSWw+MQsik5VzKOm4Dy9X +VrblXAzsOG4xZFsawnEQGMqjRjmRpViSlZBqUjmXz5q+V3tMJe7ritwZin57OsiJVP6 c6cDvvAxtddDwCVceJ08trrblw8Yn/OUrCsLRgWbFFjYLf2z44dqWemM01WjlJNl+IbD CM3lBhlFGsFdzrafyRbQpS+xdObq8ItrGwR5hVmzJtO7Rr7v0IwPN0xB3pf2THQbvvDD Tk1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FK0kwEu4kzUizKTcdb7b9atTVcQCpq+2RRFxmoaG+cE=; b=fl7RB4euOZkcFtDdYcn9oaFlBsZ+Wkt/W6qP5MYhHrmx4rXz2ViGnJSHr5w0n9aSnj TS4Cg+khQnjHpQrBKQ0npBXEaH2yFYifzdj7Vj9VufBicbBQaNMPqqIWvVvOFBk3txwJ 0kgIpCXto1kT5cu5ZS+7bm0/izOMxZ+l7zvM8zSTxCfbIhnyQxjg8tDwdlmQCk/+UlDt bbG0cqTSyDlANGwsdTsHaJsdDChdpy06fa737lCtnrTbNMzB5ZALCYa5yWkjh85l4Qho P9tR2bCfClf2DwziB2HJjb5QAlDypAGgTNpTmXIMLEGezevSJIYBjEkqisWVEpqsLi6G RqiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OmcTKVpO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o19-20020a05620a131300b0074a28c33df9si4656908qkj.618.2023.05.23.05.06.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 05:06:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OmcTKVpO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 = 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 = 's' if self.sign else '' return f'{s}extract{bitop_width}(insn, {self.pos}, {self.len})' + def referenced_fields(self): + return [] + def __eq__(self, other): return self.sign == other.sign and self.mask == other.mask @@ -315,6 +318,12 @@ def str_extract(self, lvalue_formatter): pos += f.len return ret + def referenced_fields(self): + l = [] + for f in self.subs: + l.extend(f.referenced_fields()) + return l + def __ne__(self, other): if len(self.subs) != len(other.subs): return True @@ -341,6 +350,9 @@ def __str__(self): def str_extract(self, lvalue_formatter): return str(self.value) + 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) + ')') + def referenced_fields(self): + return self.base.referenced_fields() + def __eq__(self, other): return self.func == other.func and self.base == other.base @@ -382,6 +397,9 @@ def __str__(self): def str_extract(self, lvalue_formatter): return self.func + '(ctx)' + def referenced_fields(self): + return [] + def __eq__(self, other): return self.func == other.func @@ -389,6 +407,32 @@ def __ne__(self, other): return not self.__eq__(other) # end ParameterField +class NamedField: + """Class representing a field already named in the pattern""" + def __init__(self, name, sign, len): + self.mask = 0 + self.sign = sign + self.len = len + self.name = name + + def __str__(self): + return self.name + + def str_extract(self, lvalue_formatter): + global bitop_width + s = 's' if self.sign else '' + lvalue = 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 == other.name + + def __ne__(self, other): + return not self.__eq__(other) +# end NamedField 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 - 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 = fldm self.fields = flds self.width = w + self.dangling = None def __str__(self): return self.name + ' ' + str_match_bits(self.fixedbits, self.fixedmask) @@ -433,10 +477,51 @@ def __str__(self): def str1(self, i): return str_indent(i) + self.__str__() + 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 = [] + for n, f in self.fields.items(): + for r in f.referenced_fields(): + if r not in self.fields: + dangling.append(r) + self.dangling = 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 = {} for n, f in self.fields.items(): - output(indent, lvalue_formatter(n), ' = ', - f.str_extract(lvalue_formatter), ';\n') + refs = f.referenced_fields() + graph[n] = refs + + try: + ts = 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 = self.fields[n] + output(indent, lvalue_formatter(n), ' = ', + 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 = ' => '.join(e.args[1]) + error(self.lineno, 'field definitions form a cycle: ' + cycle) # end General @@ -471,10 +556,36 @@ def output_code(self, i, extracted, outerbits, outermask): ind = str_indent(i) arg = 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 fields + # for the format before or after the ones for the pattern. + # For simplicity we don't allow cross references in both directions. + # This is also where we catch the syntax error of referring to + # a nonexistent field. + fmt_refs = 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 = 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 format ' + 'cannot use format that uses fields defined ' + '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 extracted" 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') @@ -614,8 +725,10 @@ def output_code(self, i, extracted, outerbits, outermask): ind = str_indent(i) # 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_references(): output(ind, self.base.extract_name(), '(ctx, &u.f_', self.base.base.name, ', insn);\n') extracted = 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 # A "simple" field will have only one entry; # a "multifield" will have several. @@ -751,6 +865,25 @@ def parse_field(lineno, name, toks): func = func[1] continue + if re.fullmatch(re_C_ident + ':s[0-9]+', t): + # Signed named field + subtoks = t.split(':') + n = subtoks[0] + le = int(subtoks[1]) + f = NamedField(n, True, le) + subs.append(f) + width += le + continue + if re.fullmatch(re_C_ident + ':[0-9]+', t): + # Unsigned named field + subtoks = t.split(':') + n = subtoks[0] + le = int(subtoks[1]) + f = NamedField(n, False, le) + subs.append(f) + width += le + continue + if re.fullmatch('[0-9]+:s[0-9]+', t): # Signed field extract subtoks = t.split(':s') From patchwork Tue May 23 12:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 684900 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1674204wrt; Tue, 23 May 2023 05:05:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6PxQkDt36j+7mmyCUWV1n3d4p7x/GLXiyk4yWiFx4uLfXVzqMNRbIidyptinPmR8h3TsOe X-Received: by 2002:ac8:5996:0:b0:3f3:95b9:6bc9 with SMTP id e22-20020ac85996000000b003f395b96bc9mr22554245qte.50.1684843558430; Tue, 23 May 2023 05:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684843558; cv=none; d=google.com; s=arc-20160816; b=XF8FnGXpzYJ6zRmXQpaRp2XToBuoXf3CzJDD9aXb47XdqpLnH13u1lkAW/H/6agx9W sV6l7zpP6hhMF79RH5BsOqcr8RwxRs9AetNrTGJYIv57B9TY+kRIul9VAcHcbWWZ6lIv C6daLPtxcYmWFhmDme3JcTaTNp66J0moyOFM7x4Ohvbro00Q5Q5x5N1Ayf1sPzApV7CK jVqmFlZ5aFCM1QuojabxTgMlZPmwuDVOPckW6avkBHSge8bOhA50m01u067fA5ez0xmk gUKadvA7jH2prVQrerFakgvgy/8Ng08fsqkXG1K5W8JpOliajchxWKKDF76bjyxWtepR IVsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gB3R2llxQU+c9Ja3BYRkfIk0uQTzezpbeFI9jfQINrc=; b=WbQLPo544kfFx/QJISizR087NJx5KD3b0hL5Qfd+iLhm1uEh8mKD92lEAoUNF1vO1r glTeUR/NQIYh8wk8pGUH2/Dnweaa+JDEmBkQ1+yIEGP6vSJPNXGpFVah2peCrrY/skHj 9I992qDfRfi5o2DEBoMvKfMt5O5lPnY7Uj6exblJwieReEMUc/zG/QNXq/OaULoK57i4 YGoYUxu8WH1Yf7Oj8TJcYWw6qPjxE3xSoHQRPym70eJQUmJSc/+BwizLNTF8/Viksy4Y 2+6rwGuCEpU/gAwdtAC+qybaYk+LABw+8LA4ZvaeOpXBwiEvNoHkS0qDOopJV/+Ba9fT ttVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ESU/2A9F"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c7-20020a05622a058700b003f69394b7e0si4003826qtb.489.2023.05.23.05.05.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 05:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ESU/2A9F"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. # Diagnose invalid field syntax -%field asdf +%field 1asdf diff --git a/tests/decode/err_field10.decode b/tests/decode/err_field10.decode 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 later. +# 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 later. +# 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 later. +# 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=%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 later. +# 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=%refa +# Pattern defines 'a' and sets 'd' to an indirect ref to 'c' +insn 00000000 00000000 00000000 ........ @fmt d=%refc a=6 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 later. +# 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=%imm_sz sz=1 + +# 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=%foo +i1 ........ 00000000 ........ ........ @foo alpha=1 +i2 ........ 00000001 ........ ........ @foo alpha=2 + +# Here the named field is defined in the format and referenced +# from the insn pattern: +@bar 00000010 ........ ........ ........ &imm_a alpha=4 +i3 ........ 00000000 ........ ........ @bar imm=%foo