From nobody Thu Dec 18 17:54:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619896004; cv=none; d=zohomail.com; s=zohoarc; b=TaswWtYwrnp3+E8uaWCJ+7SKFOKLITbI45/dXf4/veyEJZcMIFO/S+m+AonJ062GtTOebT/Y0wKUuo4kUY2LQYVGX4VOmJMqQMnHVT9UuTEgxeJjXNVMjintuPn7CSKSk2CehvGt/KANVaPJDAIZcZY3ExMlkKXsKLZ1C92qhEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619896004; 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=R/1WAzyuseBP9GbYXdpEWnL72IgMjHrQD+B+K1Ph/uk=; b=VXixKpR3UWnSxaP4PoHlWMCtC/fjQxyIIw/sbx+1umkUcy5jNtNgl7c+wHujoE3KfQ6B8yahCSyu7ZwdI608GZVJW+SH2geIc73koGgb3Om3uySLxAQPfzRtypGAKPt5KtwT60RNwqw8U9MDUNH9u6XYTKlT9tb4UdFbynk91v0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619896004045315.6182706468634; Sat, 1 May 2021 12:06:44 -0700 (PDT) Received: from localhost ([::1]:50634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcuws-00046E-Vj for importer@patchew.org; Sat, 01 May 2021 15:06:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcui4-0006Vf-KY for qemu-devel@nongnu.org; Sat, 01 May 2021 14:51:25 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:35447) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lcui2-0003mo-8Z for qemu-devel@nongnu.org; Sat, 01 May 2021 14:51:24 -0400 Received: by mail-pj1-x1030.google.com with SMTP id h14-20020a17090aea8eb02901553e1cc649so3490484pjz.0 for ; Sat, 01 May 2021 11:51:21 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm4971360pfa.68.2021.05.01.11.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 May 2021 11:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R/1WAzyuseBP9GbYXdpEWnL72IgMjHrQD+B+K1Ph/uk=; b=pJA3V8F2rPLHHbx8f3/7AxDF6BvlNE41+Ix+Sy7ORAqkpwrGpf6HiCtvimGcF+dkn9 KYx+dM4d6w0FuEohB4z8/xX1Cx3TDYmae7B+sf4wwEJGq9ZglcIkwvB9+zKlqHHjGLLq 8zg207W8c+WD5E1hp5FTrmhA6AF3mQlqVdF65ydW+wiqTHIq+e1+mL+bWrb+6raKjaD9 adGGQtUJXqt0UfmjM58tFwHgfzKOxF1vx+XEIvtci+fkr9qBTsM0xcsYzMMfQ268wSnD KQ/Z/VfmiQZYsq1OXaNt5FPgOk9D7ovf4LesveFlVpKrkqBvzmenzubAZAm40i43EZ0x QzUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R/1WAzyuseBP9GbYXdpEWnL72IgMjHrQD+B+K1Ph/uk=; b=tLQUfmYjALO0aFwmzUiqpaKTh1QlWhin8JbTzXRyUxbascNKCNhfK+FZVmzLvq/ozm ZIwPiRQ7bHhLNLWaFPylXARenf0CkoWUuFwDN3xR1cZaLEI9ZuxWtbITncdos8goSBW7 L+B46tVNAS7nVv63C9AwhiCYL6JEmMN9SLSv15AfZzuWO/dCTDkBX+bh7Ah2b4nuQHI+ KDVPoyVMkbGvat7hzuWGrE/1Dp58GB7ASgslaDeDbQtsrU4GomVkeiR3qv8KkCU/2hdh 0j7Yt0cXjXHiQbbtT2BLNF7FYfGGU7KKt0RWfU+UxbhhR0ehOBZwUiql7jQb7L5ZGO6h CVLA== X-Gm-Message-State: AOAM532Tl+DOLjuK1rjjUnVScgnSxUquDEbeNEfDdkQvRwqcMIICJrLI 6TlSlmD24YTcLECsT7ol1CEqWlMQNtdYTw== X-Google-Smtp-Source: ABdhPJyFsu9BIBLWGIZ6J/YEs5xduLANF1U50kk77a+KyKgIb3saBL3E26xREQwJ8DPQYXgfXQl8qA== X-Received: by 2002:a17:902:9693:b029:ee:851f:22e1 with SMTP id n19-20020a1709029693b02900ee851f22e1mr11348011plp.79.1619895080945; Sat, 01 May 2021 11:51:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 5/5] decodetree: Extend argument set syntax to allow types Date: Sat, 1 May 2021 11:51:16 -0700 Message-Id: <20210501185116.1338875-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210501185116.1338875-1-richard.henderson@linaro.org> References: <20210501185116.1338875-1-richard.henderson@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=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Luis Pires Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Rather than force all structure members to be 'int', allow the type of the member to be specified. Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- docs/devel/decodetree.rst | 11 ++++--- tests/decode/succ_argset_type1.decode | 1 + scripts/decodetree.py | 45 +++++++++++++++++---------- 3 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 tests/decode/succ_argset_type1.decode diff --git a/docs/devel/decodetree.rst b/docs/devel/decodetree.rst index 74f66bf46e..49ea50c2a7 100644 --- a/docs/devel/decodetree.rst +++ b/docs/devel/decodetree.rst @@ -40,9 +40,6 @@ and returns an integral value extracted from there. =20 A field with no ``unnamed_fields`` and no ``!function`` is in error. =20 -FIXME: the fields of the structure into which this result will be stored -is restricted to ``int``. Which means that we cannot expand 64-bit items. - Field examples: =20 +---------------------------+---------------------------------------------+ @@ -66,9 +63,14 @@ Argument Sets Syntax:: =20 args_def :=3D '&' identifier ( args_elt )+ ( !extern )? - args_elt :=3D identifier + args_elt :=3D identifier (':' identifier)? =20 Each *args_elt* defines an argument within the argument set. +If the form of the *args_elt* contains a colon, the first +identifier is the argument name and the second identifier is +the argument type. If the colon is missing, the argument +type will be ``int``. + Each argument set will be rendered as a C structure "arg_$name" with each of the fields being one of the member arguments. =20 @@ -86,6 +88,7 @@ Argument set examples:: =20 ®3 ra rb rc &loadstore reg base offset + &longldst reg base offset:int64_t =20 =20 Formats diff --git a/tests/decode/succ_argset_type1.decode b/tests/decode/succ_args= et_type1.decode new file mode 100644 index 0000000000..ed946b420d --- /dev/null +++ b/tests/decode/succ_argset_type1.decode @@ -0,0 +1 @@ +&asdf b:bool c:uint64_t a diff --git a/scripts/decodetree.py b/scripts/decodetree.py index f85da45ee3..a03dc6b5e3 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -165,11 +165,15 @@ def is_contiguous(bits): return -1 =20 =20 -def eq_fields_for_args(flds_a, flds_b): - if len(flds_a) !=3D len(flds_b): +def eq_fields_for_args(flds_a, arg): + if len(flds_a) !=3D len(arg.fields): return False + # Only allow inference on default types + for t in arg.types: + if t !=3D 'int': + return False for k, a in flds_a.items(): - if k not in flds_b: + if k not in arg.fields: return False return True =20 @@ -313,10 +317,11 @@ def __ne__(self, other): =20 class Arguments: """Class representing the extracted fields of a format""" - def __init__(self, nm, flds, extern): + def __init__(self, nm, flds, types, extern): self.name =3D nm self.extern =3D extern - self.fields =3D sorted(flds) + self.fields =3D flds + self.types =3D types =20 def __str__(self): return self.name + ' ' + str(self.fields) @@ -327,8 +332,8 @@ def struct_name(self): def output_def(self): if not self.extern: output('typedef struct {\n') - for n in self.fields: - output(' int ', n, ';\n') + for (n, t) in zip(self.fields, self.types): + output(f' {t} {n};\n') output('} ', self.struct_name(), ';\n\n') # end Arguments =20 @@ -719,21 +724,27 @@ def parse_arguments(lineno, name, toks): global anyextern =20 flds =3D [] + types =3D [] extern =3D False - for t in toks: - if re.fullmatch('!extern', t): + for n in toks: + if re.fullmatch('!extern', n): extern =3D True anyextern =3D True continue - if not re.fullmatch(re_C_ident, t): - error(lineno, f'invalid argument set token "{t}"') - if t in flds: - error(lineno, f'duplicate argument "{t}"') - flds.append(t) + if re.fullmatch(re_C_ident + ':' + re_C_ident, n): + (n, t) =3D n.split(':') + elif re.fullmatch(re_C_ident, n): + t =3D 'int' + else: + error(lineno, f'invalid argument set token "{n}"') + if n in flds: + error(lineno, f'duplicate argument "{n}"') + flds.append(n) + types.append(t) =20 if name in arguments: error(lineno, 'duplicate argument set', name) - arguments[name] =3D Arguments(name, flds, extern) + arguments[name] =3D Arguments(name, flds, types, extern) # end parse_arguments =20 =20 @@ -760,11 +771,11 @@ def infer_argument_set(flds): global decode_function =20 for arg in arguments.values(): - if eq_fields_for_args(flds, arg.fields): + if eq_fields_for_args(flds, arg): return arg =20 name =3D decode_function + str(len(arguments)) - arg =3D Arguments(name, flds.keys(), False) + arg =3D Arguments(name, flds.keys(), ['int'] * len(flds), False) arguments[name] =3D arg return arg =20 --=20 2.25.1