decodetree improvements
v2 cover decodetree improvements
Changes from v1:
* Drop unintended hunk from MultiField constructor.
* Typo fixed in ParameterField documentation.
Blurb from v1:
These are split out from my decodetree coversion of the AArch32 base instruction sets.
The first patch has been tidied per review from Peter. I now diagnose nonsense fields containing no bits. I eliminated the unused integer argument passed to the named function. I improved the documentation.
The second patch is new, a suggestion from Phillipe. This then enables the third patch, tidying up the existing usage in riscv.
r~
Richard Henderson (3):
decodetree: Allow !function with no input bits
decodetree: Suppress redundant declaration warnings target/riscv: Remove redundant declaration pragmas
target/riscv/translate.c | 19 +-------- docs/devel/decodetree.rst | 8 +++- scripts/decodetree.py | 71 ++++++++++++++++++++++++++----- tests/decode/err_field6.decode | 5 +++ tests/decode/succ_function.decode | 6 +++ 5 files changed, 79 insertions(+), 30 deletions(-) create mode 100644 tests/decode/err_field6.decode create mode 100644 tests/decode/succ_function.decode
Signature · 1 line
2.17.1
PATCH v2 1/3 decodetree: Allow !function with no input bits
Call this form a "parameter", returning a value extracted from the DisasContext.
--- docs/devel/decodetree.rst | 8 ++++- scripts/decodetree.py | 49 ++++++++++++++++++++++++------- tests/decode/err_field6.decode | 5 ++++ tests/decode/succ_function.decode | 6 ++++ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 tests/decode/err_field6.decode create mode 100644 tests/decode/succ_function.decode
docs/devel/decodetree.rst +7 -1
@@ -23,7 +23,7 @@ Fields Syntax:: - field_def := '%' identifier ( unnamed_field )+ ( !function=identifier )? + field_def := '%' identifier ( unnamed_field )* ( !function=identifier )? unnamed_field := number ':' ( 's' ) number For *unnamed_field*, the first number is the least-significant bit position
@@ -34,6 +34,12 @@ present, they are concatenated. In this way one can define disjoint fields. If ``!function`` is specified, the concatenated result is passed through the named function, taking and returning an integral value. +One may use ``!function`` with zero ``unnamed_fields``. This case is called +a *parameter*, and the named function is only passed the ``DisasContext`` +and returns an integral value extracted from there. + +A field with no ``unnamed_fields`` and no ``!function`` is in error. + 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.
scripts/decodetree.py +38 -11
68 lines not on this page · raw message
tests/decode/err_field6.decode new file +5 -0
@@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose no bits in field +%field
tests/decode/succ_function.decode new file +6 -0
@@ -0,0 +1,6 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# "Field" as parameter pulled from DisasContext. +%foo !function=foo +foo 00000000000000000000000000000000 %foo
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 1/3] decodetree: Allow !function with no input bits
Quoted 65 lines · Richard Henderson
Call this form a "parameter", returning a value extracted from the DisasContext.
Signed-off-by Richard Henderson <[email protected]>--- docs/devel/decodetree.rst | 8 ++++- scripts/decodetree.py | 49 ++++++++++++++++++++++++------- tests/decode/err_field6.decode | 5 ++++ tests/decode/succ_function.decode | 6 ++++ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 tests/decode/err_field6.decode create mode 100644 tests/decode/succ_function.decodedocs/devel/decodetree.rst +7
-1@@ -23,7 +23,7 @@ Fields Syntax:: - field_def := '%' identifier ( unnamed_field )+ ( !function=identifier )? + field_def := '%' identifier ( unnamed_field )* ( !function=identifier )? unnamed_field := number ':' ( 's' ) number For *unnamed_field*, the first number is the least-significant bit position@@ -34,6 +34,12 @@ present, they are concatenated. In this way one can define disjoint fields. If ``!function`` is specified, the concatenated result is passed through the named function, taking and returning an integral value. +One may use ``!function`` with zero ``unnamed_fields``. This case is called +a *parameter*, and the named function is only passed the ``DisasContext`` +and returns an integral value extracted from there. + +A field with no ``unnamed_fields`` and no ``!function`` is in error. + 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.scripts/decodetree.py +10
-1@@ -245,7 +245,7 @@ class ConstField: class FunctionField: - """Class representing a field passed through an expander""" + """Class representing a field passed through a function""" def __init__(self, func, base): self.mask = base.mask self.sign = base.sign@@ -266,6 +266,27 @@ class FunctionField: # end FunctionField +class ParameterField: + """Class representing a pseudo-field read from a function""" + def __init__(self, func): + self.mask = 0 + self.sign = 0 + self.func = func + + def __str__(self): + return self.func
scripts/decodetree.py class FunctionField: · line 287
Quoted 10 lines
scripts/decodetree.py +10
-0+ + def str_extract(self): + return self.func + '(ctx)' + + def __eq__(self, other): + return self.func == other.func + + def __ne__(self, other): + return not self.__eq__(other) +# end FunctionField
Nit: end ParameterField
Quoted 57 lines
scripts/decodetree.py +18
-10+ + class Arguments: """Class representing the extracted fields of a format""" def __init__(self, nm, flds, extern):@@ -433,17 +454,23 @@ def parse_field(lineno, name, toks): if width > insnwidth: error(lineno, 'field too large') - if len(subs) == 1: - f = subs[0] + if len(subs) == 0: + if func: + f = ParameterField(func) + else: + error(lineno, 'field with no value') else: - mask = 0 - for s in subs: - if mask & s.mask: - error(lineno, 'field components overlap') - mask |= s.mask - f = MultiField(subs, mask) - if func: - f = FunctionField(func, f) + if len(subs) == 1: + f = subs[0] + else: + mask = 0 + for s in subs: + if mask & s.mask: + error(lineno, 'field components overlap') + mask |= s.mask + f = MultiField(subs, mask) + if func: + f = FunctionField(func, f) if name in fields: error(lineno, 'duplicate field', name)tests/decode/err_field6.decode new file +5
-0@@ -0,0 +1,5 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# Diagnose no bits in field +%fieldtests/decode/succ_function.decode new file +0
-0
tests/decode/succ_function.decode line 6
Quoted 6 lines
tests/decode/succ_function.decode new file +6
-0@@ -0,0 +1,6 @@ +# This work is licensed under the terms of the GNU LGPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +# "Field" as parameter pulled from DisasContext. +%foo !function=foo +foo 00000000000000000000000000000000 %foo
PATCH v2 2/3 decodetree: Suppress redundant declaration warnings
In reply to Richard HendersonWe can tell that a decodetree input file is "secondary" when it uses an argument set marked "!extern". This indicates that at least one of the insn translation functions will have already been declared by the "primary" input file, but given only the secondary we cannot tell which.
Avoid redundant declaration warnings by suppressing them with pragmas.
--- scripts/decodetree.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
scripts/decodetree.py +22 -0
@@ -33,6 +33,7 @@ arguments = {} formats = {} patterns = [] allpatterns = [] +anyextern = False translate_prefix = 'trans' translate_scope = 'static '
@@ -482,12 +483,14 @@ def parse_arguments(lineno, name, toks): """Parse one argument set from TOKS at LINENO""" global arguments global re_ident + global anyextern flds = [] extern = False for t in toks: if re_fullmatch('!extern', t): extern = True + anyextern = True continue if not re_fullmatch(re_ident, t): error(lineno, 'invalid argument set token "{0}"'.format(t))
@@ -1188,6 +1191,7 @@ def main(): global insnmask global decode_function global variablewidth + global anyextern decode_scope = 'static '
@@ -1248,6 +1252,19 @@ def main(): # A single translate function can be invoked for different patterns. # Make sure that the argument sets are the same, and declare the # function only once. + # + # If we're sharing formats, we're likely also sharing trans_* functions, + # but we can't tell which ones. Prevent issues from the compiler by + # suppressing redundant declaration warnings. + if anyextern: + output("#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE\n", + "# pragma GCC diagnostic push\n", + "# pragma GCC diagnostic ignored \"-Wredundant-decls\"\n", + "# ifdef __clang__\n" + "# pragma GCC diagnostic ignored \"-Wtypedef-redefinition\"\n", + "# endif\n", + "#endif\n\n") + out_pats = {} for i in allpatterns: if i.name in out_pats:
@@ -1259,6 +1276,11 @@ def main(): out_pats[i.name] = i output('\n') + if anyextern: + output("#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE\n", + "# pragma GCC diagnostic pop\n", + "#endif\n\n") + for n in sorted(formats.keys()): f = formats[n] f.output_extract()
Signature · 1 line
2.17.1
PATCH v2 3/3 target/riscv: Remove redundant declaration pragmas
In reply to Richard HendersonThese are now generated by decodetree itself.
--- target/riscv/translate.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
target/riscv/translate.c +1 -18
@@ -708,26 +708,9 @@ static bool gen_shift(DisasContext *ctx, arg_r *a,#include "insn_trans/trans_rvd.inc.c" #include "insn_trans/trans_privileged.inc.c" -/* -* Auto-generated decoder. -* Note that the 16-bit decoder reuses some of the trans_* functions -* initially declared by the 32-bit decoder, which results in duplicate -* declaration warnings. Suppress them. -*/ -#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wredundant-decls" -# ifdef __clang__ -# pragma GCC diagnostic ignored "-Wtypedef-redefinition" -# endif -#endif - +/* Include the auto-generated decoder for 16 bit insn */ #include "decode_insn16.inc.c" -#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic pop -#endif -static void decode_opc (DisasContext *ctx) {/* check for compressed insn */
Signature · 1 line
2.17.1