aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKito Cheng <kito.cheng@sifive.com>2024-01-05 21:33:35 +0800
committerKito Cheng <kito.cheng@sifive.com>2024-01-19 15:19:39 +0800
commit4e8fef35f7c4553529e92a0d9f501b94481ede0b (patch)
treea3f59e4c375b77e8b19e2c049c80762debf37301 /gcc
parent7e949ffaafb415150047127f529377502097d897 (diff)
downloadgcc-4e8fef35f7c4553529e92a0d9f501b94481ede0b.zip
gcc-4e8fef35f7c4553529e92a0d9f501b94481ede0b.tar.gz
gcc-4e8fef35f7c4553529e92a0d9f501b94481ede0b.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/common/config/riscv/riscv-common.cc69
-rw-r--r--gcc/config/riscv/riscv-subset.h2
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 4497220..0ffbb5f 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 1446183..c8117d8 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 *);