public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] aarch64: Commonise index parsing
@ 2023-03-30 10:12 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2023-03-30 10:12 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=61dac77e931e254a3caeb4d924999e11875308d0

commit 61dac77e931e254a3caeb4d924999e11875308d0
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Thu Mar 30 11:09:05 2023 +0100

    aarch64: Commonise index parsing
    
    Just a minor clean-up to factor out the index parsing, partly to
    ensure that the error handling remains consistent.  No behavioural
    change intended.

Diff:
---
 gas/config/tc-aarch64.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index e5185353013..dafd5bc296c 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -1022,6 +1022,23 @@ aarch64_valid_suffix_char_p (aarch64_reg_type type, char ch)
     }
 }
 
+/* Parse an index expression at *STR, storing it in *IMM on success.  */
+
+static bool
+parse_index_expression (char **str, int64_t *imm)
+{
+  expressionS exp;
+
+  aarch64_get_expression (&exp, str, GE_NO_PREFIX, REJECT_ABSENT);
+  if (exp.X_op != O_constant)
+    {
+      first_error (_("constant expression required"));
+      return false;
+    }
+  *imm = exp.X_add_number;
+  return true;
+}
+
 /* Parse a register of the type TYPE.
 
    Return null if the string pointed to by *CCP is not a valid register
@@ -1116,8 +1133,6 @@ parse_typed_reg (char **ccp, aarch64_reg_type type,
 
   if (!(flags & PTR_FULL_REG) && skip_past_char (&str, '['))
     {
-      expressionS exp;
-
       /* Reject Sn[index] syntax.  */
       if (!is_typed_vecreg)
 	{
@@ -1133,18 +1148,11 @@ parse_typed_reg (char **ccp, aarch64_reg_type type,
 
       atype.defined |= NTA_HASINDEX;
 
-      aarch64_get_expression (&exp, &str, GE_NO_PREFIX, REJECT_ABSENT);
-
-      if (exp.X_op != O_constant)
-	{
-	  first_error (_("constant expression required"));
-	  return NULL;
-	}
+      if (!parse_index_expression (&str, &atype.index))
+	return NULL;
 
       if (! skip_past_char (&str, ']'))
 	return NULL;
-
-      atype.index = exp.X_add_number;
     }
   else if (!(flags & PTR_IN_REGLIST) && (atype.defined & NTA_HASINDEX) != 0)
     {
@@ -1318,18 +1326,10 @@ parse_vector_reg_list (char **ccp, aarch64_reg_type type,
     {
       if (skip_past_char (&str, '['))
 	{
-	  expressionS exp;
-
-	  aarch64_get_expression (&exp, &str, GE_NO_PREFIX, REJECT_ABSENT);
-	  if (exp.X_op != O_constant)
-	    {
-	      set_first_syntax_error (_("constant expression required."));
-	      error = true;
-	    }
+	  if (!parse_index_expression (&str, &typeinfo_first.index))
+	    error = true;
 	  if (! skip_past_char (&str, ']'))
 	    error = true;
-	  else
-	    typeinfo_first.index = exp.X_add_number;
 	}
       else
 	{

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

only message in thread, other threads:[~2023-03-30 10:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 10:12 [binutils-gdb] aarch64: Commonise index parsing Richard Sandiford

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