decodetree: Infer argument set before inferring format

Failure to confirm an argument set first may result in
the selection of a format which leaves extra arguments
to be filled in by the pattern.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20250723165458.3509150-4-peter.maydell@linaro.org
Message-id: 20250722183343.273533-1-richard.henderson@linaro.org
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Richard Henderson 2025-07-23 17:54:55 +01:00 committed by Peter Maydell
parent aba39946ba
commit b79f944e09
3 changed files with 9 additions and 3 deletions

View File

@ -1016,9 +1016,12 @@ def infer_format(arg, fieldmask, flds, width):
else:
var_flds[n] = c
if not arg:
arg = infer_argument_set(flds)
# Look for an existing format with the same argument set and fields
for fmt in formats.values():
if arg and fmt.base != arg:
if fmt.base != arg:
continue
if fieldmask != fmt.fieldmask:
continue
@ -1029,8 +1032,6 @@ def infer_format(arg, fieldmask, flds, width):
return (fmt, const_flds)
name = decode_function + '_Fmt_' + str(len(formats))
if not arg:
arg = infer_argument_set(flds)
fmt = Format(name, 0, arg, 0, 0, 0, fieldmask, var_flds, width)
formats[name] = fmt

View File

@ -41,6 +41,7 @@ succ_tests = [
'succ_argset_type1.decode',
'succ_function.decode',
'succ_ident1.decode',
'succ_infer1.decode',
'succ_named_field.decode',
'succ_pattern_group_nest1.decode',
'succ_pattern_group_nest2.decode',

View File

@ -0,0 +1,4 @@
&rprr_load rd pg rn rm dtype nreg
@rprr_load .... .... ... rm:5 ... pg:3 rn:5 rd:5 &rprr_load
LD1Q 1100 0100 000 rm:5 101 pg:3 rn:5 rd:5