qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] decodetree: Allow use of hex/bin format for argument field v


From: Richard Henderson
Subject: Re: [PATCH] decodetree: Allow use of hex/bin format for argument field values
Date: Mon, 30 Nov 2020 12:22:05 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 11/30/20 6:26 AM, Philippe Mathieu-Daudé wrote:
>          # '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

Well, the regxps are off.  No letters for the hex, and 9 accepted for binary.
I think with the right regexps, just trusting int(value, 0) is good enough.

So maybe something like

  re_C_ident + "=[+-]?([0-9]+|0x[0-9a-fA-F]+|0b[01]+)"


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]