decodetree improvements
cover decodetree improvements
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 | 76 ++++++++++++++++++++++++++----- tests/decode/err_field6.decode | 5 ++ tests/decode/succ_function.decode | 6 +++ 5 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 tests/decode/err_field6.decode create mode 100644 tests/decode/succ_function.decode
Signature · 1 line
2.17.1
PATCH 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 | 54 ++++++++++++++++++++++++------- tests/decode/err_field6.decode | 5 +++ tests/decode/succ_function.decode | 6 ++++ 4 files changed, 60 insertions(+), 13 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 +42 -12
79 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-arm] [PATCH 1/3] decodetree: Allow !function with no input bits
Quoted 46 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 | 54 ++++++++++++++++++++++++------- tests/decode/err_field6.decode | 5 +++ tests/decode/succ_function.decode | 6 ++++ 4 files changed, 60 insertions(+), 13 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 +0
-0@@ -195,7 +195,10 @@ class MultiField: """Class representing a compound instruction field"""
scripts/decodetree.py class MultiField: · line 204
Quoted 10 lines
scripts/decodetree.py +4
-1def __init__(self, subs, mask): self.subs = subs - self.sign = subs[0].sign + if len(subs): + self.sign = subs[0].sign + else: + self.sign = 0 self.mask = mask def __str__(self):
Is this change to MultiField left over from the previous implementation ? I was expecting a zero-length MultiField to now be a bug in this python script (ie we should never try to create one).
Quoted 10 lines
scripts/decodetree.py +1
-1@@ -245,7 +248,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
scripts/decodetree.py class FunctionField: · line 273
Quoted 5 lines
scripts/decodetree.py +2
-0@@ -266,6 +269,27 @@ class FunctionField: # end FunctionField +class ParameterField: + """Class representing a psuedo-field read from a function"""
"pseudo"
Quoted 8 lines
scripts/decodetree.py +8
-0+ def __init__(self, func): + self.mask = 0 + self.sign = 0 + self.func = func + + def __str__(self): + return self.func +
scripts/decodetree.py class FunctionField:
Quoted 10 lines
scripts/decodetree.py +9
-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
thanks
-- PMM
Re: [Qemu-arm] [PATCH 1/3] decodetree: Allow !function with no input bits
Quoted 11 lines · Peter Maydell
Quoted 11 lines
scripts/decodetree.py +4
-1@@ -195,7 +195,10 @@ class MultiField: """Class representing a compound instruction field""" def __init__(self, subs, mask): self.subs = subs - self.sign = subs[0].sign + if len(subs): + self.sign = subs[0].sign + else: + self.sign = 0 self.mask = mask
Quoted 6 lines
scripts/decodetree.py class MultiField: · line 204
Quoted 1 line
scripts/decodetree.py +0
-0def __str__(self):Is this change to MultiField left over from the previous implementation ? I was expecting a zero-length MultiField to now be a bug in this python script (ie we should never try to create one).
Oops, yes.
The error is emitted here:
scripts/decodetree.py def parse_field(lineno, name, toks): · line 464
Quoted 5 lines
scripts/decodetree.py +5
-0+ if len(subs) == 0: + if func: + f = ParameterField(func) + else: + error(lineno, 'field with no value')
and tested:
Quoted 7 lines
+++ b/tests/decode/err_field6.decode
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
PATCH 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 '
@@ -485,12 +486,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))
@@ -1191,6 +1194,7 @@ def main(): global insnmask global decode_function global variablewidth + global anyextern decode_scope = 'static '
@@ -1251,6 +1255,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:
@@ -1262,6 +1279,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
Re: [Qemu-devel] [PATCH 2/3] decodetree: Suppress redundant declaration warnings
Quoted 7 lines · Richard Henderson
We 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.
That was quick, thanks!
Quoted 1 line
Signed-off-by Richard Henderson <[email protected]>
Quoted 72 lines
--- 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 '@@ -485,12 +486,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))@@ -1191,6 +1194,7 @@ def main(): global insnmask global decode_function global variablewidth + global anyextern decode_scope = 'static '@@ -1251,6 +1255,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:@@ -1262,6 +1279,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()
Re: [Qemu-arm] [Qemu-devel] [PATCH 2/3] decodetree: Suppress redundant declaration warnings
In reply to Richard HendersonQuoted 10 lines · Richard Henderson
We 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.
Signed-off-by Richard Henderson <[email protected]>
Alistair
Quoted 75 lines
--- scripts/decodetree.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)scripts/decodetree.py +22
-1@@ -33,6 +33,7 @@ arguments = {} formats = {} patterns = [] allpatterns = [] +anyextern = False translate_prefix = 'trans' translate_scope = 'static '@@ -485,12 +486,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))@@ -1191,6 +1194,7 @@ def main(): global insnmask global decode_function global variablewidth + global anyextern decode_scope = 'static '@@ -1251,6 +1255,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:@@ -1262,6 +1279,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() --2.17.1
PATCH 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
Re: [Qemu-arm] [PATCH 3/3] target/riscv: Remove redundant declaration pragmas
Quoted 3 lines · Richard Henderson
These are now generated by decodetree itself.
Signed-off-by Richard Henderson <[email protected]>
Quoted 37 lines
--- 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 */
Re: [Qemu-devel] [PATCH 3/3] target/riscv: Remove redundant declaration pragmas
In reply to Richard HendersonQuoted 29 lines · On Fri, 09 Aug 2019 08:41:53 PDT (-0700), [email protected] wrote:
These are now generated by decodetree itself.
Signed-off-by Richard Henderson <[email protected]>--- target/riscv/translate.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)target/riscv/translate.c +0
-14@@ -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 -
target/riscv/translate.c static bool gen_shift(DisasContext *ctx, arg_r *a, · line 716
Quoted 10 lines
target/riscv/translate.c +1
-4+/* 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 */
I assume you're taking this along with the rest though your tree.
Re: [Qemu-arm] [Qemu-devel] [PATCH 3/3] target/riscv: Remove redundant declaration pragmas
Quoted 3 lines · Palmer Dabbelt
Acked-by Palmer Dabbelt <[email protected]>I assume you're taking this along with the rest though your tree.
Yes, that was my plan.
r~
Re: [Qemu-arm] [Qemu-devel] [PATCH 3/3] target/riscv: Remove redundant declaration pragmas
In reply to Richard HendersonQuoted 4 lines · Richard Henderson
These are now generated by decodetree itself.
Signed-off-by Richard Henderson <[email protected]>
Alistair
Quoted 40 lines
--- target/riscv/translate.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)target/riscv/translate.c +1
-19@@ -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 */ --2.17.1