Skip to content

Commit bb1e3df

Browse files
committed
SparcInstPrinter: Support llvm-objdump --print-imm-hex
... to align with other targets, e.g., https://reviews.llvm.org/D77853 (AArch64) and https://reviews.llvm.org/D83634 (AVR). binutils's sparc port uses %d when imm<=9, diverging from other ports. We do not follow the binutils sparc port behavior.
1 parent deec7fb commit bb1e3df

File tree

8 files changed

+33
-29
lines changed

8 files changed

+33
-29
lines changed

lld/test/ELF/sparcv9-reloc.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# REQUIRES: sparc
22
# RUN: llvm-mc -filetype=obj -triple=sparcv9 %s -o %t.o
33
# RUN: ld.lld %t.o --defsym=a=0x0123456789ABCDEF --defsym=b=0x0123456789A --defsym=c=0x01234567 -o %t
4-
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
4+
# RUN: llvm-objdump -d --no-show-raw-insn --no-print-imm-hex %t | FileCheck %s
55
# RUN: llvm-objdump -s %t | FileCheck --check-prefix=HEX %s
66

77
## R_SPARC_HH22, R_SPARC_HM10

lld/test/ELF/sparcv9-tls-le.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
## %hix(@tpoff(a)) = ~(st_value(a) - 1026) >> 10 = 1
77
## %lo(@tpoff(a)) = (st_value(a) - 1026) & 0x3ff | 0x1c00 = -2 (0x1ffe)
8-
# LE: sethi 1, %o0
9-
# LE-NEXT: xor %o0, -2, %o0
8+
# LE: sethi 0x1, %o0
9+
# LE-NEXT: xor %o0, -0x2, %o0
1010
sethi %tle_hix22(a), %o0
1111
xor %o0, %tle_lox10(a), %o0
1212

llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
126126
if (MO.isImm()) {
127127
switch (MI->getOpcode()) {
128128
default:
129-
O << (int)MO.getImm();
129+
markup(O, Markup::Immediate) << formatImm(int32_t(MO.getImm()));
130130
return;
131131

132132
case SP::TICCri: // Fall through

llvm/test/MC/Sparc/sparc-assembly-exprs.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: llvm-mc %s -triple=sparc -show-encoding | FileCheck %s
1+
! RUN: llvm-mc %s -triple=sparc -show-encoding | FileCheck %s
22
! RUN: llvm-mc %s -triple=sparc -filetype=obj | llvm-objdump -r -d - | FileCheck %s --check-prefix=OBJDUMP
33

44
! CHECK: mov 1033, %o1 ! encoding: [0x92,0x10,0x24,0x09]
@@ -7,12 +7,12 @@
77
mov ((12+3)<<2), %o2
88

99
! CHECK: ba symStart+4 ! encoding: [0x10,0b10AAAAAA,A,A]
10-
! OBJDUMP: ba 1
10+
! OBJDUMP: ba 0x1
1111
symStart:
1212
b symStart + 4
1313

1414
! CHECK: mov symEnd-symStart, %g1 ! encoding: [0x82,0x10,0b001AAAAA,A]
15-
! OBJDUMP: mov 24, %g1
15+
! OBJDUMP: mov 0x18, %g1
1616
mov symEnd - symStart, %g1
1717

1818
! CHECK: sethi %hi(sym+10), %g2 ! encoding: [0x05,0b00AAAAAA,A,A]

llvm/test/MC/Sparc/sparc-fixups.s

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@
55

66
.set sym, 0xfedcba98
77

8-
! CHECK: sethi 4175662, %o0
8+
! CHECK: sethi 0x3fb72e, %o0
9+
! CHECK-NEXT: xor %o0, 0x298, %o0
10+
! CHECK-NEXT: sethi 0x3b72ea, %o1
11+
! CHECK-NEXT: xor %o0, 0x188, %o1
912
sethi %hi(sym), %o0
10-
! CHECK: xor %o0, 664, %o0
1113
xor %o0, %lo(sym), %o0
14+
sethi %hi(-0x12345678), %o1
15+
xor %o0, %lo(-0x12345678), %o1
1216

13-
! CHECK: sethi 1019, %o0
17+
! CHECK: sethi 0x3fb, %o0
18+
! CHECK-NEXT: or %o0, 0x1cb, %o0
19+
! CHECK-NEXT: ld [%o0+0xa98], %o0
1420
sethi %h44(sym), %o0
15-
! CHECK: or %o0, 459, %o0
1621
or %o0, %m44(sym), %o0
17-
! CHECK: ld [%o0+2712], %o0
1822
ld [%o0 + %l44(sym)], %o0
1923

20-
! CHECK: sethi 0, %o0
24+
! CHECK: sethi 0x0, %o0
25+
! CHECK-NEXT: sethi 0x3fb72e, %o0
26+
! CHECK-NEXT: or %o0, 0x0, %o0
2127
sethi %hh(sym), %o0
22-
! CHECK: sethi 4175662, %o0
2328
sethi %lm(sym), %o0
24-
! CHECK: or %o0, 0, %o0
2529
or %o0, %hm(sym), %o0
2630

27-
! CHECK: sethi 18641, %o0
31+
! CHECK: sethi 0x48d1, %o0
32+
! CHECK-NEXT: xor %o0, -0x168, %o0
2833
sethi %hix(sym), %o0
29-
! CHECK: xor %o0, -360, %o0
3034
xor %o0, %lox(sym), %o0

llvm/test/MC/Sparc/sparc-little-endian.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
! ...and that fixups are applied to the correct bytes.
1414

1515
! CHECK: ba .BB0 ! encoding: [A,A,0b10AAAAAA,0x10]
16-
! CHECK-OBJ: 4: ff ff bf 10 ba 4194303
16+
! CHECK-OBJ: 4: ff ff bf 10 ba 0x3fffff
1717
ba .BB0

llvm/test/MC/Sparc/sparc-tls-relocations.s

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ foo:
2828
! Sequence for Local Executable model:
2929
! LE_HIX22/LE_LOX10
3030

31-
! OBJDUMP: {{[0-9,a-f]+}}: 31 00 00 00 sethi 0, %i0
31+
! OBJDUMP: {{[0-9,a-f]+}}: 31 00 00 00 sethi 0x0, %i0
3232
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LE_HIX22 Local
3333
! ASM: sethi %tle_hix22(Local), %i0 ! encoding: [0x31,0x00,0x00,0x00]
3434
sethi %tle_hix22(Local), %i0
3535

36-
! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 20 00 xor %i0, 0, %i0
36+
! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 20 00 xor %i0, 0x0, %i0
3737
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LE_LOX10 Local
3838
! ASM: xor %i0, %tle_lox10(Local), %i0 ! encoding: [0xb0,0x1e,0x20,0x00]
3939
xor %i0, %tle_lox10(Local), %i0
@@ -43,17 +43,17 @@ foo:
4343
! Local Dynamic model:
4444
! LDO_HIX22/LDO_LOX10/LDO_ADD/LDM_HI22/LDM_LO10/LDM_ADD/LDM_CALL
4545

46-
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
46+
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0x0, %i1
4747
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDO_HIX22 Local
4848
! ASM: sethi %tldo_hix22(Local), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
4949
sethi %tldo_hix22(Local), %i1
5050

51-
! OBJDUMP: {{[0-9,a-f]+}}: 35 00 00 00 sethi 0, %i2
51+
! OBJDUMP: {{[0-9,a-f]+}}: 35 00 00 00 sethi 0x0, %i2
5252
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDM_HI22 Local
5353
! ASM: sethi %tldm_hi22(Local), %i2 ! encoding: [0x35,0b00AAAAAA,A,A]
5454
sethi %tldm_hi22(Local), %i2
5555

56-
! OBJDUMP: {{[0-9,a-f]+}}: b4 06 a0 00 add %i2, 0, %i2
56+
! OBJDUMP: {{[0-9,a-f]+}}: b4 06 a0 00 add %i2, 0x0, %i2
5757
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDM_LO10 Local
5858
! ASM: add %i2, %tldm_lo10(Local), %i2 ! encoding: [0xb4,0x06,0b101000AA,A]
5959
add %i2, %tldm_lo10(Local), %i2
@@ -63,7 +63,7 @@ foo:
6363
! ASM: add %i0, %i2, %o0, %tldm_add(Local) ! encoding: [0x90,0x06,0x00,0x1a]
6464
add %i0, %i2, %o0, %tldm_add(Local)
6565

66-
! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 60 00 xor %i1, 0, %i0
66+
! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 60 00 xor %i1, 0x0, %i0
6767
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDO_LOX10 Local
6868
! ASM: xor %i1, %tldo_lox10(Local), %i0 ! encoding: [0xb0,0x1e,0b011000AA,A]
6969
xor %i1, %tldo_lox10(Local), %i0
@@ -83,12 +83,12 @@ foo:
8383
! Initial Executable model:
8484
! IE_HI22/IE_LO10/IE_LD (or IE_LDX)/IE_ADD
8585

86-
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
86+
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0x0, %i1
8787
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_IE_HI22 Extern
8888
! ASM: sethi %tie_hi22(Extern), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
8989
sethi %tie_hi22(Extern), %i1
9090

91-
! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0, %i1
91+
! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0x0, %i1
9292
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_IE_LO10 Extern
9393
! ASM: add %i1, %tie_lo10(Extern), %i1 ! encoding: [0xb2,0x06,0b011000AA,A]
9494
add %i1, %tie_lo10(Extern), %i1
@@ -111,12 +111,12 @@ foo:
111111
! General Dynamic model
112112
! GD_HI22/GD_LO10/GD_ADD/GD_CALL
113113

114-
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
114+
! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0x0, %i1
115115
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_GD_HI22 Extern
116116
! ASM: sethi %tgd_hi22(Extern), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
117117
sethi %tgd_hi22(Extern), %i1
118118

119-
! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0, %i1
119+
! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0x0, %i1
120120
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_GD_LO10 Extern
121121
! ASM: add %i1, %tgd_lo10(Extern), %i1 ! encoding: [0xb2,0x06,0b011000AA,A]
122122
add %i1, %tgd_lo10(Extern), %i1

llvm/test/MC/Sparc/sparc64-bpr-offset.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: llvm-mc -triple=sparcv9 -filetype=obj %s | llvm-objdump -d - | FileCheck %s --check-prefix=BIN
1+
! RUN: llvm-mc -triple=sparcv9 -filetype=obj %s | llvm-objdump -d --no-print-imm-hex - | FileCheck %s --check-prefix=BIN
22

33
!! SPARCv9/SPARC64 BPr branches have different offset encoding from the others,
44
!! make sure that our offset bits don't trample on other fields.

0 commit comments

Comments
 (0)