qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de,
	palmer@sifive.com, peer.adelt@hni.uni-paderborn.de,
	Alistair.Francis@wdc.com, mjc@sifive.com
Subject: Re: [Qemu-devel] [PATCH 1/7] decodetree: Add !extern flag to argument sets
Date: Tue, 23 Oct 2018 15:27:34 +0200	[thread overview]
Message-ID: <2eb3d12f-1a2b-8194-e1a4-cfd6396f3aa5@redhat.com> (raw)
In-Reply-To: <20181023120454.28553-2-richard.henderson@linaro.org>

On 23/10/18 14:04, Richard Henderson wrote:
> Allow argument sets to be shared between two decoders by avoiding
> a re-declaration error.  Make sure that anonymous argument sets
> have unique names.
> 
> 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 277f9a9bba..a9b10452ef 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:
>   #
>   #   &reg3       ra rb rc
> @@ -169,6 +172,7 @@ input_file = ''
>   output_file = None
>   output_fd = None
>   insntype = 'uint32_t'
> +decode_function = 'decode'
>   
>   re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
>   
> @@ -394,8 +398,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):
> @@ -405,10 +410,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
>   
>   
> @@ -542,7 +548,11 @@ def parse_arguments(lineno, name, toks):
>       global re_ident
>   
>       flds = []
> +    extern = False
>       for t in toks:
> +        if re_fullmatch('!extern', t):
> +            extern = True

It looks odd to match a negative form then use a positive one.

Why not simply use 'extern'?

Regardless,
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +            continue
>           if not re_fullmatch(re_ident, t):
>               error(lineno, 'invalid argument set token "{0}"'.format(t))
>           if t in flds:
> @@ -551,7 +561,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
>   
>   
> @@ -575,13 +585,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
>   
> @@ -589,6 +600,7 @@ def infer_argument_set(flds):
>   def infer_format(arg, fieldmask, flds):
>       global arguments
>       global formats
> +    global decode_function
>   
>       const_flds = {}
>       var_flds = {}
> @@ -608,7 +620,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)
>   
> @@ -973,8 +985,8 @@ def main():
>       global insnwidth
>       global insntype
>       global insnmask
> +    global decode_function
>   
> -    decode_function = 'decode'
>       decode_scope = 'static '
>   
>       long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']
> 

  parent reply	other threads:[~2018-10-23 13:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23 12:04 [Qemu-devel] [PATCH 0/7] riscv decodetree followup Richard Henderson
2018-10-23 12:04 ` [Qemu-devel] [PATCH 1/7] decodetree: Add !extern flag to argument sets Richard Henderson
2018-10-23 12:56   ` Bastian Koppelmann
2018-10-23 13:27   ` Philippe Mathieu-Daudé [this message]
2018-10-23 13:54     ` Richard Henderson
2018-10-23 18:40       ` Philippe Mathieu-Daudé
2018-10-23 12:04 ` [Qemu-devel] [PATCH 2/7] decodetree: Remove "insn" argument from trans_* expanders Richard Henderson
2018-10-23 13:04   ` Bastian Koppelmann
2018-10-23 13:08     ` Richard Henderson
2018-10-23 13:25       ` Philippe Mathieu-Daudé
2018-10-23 13:25       ` Bastian Koppelmann
2018-10-23 13:56         ` Richard Henderson
2018-10-23 12:04 ` [Qemu-devel] [PATCH 3/7] target/riscv: Update for decodetree insn argument change Richard Henderson
2018-10-23 13:40   ` Bastian Koppelmann
2018-10-23 12:04 ` [Qemu-devel] [PATCH 4/7] target/riscv: Rename some argument sets in insn32.decode Richard Henderson
2018-10-23 12:21   ` Philippe Mathieu-Daudé
2018-10-23 13:03     ` Richard Henderson
2018-10-23 13:40   ` Bastian Koppelmann
2018-10-23 12:04 ` [Qemu-devel] [PATCH 5/7] target/riscv: Convert @cs_2 insns to share translation functions Richard Henderson
2018-10-23 12:26   ` Philippe Mathieu-Daudé
2018-10-23 13:04     ` Richard Henderson
2018-10-23 13:41   ` Bastian Koppelmann
2018-10-23 12:04 ` [Qemu-devel] [PATCH 6/7] target/riscv: Convert @cl_d, @cl_w, @cs_d, @cs_w insns Richard Henderson
2018-10-23 12:27   ` Philippe Mathieu-Daudé
2018-10-23 12:04 ` [Qemu-devel] [PATCH 7/7] target/riscv: Splice decodetree inputs for riscv32 vs riscv64 Richard Henderson
2018-10-23 12:17   ` Philippe Mathieu-Daudé
2018-10-24  9:33   ` Bastian Koppelmann
2018-10-24  9:49     ` Richard Henderson

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=2eb3d12f-1a2b-8194-e1a4-cfd6396f3aa5@redhat.com \
    --to=philmd@redhat.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=mjc@sifive.com \
    --cc=palmer@sifive.com \
    --cc=peer.adelt@hni.uni-paderborn.de \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sagark@eecs.berkeley.edu \
    /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).