public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] md/define_c_enum: support value assignation
@ 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
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: YunQiang Su @ 2021-08-28 12:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: syq, xry111, YunQiang Su

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-31  9:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28 12:05 [PATCH 1/3] md/define_c_enum: support value assignation 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 ` [PATCH 1/3] md/define_c_enum: support value assignation Xi Ruoyao
2021-08-31  9:45 ` Richard Sandiford

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).