diff mbox series

[1/2] RISC-V: Allow extension name contain digit

Message ID 20211203155054.52834-2-kito.cheng@sifive.com
State Committed
Commit c8bdb3452054506f90283ea198a42a811679653d
Headers show
Series RISC-V: Vector extensions support | expand

Commit Message

Kito Cheng Dec. 3, 2021, 3:50 p.m. UTC
RISC-V spec only allow alphabetical name for extension before, however
vector extension add several extension named with digits, so we try to
extend the naming rule.

Ref:
https://github.com/riscv/riscv-isa-manual/pull/718

gcc/ChangeLog:

	* common/config/riscv/riscv-common.c
	(riscv_subset_list::parse_multiletter_ext): Allow ext. name has
	digit.
---
 gcc/common/config/riscv/riscv-common.c | 42 +++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 4 deletions(-)

Comments

Kito Cheng Jan. 6, 2022, 4:57 p.m. UTC | #1
Committed

On Fri, Dec 3, 2021 at 11:51 PM Kito Cheng <kito.cheng@sifive.com> wrote:
>
> RISC-V spec only allow alphabetical name for extension before, however
> vector extension add several extension named with digits, so we try to
> extend the naming rule.
>
> Ref:
> https://github.com/riscv/riscv-isa-manual/pull/718
>
> gcc/ChangeLog:
>
>         * common/config/riscv/riscv-common.c
>         (riscv_subset_list::parse_multiletter_ext): Allow ext. name has
>         digit.
> ---
>  gcc/common/config/riscv/riscv-common.c | 42 +++++++++++++++++++++++---
>  1 file changed, 38 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
> index b8dd0aeac3e..31b1c833965 100644
> --- a/gcc/common/config/riscv/riscv-common.c
> +++ b/gcc/common/config/riscv/riscv-common.c
> @@ -760,24 +760,58 @@ riscv_subset_list::parse_multiletter_ext (const char *p,
>        bool explicit_version_p = false;
>        char *ext;
>        char backup;
> +      size_t len;
> +      size_t end_of_version_pos, i;
> +      bool found_any_number = false;
> +      bool found_minor_version = false;
>
> -      while (*++q != '\0' && *q != '_' && !ISDIGIT (*q))
> +      /* Parse until end of this extension including version number.  */
> +      while (*++q != '\0' && *q != '_')
>         ;
>
>        backup = *q;
>        *q = '\0';
> -      ext = xstrdup (subset);
> +      len = q - subset;
>        *q = backup;
>
> +      end_of_version_pos = len;
> +      /* Find the begin of version string.  */
> +      for (i = len -1; i > 0; --i)
> +       {
> +         if (ISDIGIT (subset[i]))
> +           {
> +             found_any_number = true;
> +             continue;
> +           }
> +         /* Might be version seperator, but need to check one more char,
> +            we only allow <major>p<minor>, so we could stop parsing if found
> +            any more `p`.  */
> +         if (subset[i] == 'p' &&
> +             !found_minor_version &&
> +             found_any_number && ISDIGIT (subset[i-1]))
> +           {
> +             found_minor_version = true;
> +             continue;
> +           }
> +
> +         end_of_version_pos = i + 1;
> +         break;
> +       }
> +
> +      backup = subset[end_of_version_pos];
> +      subset[end_of_version_pos] = '\0';
> +      ext = xstrdup (subset);
> +      subset[end_of_version_pos] = backup;
> +
>        end_of_version
> -       = parsing_subset_version (ext, q, &major_version, &minor_version,
> +       = parsing_subset_version (ext, subset + end_of_version_pos, &major_version, &minor_version,
>                                   /* std_ext_p= */ false, &explicit_version_p);
>        free (ext);
>
>        if (end_of_version == NULL)
>         return NULL;
>
> -      *q = '\0';
> +      subset[end_of_version_pos] = '\0';
>
>        if (strlen (subset) == 1)
>         {
> --
> 2.34.0
>
diff mbox series

Patch

diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index b8dd0aeac3e..31b1c833965 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -760,24 +760,58 @@  riscv_subset_list::parse_multiletter_ext (const char *p,
       bool explicit_version_p = false;
       char *ext;
       char backup;
+      size_t len;
+      size_t end_of_version_pos, i;
+      bool found_any_number = false;
+      bool found_minor_version = false;
 
-      while (*++q != '\0' && *q != '_' && !ISDIGIT (*q))
+      /* Parse until end of this extension including version number.  */
+      while (*++q != '\0' && *q != '_')
 	;
 
       backup = *q;
       *q = '\0';
-      ext = xstrdup (subset);
+      len = q - subset;
       *q = backup;
 
+      end_of_version_pos = len;
+      /* Find the begin of version string.  */
+      for (i = len -1; i > 0; --i)
+	{
+	  if (ISDIGIT (subset[i]))
+	    {
+	      found_any_number = true;
+	      continue;
+	    }
+	  /* Might be version seperator, but need to check one more char,
+	     we only allow <major>p<minor>, so we could stop parsing if found
+	     any more `p`.  */
+	  if (subset[i] == 'p' &&
+	      !found_minor_version &&
+	      found_any_number && ISDIGIT (subset[i-1]))
+	    {
+	      found_minor_version = true;
+	      continue;
+	    }
+
+	  end_of_version_pos = i + 1;
+	  break;
+	}
+
+      backup = subset[end_of_version_pos];
+      subset[end_of_version_pos] = '\0';
+      ext = xstrdup (subset);
+      subset[end_of_version_pos] = backup;
+
       end_of_version
-	= parsing_subset_version (ext, q, &major_version, &minor_version,
+	= parsing_subset_version (ext, subset + end_of_version_pos, &major_version, &minor_version,
 				  /* std_ext_p= */ false, &explicit_version_p);
       free (ext);
 
       if (end_of_version == NULL)
 	return NULL;
 
-      *q = '\0';
+      subset[end_of_version_pos] = '\0';
 
       if (strlen (subset) == 1)
 	{