From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>
Subject: [PATCH] decodetree: Allow use of hex/bin format for argument field values
Date: Mon, 30 Nov 2020 13:26:39 +0100 [thread overview]
Message-ID: <20201130122639.2431070-1-f4bug@amsat.org> (raw)
ISA datasheets often use binary or hexadecimal constant values.
By doing base conversion, we might introduce bugs. Safer is to
copy/paste the datasheet value.
Add support for bin/hex constants in argument field token.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Is there a more pythonic way to write this if/elif/else
loop without re.fullmatch?
---
scripts/decodetree.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index 47aa9caf6d1..d2ecc61813f 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -849,9 +849,15 @@ def parse_generic(lineno, parent_pat, name, toks):
continue
# 'Foo=number' sets an argument field to a constant value
- if re.fullmatch(re_C_ident + '=[+-]?[0-9]+', t):
+ if re.fullmatch(re_C_ident + '=[+-]?(0[bx])?[0-9]+', t):
(fname, value) = t.split('=')
- value = int(value)
+ if re.fullmatch('[+-]?0b[0-9]+', value):
+ base = 2
+ elif re.fullmatch('[+-]?0x[0-9]+', value):
+ base = 16
+ else:
+ base = 10
+ value = int(value, base)
flds = add_field(lineno, flds, fname, ConstField(value))
continue
--
2.26.2
next reply other threads:[~2020-11-30 12:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-30 12:26 Philippe Mathieu-Daudé [this message]
2020-11-30 12:32 ` [PATCH] decodetree: Allow use of hex/bin format for argument field values Philippe Mathieu-Daudé
2020-11-30 18:22 ` Richard Henderson
2020-12-01 8:47 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201130122639.2431070-1-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).