1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "ecmascript/compiler/bytecode_circuit_builder.h"
16 #include "ecmascript/compiler/bytecodes.h"
17 #include "ecmascript/interpreter/interpreter-inl.h"
18
19 namespace panda::ecmascript::kungfu {
InitBytecodeMetaData(const uint8_t * pc)20 BytecodeMetaData BytecodeMetaData::InitBytecodeMetaData(const uint8_t *pc)
21 {
22 BytecodeInstruction inst(pc);
23 uint32_t flags = 0;
24 BytecodeKind kind = BytecodeKind::GENERAL;
25 if (inst.HasFlag(BytecodeInstruction::Flags::ACC_READ)) {
26 flags |= BytecodeFlags::READ_ACC;
27 }
28 if (inst.HasFlag(BytecodeInstruction::Flags::ACC_WRITE)) {
29 flags |= BytecodeFlags::WRITE_ACC;
30 }
31
32 switch (inst.GetOpcode()) {
33 case EcmaOpcode::GETPROPITERATOR:
34 case EcmaOpcode::TYPEOF_IMM8:
35 case EcmaOpcode::TYPEOF_IMM16:
36 case EcmaOpcode::LDSYMBOL:
37 case EcmaOpcode::LDGLOBAL:
38 case EcmaOpcode::LDBIGINT_ID16:
39 case EcmaOpcode::LDEXTERNALMODULEVAR_IMM8:
40 case EcmaOpcode::WIDE_LDEXTERNALMODULEVAR_PREF_IMM16:
41 case EcmaOpcode::GETMODULENAMESPACE_IMM8:
42 case EcmaOpcode::WIDE_GETMODULENAMESPACE_PREF_IMM16:
43 case EcmaOpcode::ISTRUE:
44 case EcmaOpcode::ISFALSE:
45 case EcmaOpcode::LDGLOBALVAR_IMM16_ID16:
46 case EcmaOpcode::LDOBJBYINDEX_IMM8_IMM16:
47 case EcmaOpcode::LDOBJBYINDEX_IMM16_IMM16:
48 case EcmaOpcode::WIDE_LDOBJBYINDEX_PREF_IMM32:
49 case EcmaOpcode::LDLEXVAR_IMM4_IMM4:
50 case EcmaOpcode::LDLEXVAR_IMM8_IMM8:
51 case EcmaOpcode::WIDE_LDLEXVAR_PREF_IMM16_IMM16:
52 case EcmaOpcode::WIDE_LDPATCHVAR_PREF_IMM16:
53 case EcmaOpcode::LDLOCALMODULEVAR_IMM8:
54 case EcmaOpcode::WIDE_LDLOCALMODULEVAR_PREF_IMM16:
55 flags |= BytecodeFlags::NO_SIDE_EFFECTS;
56 break;
57 default:
58 break;
59 }
60
61 switch (inst.GetOpcode()) {
62 case EcmaOpcode::MOV_V4_V4:
63 case EcmaOpcode::MOV_V8_V8:
64 case EcmaOpcode::MOV_V16_V16:
65 case EcmaOpcode::STA_V8:
66 case EcmaOpcode::LDA_V8:
67 kind = BytecodeKind::MOV;
68 break;
69 case EcmaOpcode::LDNAN:
70 case EcmaOpcode::LDINFINITY:
71 case EcmaOpcode::LDUNDEFINED:
72 case EcmaOpcode::LDNULL:
73 case EcmaOpcode::LDTRUE:
74 case EcmaOpcode::LDFALSE:
75 case EcmaOpcode::LDHOLE:
76 case EcmaOpcode::LDAI_IMM32:
77 case EcmaOpcode::FLDAI_IMM64:
78 case EcmaOpcode::LDFUNCTION:
79 case EcmaOpcode::LDA_STR_ID16:
80 kind = BytecodeKind::SET_CONSTANT;
81 break;
82 case EcmaOpcode::LDTHISBYVALUE_IMM8:
83 case EcmaOpcode::LDTHISBYVALUE_IMM16:
84 case EcmaOpcode::STTHISBYVALUE_IMM8_V8:
85 case EcmaOpcode::STTHISBYVALUE_IMM16_V8:
86 flags |= BytecodeFlags::READ_THIS_OBJECT;
87 break;
88 case EcmaOpcode::LDTHISBYNAME_IMM8_ID16:
89 case EcmaOpcode::LDTHISBYNAME_IMM16_ID16:
90 case EcmaOpcode::STTHISBYNAME_IMM8_ID16:
91 case EcmaOpcode::STTHISBYNAME_IMM16_ID16:
92 flags |= BytecodeFlags::READ_THIS_OBJECT;
93 [[fallthrough]];
94 case EcmaOpcode::ADD2_IMM8_V8:
95 case EcmaOpcode::SUB2_IMM8_V8:
96 case EcmaOpcode::MUL2_IMM8_V8:
97 case EcmaOpcode::DIV2_IMM8_V8:
98 case EcmaOpcode::EQ_IMM8_V8:
99 case EcmaOpcode::NOTEQ_IMM8_V8:
100 case EcmaOpcode::LESS_IMM8_V8:
101 case EcmaOpcode::LESSEQ_IMM8_V8:
102 case EcmaOpcode::GREATER_IMM8_V8:
103 case EcmaOpcode::GREATEREQ_IMM8_V8:
104 case EcmaOpcode::TONUMERIC_IMM8:
105 case EcmaOpcode::ISTRUE:
106 case EcmaOpcode::ISFALSE:
107 case EcmaOpcode::INC_IMM8:
108 case EcmaOpcode::DEC_IMM8:
109 case EcmaOpcode::NEG_IMM8:
110 case EcmaOpcode::NOT_IMM8:
111 case EcmaOpcode::MOD2_IMM8_V8:
112 case EcmaOpcode::SHL2_IMM8_V8:
113 case EcmaOpcode::SHR2_IMM8_V8:
114 case EcmaOpcode::ASHR2_IMM8_V8:
115 case EcmaOpcode::AND2_IMM8_V8:
116 case EcmaOpcode::OR2_IMM8_V8:
117 case EcmaOpcode::XOR2_IMM8_V8:
118 case EcmaOpcode::LDOBJBYNAME_IMM8_ID16:
119 case EcmaOpcode::LDOBJBYNAME_IMM16_ID16:
120 case EcmaOpcode::STOBJBYNAME_IMM8_ID16_V8:
121 case EcmaOpcode::STOBJBYNAME_IMM16_ID16_V8:
122 case EcmaOpcode::LDOBJBYINDEX_IMM8_IMM16:
123 case EcmaOpcode::LDOBJBYINDEX_IMM16_IMM16:
124 case EcmaOpcode::WIDE_LDOBJBYINDEX_PREF_IMM32:
125 case EcmaOpcode::STOBJBYINDEX_IMM8_V8_IMM16:
126 case EcmaOpcode::STOBJBYINDEX_IMM16_V8_IMM16:
127 case EcmaOpcode::WIDE_STOBJBYINDEX_PREF_V8_IMM32:
128 case EcmaOpcode::LDOBJBYVALUE_IMM8_V8:
129 case EcmaOpcode::LDOBJBYVALUE_IMM16_V8:
130 case EcmaOpcode::NEWOBJRANGE_IMM8_IMM8_V8:
131 case EcmaOpcode::NEWOBJRANGE_IMM16_IMM8_V8:
132 case EcmaOpcode::WIDE_NEWOBJRANGE_PREF_IMM16_V8:
133 case EcmaOpcode::SUPERCALLTHISRANGE_IMM8_IMM8_V8:
134 case EcmaOpcode::WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8:
135 case EcmaOpcode::CALLTHIS1_IMM8_V8_V8:
136 flags |= BytecodeFlags::SUPPORT_DEOPT;
137 break;
138 case EcmaOpcode::RETURNUNDEFINED:
139 flags |= BytecodeFlags::READ_ACC;
140 [[fallthrough]];
141 case EcmaOpcode::RETURN:
142 kind = BytecodeKind::RETURN_BC;
143 break;
144 case EcmaOpcode::SUSPENDGENERATOR_V8:
145 flags |= BytecodeFlags::READ_THIS_OBJECT;
146 U_FALLTHROUGH;
147 case EcmaOpcode::DEPRECATED_SUSPENDGENERATOR_PREF_V8_V8:
148 kind = BytecodeKind::SUSPEND;
149 break;
150 case EcmaOpcode::RESUMEGENERATOR:
151 kind = BytecodeKind::RESUME;
152 break;
153 case EcmaOpcode::DEBUGGER:
154 case EcmaOpcode::NOP:
155 kind = BytecodeKind::DISCARDED;
156 break;
157 case EcmaOpcode::THROW_PREF_NONE:
158 case EcmaOpcode::THROW_NOTEXISTS_PREF_NONE:
159 case EcmaOpcode::THROW_PATTERNNONCOERCIBLE_PREF_NONE:
160 case EcmaOpcode::THROW_DELETESUPERPROPERTY_PREF_NONE:
161 case EcmaOpcode::THROW_CONSTASSIGNMENT_PREF_V8:
162 kind = BytecodeKind::THROW_BC;
163 break;
164 case EcmaOpcode::JEQZ_IMM8:
165 case EcmaOpcode::JEQZ_IMM16:
166 case EcmaOpcode::JEQZ_IMM32:
167 case EcmaOpcode::JNEZ_IMM8:
168 case EcmaOpcode::JNEZ_IMM16:
169 case EcmaOpcode::JNEZ_IMM32:
170 kind = BytecodeKind::CONDITIONAL_JUMP;
171 break;
172 case EcmaOpcode::JMP_IMM8:
173 case EcmaOpcode::JMP_IMM16:
174 case EcmaOpcode::JMP_IMM32:
175 kind = BytecodeKind::JUMP_IMM;
176 break;
177 case EcmaOpcode::CALLRUNTIME_NOTIFYCONCURRENTRESULT_PREF_NONE:
178 flags |= BytecodeFlags::READ_THIS_OBJECT;
179 break;
180 default:
181 break;
182 }
183
184 switch (inst.GetOpcode()) {
185 case EcmaOpcode::NEWLEXENV_IMM8:
186 case EcmaOpcode::WIDE_NEWLEXENV_PREF_IMM16:
187 case EcmaOpcode::NEWLEXENVWITHNAME_IMM8_ID16:
188 case EcmaOpcode::WIDE_NEWLEXENVWITHNAME_PREF_IMM16_ID16:
189 case EcmaOpcode::POPLEXENV:
190 flags |= BytecodeFlags::WRITE_ENV;
191 case EcmaOpcode::LDLEXVAR_IMM4_IMM4:
192 case EcmaOpcode::LDLEXVAR_IMM8_IMM8:
193 case EcmaOpcode::WIDE_LDLEXVAR_PREF_IMM16_IMM16:
194 case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM8_ID16:
195 case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM16_ID16:
196 case EcmaOpcode::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:
197 case EcmaOpcode::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8:
198 case EcmaOpcode::DEFINEFUNC_IMM8_ID16_IMM8:
199 case EcmaOpcode::DEFINEFUNC_IMM16_ID16_IMM8:
200 case EcmaOpcode::DEFINEMETHOD_IMM8_ID16_IMM8:
201 case EcmaOpcode::DEFINEMETHOD_IMM16_ID16_IMM8:
202 flags |= BytecodeFlags::READ_ENV;
203 break;
204 default:
205 break;
206 }
207
208 if (kind == BytecodeKind::GENERAL ||
209 kind == BytecodeKind::THROW_BC ||
210 kind == BytecodeKind::RESUME ||
211 kind == BytecodeKind::SUSPEND) {
212 flags |= BytecodeFlags::GENERAL_BC;
213 }
214 auto size = inst.GetSize();
215 uint64_t value = SizeField::Encode(size) | KindField::Encode(kind) |
216 FlagsField::Encode(static_cast<BytecodeFlags>(flags)) |
217 OpcodeField::Encode(inst.GetOpcode());
218 return BytecodeMetaData(value);
219 }
220
Bytecodes()221 Bytecodes::Bytecodes()
222 {
223 for (uint8_t pc = 0; pc < static_cast<uint8_t>(Bytecodes::LAST_OPCODE); pc++) {
224 auto info = BytecodeMetaData::InitBytecodeMetaData(&pc);
225 bytecodes_[pc] = info;
226 }
227 auto last = (static_cast<uint16_t>(Bytecodes::LAST_CALLRUNTIME_OPCODE) & OPCODE_MASK) >> BYTE_SIZE;
228 for (uint8_t pc = 0; pc <= last; pc++) {
229 std::array<uint8_t, 2> bytecode{CALLRUNTIME_PREFIX_OPCODE_INDEX, pc}; // 2: 2 opcode
230 auto info = BytecodeMetaData::InitBytecodeMetaData(&bytecode[0]);
231 callRuntimeBytecodes_[pc] = info;
232 }
233 last = (static_cast<uint16_t>(Bytecodes::LAST_DEPRECATED_OPCODE) & OPCODE_MASK) >> BYTE_SIZE;
234 for (uint8_t pc = 0; pc <= last; pc++) {
235 std::array<uint8_t, 2> bytecode{DEPRECATED_PREFIX_OPCODE_INDEX, pc}; // 2: 2 opcode
236 auto info = BytecodeMetaData::InitBytecodeMetaData(&bytecode[0]);
237 deprecatedBytecodes_[pc] = info;
238 }
239 last = (static_cast<uint16_t>(Bytecodes::LAST_WIDE_OPCODE) & OPCODE_MASK) >> BYTE_SIZE;
240 for (uint8_t pc = 0; pc <= last; pc++) {
241 std::array<uint8_t, 2> bytecode{WIDE_PREFIX_OPCODE_INDEX, pc}; // 2: 2 opcode
242 auto info = BytecodeMetaData::InitBytecodeMetaData(&bytecode[0]);
243 wideBytecodes_[pc] = info;
244 }
245 last = (static_cast<uint16_t>(Bytecodes::LAST_THROW_OPCODE) & OPCODE_MASK) >> BYTE_SIZE;
246 for (uint8_t pc = 0; pc <= last; pc++) {
247 std::array<uint8_t, 2> bytecode{THROW_PREFIX_OPCODE_INDEX, pc}; // 2: 2 opcode
248 auto info = BytecodeMetaData::InitBytecodeMetaData(&bytecode[0]);
249 throwBytecodes_[pc] = info;
250 }
251 }
252
InitBytecodeInfo(BytecodeCircuitBuilder * builder,BytecodeInfo & info,const uint8_t * pc)253 void BytecodeInfo::InitBytecodeInfo(BytecodeCircuitBuilder *builder,
254 BytecodeInfo &info, const uint8_t *pc)
255 {
256 auto opcode = info.GetOpcode();
257 switch (opcode) {
258 case EcmaOpcode::MOV_V4_V4: {
259 uint16_t vdst = READ_INST_4_0();
260 uint16_t vsrc = READ_INST_4_1();
261 info.vregOut.emplace_back(vdst);
262 info.inputs.emplace_back(VirtualRegister(vsrc));
263 break;
264 }
265 case EcmaOpcode::MOV_V8_V8: {
266 uint16_t vdst = READ_INST_8_0();
267 uint16_t vsrc = READ_INST_8_1();
268 info.vregOut.emplace_back(vdst);
269 info.inputs.emplace_back(VirtualRegister(vsrc));
270 break;
271 }
272 case EcmaOpcode::MOV_V16_V16: {
273 uint16_t vdst = READ_INST_16_0();
274 uint16_t vsrc = READ_INST_16_2();
275 info.vregOut.emplace_back(vdst);
276 info.inputs.emplace_back(VirtualRegister(vsrc));
277 break;
278 }
279 case EcmaOpcode::LDA_STR_ID16: {
280 uint16_t stringId = READ_INST_16_0();
281 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
282 break;
283 }
284 case EcmaOpcode::LDA_V8: {
285 uint16_t vsrc = READ_INST_8_0();
286 info.inputs.emplace_back(VirtualRegister(vsrc));
287 break;
288 }
289 case EcmaOpcode::STA_V8: {
290 uint16_t vdst = READ_INST_8_0();
291 info.vregOut.emplace_back(vdst);
292 break;
293 }
294 case EcmaOpcode::LDAI_IMM32: {
295 info.inputs.emplace_back(Immediate(READ_INST_32_0()));
296 break;
297 }
298 case EcmaOpcode::FLDAI_IMM64: {
299 info.inputs.emplace_back(Immediate(READ_INST_64_0()));
300 break;
301 }
302 case EcmaOpcode::CALLARG1_IMM8_V8: {
303 uint32_t a0 = READ_INST_8_1();
304 info.inputs.emplace_back(VirtualRegister(a0));
305 break;
306 }
307 case EcmaOpcode::CALLTHIS1_IMM8_V8_V8: {
308 uint32_t startReg = READ_INST_8_1(); // this
309 uint32_t a0 = READ_INST_8_2();
310 info.inputs.emplace_back(VirtualRegister(startReg));
311 info.inputs.emplace_back(VirtualRegister(a0));
312 break;
313 }
314 case EcmaOpcode::CALLARGS2_IMM8_V8_V8: {
315 uint32_t a0 = READ_INST_8_1();
316 uint32_t a1 = READ_INST_8_2();
317 info.inputs.emplace_back(VirtualRegister(a0));
318 info.inputs.emplace_back(VirtualRegister(a1));
319 break;
320 }
321 case EcmaOpcode::CALLARGS3_IMM8_V8_V8_V8: {
322 uint32_t a0 = READ_INST_8_1();
323 uint32_t a1 = READ_INST_8_2();
324 uint32_t a2 = READ_INST_8_3();
325 info.inputs.emplace_back(VirtualRegister(a0));
326 info.inputs.emplace_back(VirtualRegister(a1));
327 info.inputs.emplace_back(VirtualRegister(a2));
328 break;
329 }
330 case EcmaOpcode::CALLTHISRANGE_IMM8_IMM8_V8: {
331 uint32_t actualNumArgs = READ_INST_8_1();
332 uint32_t startReg = READ_INST_8_2();
333 info.inputs.emplace_back(VirtualRegister(startReg));
334 for (size_t i = 1; i <= actualNumArgs; i++) {
335 info.inputs.emplace_back(VirtualRegister(startReg + i));
336 }
337 break;
338 }
339 case EcmaOpcode::WIDE_CALLTHISRANGE_PREF_IMM16_V8: {
340 uint32_t actualNumArgs = READ_INST_16_1();
341 uint32_t startReg = READ_INST_8_3();
342 info.inputs.emplace_back(VirtualRegister(startReg));
343 for (size_t i = 1; i <= actualNumArgs; i++) {
344 info.inputs.emplace_back(VirtualRegister(startReg + i));
345 }
346 break;
347 }
348 case EcmaOpcode::CALLTHIS0_IMM8_V8: {
349 int32_t startReg = READ_INST_8_1();
350 info.inputs.emplace_back(VirtualRegister(startReg));
351 break;
352 }
353 case EcmaOpcode::CALLTHIS2_IMM8_V8_V8_V8: {
354 int32_t startReg = READ_INST_8_1();
355 uint32_t a0 = READ_INST_8_2();
356 uint32_t a1 = READ_INST_8_3();
357 info.inputs.emplace_back(VirtualRegister(startReg));
358 info.inputs.emplace_back(VirtualRegister(a0));
359 info.inputs.emplace_back(VirtualRegister(a1));
360 break;
361 }
362 case EcmaOpcode::CALLTHIS3_IMM8_V8_V8_V8_V8: {
363 int32_t startReg = READ_INST_8_1();
364 uint32_t a0 = READ_INST_8_2();
365 uint32_t a1 = READ_INST_8_3();
366 uint32_t a2 = READ_INST_8_4();
367 info.inputs.emplace_back(VirtualRegister(startReg));
368 info.inputs.emplace_back(VirtualRegister(a0));
369 info.inputs.emplace_back(VirtualRegister(a1));
370 info.inputs.emplace_back(VirtualRegister(a2));
371 break;
372 }
373
374 case EcmaOpcode::APPLY_IMM8_V8_V8: {
375 uint16_t v0 = READ_INST_8_1();
376 uint16_t v1 = READ_INST_8_2();
377 info.inputs.emplace_back(VirtualRegister(v0));
378 info.inputs.emplace_back(VirtualRegister(v1));
379 break;
380 }
381 case EcmaOpcode::CALLRANGE_IMM8_IMM8_V8: {
382 int32_t actualNumArgs = READ_INST_8_1();
383 int32_t startReg = READ_INST_8_2();
384 for (int i = 0; i < actualNumArgs; i++) {
385 info.inputs.emplace_back(VirtualRegister(startReg + i));
386 }
387 break;
388 }
389 case EcmaOpcode::WIDE_CALLRANGE_PREF_IMM16_V8: {
390 int32_t actualNumArgs = READ_INST_16_1();
391 int32_t startReg = READ_INST_8_3();
392 for (int i = 0; i < actualNumArgs; i++) {
393 info.inputs.emplace_back(VirtualRegister(startReg + i));
394 }
395 break;
396 }
397 case EcmaOpcode::THROW_CONSTASSIGNMENT_PREF_V8: {
398 uint16_t v0 = READ_INST_8_1();
399 info.inputs.emplace_back(VirtualRegister(v0));
400 break;
401 }
402 case EcmaOpcode::THROW_IFNOTOBJECT_PREF_V8: {
403 uint16_t v0 = READ_INST_8_1();
404 info.inputs.emplace_back(VirtualRegister(v0));
405 break;
406 }
407 case EcmaOpcode::THROW_UNDEFINEDIFHOLE_PREF_V8_V8: {
408 uint16_t v0 = READ_INST_8_1();
409 uint16_t v1 = READ_INST_8_2();
410 info.inputs.emplace_back(VirtualRegister(v0));
411 info.inputs.emplace_back(VirtualRegister(v1));
412 break;
413 }
414 case EcmaOpcode::THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16: {
415 uint16_t stringId = READ_INST_16_1();
416 info.inputs.emplace_back(ICSlotId(stringId));
417 break;
418 }
419 case EcmaOpcode::THROW_IFSUPERNOTCORRECTCALL_PREF_IMM8: {
420 uint8_t imm = READ_INST_8_1();
421 info.inputs.emplace_back(Immediate(imm));
422 break;
423 }
424 case EcmaOpcode::THROW_IFSUPERNOTCORRECTCALL_PREF_IMM16: {
425 uint16_t imm = READ_INST_16_1();
426 info.inputs.emplace_back(Immediate(imm));
427 break;
428 }
429 case EcmaOpcode::CLOSEITERATOR_IMM8_V8: {
430 uint16_t v0 = READ_INST_8_1();
431 info.inputs.emplace_back(VirtualRegister(v0));
432 break;
433 }
434 case EcmaOpcode::ADD2_IMM8_V8: {
435 uint16_t v0 = READ_INST_8_1();
436 info.inputs.emplace_back(VirtualRegister(v0));
437 break;
438 }
439 case EcmaOpcode::SUB2_IMM8_V8: {
440 uint16_t v0 = READ_INST_8_1();
441 info.inputs.emplace_back(VirtualRegister(v0));
442 break;
443 }
444 case EcmaOpcode::MUL2_IMM8_V8: {
445 uint16_t v0 = READ_INST_8_1();
446 info.inputs.emplace_back(VirtualRegister(v0));
447 break;
448 }
449 case EcmaOpcode::DIV2_IMM8_V8: {
450 uint16_t v0 = READ_INST_8_1();
451 info.inputs.emplace_back(VirtualRegister(v0));
452 break;
453 }
454 case EcmaOpcode::MOD2_IMM8_V8: {
455 uint16_t v0 = READ_INST_8_1();
456 info.inputs.emplace_back(VirtualRegister(v0));
457 break;
458 }
459 case EcmaOpcode::EQ_IMM8_V8: {
460 uint16_t v0 = READ_INST_8_1();
461 info.inputs.emplace_back(VirtualRegister(v0));
462 break;
463 }
464 case EcmaOpcode::NOTEQ_IMM8_V8: {
465 uint16_t v0 = READ_INST_8_1();
466 info.inputs.emplace_back(VirtualRegister(v0));
467 break;
468 }
469 case EcmaOpcode::LESS_IMM8_V8: {
470 uint16_t v0 = READ_INST_8_1();
471 info.inputs.emplace_back(VirtualRegister(v0));
472 break;
473 }
474 case EcmaOpcode::LESSEQ_IMM8_V8: {
475 uint16_t v0 = READ_INST_8_1();
476 info.inputs.emplace_back(VirtualRegister(v0));
477 break;
478 }
479 case EcmaOpcode::GREATER_IMM8_V8: {
480 uint16_t v0 = READ_INST_8_1();
481 info.inputs.emplace_back(VirtualRegister(v0));
482 break;
483 }
484 case EcmaOpcode::GREATEREQ_IMM8_V8: {
485 uint16_t vs = READ_INST_8_1();
486 info.inputs.emplace_back(VirtualRegister(vs));
487 break;
488 }
489 case EcmaOpcode::SHL2_IMM8_V8: {
490 uint16_t v0 = READ_INST_8_1();
491 info.inputs.emplace_back(VirtualRegister(v0));
492 break;
493 }
494 case EcmaOpcode::SHR2_IMM8_V8: {
495 uint16_t v0 = READ_INST_8_1();
496 info.inputs.emplace_back(VirtualRegister(v0));
497 break;
498 }
499 case EcmaOpcode::ASHR2_IMM8_V8: {
500 uint16_t v0 = READ_INST_8_1();
501 info.inputs.emplace_back(VirtualRegister(v0));
502 break;
503 }
504 case EcmaOpcode::AND2_IMM8_V8: {
505 uint16_t v0 = READ_INST_8_1();
506 info.inputs.emplace_back(VirtualRegister(v0));
507 break;
508 }
509 case EcmaOpcode::OR2_IMM8_V8: {
510 uint16_t v0 = READ_INST_8_1();
511 info.inputs.emplace_back(VirtualRegister(v0));
512 break;
513 }
514 case EcmaOpcode::XOR2_IMM8_V8: {
515 uint16_t v0 = READ_INST_8_1();
516 info.inputs.emplace_back(VirtualRegister(v0));
517 break;
518 }
519 case EcmaOpcode::EXP_IMM8_V8: {
520 uint16_t v0 = READ_INST_8_1();
521 info.inputs.emplace_back(VirtualRegister(v0));
522 break;
523 }
524 case EcmaOpcode::ISIN_IMM8_V8: {
525 uint16_t v0 = READ_INST_8_1();
526 info.inputs.emplace_back(VirtualRegister(v0));
527 break;
528 }
529 case EcmaOpcode::INSTANCEOF_IMM8_V8: {
530 uint16_t v0 = READ_INST_8_1();
531 info.inputs.emplace_back(VirtualRegister(v0));
532 break;
533 }
534 case EcmaOpcode::STRICTNOTEQ_IMM8_V8: {
535 uint16_t v0 = READ_INST_8_1();
536 info.inputs.emplace_back(VirtualRegister(v0));
537 break;
538 }
539 case EcmaOpcode::STRICTEQ_IMM8_V8: {
540 uint16_t v0 = READ_INST_8_1();
541 info.inputs.emplace_back(VirtualRegister(v0));
542 break;
543 }
544 case EcmaOpcode::DELOBJPROP_V8: {
545 uint16_t v0 = READ_INST_8_0();
546 info.inputs.emplace_back(VirtualRegister(v0));
547 break;
548 }
549 case EcmaOpcode::DEFINEFUNC_IMM8_ID16_IMM8: {
550 uint16_t methodId = READ_INST_16_1();
551 uint16_t length = READ_INST_8_3();
552 info.inputs.emplace_back(ConstDataId(ConstDataIDType::MethodIDType, methodId));
553 info.inputs.emplace_back(Immediate(length));
554 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
555 break;
556 }
557 case EcmaOpcode::DEFINEFUNC_IMM16_ID16_IMM8: {
558 uint16_t methodId = READ_INST_16_2();
559 uint16_t length = READ_INST_8_4();
560 info.inputs.emplace_back(ConstDataId(ConstDataIDType::MethodIDType, methodId));
561 info.inputs.emplace_back(Immediate(length));
562 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
563 break;
564 }
565 case EcmaOpcode::DEFINEMETHOD_IMM8_ID16_IMM8: {
566 uint16_t methodId = READ_INST_16_1();
567 uint16_t length = READ_INST_8_3();
568 info.inputs.emplace_back(ConstDataId(ConstDataIDType::MethodIDType, methodId));
569 info.inputs.emplace_back(Immediate(length));
570 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
571 break;
572 }
573 case EcmaOpcode::DEFINEMETHOD_IMM16_ID16_IMM8: {
574 uint16_t methodId = READ_INST_16_2();
575 uint16_t length = READ_INST_8_4();
576 info.inputs.emplace_back(ConstDataId(ConstDataIDType::MethodIDType, methodId));
577 info.inputs.emplace_back(Immediate(length));
578 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
579 break;
580 }
581 case EcmaOpcode::NEWOBJRANGE_IMM8_IMM8_V8: {
582 uint16_t numArgs = READ_INST_8_1();
583 uint16_t firstArgRegIdx = READ_INST_8_2();
584 for (uint16_t i = 0; i < numArgs; ++i) {
585 info.inputs.emplace_back(VirtualRegister(firstArgRegIdx + i));
586 }
587 break;
588 }
589 case EcmaOpcode::NEWOBJRANGE_IMM16_IMM8_V8: {
590 uint16_t numArgs = READ_INST_8_2();
591 uint16_t firstArgRegIdx = READ_INST_8_3();
592 for (uint16_t i = 0; i < numArgs; ++i) {
593 info.inputs.emplace_back(VirtualRegister(firstArgRegIdx + i));
594 }
595 break;
596 }
597 case EcmaOpcode::WIDE_NEWOBJRANGE_PREF_IMM16_V8: {
598 uint16_t numArgs = READ_INST_16_1();
599 uint16_t firstArgRegIdx = READ_INST_8_3();
600 for (uint16_t i = 0; i < numArgs; ++i) {
601 info.inputs.emplace_back(VirtualRegister(firstArgRegIdx + i));
602 }
603 break;
604 }
605 case EcmaOpcode::LDLEXVAR_IMM4_IMM4: {
606 uint16_t level = READ_INST_4_0();
607 uint16_t slot = READ_INST_4_1();
608 info.inputs.emplace_back(Immediate(level));
609 info.inputs.emplace_back(Immediate(slot));
610 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
611 break;
612 }
613 case EcmaOpcode::LDLEXVAR_IMM8_IMM8: {
614 uint16_t level = READ_INST_8_0();
615 uint16_t slot = READ_INST_8_1();
616 info.inputs.emplace_back(Immediate(level));
617 info.inputs.emplace_back(Immediate(slot));
618 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
619 break;
620 }
621 case EcmaOpcode::WIDE_LDLEXVAR_PREF_IMM16_IMM16: {
622 uint16_t level = READ_INST_16_1();
623 uint16_t slot = READ_INST_16_3();
624 info.inputs.emplace_back(Immediate(level));
625 info.inputs.emplace_back(Immediate(slot));
626 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
627 break;
628 }
629 case EcmaOpcode::STLEXVAR_IMM4_IMM4: {
630 uint16_t level = READ_INST_4_0();
631 uint16_t slot = READ_INST_4_1();
632 info.inputs.emplace_back(Immediate(level));
633 info.inputs.emplace_back(Immediate(slot));
634 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
635 break;
636 }
637 case EcmaOpcode::STLEXVAR_IMM8_IMM8: {
638 uint16_t level = READ_INST_8_0();
639 uint16_t slot = READ_INST_8_1();
640 info.inputs.emplace_back(Immediate(level));
641 info.inputs.emplace_back(Immediate(slot));
642 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
643 info.vregOut.emplace_back(builder->GetEnvVregIdx());
644 break;
645 }
646 case EcmaOpcode::WIDE_STLEXVAR_PREF_IMM16_IMM16: {
647 uint16_t level = READ_INST_16_1();
648 uint16_t slot = READ_INST_16_3();
649 info.inputs.emplace_back(Immediate(level));
650 info.inputs.emplace_back(Immediate(slot));
651 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
652 info.vregOut.emplace_back(builder->GetEnvVregIdx());
653 break;
654 }
655 case EcmaOpcode::NEWLEXENV_IMM8: {
656 uint8_t numVars = READ_INST_8_0();
657 info.inputs.emplace_back(Immediate(numVars));
658 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
659 info.vregOut.emplace_back(builder->GetEnvVregIdx());
660 break;
661 }
662 case EcmaOpcode::WIDE_NEWLEXENV_PREF_IMM16: {
663 uint16_t numVars = READ_INST_16_1();
664 info.inputs.emplace_back(Immediate(numVars));
665 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
666 info.vregOut.emplace_back(builder->GetEnvVregIdx());
667 break;
668 }
669 case EcmaOpcode::NEWLEXENVWITHNAME_IMM8_ID16: {
670 uint16_t numVars = READ_INST_8_0();
671 uint16_t scopeId = READ_INST_16_1();
672 info.inputs.emplace_back(Immediate(numVars));
673 info.inputs.emplace_back(Immediate(scopeId));
674 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
675 info.vregOut.emplace_back(builder->GetEnvVregIdx());
676 break;
677 }
678 case EcmaOpcode::WIDE_NEWLEXENVWITHNAME_PREF_IMM16_ID16: {
679 uint16_t numVars = READ_INST_16_1();
680 uint16_t scopeId = READ_INST_16_3();
681 info.inputs.emplace_back(Immediate(numVars));
682 info.inputs.emplace_back(Immediate(scopeId));
683 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
684 info.vregOut.emplace_back(builder->GetEnvVregIdx());
685 break;
686 }
687 case EcmaOpcode::CREATEITERRESULTOBJ_V8_V8: {
688 uint16_t v0 = READ_INST_8_0();
689 uint16_t v1 = READ_INST_8_1();
690 info.inputs.emplace_back(VirtualRegister(v0));
691 info.inputs.emplace_back(VirtualRegister(v1));
692 break;
693 }
694 case EcmaOpcode::SUSPENDGENERATOR_V8: {
695 uint16_t v0 = READ_INST_8_0();
696 uint32_t offset = builder->GetPcOffset(pc);
697 info.inputs.emplace_back(Immediate(offset)); // Save the pc offset when suspend
698 info.inputs.emplace_back(VirtualRegister(v0));
699 break;
700 }
701 case EcmaOpcode::ASYNCFUNCTIONAWAITUNCAUGHT_V8: {
702 uint16_t v0 = READ_INST_8_0();
703 info.inputs.emplace_back(VirtualRegister(v0));
704 break;
705 }
706 case EcmaOpcode::ASYNCFUNCTIONRESOLVE_V8: {
707 uint16_t v0 = READ_INST_8_0();
708 info.inputs.emplace_back(VirtualRegister(v0));
709 break;
710 }
711 case EcmaOpcode::ASYNCFUNCTIONREJECT_V8: {
712 uint16_t v0 = READ_INST_8_0();
713 info.inputs.emplace_back(VirtualRegister(v0));
714 break;
715 }
716 case EcmaOpcode::CLOSEITERATOR_IMM16_V8: {
717 uint16_t v0 = READ_INST_8_2();
718 info.inputs.emplace_back(VirtualRegister(v0));
719 break;
720 }
721 case EcmaOpcode::NEWOBJAPPLY_IMM8_V8: {
722 uint16_t v0 = READ_INST_8_1();
723 info.inputs.emplace_back(VirtualRegister(v0));
724 break;
725 }
726 case EcmaOpcode::NEWOBJAPPLY_IMM16_V8: {
727 uint16_t v0 = READ_INST_8_2();
728 info.inputs.emplace_back(VirtualRegister(v0));
729 break;
730 }
731 case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8: {
732 uint16_t stringId = READ_INST_16_1();
733 uint32_t v0 = READ_INST_8_3();
734 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
735 info.inputs.emplace_back(VirtualRegister(v0));
736 break;
737 }
738 case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8: {
739 uint16_t stringId = READ_INST_16_2();
740 uint32_t v0 = READ_INST_8_4();
741 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
742 info.inputs.emplace_back(VirtualRegister(v0));
743 break;
744 }
745 case EcmaOpcode::CREATEREGEXPWITHLITERAL_IMM8_ID16_IMM8: {
746 uint16_t stringId = READ_INST_16_1();
747 uint8_t flags = READ_INST_8_3();
748 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
749 info.inputs.emplace_back(Immediate(flags));
750 break;
751 }
752 case EcmaOpcode::CREATEREGEXPWITHLITERAL_IMM16_ID16_IMM8: {
753 uint16_t stringId = READ_INST_16_2();
754 uint8_t flags = READ_INST_8_4();
755 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
756 info.inputs.emplace_back(Immediate(flags));
757 break;
758 }
759 case EcmaOpcode::GETNEXTPROPNAME_V8: {
760 uint16_t v0 = READ_INST_8_0();
761 info.inputs.emplace_back(VirtualRegister(v0));
762 break;
763 }
764 case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM8_ID16: {
765 uint16_t imm = READ_INST_16_1();
766 info.inputs.emplace_back(ConstDataId(ConstDataIDType::ObjectLiteralIDType, imm));
767 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
768 break;
769 }
770 case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM16_ID16: {
771 uint16_t imm = READ_INST_16_2();
772 info.inputs.emplace_back(ConstDataId(ConstDataIDType::ObjectLiteralIDType, imm));
773 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
774 break;
775 }
776 case EcmaOpcode::SETOBJECTWITHPROTO_IMM8_V8: {
777 uint16_t v0 = READ_INST_8_1();
778 info.inputs.emplace_back(VirtualRegister(v0));
779 break;
780 }
781 case EcmaOpcode::SETOBJECTWITHPROTO_IMM16_V8: {
782 uint16_t v0 = READ_INST_8_2();
783 info.inputs.emplace_back(VirtualRegister(v0));
784 break;
785 }
786 case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM8_ID16: {
787 uint16_t imm = READ_INST_16_1();
788 info.inputs.emplace_back(ConstDataId(ConstDataIDType::ArrayLiteralIDType, imm));
789 break;
790 }
791 case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM16_ID16: {
792 uint16_t imm = READ_INST_16_2();
793 info.inputs.emplace_back(ConstDataId(ConstDataIDType::ArrayLiteralIDType, imm));
794 break;
795 }
796 case EcmaOpcode::GETMODULENAMESPACE_IMM8: {
797 int32_t index = READ_INST_8_0();
798 info.inputs.emplace_back(Immediate(index));
799 break;
800 }
801 case EcmaOpcode::WIDE_GETMODULENAMESPACE_PREF_IMM16: {
802 int32_t index = READ_INST_16_1();
803 info.inputs.emplace_back(Immediate(index));
804 break;
805 }
806 case EcmaOpcode::STMODULEVAR_IMM8: {
807 int32_t index = READ_INST_8_0();
808 info.inputs.emplace_back(Immediate(index));
809 break;
810 }
811 case EcmaOpcode::SETGENERATORSTATE_IMM8: {
812 int32_t index = READ_INST_8_0();
813 info.inputs.emplace_back(Immediate(index));
814 break;
815 }
816 case EcmaOpcode::WIDE_STMODULEVAR_PREF_IMM16: {
817 int32_t index = READ_INST_16_1();
818 info.inputs.emplace_back(Immediate(index));
819 break;
820 }
821 case EcmaOpcode::LDLOCALMODULEVAR_IMM8: {
822 int32_t index = READ_INST_8_0();
823 info.inputs.emplace_back(Immediate(index));
824 break;
825 }
826 case EcmaOpcode::WIDE_LDLOCALMODULEVAR_PREF_IMM16: {
827 int32_t index = READ_INST_16_1();
828 info.inputs.emplace_back(Immediate(index));
829 break;
830 }
831 case EcmaOpcode::LDEXTERNALMODULEVAR_IMM8: {
832 int32_t index = READ_INST_8_0();
833 info.inputs.emplace_back(Immediate(index));
834 break;
835 }
836 case EcmaOpcode::WIDE_LDEXTERNALMODULEVAR_PREF_IMM16: {
837 int32_t index = READ_INST_16_1();
838 info.inputs.emplace_back(Immediate(index));
839 break;
840 }
841 case EcmaOpcode::STCONSTTOGLOBALRECORD_IMM16_ID16: {
842 uint16_t stringId = READ_INST_16_2();
843 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
844 break;
845 }
846 case EcmaOpcode::GETTEMPLATEOBJECT_IMM8:
847 case EcmaOpcode::GETTEMPLATEOBJECT_IMM16:
848 break;
849 case EcmaOpcode::COPYDATAPROPERTIES_V8: {
850 uint16_t v0 = READ_INST_8_0();
851 info.inputs.emplace_back(VirtualRegister(v0));
852 break;
853 }
854 case EcmaOpcode::STOWNBYINDEX_IMM8_V8_IMM16: {
855 uint8_t v0 = READ_INST_8_1();
856 uint16_t index = READ_INST_16_2();
857 info.inputs.emplace_back(VirtualRegister(v0));
858 info.inputs.emplace_back(Immediate(index));
859 break;
860 }
861 case EcmaOpcode::STOWNBYINDEX_IMM16_V8_IMM16: {
862 uint8_t v0 = READ_INST_8_2();
863 uint16_t index = READ_INST_16_3();
864 info.inputs.emplace_back(VirtualRegister(v0));
865 info.inputs.emplace_back(Immediate(index));
866 break;
867 }
868 case EcmaOpcode::WIDE_STOWNBYINDEX_PREF_V8_IMM32: {
869 uint32_t v0 = READ_INST_8_1();
870 uint32_t index = READ_INST_32_2();
871 info.inputs.emplace_back(VirtualRegister(v0));
872 info.inputs.emplace_back(Immediate(index));
873 break;
874 }
875 case EcmaOpcode::STOWNBYVALUE_IMM8_V8_V8: {
876 uint32_t v0 = READ_INST_8_1();
877 uint32_t v1 = READ_INST_8_2();
878 info.inputs.emplace_back(VirtualRegister(v0));
879 info.inputs.emplace_back(VirtualRegister(v1));
880 break;
881 }
882 case EcmaOpcode::STOWNBYVALUE_IMM16_V8_V8: {
883 uint32_t v0 = READ_INST_8_2();
884 uint32_t v1 = READ_INST_8_3();
885 info.inputs.emplace_back(VirtualRegister(v0));
886 info.inputs.emplace_back(VirtualRegister(v1));
887 break;
888 }
889 case EcmaOpcode::CREATEOBJECTWITHEXCLUDEDKEYS_IMM8_V8_V8: {
890 uint8_t numKeys = READ_INST_8_0();
891 uint16_t v0 = READ_INST_8_1();
892 uint16_t firstArgRegIdx = READ_INST_8_2();
893 info.inputs.emplace_back(Immediate(numKeys));
894 info.inputs.emplace_back(VirtualRegister(v0));
895 info.inputs.emplace_back(Immediate(firstArgRegIdx));
896 break;
897 }
898 case EcmaOpcode::WIDE_CREATEOBJECTWITHEXCLUDEDKEYS_PREF_IMM16_V8_V8: {
899 uint16_t numKeys = READ_INST_16_1();
900 uint16_t v0 = READ_INST_8_3();
901 uint16_t firstArgRegIdx = READ_INST_8_4();
902 info.inputs.emplace_back(Immediate(numKeys));
903 info.inputs.emplace_back(VirtualRegister(v0));
904 info.inputs.emplace_back(Immediate(firstArgRegIdx));
905 break;
906 }
907 case EcmaOpcode::COPYRESTARGS_IMM8: {
908 uint16_t restIdx = READ_INST_8_0();
909 info.inputs.emplace_back(Immediate(restIdx));
910 break;
911 }
912 case EcmaOpcode::WIDE_COPYRESTARGS_PREF_IMM16: {
913 uint16_t restIdx = READ_INST_16_1();
914 info.inputs.emplace_back(Immediate(restIdx));
915 break;
916 }
917 case EcmaOpcode::DEFINEGETTERSETTERBYVALUE_V8_V8_V8_V8: {
918 uint16_t v0 = READ_INST_8_0();
919 uint16_t v1 = READ_INST_8_1();
920 uint16_t v2 = READ_INST_8_2();
921 uint16_t v3 = READ_INST_8_3();
922 info.inputs.emplace_back(VirtualRegister(v0));
923 info.inputs.emplace_back(VirtualRegister(v1));
924 info.inputs.emplace_back(VirtualRegister(v2));
925 info.inputs.emplace_back(VirtualRegister(v3));
926 break;
927 }
928 case EcmaOpcode::LDOBJBYINDEX_IMM8_IMM16: {
929 uint32_t idx = READ_INST_16_1();
930 info.inputs.emplace_back(Immediate(idx));
931 break;
932 }
933 case EcmaOpcode::LDOBJBYINDEX_IMM16_IMM16: {
934 uint32_t idx = READ_INST_16_2();
935 info.inputs.emplace_back(Immediate(idx));
936 break;
937 }
938 case EcmaOpcode::WIDE_LDOBJBYINDEX_PREF_IMM32: {
939 uint32_t idx = READ_INST_32_1();
940 info.inputs.emplace_back(Immediate(idx));
941 break;
942 }
943 case EcmaOpcode::STOBJBYINDEX_IMM8_V8_IMM16: {
944 uint8_t v0 = READ_INST_8_1();
945 uint16_t index = READ_INST_16_2();
946 info.inputs.emplace_back(VirtualRegister(v0));
947 info.inputs.emplace_back(Immediate(index));
948 break;
949 }
950 case EcmaOpcode::STOBJBYINDEX_IMM16_V8_IMM16: {
951 uint8_t v0 = READ_INST_8_2();
952 uint16_t index = READ_INST_16_3();
953 info.inputs.emplace_back(VirtualRegister(v0));
954 info.inputs.emplace_back(Immediate(index));
955 break;
956 }
957 case EcmaOpcode::WIDE_STOBJBYINDEX_PREF_V8_IMM32: {
958 uint8_t v0 = READ_INST_8_1();
959 uint32_t index = READ_INST_32_2();
960 info.inputs.emplace_back(VirtualRegister(v0));
961 info.inputs.emplace_back(Immediate(index));
962 break;
963 }
964 case EcmaOpcode::LDOBJBYVALUE_IMM8_V8: {
965 uint16_t slotId = READ_INST_8_0();
966 uint32_t v0 = READ_INST_8_1();
967 info.inputs.emplace_back(ICSlotId(slotId));
968 info.inputs.emplace_back(VirtualRegister(v0));
969 break;
970 }
971 case EcmaOpcode::LDOBJBYVALUE_IMM16_V8: {
972 uint16_t slotId = READ_INST_16_0();
973 uint32_t v0 = READ_INST_8_2();
974 info.inputs.emplace_back(ICSlotId(slotId));
975 info.inputs.emplace_back(VirtualRegister(v0));
976 break;
977 }
978 case EcmaOpcode::STOBJBYVALUE_IMM8_V8_V8: {
979 uint16_t slotId = READ_INST_8_0();
980 uint32_t v0 = READ_INST_8_1();
981 uint32_t v1 = READ_INST_8_2();
982 info.inputs.emplace_back(ICSlotId(slotId));
983 info.inputs.emplace_back(VirtualRegister(v0));
984 info.inputs.emplace_back(VirtualRegister(v1));
985 break;
986 }
987 case EcmaOpcode::STOBJBYVALUE_IMM16_V8_V8: {
988 uint16_t slotId = READ_INST_16_0();
989 uint32_t v0 = READ_INST_8_2();
990 uint32_t v1 = READ_INST_8_3();
991 info.inputs.emplace_back(ICSlotId(slotId));
992 info.inputs.emplace_back(VirtualRegister(v0));
993 info.inputs.emplace_back(VirtualRegister(v1));
994 break;
995 }
996 case EcmaOpcode::LDSUPERBYVALUE_IMM8_V8: {
997 uint32_t v0 = READ_INST_8_1();
998 info.inputs.emplace_back(VirtualRegister(v0));
999 break;
1000 }
1001 case EcmaOpcode::LDSUPERBYVALUE_IMM16_V8: {
1002 uint32_t v0 = READ_INST_8_2();
1003 info.inputs.emplace_back(VirtualRegister(v0));
1004 break;
1005 }
1006 case EcmaOpcode::STSUPERBYVALUE_IMM8_V8_V8: {
1007 uint32_t v0 = READ_INST_8_1();
1008 uint32_t v1 = READ_INST_8_2();
1009 info.inputs.emplace_back(VirtualRegister(v0));
1010 info.inputs.emplace_back(VirtualRegister(v1));
1011 break;
1012 }
1013 case EcmaOpcode::STSUPERBYVALUE_IMM16_V8_V8: {
1014 uint32_t v0 = READ_INST_8_2();
1015 uint32_t v1 = READ_INST_8_3();
1016 info.inputs.emplace_back(VirtualRegister(v0));
1017 info.inputs.emplace_back(VirtualRegister(v1));
1018 break;
1019 }
1020 case EcmaOpcode::TRYLDGLOBALBYNAME_IMM8_ID16: {
1021 uint16_t slotId = READ_INST_8_0();
1022 uint16_t stringId = READ_INST_16_1();
1023 info.inputs.emplace_back(ICSlotId(slotId));
1024 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1025 break;
1026 }
1027 case EcmaOpcode::TRYLDGLOBALBYNAME_IMM16_ID16: {
1028 uint16_t slotId = READ_INST_16_0();
1029 uint16_t stringId = READ_INST_16_2();
1030 info.inputs.emplace_back(ICSlotId(slotId));
1031 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1032 break;
1033 }
1034 case EcmaOpcode::TRYSTGLOBALBYNAME_IMM8_ID16: {
1035 uint16_t slotId = READ_INST_8_0();
1036 uint16_t stringId = READ_INST_16_1();
1037 info.inputs.emplace_back(ICSlotId(slotId));
1038 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1039 break;
1040 }
1041 case EcmaOpcode::TRYSTGLOBALBYNAME_IMM16_ID16: {
1042 uint16_t slotId = READ_INST_16_0();
1043 uint16_t stringId = READ_INST_16_2();
1044 info.inputs.emplace_back(ICSlotId(slotId));
1045 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1046 break;
1047 }
1048 case EcmaOpcode::STTOGLOBALRECORD_IMM16_ID16: {
1049 uint16_t stringId = READ_INST_16_2();
1050 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1051 break;
1052 }
1053 case EcmaOpcode::STOWNBYVALUEWITHNAMESET_IMM8_V8_V8: {
1054 uint32_t v0 = READ_INST_8_1();
1055 uint32_t v1 = READ_INST_8_2();
1056 info.inputs.emplace_back(VirtualRegister(v0));
1057 info.inputs.emplace_back(VirtualRegister(v1));
1058 break;
1059 }
1060 case EcmaOpcode::STOWNBYVALUEWITHNAMESET_IMM16_V8_V8: {
1061 uint32_t v0 = READ_INST_8_2();
1062 uint32_t v1 = READ_INST_8_3();
1063 info.inputs.emplace_back(VirtualRegister(v0));
1064 info.inputs.emplace_back(VirtualRegister(v1));
1065 break;
1066 }
1067 case EcmaOpcode::STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8: {
1068 uint16_t stringId = READ_INST_16_1();
1069 uint32_t v0 = READ_INST_8_3();
1070 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1071 info.inputs.emplace_back(VirtualRegister(v0));
1072 break;
1073 }
1074 case EcmaOpcode::STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8: {
1075 uint16_t stringId = READ_INST_16_2();
1076 uint32_t v0 = READ_INST_8_4();
1077 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1078 info.inputs.emplace_back(VirtualRegister(v0));
1079 break;
1080 }
1081 case EcmaOpcode::STTHISBYVALUE_IMM8_V8: {
1082 uint16_t slotId = READ_INST_8_0();
1083 uint32_t v0 = READ_INST_8_1();
1084 info.inputs.emplace_back(ICSlotId(slotId));
1085 info.inputs.emplace_back(VirtualRegister(v0));
1086 break;
1087 }
1088 case EcmaOpcode::STTHISBYVALUE_IMM16_V8: {
1089 uint16_t slotId = READ_INST_16_0();
1090 uint32_t v0 = READ_INST_8_2();
1091 info.inputs.emplace_back(ICSlotId(slotId));
1092 info.inputs.emplace_back(VirtualRegister(v0));
1093 break;
1094 }
1095 // not implement
1096 case EcmaOpcode::JSTRICTEQZ_IMM8:
1097 case EcmaOpcode::JSTRICTEQZ_IMM16:
1098 case EcmaOpcode::JNSTRICTEQZ_IMM8:
1099 case EcmaOpcode::JNSTRICTEQZ_IMM16:
1100 case EcmaOpcode::JEQNULL_IMM8:
1101 case EcmaOpcode::JEQNULL_IMM16:
1102 case EcmaOpcode::JNENULL_IMM8:
1103 case EcmaOpcode::JNENULL_IMM16:
1104 case EcmaOpcode::JSTRICTEQNULL_IMM8:
1105 case EcmaOpcode::JSTRICTEQNULL_IMM16:
1106 case EcmaOpcode::JNSTRICTEQNULL_IMM8:
1107 case EcmaOpcode::JNSTRICTEQNULL_IMM16:
1108 case EcmaOpcode::JEQUNDEFINED_IMM8:
1109 case EcmaOpcode::JEQUNDEFINED_IMM16:
1110 case EcmaOpcode::JNEUNDEFINED_IMM8:
1111 case EcmaOpcode::JNEUNDEFINED_IMM16:
1112 case EcmaOpcode::JSTRICTEQUNDEFINED_IMM8:
1113 case EcmaOpcode::JSTRICTEQUNDEFINED_IMM16:
1114 case EcmaOpcode::JNSTRICTEQUNDEFINED_IMM8:
1115 case EcmaOpcode::JNSTRICTEQUNDEFINED_IMM16:
1116 case EcmaOpcode::JEQ_V8_IMM8:
1117 case EcmaOpcode::JEQ_V8_IMM16:
1118 case EcmaOpcode::JNE_V8_IMM8:
1119 case EcmaOpcode::JNE_V8_IMM16:
1120 case EcmaOpcode::JSTRICTEQ_V8_IMM8:
1121 case EcmaOpcode::JSTRICTEQ_V8_IMM16:
1122 case EcmaOpcode::JNSTRICTEQ_V8_IMM8:
1123 case EcmaOpcode::JNSTRICTEQ_V8_IMM16:
1124 case EcmaOpcode::LDTHIS:
1125 break;
1126 case EcmaOpcode::LDTHISBYNAME_IMM8_ID16: {
1127 uint16_t slotId = READ_INST_8_0();
1128 uint16_t stringId = READ_INST_16_1();
1129 info.inputs.emplace_back(ICSlotId(slotId));
1130 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1131 break;
1132 }
1133 case EcmaOpcode::LDTHISBYNAME_IMM16_ID16: {
1134 uint16_t slotId = READ_INST_16_0();
1135 uint16_t stringId = READ_INST_16_2();
1136 info.inputs.emplace_back(ICSlotId(slotId));
1137 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1138 break;
1139 }
1140 case EcmaOpcode::STTHISBYNAME_IMM8_ID16: {
1141 uint16_t slotId = READ_INST_8_0();
1142 uint16_t stringId = READ_INST_16_1();
1143 info.inputs.emplace_back(ICSlotId(slotId));
1144 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1145 break;
1146 }
1147 case EcmaOpcode::STTHISBYNAME_IMM16_ID16: {
1148 uint16_t slotId = READ_INST_16_0();
1149 uint16_t stringId = READ_INST_16_2();
1150 info.inputs.emplace_back(ICSlotId(slotId));
1151 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1152 break;
1153 }
1154 case EcmaOpcode::LDGLOBALVAR_IMM16_ID16: {
1155 uint16_t slotId = READ_INST_16_0();
1156 uint16_t stringId = READ_INST_16_2();
1157 info.inputs.emplace_back(ICSlotId(slotId));
1158 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1159 break;
1160 }
1161 case EcmaOpcode::LDOBJBYNAME_IMM8_ID16: {
1162 uint16_t slotId = READ_INST_8_0();
1163 uint16_t stringId = READ_INST_16_1();
1164 info.inputs.emplace_back(ICSlotId(slotId));
1165 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1166 break;
1167 }
1168 case EcmaOpcode::LDOBJBYNAME_IMM16_ID16: {
1169 uint16_t slotId = READ_INST_16_0();
1170 uint16_t stringId = READ_INST_16_2();
1171 info.inputs.emplace_back(ICSlotId(slotId));
1172 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1173 break;
1174 }
1175 case EcmaOpcode::STOBJBYNAME_IMM8_ID16_V8: {
1176 uint16_t slotId = READ_INST_8_0();
1177 uint16_t stringId = READ_INST_16_1();
1178 uint32_t v0 = READ_INST_8_3();
1179 info.inputs.emplace_back(ICSlotId(slotId));
1180 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1181 info.inputs.emplace_back(VirtualRegister(v0));
1182 break;
1183 }
1184 case EcmaOpcode::STOBJBYNAME_IMM16_ID16_V8: {
1185 uint16_t slotId = READ_INST_16_0();
1186 uint16_t stringId = READ_INST_16_2();
1187 uint32_t v0 = READ_INST_8_4();
1188 info.inputs.emplace_back(ICSlotId(slotId));
1189 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1190 info.inputs.emplace_back(VirtualRegister(v0));
1191 break;
1192 }
1193 case EcmaOpcode::LDSUPERBYNAME_IMM8_ID16: {
1194 uint16_t stringId = READ_INST_16_1();
1195 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1196 break;
1197 }
1198 case EcmaOpcode::LDSUPERBYNAME_IMM16_ID16: {
1199 uint16_t stringId = READ_INST_16_2();
1200 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1201 break;
1202 }
1203 case EcmaOpcode::STSUPERBYNAME_IMM8_ID16_V8: {
1204 uint16_t stringId = READ_INST_16_1();
1205 uint32_t v0 = READ_INST_8_3();
1206 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1207 info.inputs.emplace_back(VirtualRegister(v0));
1208 break;
1209 }
1210 case EcmaOpcode::STSUPERBYNAME_IMM16_ID16_V8: {
1211 uint16_t stringId = READ_INST_16_2();
1212 uint32_t v0 = READ_INST_8_4();
1213 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1214 info.inputs.emplace_back(VirtualRegister(v0));
1215 break;
1216 }
1217 case EcmaOpcode::STGLOBALVAR_IMM16_ID16: {
1218 uint16_t slotId = READ_INST_16_0();
1219 uint32_t stringId = READ_INST_16_2();
1220 info.inputs.emplace_back(ICSlotId(slotId));
1221 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1222 break;
1223 }
1224 case EcmaOpcode::CREATEGENERATOROBJ_V8: {
1225 uint16_t v0 = READ_INST_8_0();
1226 info.inputs.emplace_back(VirtualRegister(v0));
1227 break;
1228 }
1229 case EcmaOpcode::CREATEASYNCGENERATOROBJ_V8: {
1230 uint16_t v0 = READ_INST_8_0();
1231 info.inputs.emplace_back(VirtualRegister(v0));
1232 break;
1233 }
1234 case EcmaOpcode::ASYNCGENERATORRESOLVE_V8_V8_V8: {
1235 uint16_t v0 = READ_INST_8_0();
1236 uint16_t v1 = READ_INST_8_1();
1237 uint16_t v2 = READ_INST_8_2();
1238 info.inputs.emplace_back(VirtualRegister(v0));
1239 info.inputs.emplace_back(VirtualRegister(v1));
1240 info.inputs.emplace_back(VirtualRegister(v2));
1241 break;
1242 }
1243 case EcmaOpcode::ASYNCGENERATORREJECT_V8: {
1244 uint16_t v0 = READ_INST_8_0();
1245 info.inputs.emplace_back(VirtualRegister(v0));
1246 break;
1247 }
1248 case EcmaOpcode::STARRAYSPREAD_V8_V8: {
1249 uint16_t v0 = READ_INST_8_0();
1250 uint16_t v1 = READ_INST_8_1();
1251 info.inputs.emplace_back(VirtualRegister(v0));
1252 info.inputs.emplace_back(VirtualRegister(v1));
1253 break;
1254 }
1255 case EcmaOpcode::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8: {
1256 uint16_t methodId = READ_INST_16_1();
1257 uint16_t literaId = READ_INST_16_3();
1258 uint16_t length = READ_INST_16_5();
1259 uint16_t v0 = READ_INST_8_7();
1260 info.inputs.emplace_back(ConstDataId(ConstDataIDType::MethodIDType, methodId));
1261 info.inputs.emplace_back(ConstDataId(ConstDataIDType::ClassLiteralIDType, literaId));
1262 info.inputs.emplace_back(Immediate(length));
1263 info.inputs.emplace_back(VirtualRegister(v0));
1264 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
1265 break;
1266 }
1267 case EcmaOpcode::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8: {
1268 uint16_t methodId = READ_INST_16_2();
1269 uint16_t literaId = READ_INST_16_4();
1270 uint16_t length = READ_INST_16_6();
1271 uint16_t v0 = READ_INST_8_8();
1272 info.inputs.emplace_back(ConstDataId(ConstDataIDType::MethodIDType, methodId));
1273 info.inputs.emplace_back(ConstDataId(ConstDataIDType::ClassLiteralIDType, literaId));
1274 info.inputs.emplace_back(Immediate(length));
1275 info.inputs.emplace_back(VirtualRegister(v0));
1276 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
1277 break;
1278 }
1279 case EcmaOpcode::LDFUNCTION: {
1280 break;
1281 }
1282 case EcmaOpcode::LDBIGINT_ID16: {
1283 uint32_t stringId = READ_INST_16_0();
1284 info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
1285 break;
1286 }
1287 case EcmaOpcode::DYNAMICIMPORT: {
1288 break;
1289 }
1290 case EcmaOpcode::SUPERCALLTHISRANGE_IMM8_IMM8_V8:
1291 case EcmaOpcode::SUPERCALLARROWRANGE_IMM8_IMM8_V8: {
1292 uint16_t range = READ_INST_8_1();
1293 uint16_t v0 = READ_INST_8_2();
1294 for (size_t i = 0; i < range; i++) {
1295 info.inputs.emplace_back(VirtualRegister(v0 + i));
1296 }
1297 break;
1298 }
1299 case EcmaOpcode::WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8:
1300 case EcmaOpcode::WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8: {
1301 uint16_t range = READ_INST_16_1();
1302 uint16_t v0 = READ_INST_8_3();
1303 for (size_t i = 0; i < range; i++) {
1304 info.inputs.emplace_back(VirtualRegister(v0 + i));
1305 }
1306 break;
1307 }
1308 case EcmaOpcode::SUPERCALLSPREAD_IMM8_V8: {
1309 uint16_t v0 = READ_INST_8_1();
1310 info.inputs.emplace_back(VirtualRegister(v0));
1311 break;
1312 }
1313 case EcmaOpcode::POPLEXENV: {
1314 info.inputs.emplace_back(VirtualRegister(builder->GetEnvVregIdx()));
1315 info.vregOut.emplace_back(builder->GetEnvVregIdx());
1316 break;
1317 }
1318 case EcmaOpcode::TONUMERIC_IMM8:
1319 case EcmaOpcode::INC_IMM8:
1320 case EcmaOpcode::DEC_IMM8:
1321 case EcmaOpcode::NOT_IMM8:
1322 case EcmaOpcode::NEG_IMM8:
1323 case EcmaOpcode::JMP_IMM8:
1324 case EcmaOpcode::JMP_IMM16:
1325 case EcmaOpcode::JMP_IMM32:
1326 case EcmaOpcode::JEQZ_IMM8:
1327 case EcmaOpcode::JEQZ_IMM16:
1328 case EcmaOpcode::JEQZ_IMM32:
1329 case EcmaOpcode::JNEZ_IMM8:
1330 case EcmaOpcode::JNEZ_IMM16:
1331 case EcmaOpcode::JNEZ_IMM32:
1332 case EcmaOpcode::RETURN:
1333 case EcmaOpcode::RETURNUNDEFINED:
1334 case EcmaOpcode::LDNAN:
1335 case EcmaOpcode::LDINFINITY:
1336 case EcmaOpcode::LDNEWTARGET:
1337 case EcmaOpcode::LDUNDEFINED:
1338 case EcmaOpcode::LDNULL:
1339 case EcmaOpcode::LDSYMBOL:
1340 case EcmaOpcode::LDGLOBAL:
1341 case EcmaOpcode::LDTRUE:
1342 case EcmaOpcode::LDFALSE:
1343 case EcmaOpcode::LDHOLE:
1344 case EcmaOpcode::CALLARG0_IMM8:
1345 case EcmaOpcode::GETUNMAPPEDARGS:
1346 case EcmaOpcode::ASYNCFUNCTIONENTER:
1347 case EcmaOpcode::TYPEOF_IMM8:
1348 case EcmaOpcode::TYPEOF_IMM16:
1349 case EcmaOpcode::TONUMBER_IMM8:
1350 case EcmaOpcode::THROW_PREF_NONE:
1351 case EcmaOpcode::GETPROPITERATOR:
1352 case EcmaOpcode::GETRESUMEMODE:
1353 case EcmaOpcode::CREATEEMPTYARRAY_IMM8:
1354 case EcmaOpcode::CREATEEMPTYARRAY_IMM16:
1355 case EcmaOpcode::CREATEEMPTYOBJECT:
1356 case EcmaOpcode::DEBUGGER:
1357 case EcmaOpcode::ISTRUE:
1358 case EcmaOpcode::ISFALSE:
1359 case EcmaOpcode::NOP:
1360 case EcmaOpcode::GETITERATOR_IMM8:
1361 case EcmaOpcode::GETITERATOR_IMM16:
1362 case EcmaOpcode::GETASYNCITERATOR_IMM8:
1363 case EcmaOpcode::THROW_NOTEXISTS_PREF_NONE:
1364 case EcmaOpcode::THROW_PATTERNNONCOERCIBLE_PREF_NONE:
1365 case EcmaOpcode::THROW_DELETESUPERPROPERTY_PREF_NONE:
1366 case EcmaOpcode::RESUMEGENERATOR:
1367 case EcmaOpcode::CALLRUNTIME_NOTIFYCONCURRENTRESULT_PREF_NONE:
1368 break;
1369 case EcmaOpcode::LDTHISBYVALUE_IMM8: {
1370 uint16_t slotId = READ_INST_8_0();
1371 info.inputs.emplace_back(ICSlotId(slotId));
1372 break;
1373 }
1374 case EcmaOpcode::LDTHISBYVALUE_IMM16: {
1375 uint16_t slotId = READ_INST_16_0();
1376 info.inputs.emplace_back(ICSlotId(slotId));
1377 break;
1378 }
1379 case EcmaOpcode::WIDE_LDPATCHVAR_PREF_IMM16: {
1380 uint16_t index = READ_INST_16_1();
1381 info.inputs.emplace_back(Immediate(index));
1382 break;
1383 }
1384 case EcmaOpcode::WIDE_STPATCHVAR_PREF_IMM16: {
1385 uint16_t index = READ_INST_16_1();
1386 info.inputs.emplace_back(Immediate(index));
1387 break;
1388 }
1389 default: {
1390 LOG_COMPILER(FATAL) << "Error bytecode: " << static_cast<uint16_t>(opcode);
1391 UNREACHABLE();
1392 break;
1393 }
1394 }
1395 }
1396
GetBytecodeInfo() const1397 const BytecodeInfo &BytecodeIterator::GetBytecodeInfo() const
1398 {
1399 return builder_->GetBytecodeInfo(index_);
1400 }
1401
PeekNextPc(size_t i) const1402 const uint8_t *BytecodeIterator::PeekNextPc(size_t i) const
1403 {
1404 ASSERT(index_ + i <= end_);
1405 return builder_->GetPCByIndex(index_ + i);
1406 }
1407
PeekPrevPc(size_t i) const1408 const uint8_t *BytecodeIterator::PeekPrevPc(size_t i) const
1409 {
1410 ASSERT(index_ - i >= start_);
1411 return builder_->GetPCByIndex(index_ - i);
1412 }
1413 } // panda::ecmascript::kungfu
1414