From: Xi Ruoyao <xry111@mengyan1223.wang>
To: YunQiang Su <yunqiang.su@cipunited.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/3] md/define_c_enum: support value assignation
Date: Sun, 29 Aug 2021 13:41:56 +0800 [thread overview]
Message-ID: <e83a89212f4ff496d39fb69c6f9d057826214e02.camel@mengyan1223.wang> (raw)
In-Reply-To: <20210828120549.263010-1-yunqiang.su@cipunited.com>
On Sat, 2021-08-28 at 08:05 -0400, YunQiang Su wrote:
> Currently, the enums from define_c_enum and define_enum can only
> has values one by one from 0.
>
> In fact we can support the behaviour just like C, aka like
> (define_enum "mips_isa" [mips1=1 mips2 mips32=32 mips32r2]),
> then we can get
> enum mips_isa {
> MIPS_ISA_MIPS1 = 1,
> MIPS_ISA_MIPS2 = 2,
> MIPS_ISA_MIPS32 = 32,
> MIPS_ISA_MIPS32R2 = 33
> };
IMO we can just define the enum in mips.h. In a private communication
YunQiang has explained he doesn't want to introduce a new large enum at
the top of mips.h though.
How do others think?
> gcc/ChangeLog:
> * read-md.c (md_reader::handle_enum): support value
> assignation.
> * doc/md.texi: record define_c_enum value assignation support.
> ---
> gcc/doc/md.texi | 4 ++++
> gcc/read-md.c | 15 +++++++++++++--
> 2 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
> index f8047aefc..1c1282c4c 100644
> --- a/gcc/doc/md.texi
> +++ b/gcc/doc/md.texi
> @@ -11074,6 +11074,8 @@ The syntax is as follows:
> (define_c_enum "@var{name}" [
> @var{value0}
> @var{value1}
> + @var{value32}=32
> + @var{value33}
> @dots{}
> @var{valuen}
> ])
> @@ -11086,6 +11088,8 @@ in @file{insn-constants.h}:
> enum @var{name} @{
> @var{value0} = 0,
> @var{value1} = 1,
> + @var{value32} = 32,
> + @var{value33} = 33,
> @dots{}
> @var{valuen} = @var{n}
> @};
> diff --git a/gcc/read-md.c b/gcc/read-md.c
> index bb419e0f6..43dfbe264 100644
> --- a/gcc/read-md.c
> +++ b/gcc/read-md.c
> @@ -901,7 +901,8 @@ md_decimal_string (int number)
> void
> md_reader::handle_enum (file_location loc, bool md_p)
> {
> - char *enum_name, *value_name;
> + char *enum_name, *value_name, *token;
> + unsigned int cur_value;
> struct md_name name;
> struct enum_type *def;
> struct enum_value *ev;
> @@ -928,6 +929,7 @@ md_reader::handle_enum (file_location loc, bool
> md_p)
> *slot = def;
> }
>
> + cur_value = def->num_values;
> require_char_ws ('[');
>
> while ((c = read_skip_spaces ()) != ']')
> @@ -945,20 +947,29 @@ md_reader::handle_enum (file_location loc, bool
> md_p)
> if (md_p)
> {
> value_name = concat (def->name, "_", name.string, NULL);
> + value_name = strtok (value_name, "=");
> + token = strtok (NULL, "=");
> + if (token)
> + cur_value = atoi (token);
> upcase_string (value_name);
> ev->name = xstrdup (name.string);
> }
> else
> {
> value_name = xstrdup (name.string);
> + value_name = strtok (value_name, "=");
> + token = strtok (NULL, "=");
> + if (token)
> + cur_value = atoi (token);
> ev->name = value_name;
> }
> ev->def = add_constant (get_md_constants (), value_name,
> - md_decimal_string (def->num_values),
> def);
> + md_decimal_string (cur_value), def);
>
> *def->tail_ptr = ev;
> def->tail_ptr = &ev->next;
> def->num_values++;
> + cur_value++;
> }
> }
>
--
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University
next prev parent reply other threads:[~2021-08-29 5:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-28 12:05 YunQiang Su
2021-08-28 12:05 ` [PATCH 2/3] MIPS: use mips_isa enum instead hardcoded numbers YunQiang Su
2021-08-29 5:46 ` Xi Ruoyao
2021-08-30 2:06 ` YunQiang Su
2021-08-28 12:05 ` [PATCH 3/3] MIPS: add .module mipsREV to all output asm file YunQiang Su
2021-08-29 5:41 ` Xi Ruoyao [this message]
2021-08-31 9:45 ` [PATCH 1/3] md/define_c_enum: support value assignation Richard Sandiford
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=e83a89212f4ff496d39fb69c6f9d057826214e02.camel@mengyan1223.wang \
--to=xry111@mengyan1223.wang \
--cc=gcc-patches@gcc.gnu.org \
--cc=yunqiang.su@cipunited.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).