14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_COMPILER_INTERPRETER_STUB_INL_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_INTERPRETER_STUB_INL_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/compiler/interpreter_stub.h" 204514f5e3Sopenharmony_ci#include "ecmascript/compiler/new_object_stub_builder.h" 214514f5e3Sopenharmony_ci#include "ecmascript/compiler/share_gate_meta_data.h" 224514f5e3Sopenharmony_ci#include "ecmascript/module/js_module_source_text.h" 234514f5e3Sopenharmony_ci#include "ecmascript/global_env.h" 244514f5e3Sopenharmony_ci#include "ecmascript/js_async_generator_object.h" 254514f5e3Sopenharmony_ci#include "ecmascript/js_arguments.h" 264514f5e3Sopenharmony_ci#include "ecmascript/js_function.h" 274514f5e3Sopenharmony_ci#include "ecmascript/js_generator_object.h" 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu { 304514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetVregValue(GateRef glue, GateRef sp, GateRef idx, GateRef val) 314514f5e3Sopenharmony_ci{ 324514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, sp, PtrMul(IntPtr(sizeof(JSTaggedType)), idx), val); 334514f5e3Sopenharmony_ci} 344514f5e3Sopenharmony_ci 354514f5e3Sopenharmony_ciinline GateRef InterpreterStubBuilder::GetVregValue(GateRef sp, GateRef idx) 364514f5e3Sopenharmony_ci{ 374514f5e3Sopenharmony_ci return Load(VariableType::JS_ANY(), sp, PtrMul(IntPtr(sizeof(JSTaggedType)), idx)); 384514f5e3Sopenharmony_ci} 394514f5e3Sopenharmony_ci 404514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_0(GateRef pc) 414514f5e3Sopenharmony_ci{ 424514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 434514f5e3Sopenharmony_ci} 444514f5e3Sopenharmony_ci 454514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_1(GateRef pc) 464514f5e3Sopenharmony_ci{ 474514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(2)); // 2 : skip 1 byte of bytecode 484514f5e3Sopenharmony_ci} 494514f5e3Sopenharmony_ci 504514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_2(GateRef pc) 514514f5e3Sopenharmony_ci{ 524514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(3)); // 3 : skip 1 byte of bytecode 534514f5e3Sopenharmony_ci} 544514f5e3Sopenharmony_ci 554514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_3(GateRef pc) 564514f5e3Sopenharmony_ci{ 574514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(4)); // 4 : skip 1 byte of bytecode 584514f5e3Sopenharmony_ci} 594514f5e3Sopenharmony_ci 604514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_4(GateRef pc) 614514f5e3Sopenharmony_ci{ 624514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(5)); // 5 : skip 1 byte of bytecode 634514f5e3Sopenharmony_ci} 644514f5e3Sopenharmony_ci 654514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_5(GateRef pc) 664514f5e3Sopenharmony_ci{ 674514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(6)); // 6 : skip 1 byte of bytecode 684514f5e3Sopenharmony_ci} 694514f5e3Sopenharmony_ci 704514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_6(GateRef pc) 714514f5e3Sopenharmony_ci{ 724514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(7)); // 7 : skip 1 byte of bytecode 734514f5e3Sopenharmony_ci} 744514f5e3Sopenharmony_ci 754514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_7(GateRef pc) 764514f5e3Sopenharmony_ci{ 774514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(8)); // 8 : skip 1 byte of bytecode 784514f5e3Sopenharmony_ci} 794514f5e3Sopenharmony_ci 804514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_8(GateRef pc) 814514f5e3Sopenharmony_ci{ 824514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(9)); // 9 : skip 1 byte of bytecode 834514f5e3Sopenharmony_ci} 844514f5e3Sopenharmony_ci 854514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst8_9(GateRef pc) 864514f5e3Sopenharmony_ci{ 874514f5e3Sopenharmony_ci return Load(VariableType::INT8(), pc, IntPtr(10)); // 10 : skip 1 byte of bytecode 884514f5e3Sopenharmony_ci} 894514f5e3Sopenharmony_ci 904514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst4_0(GateRef pc) 914514f5e3Sopenharmony_ci{ 924514f5e3Sopenharmony_ci return Int8And(Load(VariableType::INT8(), pc, IntPtr(1)), Int8(0xf)); 934514f5e3Sopenharmony_ci} 944514f5e3Sopenharmony_ci 954514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst4_1(GateRef pc) 964514f5e3Sopenharmony_ci{ 974514f5e3Sopenharmony_ci // 1 : skip 1 byte of bytecode 984514f5e3Sopenharmony_ci return Int8And( 994514f5e3Sopenharmony_ci Int8LSR(Load(VariableType::INT8(), pc, IntPtr(1)), Int8(4)), Int8(0xf)); // 4: read 4 byte of bytecode 1004514f5e3Sopenharmony_ci} 1014514f5e3Sopenharmony_ci 1024514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst4_2(GateRef pc) 1034514f5e3Sopenharmony_ci{ 1044514f5e3Sopenharmony_ci // 2 : skip 1 byte of bytecode 1054514f5e3Sopenharmony_ci return Int8And(Load(VariableType::INT8(), pc, IntPtr(2)), Int8(0xf)); 1064514f5e3Sopenharmony_ci} 1074514f5e3Sopenharmony_ci 1084514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst4_3(GateRef pc) 1094514f5e3Sopenharmony_ci{ 1104514f5e3Sopenharmony_ci // 2 : skip 1 byte of bytecode 1114514f5e3Sopenharmony_ci return Int8And( 1124514f5e3Sopenharmony_ci Int8LSR(Load(VariableType::INT8(), pc, IntPtr(2)), Int8(4)), Int8(0xf)); // 4 : read 4 byte of bytecode 1134514f5e3Sopenharmony_ci} 1144514f5e3Sopenharmony_ci 1154514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInstSigned8_0(GateRef pc) 1164514f5e3Sopenharmony_ci{ 1174514f5e3Sopenharmony_ci GateRef x = Load(VariableType::INT8(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 1184514f5e3Sopenharmony_ci return GetEnvironment()->GetBuilder()->SExtInt1ToInt32(x); 1194514f5e3Sopenharmony_ci} 1204514f5e3Sopenharmony_ci 1214514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInstSigned16_0(GateRef pc) 1224514f5e3Sopenharmony_ci{ 1234514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 1244514f5e3Sopenharmony_ci GateRef currentInst = Load(VariableType::INT16(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 1254514f5e3Sopenharmony_ci return GetEnvironment()->GetBuilder()->SExtInt16ToInt32(currentInst); 1264514f5e3Sopenharmony_ci } 1274514f5e3Sopenharmony_ci /* 2 : skip 8 bits of opcode and 8 bits of low bits */ 1284514f5e3Sopenharmony_ci GateRef currentInst = Load(VariableType::INT8(), pc, IntPtr(2)); 1294514f5e3Sopenharmony_ci GateRef currentInst1 = GetEnvironment()->GetBuilder()->SExtInt1ToInt32(currentInst); 1304514f5e3Sopenharmony_ci GateRef currentInst2 = Int32LSL(currentInst1, Int32(8)); // 8 : set as high 8 bits 1314514f5e3Sopenharmony_ci return Int32Add(currentInst2, ZExtInt8ToInt32(ReadInst8_0(pc))); 1324514f5e3Sopenharmony_ci} 1334514f5e3Sopenharmony_ci 1344514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInstSigned32_0(GateRef pc) 1354514f5e3Sopenharmony_ci{ 1364514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 1374514f5e3Sopenharmony_ci GateRef x = Load(VariableType::INT32(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 1384514f5e3Sopenharmony_ci return GetEnvironment()->GetBuilder()->SExtInt1ToInt32(x); 1394514f5e3Sopenharmony_ci } 1404514f5e3Sopenharmony_ci /* 4 : skip 8 bits of opcode and 24 bits of low bits */ 1414514f5e3Sopenharmony_ci GateRef x = Load(VariableType::INT8(), pc, IntPtr(4)); 1424514f5e3Sopenharmony_ci GateRef currentInst = GetEnvironment()->GetBuilder()->SExtInt1ToInt32(x); 1434514f5e3Sopenharmony_ci GateRef currentInst1 = Int32LSL(currentInst, Int32(8)); // 8 : set as high 8 bits 1444514f5e3Sopenharmony_ci GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8_2(pc))); 1454514f5e3Sopenharmony_ci GateRef currentInst3 = Int32LSL(currentInst2, Int32(8)); // 8 : set as high 8 bits 1464514f5e3Sopenharmony_ci GateRef currentInst4 = Int32Add(currentInst3, ZExtInt8ToInt32(ReadInst8_1(pc))); 1474514f5e3Sopenharmony_ci GateRef currentInst5 = Int32LSL(currentInst4, Int32(8)); // 8 : set as high 8 bits 1484514f5e3Sopenharmony_ci return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8_0(pc))); 1494514f5e3Sopenharmony_ci} 1504514f5e3Sopenharmony_ci 1514514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_0(GateRef pc) 1524514f5e3Sopenharmony_ci{ 1534514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 1544514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 1554514f5e3Sopenharmony_ci } 1564514f5e3Sopenharmony_ci /* 2 : skip 8 bits of opcode and 8 bits of low bits */ 1574514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_1(pc)); 1584514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 1594514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_0(pc))); 1604514f5e3Sopenharmony_ci} 1614514f5e3Sopenharmony_ci 1624514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_1(GateRef pc) 1634514f5e3Sopenharmony_ci{ 1644514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 1654514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(2)); // 2 : skip 2 bytes of bytecode 1664514f5e3Sopenharmony_ci } 1674514f5e3Sopenharmony_ci /* 3 : skip 8 bits of opcode, 8 bits of prefix and 8 bits of low bits */ 1684514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_2(pc)); 1694514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 1704514f5e3Sopenharmony_ci /* 2 : skip 8 bits of opcode and 8 bits of prefix */ 1714514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_1(pc))); 1724514f5e3Sopenharmony_ci} 1734514f5e3Sopenharmony_ci 1744514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_2(GateRef pc) 1754514f5e3Sopenharmony_ci{ 1764514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 1774514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(3)); // 3 : skip 3 bytes of bytecode 1784514f5e3Sopenharmony_ci } 1794514f5e3Sopenharmony_ci /* 4 : skip 8 bits of opcode, first parameter of 16 bits and 8 bits of low bits */ 1804514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_3(pc)); 1814514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 1824514f5e3Sopenharmony_ci /* 3 : skip 8 bits of opcode and first parameter of 16 bits */ 1834514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_2(pc))); 1844514f5e3Sopenharmony_ci} 1854514f5e3Sopenharmony_ci 1864514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_3(GateRef pc) 1874514f5e3Sopenharmony_ci{ 1884514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 1894514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(4)); // 4 : skip 4 bytes of bytecode 1904514f5e3Sopenharmony_ci } 1914514f5e3Sopenharmony_ci /* 5 : skip 8 bits of opcode, 8 bits of prefix, first parameter of 16 bits and 8 bits of low bits */ 1924514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_4(pc)); 1934514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 1944514f5e3Sopenharmony_ci /* 4 : skip 8 bits of opcode, 8 bits of prefix and first parameter of 16 bits */ 1954514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_3(pc))); 1964514f5e3Sopenharmony_ci} 1974514f5e3Sopenharmony_ci 1984514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_4(GateRef pc) 1994514f5e3Sopenharmony_ci{ 2004514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 2014514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(5)); // 5 : skip 5 bytes of bytecode 2024514f5e3Sopenharmony_ci } 2034514f5e3Sopenharmony_ci /* 7 : skip 8 bits of opcode, 8 bits of prefix, first 2 parameters of 16 bits and 8 bits of low bits */ 2044514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_5(pc)); 2054514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 2064514f5e3Sopenharmony_ci /* 6 : skip 8 bits of opcode, 8 bits of prefix and first 2 parameters of 16 bits */ 2074514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_4(pc))); 2084514f5e3Sopenharmony_ci} 2094514f5e3Sopenharmony_ci 2104514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_5(GateRef pc) 2114514f5e3Sopenharmony_ci{ 2124514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 2134514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(6)); // 6 : skip 6 bytes of bytecode 2144514f5e3Sopenharmony_ci } 2154514f5e3Sopenharmony_ci /* 7 : skip 8 bits of opcode, 8 bits of prefix, first 2 parameters of 16 bits and 8 bits of low bits */ 2164514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_6(pc)); 2174514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 2184514f5e3Sopenharmony_ci /* 6 : skip 8 bits of opcode, 8 bits of prefix and first 2 parameters of 16 bits */ 2194514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_5(pc))); 2204514f5e3Sopenharmony_ci} 2214514f5e3Sopenharmony_ci 2224514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_6(GateRef pc) 2234514f5e3Sopenharmony_ci{ 2244514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 2254514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(7)); // 7 : skip 7 bytes of bytecode 2264514f5e3Sopenharmony_ci } 2274514f5e3Sopenharmony_ci /* 7 : skip 8 bits of opcode, 8 bits of prefix, first 2 parameters of 16 bits and 8 bits of low bits */ 2284514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_7(pc)); 2294514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 2304514f5e3Sopenharmony_ci /* 6 : skip 8 bits of opcode, 8 bits of prefix and first 2 parameters of 16 bits */ 2314514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_6(pc))); 2324514f5e3Sopenharmony_ci} 2334514f5e3Sopenharmony_ci 2344514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst16_7(GateRef pc) 2354514f5e3Sopenharmony_ci{ 2364514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 2374514f5e3Sopenharmony_ci return Load(VariableType::INT16(), pc, IntPtr(8)); // 8 : skip 8 bytes of bytecode 2384514f5e3Sopenharmony_ci } 2394514f5e3Sopenharmony_ci /* 7 : skip 8 bits of opcode, 8 bits of prefix, first 2 parameters of 16 bits and 8 bits of low bits */ 2404514f5e3Sopenharmony_ci GateRef currentInst1 = ZExtInt8ToInt16(ReadInst8_8(pc)); 2414514f5e3Sopenharmony_ci GateRef currentInst2 = Int16LSL(currentInst1, Int16(8)); // 8 : set as high 8 bits 2424514f5e3Sopenharmony_ci /* 6 : skip 8 bits of opcode, 8 bits of prefix and first 2 parameters of 16 bits */ 2434514f5e3Sopenharmony_ci return Int16Add(currentInst2, ZExtInt8ToInt16(ReadInst8_9(pc))); 2444514f5e3Sopenharmony_ci} 2454514f5e3Sopenharmony_ci 2464514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetFrame(GateRef CurrentSp) 2474514f5e3Sopenharmony_ci{ 2484514f5e3Sopenharmony_ci return PtrSub(CurrentSp, IntPtr(AsmInterpretedFrame::GetSize(GetEnvironment()->IsArch32Bit()))); 2494514f5e3Sopenharmony_ci} 2504514f5e3Sopenharmony_ci 2514514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetPcFromFrame(GateRef frame) 2524514f5e3Sopenharmony_ci{ 2534514f5e3Sopenharmony_ci return Load(VariableType::NATIVE_POINTER(), frame, 2544514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetPcOffset(GetEnvironment()->IsArch32Bit()))); 2554514f5e3Sopenharmony_ci} 2564514f5e3Sopenharmony_ci 2574514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetFunctionFromFrame(GateRef frame) 2584514f5e3Sopenharmony_ci{ 2594514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), frame, 2604514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetFunctionOffset(GetEnvironment()->IsArch32Bit()))); 2614514f5e3Sopenharmony_ci} 2624514f5e3Sopenharmony_ci 2634514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetNewTarget(GateRef sp) 2644514f5e3Sopenharmony_ci{ 2654514f5e3Sopenharmony_ci GateRef function = Load(VariableType::JS_POINTER(), GetFrame(sp), 2664514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetFunctionOffset(GetEnvironment()->IsArch32Bit()))); 2674514f5e3Sopenharmony_ci GateRef method = GetMethodFromFunction(function); 2684514f5e3Sopenharmony_ci GateRef callField = GetCallFieldFromMethod(method); 2694514f5e3Sopenharmony_ci // ASSERT: callField has "extra" bit. 2704514f5e3Sopenharmony_ci GateRef numVregs = TruncInt64ToInt32(Int64And(Int64LSR(callField, Int64(MethodLiteral::NumVregsBits::START_BIT)), 2714514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::NumVregsBits::SIZE) - 1))); 2724514f5e3Sopenharmony_ci GateRef haveFunc = ZExtInt1ToInt32(Int64NotEqual(Int64And(Int64LSR(callField, 2734514f5e3Sopenharmony_ci Int64(MethodLiteral::HaveFuncBit::START_BIT)), 2744514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::HaveFuncBit::SIZE) - 1)), Int64(0))); 2754514f5e3Sopenharmony_ci GateRef idx = ZExtInt32ToPtr(Int32Add(numVregs, haveFunc)); 2764514f5e3Sopenharmony_ci return Load(VariableType::JS_ANY(), sp, PtrMul(IntPtr(JSTaggedValue::TaggedTypeSize()), idx)); 2774514f5e3Sopenharmony_ci} 2784514f5e3Sopenharmony_ci 2794514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetThisFromFrame(GateRef frame) 2804514f5e3Sopenharmony_ci{ 2814514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), frame, 2824514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetThisOffset(GetEnvironment()->IsArch32Bit()))); 2834514f5e3Sopenharmony_ci} 2844514f5e3Sopenharmony_ci 2854514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetCallSizeFromFrame(GateRef frame) 2864514f5e3Sopenharmony_ci{ 2874514f5e3Sopenharmony_ci return Load(VariableType::NATIVE_POINTER(), frame, 2884514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetCallSizeOffset(GetEnvironment()->IsArch32Bit()))); 2894514f5e3Sopenharmony_ci} 2904514f5e3Sopenharmony_ci 2914514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetAccFromFrame(GateRef frame) 2924514f5e3Sopenharmony_ci{ 2934514f5e3Sopenharmony_ci return Load(VariableType::JS_ANY(), frame, 2944514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetAccOffset(GetEnvironment()->IsArch32Bit()))); 2954514f5e3Sopenharmony_ci} 2964514f5e3Sopenharmony_ci 2974514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetEnvFromFrame(GateRef frame) 2984514f5e3Sopenharmony_ci{ 2994514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), frame, 3004514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetEnvOffset(GetEnvironment()->IsArch32Bit()))); 3014514f5e3Sopenharmony_ci} 3024514f5e3Sopenharmony_ci 3034514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetEnvFromFunction(GateRef function) 3044514f5e3Sopenharmony_ci{ 3054514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), function, IntPtr(JSFunction::LEXICAL_ENV_OFFSET)); 3064514f5e3Sopenharmony_ci} 3074514f5e3Sopenharmony_ci 3084514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetProfileTypeInfoFromFunction(GateRef function) 3094514f5e3Sopenharmony_ci{ 3104514f5e3Sopenharmony_ci GateRef raw = Load(VariableType::JS_POINTER(), function, IntPtr(JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET)); 3114514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), raw, IntPtr(ProfileTypeInfoCell::VALUE_OFFSET)); 3124514f5e3Sopenharmony_ci} 3134514f5e3Sopenharmony_ci 3144514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetModuleFromFunction(GateRef function) 3154514f5e3Sopenharmony_ci{ 3164514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), function, IntPtr(JSFunction::ECMA_MODULE_OFFSET)); 3174514f5e3Sopenharmony_ci} 3184514f5e3Sopenharmony_ci 3194514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetSendableEnvFromModule(GateRef module) 3204514f5e3Sopenharmony_ci{ 3214514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), module, IntPtr(SourceTextModule::SENDABLE_ENV_OFFSET)); 3224514f5e3Sopenharmony_ci} 3234514f5e3Sopenharmony_ci 3244514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetHomeObjectFromFunction(GateRef function) 3254514f5e3Sopenharmony_ci{ 3264514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), function, IntPtr(JSFunction::HOME_OBJECT_OFFSET)); 3274514f5e3Sopenharmony_ci} 3284514f5e3Sopenharmony_ci 3294514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetConstpoolFromMethod(GateRef method) 3304514f5e3Sopenharmony_ci{ 3314514f5e3Sopenharmony_ci return Load(VariableType::JS_POINTER(), method, IntPtr(Method::CONSTANT_POOL_OFFSET)); 3324514f5e3Sopenharmony_ci} 3334514f5e3Sopenharmony_ci 3344514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetModule(GateRef sp) 3354514f5e3Sopenharmony_ci{ 3364514f5e3Sopenharmony_ci GateRef currentFunc = GetFunctionFromFrame(GetFrame(sp)); 3374514f5e3Sopenharmony_ci return GetModuleFromFunction(currentFunc); 3384514f5e3Sopenharmony_ci} 3394514f5e3Sopenharmony_ci 3404514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetResumeModeFromGeneratorObject(GateRef obj) 3414514f5e3Sopenharmony_ci{ 3424514f5e3Sopenharmony_ci GateRef bitfieldOffset = IntPtr(JSGeneratorObject::BIT_FIELD_OFFSET); 3434514f5e3Sopenharmony_ci GateRef bitfield = Load(VariableType::INT32(), obj, bitfieldOffset); 3444514f5e3Sopenharmony_ci return Int32And( 3454514f5e3Sopenharmony_ci Int32LSR(bitfield, Int32(JSGeneratorObject::ResumeModeBits::START_BIT)), 3464514f5e3Sopenharmony_ci Int32((1LU << JSGeneratorObject::ResumeModeBits::SIZE) - 1)); 3474514f5e3Sopenharmony_ci} 3484514f5e3Sopenharmony_ci 3494514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetResumeModeFromAsyncGeneratorObject(GateRef obj) 3504514f5e3Sopenharmony_ci{ 3514514f5e3Sopenharmony_ci GateRef bitfieldOffset = IntPtr(JSAsyncGeneratorObject::BIT_FIELD_OFFSET); 3524514f5e3Sopenharmony_ci GateRef bitfield = Load(VariableType::INT32(), obj, bitfieldOffset); 3534514f5e3Sopenharmony_ci return Int32And( 3544514f5e3Sopenharmony_ci Int32LSR(bitfield, Int32(JSAsyncGeneratorObject::ResumeModeBits::START_BIT)), 3554514f5e3Sopenharmony_ci Int32((1LU << JSAsyncGeneratorObject::ResumeModeBits::SIZE) - 1)); 3564514f5e3Sopenharmony_ci} 3574514f5e3Sopenharmony_ci 3584514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetPcToFrame(GateRef glue, GateRef frame, GateRef value) 3594514f5e3Sopenharmony_ci{ 3604514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, frame, 3614514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetPcOffset(GetEnvironment()->IsArch32Bit())), value); 3624514f5e3Sopenharmony_ci} 3634514f5e3Sopenharmony_ci 3644514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetCallSizeToFrame(GateRef glue, GateRef frame, GateRef value) 3654514f5e3Sopenharmony_ci{ 3664514f5e3Sopenharmony_ci Store(VariableType::NATIVE_POINTER(), glue, frame, 3674514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetCallSizeOffset(GetEnvironment()->IsArch32Bit())), value); 3684514f5e3Sopenharmony_ci} 3694514f5e3Sopenharmony_ci 3704514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetAccToFrame(GateRef glue, GateRef frame, GateRef value) 3714514f5e3Sopenharmony_ci{ 3724514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, frame, 3734514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetAccOffset(GetEnvironment()->IsArch32Bit())), value); 3744514f5e3Sopenharmony_ci} 3754514f5e3Sopenharmony_ci 3764514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetEnvToFrame(GateRef glue, GateRef frame, GateRef value) 3774514f5e3Sopenharmony_ci{ 3784514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, frame, 3794514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetEnvOffset(GetEnvironment()->IsArch32Bit())), value); 3804514f5e3Sopenharmony_ci} 3814514f5e3Sopenharmony_ci 3824514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetFunctionToFrame(GateRef glue, GateRef frame, GateRef value) 3834514f5e3Sopenharmony_ci{ 3844514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, frame, 3854514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetFunctionOffset(GetEnvironment()->IsArch32Bit())), value); 3864514f5e3Sopenharmony_ci} 3874514f5e3Sopenharmony_ci 3884514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetHomeObjectToFunction(GateRef glue, GateRef function, GateRef value) 3894514f5e3Sopenharmony_ci{ 3904514f5e3Sopenharmony_ci GateRef offset = IntPtr(JSFunction::HOME_OBJECT_OFFSET); 3914514f5e3Sopenharmony_ci Store(VariableType::JS_ANY(), glue, function, offset, value); 3924514f5e3Sopenharmony_ci} 3934514f5e3Sopenharmony_ci 3944514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetFrameState(GateRef glue, GateRef sp, GateRef function, GateRef acc, 3954514f5e3Sopenharmony_ci GateRef env, GateRef pc, GateRef prev, GateRef type) 3964514f5e3Sopenharmony_ci{ 3974514f5e3Sopenharmony_ci GateRef state = GetFrame(sp); 3984514f5e3Sopenharmony_ci SetFunctionToFrame(glue, state, function); 3994514f5e3Sopenharmony_ci SetAccToFrame(glue, state, acc); 4004514f5e3Sopenharmony_ci SetEnvToFrame(glue, state, env); 4014514f5e3Sopenharmony_ci SetPcToFrame(glue, state, pc); 4024514f5e3Sopenharmony_ci GateRef prevOffset = IntPtr(AsmInterpretedFrame::GetBaseOffset(GetEnvironment()->IsArch32Bit())); 4034514f5e3Sopenharmony_ci Store(VariableType::NATIVE_POINTER(), glue, state, prevOffset, prev); 4044514f5e3Sopenharmony_ci GateRef frameTypeOffset = PtrAdd(prevOffset, IntPtr( 4054514f5e3Sopenharmony_ci InterpretedFrameBase::GetTypeOffset(GetEnvironment()->IsArch32Bit()))); 4064514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, state, frameTypeOffset, type); 4074514f5e3Sopenharmony_ci} 4084514f5e3Sopenharmony_ci 4094514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetCurrentSpFrame(GateRef glue) 4104514f5e3Sopenharmony_ci{ 4114514f5e3Sopenharmony_ci bool isArch32 = GetEnvironment()->Is32Bit(); 4124514f5e3Sopenharmony_ci GateRef spOffset = IntPtr(JSThread::GlueData::GetCurrentFrameOffset(isArch32)); 4134514f5e3Sopenharmony_ci return Load(VariableType::NATIVE_POINTER(), glue, spOffset); 4144514f5e3Sopenharmony_ci} 4154514f5e3Sopenharmony_ci 4164514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetCurrentSpFrame(GateRef glue, GateRef value) 4174514f5e3Sopenharmony_ci{ 4184514f5e3Sopenharmony_ci GateRef spOffset = IntPtr(JSThread::GlueData::GetCurrentFrameOffset(GetEnvironment()->Is32Bit())); 4194514f5e3Sopenharmony_ci Store(VariableType::NATIVE_POINTER(), glue, glue, spOffset, value); 4204514f5e3Sopenharmony_ci} 4214514f5e3Sopenharmony_ci 4224514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetLastLeaveFrame(GateRef glue) 4234514f5e3Sopenharmony_ci{ 4244514f5e3Sopenharmony_ci bool isArch32 = GetEnvironment()->Is32Bit(); 4254514f5e3Sopenharmony_ci GateRef spOffset = IntPtr(JSThread::GlueData::GetLeaveFrameOffset(isArch32)); 4264514f5e3Sopenharmony_ci return Load(VariableType::NATIVE_POINTER(), glue, spOffset); 4274514f5e3Sopenharmony_ci} 4284514f5e3Sopenharmony_ci 4294514f5e3Sopenharmony_civoid InterpreterStubBuilder::SetLastLeaveFrame(GateRef glue, GateRef value) 4304514f5e3Sopenharmony_ci{ 4314514f5e3Sopenharmony_ci GateRef spOffset = IntPtr(JSThread::GlueData::GetLeaveFrameOffset(GetEnvironment()->Is32Bit())); 4324514f5e3Sopenharmony_ci Store(VariableType::NATIVE_POINTER(), glue, glue, spOffset, value); 4334514f5e3Sopenharmony_ci} 4344514f5e3Sopenharmony_ci 4354514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::CheckStackOverflow(GateRef glue, GateRef sp) 4364514f5e3Sopenharmony_ci{ 4374514f5e3Sopenharmony_ci GateRef frameBaseOffset = IntPtr(JSThread::GlueData::GetFrameBaseOffset(GetEnvironment()->IsArch32Bit())); 4384514f5e3Sopenharmony_ci GateRef frameBase = Load(VariableType::NATIVE_POINTER(), glue, frameBaseOffset); 4394514f5e3Sopenharmony_ci return Int64UnsignedLessThanOrEqual(sp, 4404514f5e3Sopenharmony_ci PtrAdd(frameBase, IntPtr(JSThread::RESERVE_STACK_SIZE * sizeof(JSTaggedType)))); 4414514f5e3Sopenharmony_ci} 4424514f5e3Sopenharmony_ci 4434514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::PushArg(GateRef glue, GateRef sp, GateRef value) 4444514f5e3Sopenharmony_ci{ 4454514f5e3Sopenharmony_ci GateRef newSp = PtrSub(sp, IntPtr(sizeof(JSTaggedType))); 4464514f5e3Sopenharmony_ci // 0 : skip 0 byte of bytecode 4474514f5e3Sopenharmony_ci Store(VariableType::INT64(), glue, newSp, IntPtr(0), value); 4484514f5e3Sopenharmony_ci return newSp; 4494514f5e3Sopenharmony_ci} 4504514f5e3Sopenharmony_ci 4514514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::PushUndefined(GateRef glue, GateRef sp, GateRef num) 4524514f5e3Sopenharmony_ci{ 4534514f5e3Sopenharmony_ci auto env = GetEnvironment(); 4544514f5e3Sopenharmony_ci Label subEntry(env); 4554514f5e3Sopenharmony_ci env->SubCfgEntry(&subEntry); 4564514f5e3Sopenharmony_ci DEFVARIABLE(newSp, VariableType::NATIVE_POINTER(), sp); 4574514f5e3Sopenharmony_ci DEFVARIABLE(i, VariableType::INT32(), Int32(0)); 4584514f5e3Sopenharmony_ci Label pushUndefinedBegin(env); 4594514f5e3Sopenharmony_ci Label pushUndefinedAgain(env); 4604514f5e3Sopenharmony_ci Label pushUndefinedEnd(env); 4614514f5e3Sopenharmony_ci BRANCH(Int32LessThan(*i, num), &pushUndefinedBegin, &pushUndefinedEnd); 4624514f5e3Sopenharmony_ci LoopBegin(&pushUndefinedBegin); 4634514f5e3Sopenharmony_ci newSp = PushArg(glue, *newSp, Undefined()); 4644514f5e3Sopenharmony_ci i = Int32Add(*i, Int32(1)); // 1 : set as high 1 bits 4654514f5e3Sopenharmony_ci BRANCH(Int32LessThan(*i, num), &pushUndefinedAgain, &pushUndefinedEnd); 4664514f5e3Sopenharmony_ci Bind(&pushUndefinedAgain); 4674514f5e3Sopenharmony_ci LoopEnd(&pushUndefinedBegin); 4684514f5e3Sopenharmony_ci Bind(&pushUndefinedEnd); 4694514f5e3Sopenharmony_ci auto ret = *newSp; 4704514f5e3Sopenharmony_ci env->SubCfgExit(); 4714514f5e3Sopenharmony_ci return ret; 4724514f5e3Sopenharmony_ci} 4734514f5e3Sopenharmony_ci 4744514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::PushRange(GateRef glue, GateRef sp, GateRef array, GateRef startIndex, GateRef endIndex) 4754514f5e3Sopenharmony_ci{ 4764514f5e3Sopenharmony_ci auto env = GetEnvironment(); 4774514f5e3Sopenharmony_ci Label subEntry(env); 4784514f5e3Sopenharmony_ci env->SubCfgEntry(&subEntry); 4794514f5e3Sopenharmony_ci DEFVARIABLE(newSp, VariableType::NATIVE_POINTER(), sp); 4804514f5e3Sopenharmony_ci DEFVARIABLE(i, VariableType::INT32(), endIndex); 4814514f5e3Sopenharmony_ci Label pushArgsBegin(env); 4824514f5e3Sopenharmony_ci Label pushArgsAgain(env); 4834514f5e3Sopenharmony_ci Label pushArgsEnd(env); 4844514f5e3Sopenharmony_ci BRANCH(Int32GreaterThanOrEqual(*i, startIndex), &pushArgsBegin, &pushArgsEnd); 4854514f5e3Sopenharmony_ci LoopBegin(&pushArgsBegin); 4864514f5e3Sopenharmony_ci GateRef arg = GetVregValue(array, ZExtInt32ToPtr(*i)); 4874514f5e3Sopenharmony_ci newSp = PushArg(glue, *newSp, arg); 4884514f5e3Sopenharmony_ci i = Int32Sub(*i, Int32(1)); // 1 : set as high 1 bits 4894514f5e3Sopenharmony_ci BRANCH(Int32GreaterThanOrEqual(*i, startIndex), &pushArgsAgain, &pushArgsEnd); 4904514f5e3Sopenharmony_ci Bind(&pushArgsAgain); 4914514f5e3Sopenharmony_ci LoopEnd(&pushArgsBegin); 4924514f5e3Sopenharmony_ci Bind(&pushArgsEnd); 4934514f5e3Sopenharmony_ci auto ret = *newSp; 4944514f5e3Sopenharmony_ci env->SubCfgExit(); 4954514f5e3Sopenharmony_ci return ret; 4964514f5e3Sopenharmony_ci} 4974514f5e3Sopenharmony_ci 4984514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetStartIdxAndNumArgs(GateRef sp, GateRef restIdx) 4994514f5e3Sopenharmony_ci{ 5004514f5e3Sopenharmony_ci auto env = GetEnvironment(); 5014514f5e3Sopenharmony_ci Label subEntry(env); 5024514f5e3Sopenharmony_ci env->SubCfgEntry(&subEntry); 5034514f5e3Sopenharmony_ci DEFVARIABLE(numArgs, VariableType::INT32(), Int32(0)); 5044514f5e3Sopenharmony_ci GateRef state = PtrSub(sp, IntPtr(AsmInterpretedFrame::GetSize(env->IsArch32Bit()))); 5054514f5e3Sopenharmony_ci GateRef function = GetFunctionFromFrame(state); 5064514f5e3Sopenharmony_ci GateRef method = GetMethodFromJSFunctionOrProxy(function); 5074514f5e3Sopenharmony_ci GateRef callField = GetCallFieldFromMethod(method); 5084514f5e3Sopenharmony_ci // ASSERT: callField has "extra" bit. 5094514f5e3Sopenharmony_ci GateRef numVregs = TruncInt64ToInt32(Int64And(Int64LSR(callField, Int64(MethodLiteral::NumVregsBits::START_BIT)), 5104514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::NumVregsBits::SIZE) - 1))); 5114514f5e3Sopenharmony_ci GateRef haveFunc = Int64NotEqual(Int64And(Int64LSR(callField, Int64(MethodLiteral::HaveFuncBit::START_BIT)), 5124514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::HaveFuncBit::SIZE) - 1)), Int64(0)); 5134514f5e3Sopenharmony_ci GateRef haveNewTarget = Int64NotEqual( 5144514f5e3Sopenharmony_ci Int64And(Int64LSR(callField, Int64(MethodLiteral::HaveNewTargetBit::START_BIT)), 5154514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::HaveNewTargetBit::SIZE) - 1)), Int64(0)); 5164514f5e3Sopenharmony_ci GateRef haveThis = Int64NotEqual(Int64And(Int64LSR(callField, Int64(MethodLiteral::HaveThisBit::START_BIT)), 5174514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::HaveThisBit::SIZE) - 1)), Int64(0)); 5184514f5e3Sopenharmony_ci GateRef copyArgs = Int32Add(Int32Add(ZExtInt1ToInt32(haveFunc), ZExtInt1ToInt32(haveNewTarget)), 5194514f5e3Sopenharmony_ci ZExtInt1ToInt32(haveThis)); 5204514f5e3Sopenharmony_ci numArgs = TruncInt64ToInt32(Int64And(Int64LSR(callField, Int64(MethodLiteral::NumArgsBits::START_BIT)), 5214514f5e3Sopenharmony_ci Int64((1LLU << MethodLiteral::NumArgsBits::SIZE) - 1))); 5224514f5e3Sopenharmony_ci GateRef fp = Load(VariableType::NATIVE_POINTER(), state, 5234514f5e3Sopenharmony_ci IntPtr(AsmInterpretedFrame::GetFpOffset(env->IsArch32Bit()))); 5244514f5e3Sopenharmony_ci Label actualEqualDeclared(env); 5254514f5e3Sopenharmony_ci Label actualNotEqualDeclared(env); 5264514f5e3Sopenharmony_ci BRANCH(Int32UnsignedGreaterThan(ChangeIntPtrToInt32(PtrSub(fp, sp)), 5274514f5e3Sopenharmony_ci Int32Mul(Int32Add(Int32Add(numVregs, copyArgs), *numArgs), 5284514f5e3Sopenharmony_ci Int32(sizeof(JSTaggedType)))), 5294514f5e3Sopenharmony_ci &actualNotEqualDeclared, &actualEqualDeclared); 5304514f5e3Sopenharmony_ci Bind(&actualNotEqualDeclared); 5314514f5e3Sopenharmony_ci { 5324514f5e3Sopenharmony_ci numArgs = GetInt32OfTInt(Load(VariableType::JS_ANY(), fp, IntPtr(-sizeof(JSTaggedType)))); 5334514f5e3Sopenharmony_ci Jump(&actualEqualDeclared); 5344514f5e3Sopenharmony_ci } 5354514f5e3Sopenharmony_ci Bind(&actualEqualDeclared); 5364514f5e3Sopenharmony_ci GateRef startIdx = Int32Add(Int32Add(numVregs, copyArgs), restIdx); 5374514f5e3Sopenharmony_ci Label numArgsGreater(env); 5384514f5e3Sopenharmony_ci Label numArgsNotGreater(env); 5394514f5e3Sopenharmony_ci Label exit(env); 5404514f5e3Sopenharmony_ci BRANCH(Int32UnsignedGreaterThan(*numArgs, restIdx), &numArgsGreater, &numArgsNotGreater); 5414514f5e3Sopenharmony_ci Bind(&numArgsGreater); 5424514f5e3Sopenharmony_ci { 5434514f5e3Sopenharmony_ci numArgs = Int32Sub(*numArgs, restIdx); 5444514f5e3Sopenharmony_ci Jump(&exit); 5454514f5e3Sopenharmony_ci } 5464514f5e3Sopenharmony_ci Bind(&numArgsNotGreater); 5474514f5e3Sopenharmony_ci { 5484514f5e3Sopenharmony_ci numArgs = Int32(0); 5494514f5e3Sopenharmony_ci Jump(&exit); 5504514f5e3Sopenharmony_ci } 5514514f5e3Sopenharmony_ci Bind(&exit); 5524514f5e3Sopenharmony_ci // 32: high 32 bits = startIdx, low 32 bits = numArgs 5534514f5e3Sopenharmony_ci GateRef ret = Int64Or(Int64LSL(ZExtInt32ToInt64(startIdx), Int64(32)), ZExtInt32ToInt64(*numArgs)); 5544514f5e3Sopenharmony_ci env->SubCfgExit(); 5554514f5e3Sopenharmony_ci return ret; 5564514f5e3Sopenharmony_ci} 5574514f5e3Sopenharmony_ci 5584514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetCurrentFrame(GateRef glue) 5594514f5e3Sopenharmony_ci{ 5604514f5e3Sopenharmony_ci return GetLastLeaveFrame(glue); 5614514f5e3Sopenharmony_ci} 5624514f5e3Sopenharmony_ci 5634514f5e3Sopenharmony_civoid InterpreterStubBuilder::UpdateProfileTypeInfoCellToFunction(GateRef glue, GateRef function, 5644514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef slotId) 5654514f5e3Sopenharmony_ci{ 5664514f5e3Sopenharmony_ci auto env = GetEnvironment(); 5674514f5e3Sopenharmony_ci Label subEntry(env); 5684514f5e3Sopenharmony_ci env->SubCfgEntry(&subEntry); 5694514f5e3Sopenharmony_ci 5704514f5e3Sopenharmony_ci Label profileTypeInfoNotUndefined(env); 5714514f5e3Sopenharmony_ci Label slotValueUpdate(env); 5724514f5e3Sopenharmony_ci Label slotValueNotUndefined(env); 5734514f5e3Sopenharmony_ci Label slotValueNotHole(env); 5744514f5e3Sopenharmony_ci Label profileTypeInfoEnd(env); 5754514f5e3Sopenharmony_ci NewObjectStubBuilder newBuilder(this); 5764514f5e3Sopenharmony_ci BRANCH(TaggedIsUndefined(profileTypeInfo), &profileTypeInfoEnd, &profileTypeInfoNotUndefined); 5774514f5e3Sopenharmony_ci Bind(&profileTypeInfoNotUndefined); 5784514f5e3Sopenharmony_ci { 5794514f5e3Sopenharmony_ci GateRef slotValue = GetValueFromTaggedArray(profileTypeInfo, slotId); 5804514f5e3Sopenharmony_ci BRANCH_UNLIKELY(TaggedIsUndefined(slotValue), &slotValueUpdate, &slotValueNotUndefined); 5814514f5e3Sopenharmony_ci Bind(&slotValueUpdate); 5824514f5e3Sopenharmony_ci { 5834514f5e3Sopenharmony_ci GateRef newProfileTypeInfoCell = newBuilder.NewProfileTypeInfoCell(glue, Undefined()); 5844514f5e3Sopenharmony_ci SetValueToTaggedArray(VariableType::JS_ANY(), glue, profileTypeInfo, slotId, newProfileTypeInfoCell, 5854514f5e3Sopenharmony_ci MemoryAttribute::NeedNotShareBarrier()); 5864514f5e3Sopenharmony_ci SetRawProfileTypeInfoToFunction(glue, function, newProfileTypeInfoCell, 5874514f5e3Sopenharmony_ci MemoryAttribute::NeedNotShareBarrier()); 5884514f5e3Sopenharmony_ci Jump(&profileTypeInfoEnd); 5894514f5e3Sopenharmony_ci } 5904514f5e3Sopenharmony_ci Bind(&slotValueNotUndefined); 5914514f5e3Sopenharmony_ci BRANCH_UNLIKELY(TaggedIsHole(slotValue), &profileTypeInfoEnd, &slotValueNotHole); 5924514f5e3Sopenharmony_ci Bind(&slotValueNotHole); 5934514f5e3Sopenharmony_ci { 5944514f5e3Sopenharmony_ci UpdateProfileTypeInfoCellType(glue, slotValue); 5954514f5e3Sopenharmony_ci SetRawProfileTypeInfoToFunction(glue, function, slotValue, MemoryAttribute::NeedNotShareBarrier()); 5964514f5e3Sopenharmony_ci TryToJitReuseCompiledFunc(glue, function, slotValue); 5974514f5e3Sopenharmony_ci } 5984514f5e3Sopenharmony_ci Jump(&profileTypeInfoEnd); 5994514f5e3Sopenharmony_ci } 6004514f5e3Sopenharmony_ci Bind(&profileTypeInfoEnd); 6014514f5e3Sopenharmony_ci 6024514f5e3Sopenharmony_ci env->SubCfgExit(); 6034514f5e3Sopenharmony_ci} 6044514f5e3Sopenharmony_ci 6054514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst32_0(GateRef pc) 6064514f5e3Sopenharmony_ci{ 6074514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 6084514f5e3Sopenharmony_ci return Load(VariableType::INT32(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 6094514f5e3Sopenharmony_ci } 6104514f5e3Sopenharmony_ci GateRef currentInst = ZExtInt8ToInt32(ReadInst8_3(pc)); 6114514f5e3Sopenharmony_ci GateRef currentInst1 = Int32LSL(currentInst, Int32(8)); // 8 : set as high 8 bits 6124514f5e3Sopenharmony_ci GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8_2(pc))); 6134514f5e3Sopenharmony_ci GateRef currentInst3 = Int32LSL(currentInst2, Int32(8)); // 8 : set as high 8 bits 6144514f5e3Sopenharmony_ci GateRef currentInst4 = Int32Add(currentInst3, ZExtInt8ToInt32(ReadInst8_1(pc))); 6154514f5e3Sopenharmony_ci GateRef currentInst5 = Int32LSL(currentInst4, Int32(8)); // 8 : set as high 8 bits 6164514f5e3Sopenharmony_ci return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8_0(pc))); 6174514f5e3Sopenharmony_ci} 6184514f5e3Sopenharmony_ci 6194514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst32_1(GateRef pc) 6204514f5e3Sopenharmony_ci{ 6214514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 6224514f5e3Sopenharmony_ci return Load(VariableType::INT32(), pc, IntPtr(2)); // 2 : skip 2 bytes of bytecode 6234514f5e3Sopenharmony_ci } 6244514f5e3Sopenharmony_ci GateRef currentInst = ZExtInt8ToInt32(ReadInst8_4(pc)); 6254514f5e3Sopenharmony_ci GateRef currentInst1 = Int32LSL(currentInst, Int32(8)); // 8 : set as high 8 bits 6264514f5e3Sopenharmony_ci GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8_3(pc))); 6274514f5e3Sopenharmony_ci GateRef currentInst3 = Int32LSL(currentInst2, Int32(8)); // 8 : set as high 8 bits 6284514f5e3Sopenharmony_ci GateRef currentInst4 = Int32Add(currentInst3, ZExtInt8ToInt32(ReadInst8_2(pc))); 6294514f5e3Sopenharmony_ci GateRef currentInst5 = Int32LSL(currentInst4, Int32(8)); // 8 : set as high 8 bits 6304514f5e3Sopenharmony_ci return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8_1(pc))); 6314514f5e3Sopenharmony_ci} 6324514f5e3Sopenharmony_ci 6334514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst32_2(GateRef pc) 6344514f5e3Sopenharmony_ci{ 6354514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 6364514f5e3Sopenharmony_ci return Load(VariableType::INT32(), pc, IntPtr(3)); // 3 : skip 3 bytes of bytecode 6374514f5e3Sopenharmony_ci } 6384514f5e3Sopenharmony_ci GateRef currentInst = ZExtInt8ToInt32(ReadInst8_5(pc)); 6394514f5e3Sopenharmony_ci GateRef currentInst1 = Int32LSL(currentInst, Int32(8)); // 8 : set as high 8 bits 6404514f5e3Sopenharmony_ci GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8_4(pc))); 6414514f5e3Sopenharmony_ci GateRef currentInst3 = Int32LSL(currentInst2, Int32(8)); // 8 : set as high 8 bits 6424514f5e3Sopenharmony_ci GateRef currentInst4 = Int32Add(currentInst3, ZExtInt8ToInt32(ReadInst8_3(pc))); 6434514f5e3Sopenharmony_ci GateRef currentInst5 = Int32LSL(currentInst4, Int32(8)); // 8 : set as high 8 bits 6444514f5e3Sopenharmony_ci return Int32Add(currentInst5, ZExtInt8ToInt32(ReadInst8_2(pc))); 6454514f5e3Sopenharmony_ci} 6464514f5e3Sopenharmony_ci 6474514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::ReadInst64_0(GateRef pc) 6484514f5e3Sopenharmony_ci{ 6494514f5e3Sopenharmony_ci if (GetEnvironment()->IsAArch64() || GetEnvironment()->IsAmd64()) { 6504514f5e3Sopenharmony_ci return Load(VariableType::INT64(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode 6514514f5e3Sopenharmony_ci } 6524514f5e3Sopenharmony_ci GateRef currentInst = ZExtInt8ToInt64(ReadInst8_7(pc)); 6534514f5e3Sopenharmony_ci GateRef currentInst1 = Int64LSL(currentInst, Int64(8)); // 8 : set as high 8 bits 6544514f5e3Sopenharmony_ci GateRef currentInst2 = Int64Add(currentInst1, ZExtInt8ToInt64(ReadInst8_6(pc))); 6554514f5e3Sopenharmony_ci GateRef currentInst3 = Int64LSL(currentInst2, Int64(8)); // 8 : set as high 8 bits 6564514f5e3Sopenharmony_ci GateRef currentInst4 = Int64Add(currentInst3, ZExtInt8ToInt64(ReadInst8_5(pc))); 6574514f5e3Sopenharmony_ci GateRef currentInst5 = Int64LSL(currentInst4, Int64(8)); // 8 : set as high 8 bits 6584514f5e3Sopenharmony_ci GateRef currentInst6 = Int64Add(currentInst5, ZExtInt8ToInt64(ReadInst8_4(pc))); 6594514f5e3Sopenharmony_ci GateRef currentInst7 = Int64LSL(currentInst6, Int64(8)); // 8 : set as high 8 bits 6604514f5e3Sopenharmony_ci GateRef currentInst8 = Int64Add(currentInst7, ZExtInt8ToInt64(ReadInst8_3(pc))); 6614514f5e3Sopenharmony_ci GateRef currentInst9 = Int64LSL(currentInst8, Int64(8)); // 8 : set as high 8 bits 6624514f5e3Sopenharmony_ci GateRef currentInst10 = Int64Add(currentInst9, ZExtInt8ToInt64(ReadInst8_2(pc))); 6634514f5e3Sopenharmony_ci GateRef currentInst11 = Int64LSL(currentInst10, Int64(8)); // 8 : set as high 8 bits 6644514f5e3Sopenharmony_ci GateRef currentInst12 = Int64Add(currentInst11, ZExtInt8ToInt64(ReadInst8_1(pc))); 6654514f5e3Sopenharmony_ci GateRef currentInst13 = Int64LSL(currentInst12, Int64(8)); // 8 : set as high 8 bits 6664514f5e3Sopenharmony_ci return Int64Add(currentInst13, ZExtInt8ToInt64(ReadInst8_0(pc))); 6674514f5e3Sopenharmony_ci} 6684514f5e3Sopenharmony_ci 6694514f5e3Sopenharmony_citemplate<typename... Args> 6704514f5e3Sopenharmony_civoid InterpreterStubBuilder::DispatchBase(GateRef target, GateRef glue, Args... args) 6714514f5e3Sopenharmony_ci{ 6724514f5e3Sopenharmony_ci GetEnvironment()->GetBuilder()->CallBCHandler(glue, target, {glue, args...}); 6734514f5e3Sopenharmony_ci} 6744514f5e3Sopenharmony_ci 6754514f5e3Sopenharmony_civoid InterpreterStubBuilder::Dispatch(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, GateRef profileTypeInfo, 6764514f5e3Sopenharmony_ci GateRef acc, GateRef hotnessCounter, GateRef format) 6774514f5e3Sopenharmony_ci{ 6784514f5e3Sopenharmony_ci GateRef newPc = PtrAdd(pc, format); 6794514f5e3Sopenharmony_ci GateRef opcode = Load(VariableType::INT8(), newPc); 6804514f5e3Sopenharmony_ci GateRef target = PtrMul(ZExtInt32ToPtr(ZExtInt8ToInt32(opcode)), IntPtrSize()); 6814514f5e3Sopenharmony_ci DispatchBase(target, glue, sp, newPc, constpool, profileTypeInfo, acc, hotnessCounter); 6824514f5e3Sopenharmony_ci Return(); 6834514f5e3Sopenharmony_ci} 6844514f5e3Sopenharmony_ci 6854514f5e3Sopenharmony_civoid InterpreterStubBuilder::DispatchLast(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 6864514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) 6874514f5e3Sopenharmony_ci{ 6884514f5e3Sopenharmony_ci GateRef target = PtrMul(IntPtr(BytecodeStubCSigns::ID_ExceptionHandler), IntPtrSize()); 6894514f5e3Sopenharmony_ci DispatchBase(target, glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter); 6904514f5e3Sopenharmony_ci Return(); 6914514f5e3Sopenharmony_ci} 6924514f5e3Sopenharmony_ci 6934514f5e3Sopenharmony_civoid InterpreterStubBuilder::DispatchDebugger(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 6944514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) 6954514f5e3Sopenharmony_ci{ 6964514f5e3Sopenharmony_ci GateRef opcode = Load(VariableType::INT8(), pc); 6974514f5e3Sopenharmony_ci GateRef target = PtrMul(ZExtInt32ToPtr(ZExtInt8ToInt32(opcode)), IntPtrSize()); 6984514f5e3Sopenharmony_ci auto args = { glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter }; 6994514f5e3Sopenharmony_ci GetEnvironment()->GetBuilder()->CallBCDebugger(glue, target, args); 7004514f5e3Sopenharmony_ci Return(); 7014514f5e3Sopenharmony_ci} 7024514f5e3Sopenharmony_ci 7034514f5e3Sopenharmony_civoid InterpreterStubBuilder::DispatchDebuggerLast(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 7044514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter) 7054514f5e3Sopenharmony_ci{ 7064514f5e3Sopenharmony_ci GateRef target = PtrMul(IntPtr(BytecodeStubCSigns::ID_ExceptionHandler), IntPtrSize()); 7074514f5e3Sopenharmony_ci auto args = { glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter }; 7084514f5e3Sopenharmony_ci GetEnvironment()->GetBuilder()->CallBCDebugger(glue, target, args); 7094514f5e3Sopenharmony_ci Return(); 7104514f5e3Sopenharmony_ci} 7114514f5e3Sopenharmony_ci 7124514f5e3Sopenharmony_ciGateRef InterpreterStubBuilder::GetHotnessCounterFromMethod(GateRef method) 7134514f5e3Sopenharmony_ci{ 7144514f5e3Sopenharmony_ci GateRef x = Load(VariableType::INT16(), method, IntPtr(Method::LITERAL_INFO_OFFSET)); 7154514f5e3Sopenharmony_ci return GetEnvironment()->GetBuilder()->SExtInt1ToInt32(x); 7164514f5e3Sopenharmony_ci} 7174514f5e3Sopenharmony_ci 7184514f5e3Sopenharmony_civoid InterpreterStubBuilder::DispatchWithId(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 7194514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, 7204514f5e3Sopenharmony_ci GateRef hotnessCounter, GateRef index) 7214514f5e3Sopenharmony_ci{ 7224514f5e3Sopenharmony_ci GateRef target = PtrMul(index, IntPtrSize()); 7234514f5e3Sopenharmony_ci DispatchBase(target, glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter); 7244514f5e3Sopenharmony_ci Return(); 7254514f5e3Sopenharmony_ci} 7264514f5e3Sopenharmony_ci 7274514f5e3Sopenharmony_ci#define DISPATCH_LAST(acc) \ 7284514f5e3Sopenharmony_ci DispatchLast(glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter) 7294514f5e3Sopenharmony_ci#define DISPATCH(acc) \ 7304514f5e3Sopenharmony_ci Dispatch(glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter, offset) 7314514f5e3Sopenharmony_civoid InterpreterStubBuilder::CheckException(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 7324514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter, 7334514f5e3Sopenharmony_ci GateRef res, GateRef offset) 7344514f5e3Sopenharmony_ci{ 7354514f5e3Sopenharmony_ci auto env = GetEnvironment(); 7364514f5e3Sopenharmony_ci Label isException(env); 7374514f5e3Sopenharmony_ci Label notException(env); 7384514f5e3Sopenharmony_ci BRANCH(TaggedIsException(res), &isException, ¬Exception); 7394514f5e3Sopenharmony_ci Bind(&isException); 7404514f5e3Sopenharmony_ci { 7414514f5e3Sopenharmony_ci DISPATCH_LAST(acc); 7424514f5e3Sopenharmony_ci } 7434514f5e3Sopenharmony_ci Bind(¬Exception); 7444514f5e3Sopenharmony_ci { 7454514f5e3Sopenharmony_ci DISPATCH(acc); 7464514f5e3Sopenharmony_ci } 7474514f5e3Sopenharmony_ci} 7484514f5e3Sopenharmony_ci 7494514f5e3Sopenharmony_civoid InterpreterStubBuilder::CheckPendingException(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 7504514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter, 7514514f5e3Sopenharmony_ci GateRef res, GateRef offset) 7524514f5e3Sopenharmony_ci{ 7534514f5e3Sopenharmony_ci auto env = GetEnvironment(); 7544514f5e3Sopenharmony_ci Label isException(env); 7554514f5e3Sopenharmony_ci Label notException(env); 7564514f5e3Sopenharmony_ci BRANCH(HasPendingException(glue), &isException, ¬Exception); 7574514f5e3Sopenharmony_ci Bind(&isException); 7584514f5e3Sopenharmony_ci { 7594514f5e3Sopenharmony_ci DISPATCH_LAST(acc); 7604514f5e3Sopenharmony_ci } 7614514f5e3Sopenharmony_ci Bind(¬Exception); 7624514f5e3Sopenharmony_ci { 7634514f5e3Sopenharmony_ci DISPATCH(res); 7644514f5e3Sopenharmony_ci } 7654514f5e3Sopenharmony_ci} 7664514f5e3Sopenharmony_ci 7674514f5e3Sopenharmony_civoid InterpreterStubBuilder::CheckExceptionWithVar(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 7684514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter, 7694514f5e3Sopenharmony_ci GateRef res, GateRef offset) 7704514f5e3Sopenharmony_ci{ 7714514f5e3Sopenharmony_ci auto env = GetEnvironment(); 7724514f5e3Sopenharmony_ci Label isException(env); 7734514f5e3Sopenharmony_ci Label notException(env); 7744514f5e3Sopenharmony_ci BRANCH(TaggedIsException(res), &isException, ¬Exception); 7754514f5e3Sopenharmony_ci Bind(&isException); 7764514f5e3Sopenharmony_ci { 7774514f5e3Sopenharmony_ci DISPATCH_LAST(acc); 7784514f5e3Sopenharmony_ci } 7794514f5e3Sopenharmony_ci Bind(¬Exception); 7804514f5e3Sopenharmony_ci { 7814514f5e3Sopenharmony_ci DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc); 7824514f5e3Sopenharmony_ci varAcc = res; 7834514f5e3Sopenharmony_ci DISPATCH(*varAcc); 7844514f5e3Sopenharmony_ci } 7854514f5e3Sopenharmony_ci} 7864514f5e3Sopenharmony_ci 7874514f5e3Sopenharmony_civoid InterpreterStubBuilder::CheckExceptionWithJump(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, 7884514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef acc, GateRef hotnessCounter, 7894514f5e3Sopenharmony_ci GateRef res, Label *jump) 7904514f5e3Sopenharmony_ci{ 7914514f5e3Sopenharmony_ci auto env = GetEnvironment(); 7924514f5e3Sopenharmony_ci Label isException(env); 7934514f5e3Sopenharmony_ci Label notException(env); 7944514f5e3Sopenharmony_ci BRANCH(TaggedIsException(res), &isException, ¬Exception); 7954514f5e3Sopenharmony_ci Bind(&isException); 7964514f5e3Sopenharmony_ci { 7974514f5e3Sopenharmony_ci DISPATCH_LAST(acc); 7984514f5e3Sopenharmony_ci } 7994514f5e3Sopenharmony_ci Bind(¬Exception); 8004514f5e3Sopenharmony_ci { 8014514f5e3Sopenharmony_ci Jump(jump); 8024514f5e3Sopenharmony_ci } 8034514f5e3Sopenharmony_ci} 8044514f5e3Sopenharmony_ci 8054514f5e3Sopenharmony_ciGateRef InterpreterToolsStubBuilder::GetStringId(const StringIdInfo &info) 8064514f5e3Sopenharmony_ci{ 8074514f5e3Sopenharmony_ci if (info.GetStringIdType() == StringIdInfo::StringIdType::STRING_ID) { 8084514f5e3Sopenharmony_ci return info.GetStringId(); 8094514f5e3Sopenharmony_ci } 8104514f5e3Sopenharmony_ci GateRef stringId; 8114514f5e3Sopenharmony_ci switch (info.GetOffset()) { 8124514f5e3Sopenharmony_ci case StringIdInfo::Offset::BYTE_0: { 8134514f5e3Sopenharmony_ci if (info.GetLength() == StringIdInfo::Length::BITS_16) { 8144514f5e3Sopenharmony_ci stringId = ZExtInt16ToInt32(ReadInst16_0(info.GetPc())); 8154514f5e3Sopenharmony_ci } else { 8164514f5e3Sopenharmony_ci std::abort(); 8174514f5e3Sopenharmony_ci } 8184514f5e3Sopenharmony_ci break; 8194514f5e3Sopenharmony_ci } 8204514f5e3Sopenharmony_ci case StringIdInfo::Offset::BYTE_1: { 8214514f5e3Sopenharmony_ci if (info.GetLength() == StringIdInfo::Length::BITS_16) { 8224514f5e3Sopenharmony_ci stringId = ZExtInt16ToInt32(ReadInst16_1(info.GetPc())); 8234514f5e3Sopenharmony_ci } else if (info.GetLength() == StringIdInfo::Length::BITS_32) { 8244514f5e3Sopenharmony_ci stringId = ReadInst32_1(info.GetPc()); 8254514f5e3Sopenharmony_ci } else { 8264514f5e3Sopenharmony_ci std::abort(); 8274514f5e3Sopenharmony_ci } 8284514f5e3Sopenharmony_ci break; 8294514f5e3Sopenharmony_ci } 8304514f5e3Sopenharmony_ci case StringIdInfo::Offset::BYTE_2: { 8314514f5e3Sopenharmony_ci if (info.GetLength() == StringIdInfo::Length::BITS_16) { 8324514f5e3Sopenharmony_ci stringId = ZExtInt16ToInt32(ReadInst16_2(info.GetPc())); 8334514f5e3Sopenharmony_ci } else { 8344514f5e3Sopenharmony_ci std::abort(); 8354514f5e3Sopenharmony_ci } 8364514f5e3Sopenharmony_ci break; 8374514f5e3Sopenharmony_ci } 8384514f5e3Sopenharmony_ci default: { 8394514f5e3Sopenharmony_ci std::abort(); 8404514f5e3Sopenharmony_ci break; 8414514f5e3Sopenharmony_ci } 8424514f5e3Sopenharmony_ci } 8434514f5e3Sopenharmony_ci return stringId; 8444514f5e3Sopenharmony_ci} 8454514f5e3Sopenharmony_ci#undef DISPATCH_LAST 8464514f5e3Sopenharmony_ci#undef DISPATCH 8474514f5e3Sopenharmony_ci} // namespace panda::ecmascript::kungfu 8484514f5e3Sopenharmony_ci#endif // ECMASCRIPT_COMPILER_INTERPRETER_STUB_INL_H 849