From: Richard Henderson <richard.henderson@linaro.org> To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Alistair.Francis@wdc.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, philmd@redhat.com Subject: [Qemu-devel] [PATCH 1/3] decodetree: Allow !function with no input bits Date: Fri, 9 Aug 2019 08:41:51 -0700 [thread overview] Message-ID: <20190809154153.31763-2-richard.henderson@linaro.org> (raw) In-Reply-To: <20190809154153.31763-1-richard.henderson@linaro.org> Call this form a "parameter", returning a value extracted from the DisasContext. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- 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 diff --git a/docs/devel/decodetree.rst b/docs/devel/decodetree.rst index 44ac621ea8..ce7f52308f 100644 --- a/docs/devel/decodetree.rst +++ b/docs/devel/decodetree.rst @@ -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. diff --git a/scripts/decodetree.py b/scripts/decodetree.py index d7a59d63ac..a2490aeb74 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -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 def __str__(self): @@ -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 @@ -266,6 +269,27 @@ class FunctionField: # end FunctionField +class ParameterField: + """Class representing a psuedo-field read from a function""" + def __init__(self, func): + self.mask = 0 + self.sign = 0 + self.func = func + + def __str__(self): + return self.func + + 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 + + class Arguments: """Class representing the extracted fields of a format""" def __init__(self, nm, flds, extern): @@ -433,17 +457,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) diff --git a/tests/decode/err_field6.decode b/tests/decode/err_field6.decode new file mode 100644 index 0000000000..a719884572 --- /dev/null +++ b/tests/decode/err_field6.decode @@ -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 diff --git a/tests/decode/succ_function.decode b/tests/decode/succ_function.decode new file mode 100644 index 0000000000..7751b1784e --- /dev/null +++ b/tests/decode/succ_function.decode @@ -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 -- 2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Richard Henderson <richard.henderson@linaro.org> To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-riscv@nongnu.org, peter.maydell@linaro.org, philmd@redhat.com, Alistair.Francis@wdc.com Subject: [Qemu-riscv] [PATCH 1/3] decodetree: Allow !function with no input bits Date: Fri, 9 Aug 2019 08:41:51 -0700 [thread overview] Message-ID: <20190809154153.31763-2-richard.henderson@linaro.org> (raw) In-Reply-To: <20190809154153.31763-1-richard.henderson@linaro.org> Call this form a "parameter", returning a value extracted from the DisasContext. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- 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 diff --git a/docs/devel/decodetree.rst b/docs/devel/decodetree.rst index 44ac621ea8..ce7f52308f 100644 --- a/docs/devel/decodetree.rst +++ b/docs/devel/decodetree.rst @@ -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. diff --git a/scripts/decodetree.py b/scripts/decodetree.py index d7a59d63ac..a2490aeb74 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -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 def __str__(self): @@ -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 @@ -266,6 +269,27 @@ class FunctionField: # end FunctionField +class ParameterField: + """Class representing a psuedo-field read from a function""" + def __init__(self, func): + self.mask = 0 + self.sign = 0 + self.func = func + + def __str__(self): + return self.func + + 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 + + class Arguments: """Class representing the extracted fields of a format""" def __init__(self, nm, flds, extern): @@ -433,17 +457,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) diff --git a/tests/decode/err_field6.decode b/tests/decode/err_field6.decode new file mode 100644 index 0000000000..a719884572 --- /dev/null +++ b/tests/decode/err_field6.decode @@ -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 diff --git a/tests/decode/succ_function.decode b/tests/decode/succ_function.decode new file mode 100644 index 0000000000..7751b1784e --- /dev/null +++ b/tests/decode/succ_function.decode @@ -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 -- 2.17.1
next prev parent reply other threads:[~2019-08-09 15:43 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-09 15:41 [Qemu-devel] [PATCH 0/3] decodetree improvements Richard Henderson 2019-08-09 15:41 ` [Qemu-riscv] " Richard Henderson 2019-08-09 15:41 ` Richard Henderson [this message] 2019-08-09 15:41 ` [Qemu-riscv] [PATCH 1/3] decodetree: Allow !function with no input bits Richard Henderson 2019-08-09 15:52 ` [Qemu-devel] " Peter Maydell 2019-08-09 15:52 ` [Qemu-riscv] " Peter Maydell 2019-08-09 15:57 ` [Qemu-devel] " Richard Henderson 2019-08-09 15:57 ` [Qemu-riscv] " Richard Henderson 2019-08-09 15:41 ` [Qemu-devel] [PATCH 2/3] decodetree: Suppress redundant declaration warnings Richard Henderson 2019-08-09 15:41 ` [Qemu-riscv] " Richard Henderson 2019-08-09 15:48 ` [Qemu-devel] " Philippe Mathieu-Daudé 2019-08-09 15:48 ` [Qemu-riscv] " Philippe Mathieu-Daudé 2019-08-10 2:02 ` [Qemu-devel] " Alistair Francis 2019-08-10 2:02 ` [Qemu-riscv] " Alistair Francis 2019-08-09 15:41 ` [Qemu-devel] [PATCH 3/3] target/riscv: Remove redundant declaration pragmas Richard Henderson 2019-08-09 15:41 ` [Qemu-riscv] " Richard Henderson 2019-08-09 15:48 ` [Qemu-devel] " Philippe Mathieu-Daudé 2019-08-09 15:48 ` [Qemu-riscv] " Philippe Mathieu-Daudé 2019-08-09 17:43 ` [Qemu-devel] " Palmer Dabbelt 2019-08-09 17:43 ` [Qemu-riscv] " Palmer Dabbelt 2019-08-10 0:05 ` Richard Henderson 2019-08-10 0:05 ` [Qemu-riscv] " Richard Henderson 2019-08-10 2:03 ` Alistair Francis 2019-08-10 2:03 ` [Qemu-riscv] " Alistair Francis
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190809154153.31763-2-richard.henderson@linaro.org \ --to=richard.henderson@linaro.org \ --cc=Alistair.Francis@wdc.com \ --cc=peter.maydell@linaro.org \ --cc=philmd@redhat.com \ --cc=qemu-arm@nongnu.org \ --cc=qemu-devel@nongnu.org \ --cc=qemu-riscv@nongnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.