Debian Codegraph @

loong64/loong64asm/objdump_test.go

raw symbols SCIP
1 // Copyright 2024 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package loong64asm
6
7 import (
8 "strconv"
9 "strings"
10 "testing"
11 )
12
13 func TestObjdumpLoong64TestDecodeGNUSyntaxdata(t *testing.T) {
14 testObjdumpLoong64(t, testdataCases(t, "gnu"))
15 }
16
17 func TestObjdumpLoong64TestDecodeGoSyntaxdata(t *testing.T) {
18 testObjdumpLoong64(t, testdataCases(t, "plan9"))
19 }
20
21 func TestObjdumpLoong64Manual(t *testing.T) {
22 testObjdumpLoong64(t, hexCases(t, objdumpManualTests))
23 }
24
25 // objdumpManualTests holds test cases that will be run by TestObjdumpLoong64Manual.
26 // If you are debugging a few cases that turned up in a longer run, it can be useful
27 // to list them here and then use -run=Manual, particularly with tracing enabled.
28 // Note that these are byte sequences, so they must be reversed from the usual
29 // word presentation.
30 var objdumpManualTests = `
31 00007238
32 00807238
33 00004003
34 00100050
35 ac410028
36 ac41002a
37 ac41c028
38 ac414028
39 ac41402a
40 ac418028
41 ac41802a
42 ac397838
43 acb97938
44 acb97838
45 ac397938
46 ac397a38
47 acb97b38
48 acb97a38
49 ac397b38
50 ac110026
51 ac110024
52 ac390038
53 ac392038
54 ac390c38
55 ac390438
56 ac392438
57 ac390838
58 ac392838
59 ac391600
60 ac391400
61 ac391500
62 ac418003
63 `
64
65 // allowedMismatchObjdump reports whether the mismatch between text and dec
66 // should be allowed by the test.
67 func allowedMismatchObjdump(text string, inst *Inst, dec ExtInst) bool {
68 // GNU objdump use register, decode use alias of register, so corrected it in here
69 var dec_text = strings.Replace(dec.text, " ", ",", -1)
70 var decsp []string = strings.Split(dec_text, ",")
71 var num int = cap(decsp)
72 for i := 0; i < num; i++ {
73 dex := strings.Index(decsp[i], "$r")
74 fdex := strings.Index(decsp[i], "$f")
75 ddex := strings.Index(decsp[i], "(")
76 if ddex > 0 {
77 // ldptr.w $r12,$r13,16(0x10)
78 decsp[i] = decsp[i][0:ddex]
79 }
80 xdex := strings.Index(decsp[i], "0x")
81 // convert registers to registers aliases
82 if dex >= 0 {
83 reg, _ := strconv.Atoi(decsp[i][dex+2:])
84 // r12~r20 $t0~t8
85 if reg >= 12 && reg <= 20 {
86 decsp[i] = strings.Join([]string{"t", strconv.Itoa(reg - 12)}, "")
87 }
88 // r4~r11 $a0~a7
89 if reg >= 4 && reg <= 11 {
90 decsp[i] = strings.Join([]string{"a", strconv.Itoa(reg - 4)}, "")
91 }
92 // r23~r31 $s0~s8
93 if reg >= 23 && reg <= 31 {
94 decsp[i] = strings.Join([]string{"s", strconv.Itoa(reg - 23)}, "")
95 }
96 // r0 zero
97 if reg == 0 {
98 decsp[i] = strings.Join([]string{"zero"}, "")
99 }
100 // r1 ra
101 if reg == 1 {
102 decsp[i] = strings.Join([]string{"ra"}, "")
103 }
104 // r2 tp
105 if reg == 2 {
106 decsp[i] = strings.Join([]string{"tp"}, "")
107 }
108 // r3 sp
109 if reg == 3 {
110 decsp[i] = strings.Join([]string{"sp"}, "")
111 }
112 // r21 x
113 if reg == 21 {
114 decsp[i] = strings.Join([]string{"x"}, "")
115 }
116 // r22 fp
117 if reg == 22 {
118 decsp[i] = strings.Join([]string{"fp"}, "")
119 }
120 }
121 // convert hexadecimal to decimal
122 if xdex >= 0 {
123 parseint, _ := strconv.ParseInt(decsp[i][xdex+2:], 16, 32)
124 decsp[i] = strings.Join([]string{strconv.Itoa(int(parseint))}, "")
125 }
126 // convert floating-point registers to floating-point aliases
127 if fdex >= 0 && !strings.Contains(decsp[i], "$fcc") {
128 freg, _ := strconv.Atoi(decsp[i][fdex+2:])
129 // f0~f7 fa0~fa7
130 if freg >= 0 && freg <= 7 {
131 decsp[i] = strings.Join([]string{"fa", strconv.Itoa(freg - 0)}, "")
132 }
133 // f8~f23 ft0~ft15
134 if freg >= 8 && freg <= 23 {
135 decsp[i] = strings.Join([]string{"ft", strconv.Itoa(freg - 8)}, "")
136 }
137 // f24~f31 fs0~fs7
138 if freg >= 24 && freg <= 31 {
139 decsp[i] = strings.Join([]string{"fs", strconv.Itoa(freg - 24)}, "")
140 }
141 }
142 }
143
144 return false
145 }