[binutils-gdb] gas: ginsn: do not emit an unnecessary trailing comma in textual dump
Indu Bhagat
ibhagat@sourceware.org
Thu Aug 1 18:50:35 GMT 2024
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=67f39cdbc9d07ae5f14f988aedc887bb5bbae495
commit 67f39cdbc9d07ae5f14f988aedc887bb5bbae495
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date: Thu Aug 1 11:34:08 2024 -0700
gas: ginsn: do not emit an unnecessary trailing comma in textual dump
For ginsns with less than 2 source operands or no destination operands,
the current textual dump contains a superfluous comma, like the relevant
testcases show.
Adjust the code a bit to not emit the lone trailing comma. Also, adjust
the aarch64 and x86_64 testcases.
gas/
* ginsn.c (ginsn_src_print): Do not use a trailing comma when
printing the src of ginsn.
(ginsn_print): Check the strlen and prefix a comma before the
src string.
gas/testsuite/
* gas/scfi/aarch64/ginsn-cofi-1.l: Adjust the expected textual
dump of the ginsn.
* gas/scfi/x86_64/ginsn-cofi-1.l: Likewise.
Diff:
---
gas/ginsn.c | 20 +++++++++++++-------
gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l | 2 +-
gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l | 10 +++++-----
3 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/gas/ginsn.c b/gas/ginsn.c
index 20e83c5d51e..08c8e5ac3f8 100644
--- a/gas/ginsn.c
+++ b/gas/ginsn.c
@@ -477,14 +477,14 @@ ginsn_src_print (struct ginsn_src *src)
switch (src->type)
{
case GINSN_SRC_REG:
- snprintf (src_str, len, "%%r%d, ", ginsn_get_src_reg (src));
+ snprintf (src_str, len, "%%r%d", ginsn_get_src_reg (src));
break;
case GINSN_SRC_IMM:
- snprintf (src_str, len, "%lld, ",
+ snprintf (src_str, len, "%lld",
(long long int) ginsn_get_src_imm (src));
break;
case GINSN_SRC_INDIRECT:
- snprintf (src_str, len, "[%%r%d+%lld], ", ginsn_get_src_reg (src),
+ snprintf (src_str, len, "[%%r%d+%lld]", ginsn_get_src_reg (src),
(long long int) ginsn_get_src_disp (src));
break;
default:
@@ -578,16 +578,22 @@ ginsn_print (ginsnS *ginsn)
/* src 2. */
src = ginsn_get_src2 (ginsn);
src_buf = ginsn_src_print (src);
- str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
- "%s", src_buf);
+ if (strlen (src_buf))
+ {
+ str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
+ ", %s", src_buf);
+ }
free (src_buf);
gas_assert (str_size >= 0 && str_size < GINSN_LISTING_LEN);
/* dst. */
dst = ginsn_get_dst (ginsn);
char *dst_buf = ginsn_dst_print (dst);
- str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
- "%s", dst_buf);
+ if (strlen (dst_buf))
+ {
+ str_size += snprintf (ginsn_str + str_size, GINSN_LISTING_LEN - str_size,
+ ", %s", dst_buf);
+ }
free (dst_buf);
end:
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l b/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
index d05e19d059d..168547cf938 100644
--- a/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
+++ b/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
@@ -19,7 +19,7 @@ AARCH64 GAS .*
11 \?\?\?\? 02000014 b .L3
11 ginsn: JMP
12 \?\?\?\? 20021FD6 br x17
- 12 ginsn: JMP %r17,
+ 12 ginsn: JMP %r17
13 .L3:
13 ginsn: SYM .L3
14 \?\?\?\? 60003FD6 blr x3
diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l b/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l
index 3261b76a5fd..fdb2dcb5c22 100644
--- a/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l
+++ b/gas/testsuite/gas/scfi/x86_64/ginsn-cofi-1.l
@@ -18,7 +18,7 @@ GAS LISTING .*
11 \?\?\?\? E200 loop foo
11 ginsn: JCC
12 \?\?\?\? 3EFFE0 notrack jmp \*%rax
- 12 ginsn: JMP %r0,
+ 12 ginsn: JMP %r0
13 \?\?\?\? 41FFD0 call \*%r8
13 ginsn: CALL
14 \?\?\?\? FF14C500 call \*cost_arr\(,%rax,8\)
@@ -33,15 +33,15 @@ GAS LISTING .*
17 \?\?\?\? 67E316 jecxz .L179
17 ginsn: JCC
18 \?\?\?\? 41FFE0 jmp \*%r8
- 18 ginsn: JMP %r8,
+ 18 ginsn: JMP %r8
19 \?\?\?\? FF6730 jmp \*48\(%rdi\)
- 19 ginsn: JMP %r5,
+ 19 ginsn: JMP %r5
20 \?\?\?\? FF24C500 jmp \*cost_arr\(,%rax,8\)
20 000000
- 20 ginsn: JMP %r0,
+ 20 ginsn: JMP %r0
21 \?\?\?\? FF242500 jmp \*symbol\+1
21 000000
- 21 ginsn: JMP %r4,
+ 21 ginsn: JMP %r4
22 \?\?\?\? 7000 jo .L179
22 ginsn: JCC
23 .L179:
More information about the Binutils-cvs
mailing list