]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Extract part parsing base ISA logic into a standalone function [NFC]
authorKito Cheng <kito.cheng@sifive.com>
Fri, 5 Jan 2024 13:33:35 +0000 (21:33 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Fri, 19 Jan 2024 07:19:39 +0000 (15:19 +0800)
Minor refactor, preparation for further change.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc
(riscv_subset_list::parse_base_ext): New.
(riscv_subset_list::parse): Extract part of logic into
riscv_subset_list::parse_base_ext.
* config/riscv/riscv-subset.h (riscv_subset_list::parse_base_ext):
New.

gcc/common/config/riscv/riscv-common.cc
gcc/config/riscv/riscv-subset.h

index 449722070d4fc280b0af2ad047ee60c17c65411a..0ffbb5f604cc00b4403f32e29bc51bd42e6c8ca3 100644 (file)
@@ -971,25 +971,37 @@ riscv_subset_list::parsing_subset_version (const char *ext,
   return p;
 }
 
-/* Parsing function for standard extensions.
+/* Parsing function for base extensions, rv[32|64][i|e|g]
 
    Return Value:
-     Points to the end of extensions.
+     Points to the end of extensions, return NULL if any error.
 
    Arguments:
      `p`: Current parsing position.  */
-
 const char *
-riscv_subset_list::parse_std_ext (const char *p)
+riscv_subset_list::parse_base_ext (const char *p)
 {
-  const char *all_std_exts = riscv_supported_std_ext ();
-  const char *std_exts = all_std_exts;
-
   unsigned major_version = 0;
   unsigned minor_version = 0;
-  char std_ext = '\0';
   bool explicit_version_p = false;
 
+  if (startswith (p, "rv32"))
+    {
+      m_xlen = 32;
+      p += 4;
+    }
+  else if (startswith (p, "rv64"))
+    {
+      m_xlen = 64;
+      p += 4;
+    }
+  else
+    {
+      error_at (m_loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64",
+               m_arch);
+      return NULL;
+    }
+
   /* First letter must start with i, e or g.  */
   switch (*p)
     {
@@ -1044,6 +1056,28 @@ riscv_subset_list::parse_std_ext (const char *p)
                "%<i%> or %<g%>", m_arch);
       return NULL;
     }
+  return p;
+}
+
+
+/* Parsing function for standard extensions.
+
+   Return Value:
+     Points to the end of extensions.
+
+   Arguments:
+     `p`: Current parsing position.  */
+
+const char *
+riscv_subset_list::parse_std_ext (const char *p)
+{
+  const char *all_std_exts = riscv_supported_std_ext ();
+  const char *std_exts = all_std_exts;
+
+  unsigned major_version = 0;
+  unsigned minor_version = 0;
+  char std_ext = '\0';
+  bool explicit_version_p = false;
 
   while (p != NULL && *p)
     {
@@ -1509,22 +1543,9 @@ riscv_subset_list::parse (const char *arch, location_t loc)
   riscv_subset_list *subset_list = new riscv_subset_list (arch, loc);
   riscv_subset_t *itr;
   const char *p = arch;
-  if (startswith (p, "rv32"))
-    {
-      subset_list->m_xlen = 32;
-      p += 4;
-    }
-  else if (startswith (p, "rv64"))
-    {
-      subset_list->m_xlen = 64;
-      p += 4;
-    }
-  else
-    {
-      error_at (loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64",
-               arch);
-      goto fail;
-    }
+  p = subset_list->parse_base_ext (p);
+  if (p == NULL)
+    goto fail;
 
   /* Parsing standard extension.  */
   p = subset_list->parse_std_ext (p);
index 14461838db5ac305f3fe106e3671b4a8484a4e0f..c8117d8daf235e09a2e91476d72226f01b0c58bf 100644 (file)
@@ -67,6 +67,8 @@ private:
   const char *parsing_subset_version (const char *, const char *, unsigned *,
                                      unsigned *, bool, bool *);
 
+  const char *parse_base_ext (const char *);
+
   const char *parse_std_ext (const char *);
 
   const char *parse_single_std_ext (const char *);