forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch-pretty.js
218 lines (213 loc) · 5.94 KB
/
switch-pretty.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -strict -target=HBC -dump-bytecode -pretty-disassemble -O %s | %FileCheck --match-full-lines %s
function g() {}
function f(x) {
switch (x) {
case 0:
return 32;
case 1:
return 342;
case 2:
return 322;
case 3:
return 132;
case 4:
g();
return 342;
case 5:
return 362;
case 6:
return 323;
case 7:
return 3234;
case 8:
return 2332;
case 9:
return 3642;
case 10:
return 3211;
case 11:
return 2332;
case 12:
return 3243;
case 13:
return 3254;
case 14:
return 3342;
case 15:
return 3523;
case 16:
return 3352;
}
switch (x) {
case 1:
return 342;
case 2:
return 322;
case 3:
return 132;
case 4:
g();
return 342;
case 8:
return 2332;
case 9:
return 3642;
case 10:
return 3211;
case 11:
return 2332;
case 12:
return 3243;
case 13:
return 3254;
case 14:
return 3342;
default:
g();
break;
}
}
//CHECK-LABEL:Function<f>(2 params, 10 registers, 0 symbols):
//CHECK-NEXT:Offset in debug table: {{.*}}
//CHECK-NEXT: LoadParam r0, 1
//CHECK-NEXT: SwitchImm r0, 292, L18, 0, 16
//CHECK-NEXT:L17:
//CHECK-NEXT: LoadConstInt r1, 3352
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L16:
//CHECK-NEXT: LoadConstInt r1, 3523
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L15:
//CHECK-NEXT: LoadConstInt r1, 3342
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L14:
//CHECK-NEXT: LoadConstInt r1, 3254
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L13:
//CHECK-NEXT: LoadConstInt r1, 3243
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L12:
//CHECK-NEXT: LoadConstInt r1, 2332
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L11:
//CHECK-NEXT: LoadConstInt r1, 3211
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L10:
//CHECK-NEXT: LoadConstInt r1, 3642
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L9:
//CHECK-NEXT: LoadConstInt r1, 2332
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L8:
//CHECK-NEXT: LoadConstInt r1, 3234
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L7:
//CHECK-NEXT: LoadConstInt r1, 323
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L6:
//CHECK-NEXT: LoadConstInt r1, 362
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L5:
//CHECK-NEXT: GetGlobalObject r1
//CHECK-NEXT: GetByIdShort r2, r1, 1, "g"
//CHECK-NEXT: LoadConstUndefined r1
//CHECK-NEXT: Call1 r1, r2, r1
//CHECK-NEXT: LoadConstInt r1, 342
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L4:
//CHECK-NEXT: LoadConstUInt8 r1, 132
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L3:
//CHECK-NEXT: LoadConstInt r1, 322
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L2:
//CHECK-NEXT: LoadConstInt r1, 342
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L1:
//CHECK-NEXT: LoadConstUInt8 r1, 32
//CHECK-NEXT: Ret r1
//CHECK-NEXT:L18:
//CHECK-NEXT: SwitchImm r0, 199, L23, 1, 14
//CHECK-NEXT:L30:
//CHECK-NEXT: LoadConstInt r0, 3342
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L29:
//CHECK-NEXT: LoadConstInt r0, 3254
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L28:
//CHECK-NEXT: LoadConstInt r0, 3243
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L27:
//CHECK-NEXT: LoadConstInt r0, 2332
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L26:
//CHECK-NEXT: LoadConstInt r0, 3211
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L25:
//CHECK-NEXT: LoadConstInt r0, 3642
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L24:
//CHECK-NEXT: LoadConstInt r0, 2332
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L22:
//CHECK-NEXT: GetGlobalObject r0
//CHECK-NEXT: GetByIdShort r1, r0, 1, "g"
//CHECK-NEXT: LoadConstUndefined r0
//CHECK-NEXT: Call1 r0, r1, r0
//CHECK-NEXT: LoadConstInt r0, 342
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L21:
//CHECK-NEXT: LoadConstUInt8 r0, 132
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L20:
//CHECK-NEXT: LoadConstInt r0, 322
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L19:
//CHECK-NEXT: LoadConstInt r0, 342
//CHECK-NEXT: Ret r0
//CHECK-NEXT:L23:
//CHECK-NEXT: GetGlobalObject r0
//CHECK-NEXT: GetByIdShort r1, r0, 1, "g"
//CHECK-NEXT: LoadConstUndefined r0
//CHECK-NEXT: Call1 r1, r1, r0
//CHECK-NEXT: Ret r0
//CHECK-LABEL: Jump Tables:
//CHECK-NEXT: offset 292
//CHECK-NEXT: 0 : L1
//CHECK-NEXT: 1 : L2
//CHECK-NEXT: 2 : L3
//CHECK-NEXT: 3 : L4
//CHECK-NEXT: 4 : L5
//CHECK-NEXT: 5 : L6
//CHECK-NEXT: 6 : L7
//CHECK-NEXT: 7 : L8
//CHECK-NEXT: 8 : L9
//CHECK-NEXT: 9 : L10
//CHECK-NEXT: 10 : L11
//CHECK-NEXT: 11 : L12
//CHECK-NEXT: 12 : L13
//CHECK-NEXT: 13 : L14
//CHECK-NEXT: 14 : L15
//CHECK-NEXT: 15 : L16
//CHECK-NEXT: 16 : L17
//CHECK-NEXT: offset 199
//CHECK-NEXT: 1 : L19
//CHECK-NEXT: 2 : L20
//CHECK-NEXT: 3 : L21
//CHECK-NEXT: 4 : L22
//CHECK-NEXT: 5 : L23
//CHECK-NEXT: 6 : L23
//CHECK-NEXT: 7 : L23
//CHECK-NEXT: 8 : L24
//CHECK-NEXT: 9 : L25
//CHECK-NEXT: 10 : L26
//CHECK-NEXT: 11 : L27
//CHECK-NEXT: 12 : L28
//CHECK-NEXT: 13 : L29
//CHECK-NEXT: 14 : L30