public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8269] RISC-V: Extract part parsing base ISA logic into a standalone function [NFC]
@ 2024-01-19  7:27 Kito Cheng
  0 siblings, 0 replies; only message in thread
From: Kito Cheng @ 2024-01-19  7:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4e8fef35f7c4553529e92a0d9f501b94481ede0b

commit r14-8269-g4e8fef35f7c4553529e92a0d9f501b94481ede0b
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Fri Jan 5 21:33:35 2024 +0800

    RISC-V: Extract part parsing base ISA logic into a standalone function [NFC]
    
    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.

Diff:
---
 gcc/common/config/riscv/riscv-common.cc | 69 +++++++++++++++++++++------------
 gcc/config/riscv/riscv-subset.h         |  2 +
 2 files changed, 47 insertions(+), 24 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index 449722070d4..0ffbb5f604c 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -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);
diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h
index 14461838db5..c8117d8daf2 100644
--- a/gcc/config/riscv/riscv-subset.h
+++ b/gcc/config/riscv/riscv-subset.h
@@ -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 *);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-19  7:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-19  7:27 [gcc r14-8269] RISC-V: Extract part parsing base ISA logic into a standalone function [NFC] Kito Cheng

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