public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kito Cheng <kito@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6286] RISC-V: Allow extension name contain digit
Date: Thu,  6 Jan 2022 16:56:35 +0000 (GMT)	[thread overview]
Message-ID: <20220106165635.43CED3858408@sourceware.org> (raw)

https://gcc.gnu.org/g:c8bdb3452054506f90283ea198a42a811679653d

commit r12-6286-gc8bdb3452054506f90283ea198a42a811679653d
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Fri Dec 3 23:50:53 2021 +0800

    RISC-V: Allow extension name contain digit
    
    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.

Diff:
---
 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 338d09fb211..ecbca6cc544 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -785,24 +785,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)
 	{


                 reply	other threads:[~2022-01-06 16:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220106165635.43CED3858408@sourceware.org \
    --to=kito@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).