From: YunQiang Su <yunqiang.su@cipunited.com>
To: gcc-patches@gcc.gnu.org
Cc: syq@debian.org, xry111@mengyan1223.wang,
YunQiang Su <yunqiang.su@cipunited.com>
Subject: [PATCH 1/3] md/define_c_enum: support value assignation
Date: Sat, 28 Aug 2021 08:05:47 -0400 [thread overview]
Message-ID: <20210828120549.263010-1-yunqiang.su@cipunited.com> (raw)
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
};
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++;
}
}
--
2.30.2
next reply other threads:[~2021-08-28 12:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-28 12:05 YunQiang Su [this message]
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 ` [PATCH 1/3] md/define_c_enum: support value assignation Xi Ruoyao
2021-08-31 9:45 ` 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=20210828120549.263010-1-yunqiang.su@cipunited.com \
--to=yunqiang.su@cipunited.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=syq@debian.org \
--cc=xry111@mengyan1223.wang \
/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).