From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [Qemu-devel] [PULL 1/3] decodetree: Add !extern flag to argument sets
Date: Wed, 31 Oct 2018 16:53:19 +0000 [thread overview]
Message-ID: <20181031165321.4422-2-richard.henderson@linaro.org> (raw)
In-Reply-To: <20181031165321.4422-1-richard.henderson@linaro.org>
Allow argument sets to be shared between two decoders by avoiding
a re-declaration error. Make sure that anonymous argument sets
and anonymous formats have unique names.
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
scripts/decodetree.py | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index 457cffea90..28bbd4e3c1 100755
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -63,13 +63,16 @@
#
# *** Argument set syntax:
#
-# args_def := '&' identifier ( args_elt )+
+# args_def := '&' identifier ( args_elt )+ ( !extern )?
# args_elt := identifier
#
# Each args_elt defines an argument within the argument set.
# Each argument set will be rendered as a C structure "arg_$name"
# with each of the fields being one of the member arguments.
#
+# If !extern is specified, the backing structure is assumed to
+# have been already declared, typically via a second decoder.
+#
# Argument set examples:
#
# ®3 ra rb rc
@@ -167,6 +170,7 @@ input_file = ''
output_file = None
output_fd = None
insntype = 'uint32_t'
+decode_function = 'decode'
re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
@@ -392,8 +396,9 @@ class FunctionField:
class Arguments:
"""Class representing the extracted fields of a format"""
- def __init__(self, nm, flds):
+ def __init__(self, nm, flds, extern):
self.name = nm
+ self.extern = extern
self.fields = sorted(flds)
def __str__(self):
@@ -403,10 +408,11 @@ class Arguments:
return 'arg_' + self.name
def output_def(self):
- output('typedef struct {\n')
- for n in self.fields:
- output(' int ', n, ';\n')
- output('} ', self.struct_name(), ';\n\n')
+ if not self.extern:
+ output('typedef struct {\n')
+ for n in self.fields:
+ output(' int ', n, ';\n')
+ output('} ', self.struct_name(), ';\n\n')
# end Arguments
@@ -540,7 +546,11 @@ def parse_arguments(lineno, name, toks):
global re_ident
flds = []
+ extern = False
for t in toks:
+ if re_fullmatch('!extern', t):
+ extern = True
+ continue
if not re_fullmatch(re_ident, t):
error(lineno, 'invalid argument set token "{0}"'.format(t))
if t in flds:
@@ -549,7 +559,7 @@ def parse_arguments(lineno, name, toks):
if name in arguments:
error(lineno, 'duplicate argument set', name)
- arguments[name] = Arguments(name, flds)
+ arguments[name] = Arguments(name, flds, extern)
# end parse_arguments
@@ -573,13 +583,14 @@ def add_field_byname(lineno, flds, new_name, old_name):
def infer_argument_set(flds):
global arguments
+ global decode_function
for arg in arguments.values():
if eq_fields_for_args(flds, arg.fields):
return arg
- name = str(len(arguments))
- arg = Arguments(name, flds.keys())
+ name = decode_function + str(len(arguments))
+ arg = Arguments(name, flds.keys(), False)
arguments[name] = arg
return arg
@@ -587,6 +598,7 @@ def infer_argument_set(flds):
def infer_format(arg, fieldmask, flds):
global arguments
global formats
+ global decode_function
const_flds = {}
var_flds = {}
@@ -606,7 +618,7 @@ def infer_format(arg, fieldmask, flds):
continue
return (fmt, const_flds)
- name = 'Fmt_' + str(len(formats))
+ name = decode_function + '_Fmt_' + str(len(formats))
if not arg:
arg = infer_argument_set(flds)
@@ -971,8 +983,8 @@ def main():
global insnwidth
global insntype
global insnmask
+ global decode_function
- decode_function = 'decode'
decode_scope = 'static '
long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']
--
2.17.2
next prev parent reply other threads:[~2018-10-31 16:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-31 16:53 [Qemu-devel] [PULL 0/3] decodetree improvements Richard Henderson
2018-10-31 16:53 ` Richard Henderson [this message]
2018-10-31 16:53 ` [Qemu-devel] [PULL 2/3] decodetree: Remove "insn" argument from trans_* expanders Richard Henderson
2018-10-31 16:53 ` [Qemu-devel] [PULL 3/3] decodetree: Allow multiple input files Richard Henderson
2018-11-02 6:21 ` [Qemu-devel] [PULL 0/3] decodetree improvements no-reply
2018-11-02 9:49 ` Peter Maydell
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=20181031165321.4422-2-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).