[PATCH] LoongArch: Add support for b ".L1" and beq "$t0", "$t1", ".L1"

mengqinggang mengqinggang@loongson.cn
Wed Dec 6 03:17:24 GMT 2023


Support register and symbol names enclosed in double quotation marks.
---
 .../gas/loongarch/double_quotation_marks.d    | 11 +++++
 .../gas/loongarch/double_quotation_marks.s    |  2 +
 opcodes/loongarch-coder.c                     | 41 ++++++++++++++++---
 3 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.d
 create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.s

diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.d b/gas/testsuite/gas/loongarch/double_quotation_marks.d
new file mode 100644
index 00000000000..99c6d343e4c
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/double_quotation_marks.d
@@ -0,0 +1,11 @@
+#as:
+#objdump: -dr
+
+.*:[    ]+file format .*
+
+
+Disassembly of section .text:
+
+.* <.text>:
+[ 	]+0:[ 	]+5800018d[ 	]+beq[ 	]+\$t0, \$t1, 0[ 	]+# 0x0
+[ 	]+0: R_LARCH_B16[ 	]+.L1
diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s
new file mode 100644
index 00000000000..bb8acb99a40
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s
@@ -0,0 +1,2 @@
+# Before only support beq $t0, $t1, .L1
+beq "$t0", "$t1", ".L1"
diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c
index a68ae1c3106..198de81aa25 100644
--- a/opcodes/loongarch-coder.c
+++ b/opcodes/loongarch-coder.c
@@ -254,16 +254,45 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[])
 {
   size_t num = 0;
 
+  /* Supporting <b ".L1"> or <beq "r1", "r2", ".L1">, ignore the first '"'.
+     Mismatched '"' is judged by common code and the white characters also
+     removed by common code. The code like <b ".L1"> or <b "r1","r2",".L1">.  */
+  if ('"' == *args)
+    args++;
+
   if (*args)
     arg_strs[num++] = args;
   for (; *args; args++)
-    if (*args == ',')
-      {
-	if (MAX_ARG_NUM_PLUS_2 - 1 == num)
+    {
+      /* Supporting <b ".L1"> or <beq "r1","r2",".L1>",
+	 ignore the last '"'.  */
+      if (('"' == *args) && ('\0' == *(args+1)))
+	{
+	  *args = '\0';
 	  break;
-	else
-	  *args = '\0', arg_strs[num++] = args + 1;
-      }
+	}
+
+      /* Supporting <b ".L1"> or <beq "r1","r2",".L1>",
+	 ignore the '"' before ','.  */
+      if (('"' == *args) && (',' == *(args+1)))
+	*args = '\0';
+
+      if (*args == ',')
+	{
+	  if (MAX_ARG_NUM_PLUS_2 - 1 == num)
+	    break;
+	  else
+	    {
+	      *args = '\0';
+	      /* Supporting <b ".L1"> or <beq "r1","r2",".L1">,
+		 ignore the '"' after ','.  */
+	      if('"' == *(args+1))
+		arg_strs[num++] = args + 2;
+	      else
+		arg_strs[num++] = args + 1;
+	    }
+	}
+    }
   arg_strs[num] = NULL;
   return num;
 }
-- 
2.36.0



More information about the Binutils mailing list