qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] decodetree: Allow use of hex/bin format for argument field values
@ 2020-12-01 10:34 Philippe Mathieu-Daudé
  2020-12-01 12:31 ` Richard Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-12-01 10:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Philippe Mathieu-Daudé,
	Richard Henderson, Eduardo Habkost, Cleber Rosa

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.

To add support for bin/hex constants in argument field token,
extend the re_num_ident regexp and use '0' as radix base when
parsing the integer (to interpret it as a code literal).

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v2: Fix regexp (Richard)
---
 scripts/decodetree.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index 47aa9caf6d1..c8136073535 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -50,6 +50,7 @@
 re_fld_ident = '%[a-zA-Z0-9_]*'
 re_fmt_ident = '@[a-zA-Z0-9_]*'
 re_pat_ident = '[a-zA-Z0-9_]*'
+re_num_ident = '[+-]?([0-9]+|0x[0-9a-fA-F]+|0b[01]+)'
 
 def error_with_file(file, lineno, *args):
     """Print an error message from file:line and args and exit."""
@@ -849,9 +850,9 @@ 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 + '=' + re_num_ident, t):
             (fname, value) = t.split('=')
-            value = int(value)
+            value = int(value, 0)
             flds = add_field(lineno, flds, fname, ConstField(value))
             continue
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] decodetree: Allow use of hex/bin format for argument field values
  2020-12-01 10:34 [PATCH v2] decodetree: Allow use of hex/bin format for argument field values Philippe Mathieu-Daudé
@ 2020-12-01 12:31 ` Richard Henderson
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2020-12-01 12:31 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Paolo Bonzini, Eduardo Habkost, Cleber Rosa

On 12/1/20 4:34 AM, Philippe Mathieu-Daudé wrote:
> 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.
> 
> To add support for bin/hex constants in argument field token,
> extend the re_num_ident regexp and use '0' as radix base when
> parsing the integer (to interpret it as a code literal).
> 
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v2: Fix regexp (Richard)
> ---
>  scripts/decodetree.py | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/decodetree.py b/scripts/decodetree.py
> index 47aa9caf6d1..c8136073535 100644
> --- a/scripts/decodetree.py
> +++ b/scripts/decodetree.py
> @@ -50,6 +50,7 @@
>  re_fld_ident = '%[a-zA-Z0-9_]*'
>  re_fmt_ident = '@[a-zA-Z0-9_]*'
>  re_pat_ident = '[a-zA-Z0-9_]*'
> +re_num_ident = '[+-]?([0-9]+|0x[0-9a-fA-F]+|0b[01]+)'

re_num or re_number, perhaps -- it's not an identifier.

>          # '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 + '=' + re_num_ident, t):
>              (fname, value) = t.split('=')
> -            value = int(value)
> +            value = int(value, 0)
>              flds = add_field(lineno, flds, fname, ConstField(value))
>              continue

It occurs to me that we don't actually have to interpret this string --
decodetree doesn't do anything with it but pass it along to the generated C
code.  We could in fact accept a re_C_ident as well, to allow symbolic values.
 So long as the symbols are defined before the decode.c.inc file is included.

So perhaps just change ConstField to not expect an integral value, and just
store the string.


r~


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-01 12:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01 10:34 [PATCH v2] decodetree: Allow use of hex/bin format for argument field values Philippe Mathieu-Daudé
2020-12-01 12:31 ` Richard Henderson

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).