14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2023 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_OPCODE_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_OPCODE_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include <string> 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_ci#include "ecmascript/compiler/bytecodes.h" 224514f5e3Sopenharmony_ci 234514f5e3Sopenharmony_ci#include "ecmascript/compiler/lcr_opcodes.h" 244514f5e3Sopenharmony_ci#include "ecmascript/compiler/mcr_opcodes.h" 254514f5e3Sopenharmony_ci#include "ecmascript/compiler/hcr_opcodes.h" 264514f5e3Sopenharmony_ci 274514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu { 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_ci#define SHARE_IMMUTABLE_META_DATA_CACHE_LIST(V) \ 304514f5e3Sopenharmony_ci V(CircuitRoot, CIRCUIT_ROOT, GateFlags::NONE_FLAG, 0, 0, 0) \ 314514f5e3Sopenharmony_ci V(StateEntry, STATE_ENTRY, GateFlags::ROOT, 0, 0, 0) \ 324514f5e3Sopenharmony_ci V(DependEntry, DEPEND_ENTRY, GateFlags::ROOT, 0, 0, 0) \ 334514f5e3Sopenharmony_ci V(OrdinaryBlock, ORDINARY_BLOCK, GateFlags::CONTROL, 1, 0, 0) \ 344514f5e3Sopenharmony_ci V(DefaultCase, DEFAULT_CASE, GateFlags::CONTROL, 1, 0, 0) \ 354514f5e3Sopenharmony_ci V(ReturnList, RETURN_LIST, GateFlags::ROOT, 0, 0, 0) \ 364514f5e3Sopenharmony_ci V(ArgList, ARG_LIST, GateFlags::ROOT, 0, 0, 0) \ 374514f5e3Sopenharmony_ci V(Dead, DEAD, GateFlags::NONE_FLAG, 0, 0, 0) \ 384514f5e3Sopenharmony_ci V(Throw, THROW, GateFlags::CONTROL, 1, 1, 1) \ 394514f5e3Sopenharmony_ci V(LoopExit, LOOP_EXIT, GateFlags::CONTROL, 1, 0, 0) \ 404514f5e3Sopenharmony_ci V(LoopExitDepend, LOOP_EXIT_DEPEND, GateFlags::FIXED, 1, 1, 0) \ 414514f5e3Sopenharmony_ci V(LoopExitValue, LOOP_EXIT_VALUE, GateFlags::FIXED, 1, 0, 1) \ 424514f5e3Sopenharmony_ci V(DependRelay, DEPEND_RELAY, GateFlags::FIXED, 1, 1, 0) \ 434514f5e3Sopenharmony_ci V(IfTrue, IF_TRUE, GateFlags::CONTROL, 1, 0, 0) \ 444514f5e3Sopenharmony_ci V(IfFalse, IF_FALSE, GateFlags::CONTROL, 1, 0, 0) \ 454514f5e3Sopenharmony_ci V(IfSuccess, IF_SUCCESS, GateFlags::CONTROL, 1, 0, 0) \ 464514f5e3Sopenharmony_ci V(IfException, IF_EXCEPTION, GateFlags::CONTROL, 1, 1, 0) \ 474514f5e3Sopenharmony_ci V(GetException, GET_EXCEPTION, GateFlags::NONE_FLAG, 1, 1, 0) \ 484514f5e3Sopenharmony_ci V(GetUnsharedConstPool, GET_UNSHARED_CONSTPOOL, GateFlags::NO_WRITE, 0, 0, 1) \ 494514f5e3Sopenharmony_ci V(GetGlobalEnv, GET_GLOBAL_ENV, GateFlags::NO_WRITE, 0, 1, 0) \ 504514f5e3Sopenharmony_ci V(GetSuperConstructor, GET_SUPER_CONSTRUCTOR, GateFlags::NO_WRITE, 1, 1, 1) \ 514514f5e3Sopenharmony_ci V(CheckSafePointAndStackOver, CHECK_SAFEPOINT_AND_STACKOVER, GateFlags::NO_WRITE, 1, 1, 0) \ 524514f5e3Sopenharmony_ci V(DeoptCheck, DEOPT_CHECK, GateFlags::NO_WRITE, 1, 1, 3) \ 534514f5e3Sopenharmony_ci V(LoopBack, LOOP_BACK, GateFlags::CONTROL, 1, 0, 0) \ 544514f5e3Sopenharmony_ci V(Return, RETURN, GateFlags::HAS_ROOT, 1, 1, 1) \ 554514f5e3Sopenharmony_ci V(ReturnVoid, RETURN_VOID, GateFlags::HAS_ROOT, 1, 1, 0) \ 564514f5e3Sopenharmony_ci V(StateSplit, STATE_SPLIT, GateFlags::CHECKABLE, 1, 1, 0) \ 574514f5e3Sopenharmony_ci V(GetEnv, GET_ENV, GateFlags::NO_WRITE, 0, 1, 1) 584514f5e3Sopenharmony_ci 594514f5e3Sopenharmony_ci#define SHARE_GATE_META_DATA_LIST_WITH_VALUE_IN(V) \ 604514f5e3Sopenharmony_ci V(FrameValues, FRAME_VALUES, GateFlags::NONE_FLAG, 0, 0, value) \ 614514f5e3Sopenharmony_ci V(ValueSelector, VALUE_SELECTOR, GateFlags::FIXED, 1, 0, value) 624514f5e3Sopenharmony_ci 634514f5e3Sopenharmony_ci#define SHARE_GATE_META_DATA_LIST_WITH_SIZE(V) \ 644514f5e3Sopenharmony_ci V(LoopBegin, LOOP_BEGIN, GateFlags::CONTROL, value, 0, 0) \ 654514f5e3Sopenharmony_ci V(Merge, MERGE, GateFlags::CONTROL, value, 0, 0) \ 664514f5e3Sopenharmony_ci V(DependSelector, DEPEND_SELECTOR, GateFlags::FIXED, 1, value, 0) \ 674514f5e3Sopenharmony_ci SHARE_GATE_META_DATA_LIST_WITH_VALUE_IN(V) 684514f5e3Sopenharmony_ci 694514f5e3Sopenharmony_ci#define SHARE_GATE_META_DATA_LIST_WITH_VALUE(V) \ 704514f5e3Sopenharmony_ci V(Constant, CONSTANT, GateFlags::NONE_FLAG, 0, 0, 0) \ 714514f5e3Sopenharmony_ci V(FrameArgs, FRAME_ARGS, GateFlags::HAS_FRAME_STATE, 0, 0, 7) \ 724514f5e3Sopenharmony_ci V(FrameState, FRAME_STATE, GateFlags::HAS_FRAME_STATE, 0, 0, 2) \ 734514f5e3Sopenharmony_ci V(IfBranch, IF_BRANCH, GateFlags::CONTROL, 1, 0, 1) \ 744514f5e3Sopenharmony_ci V(RelocatableData, RELOCATABLE_DATA, GateFlags::NONE_FLAG, 0, 0, 0) \ 754514f5e3Sopenharmony_ci V(SwitchBranch, SWITCH_BRANCH, GateFlags::CONTROL, 1, 0, 1) \ 764514f5e3Sopenharmony_ci V(SwitchCase, SWITCH_CASE, GateFlags::CONTROL, 1, 0, 0) \ 774514f5e3Sopenharmony_ci V(GetSharedConstPool, GET_SHARED_CONSTPOOL, GateFlags::NO_WRITE, 0, 0, 1) 784514f5e3Sopenharmony_ci 794514f5e3Sopenharmony_ci#define SHARE_GATE_OPCODE_LIST(V) \ 804514f5e3Sopenharmony_ci V(CONSTSTRING) 814514f5e3Sopenharmony_ci 824514f5e3Sopenharmony_ci#define SHARE_GATE_META_DATA_LIST_WITH_ONE_PARAMETER(V) \ 834514f5e3Sopenharmony_ci V(Arg, ARG, GateFlags::HAS_ROOT, 0, 0, 0) \ 844514f5e3Sopenharmony_ci V(InitVreg, INITVREG, GateFlags::HAS_ROOT, 0, 0, 0) \ 854514f5e3Sopenharmony_ci SHARE_GATE_META_DATA_LIST_WITH_VALUE(V) 864514f5e3Sopenharmony_ci 874514f5e3Sopenharmony_ci#define IMMUTABLE_META_DATA_CACHE_LIST(V) \ 884514f5e3Sopenharmony_ci SHARE_IMMUTABLE_META_DATA_CACHE_LIST(V) \ 894514f5e3Sopenharmony_ci LCR_IMMUTABLE_META_DATA_CACHE_LIST(V) \ 904514f5e3Sopenharmony_ci MCR_IMMUTABLE_META_DATA_CACHE_LIST(V) \ 914514f5e3Sopenharmony_ci HCR_IMMUTABLE_META_DATA_CACHE_LIST(V) 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_VALUE_IN(V) \ 944514f5e3Sopenharmony_ci SHARE_GATE_META_DATA_LIST_WITH_VALUE_IN(V) \ 954514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_VALUE_IN(V) \ 964514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_VALUE_IN(V) 974514f5e3Sopenharmony_ci 984514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_PC_OFFSET(V) \ 994514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_PC_OFFSET(V) \ 1004514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_PC_OFFSET(V) 1014514f5e3Sopenharmony_ci 1024514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_FOR_CALL(V) \ 1034514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_FOR_CALL(V) 1044514f5e3Sopenharmony_ci 1054514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_FOR_NEW(V) \ 1064514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_FOR_NEW(V) 1074514f5e3Sopenharmony_ci 1084514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_PC_OFFSET_FIXED_VALUE(V) \ 1094514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_PC_OFFSET_FIXED_VALUE(V) 1104514f5e3Sopenharmony_ci 1114514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_SIZE(V) \ 1124514f5e3Sopenharmony_ci SHARE_GATE_META_DATA_LIST_WITH_SIZE(V) \ 1134514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_SIZE(V) \ 1144514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_SIZE(V) 1154514f5e3Sopenharmony_ci 1164514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_GATE_TYPE(V) \ 1174514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_GATE_TYPE(V) 1184514f5e3Sopenharmony_ci 1194514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_VALUE(V) \ 1204514f5e3Sopenharmony_ci SHARE_GATE_META_DATA_LIST_WITH_VALUE(V) \ 1214514f5e3Sopenharmony_ci LCR_GATE_META_DATA_LIST_WITH_VALUE(V) \ 1224514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_VALUE(V) \ 1234514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_VALUE(V) 1244514f5e3Sopenharmony_ci 1254514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_ONE_PARAMETER(V) \ 1264514f5e3Sopenharmony_ci SHARE_GATE_META_DATA_LIST_WITH_ONE_PARAMETER(V) \ 1274514f5e3Sopenharmony_ci LCR_GATE_META_DATA_LIST_WITH_ONE_PARAMETER(V) \ 1284514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_ONE_PARAMETER(V) \ 1294514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_ONE_PARAMETER(V) 1304514f5e3Sopenharmony_ci 1314514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_BOOL(V) \ 1324514f5e3Sopenharmony_ci MCR_GATE_META_DATA_LIST_WITH_BOOL(V) 1334514f5e3Sopenharmony_ci 1344514f5e3Sopenharmony_ci#define GATE_META_DATA_LIST_WITH_BOOL_VALUE_IN(V) \ 1354514f5e3Sopenharmony_ci HCR_GATE_META_DATA_LIST_WITH_BOOL_VALUE_IN(V) 1364514f5e3Sopenharmony_ci 1374514f5e3Sopenharmony_ci#define GATE_OPCODE_LIST(V) \ 1384514f5e3Sopenharmony_ci SHARE_GATE_OPCODE_LIST(V) \ 1394514f5e3Sopenharmony_ci HCR_GATE_OPCODE_LIST(V) 1404514f5e3Sopenharmony_ci 1414514f5e3Sopenharmony_cienum class OpCode : uint16_t { 1424514f5e3Sopenharmony_ci NOP = 0, 1434514f5e3Sopenharmony_ci#define DECLARE_GATE_OPCODE(NAME, OP, R, S, D, V) OP, 1444514f5e3Sopenharmony_ci IMMUTABLE_META_DATA_CACHE_LIST(DECLARE_GATE_OPCODE) 1454514f5e3Sopenharmony_ci GATE_META_DATA_LIST_WITH_SIZE(DECLARE_GATE_OPCODE) 1464514f5e3Sopenharmony_ci GATE_META_DATA_LIST_WITH_ONE_PARAMETER(DECLARE_GATE_OPCODE) 1474514f5e3Sopenharmony_ci GATE_META_DATA_LIST_WITH_PC_OFFSET(DECLARE_GATE_OPCODE) 1484514f5e3Sopenharmony_ci GATE_META_DATA_LIST_FOR_CALL(DECLARE_GATE_OPCODE) 1494514f5e3Sopenharmony_ci GATE_META_DATA_LIST_FOR_NEW(DECLARE_GATE_OPCODE) 1504514f5e3Sopenharmony_ci GATE_META_DATA_LIST_WITH_PC_OFFSET_FIXED_VALUE(DECLARE_GATE_OPCODE) 1514514f5e3Sopenharmony_ci GATE_META_DATA_LIST_WITH_BOOL(DECLARE_GATE_OPCODE) 1524514f5e3Sopenharmony_ci GATE_META_DATA_LIST_WITH_BOOL_VALUE_IN(DECLARE_GATE_OPCODE) 1534514f5e3Sopenharmony_ci#undef DECLARE_GATE_OPCODE 1544514f5e3Sopenharmony_ci#define DECLARE_GATE_OPCODE(NAME) NAME, 1554514f5e3Sopenharmony_ci GATE_OPCODE_LIST(DECLARE_GATE_OPCODE) 1564514f5e3Sopenharmony_ci#undef DECLARE_GATE_OPCODE 1574514f5e3Sopenharmony_ci}; 1584514f5e3Sopenharmony_ci 1594514f5e3Sopenharmony_ci// Special virtual register in the OSR. 1604514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_GLUE = -1; 1614514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_ARGS = -2; 1624514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_ARGV = -3; 1634514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_FUNCTION = -4; 1644514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_NEW_TARGET = -5; 1654514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_THIS_OBJECT = -6; 1664514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_NUM_ARGS = -7; 1674514f5e3Sopenharmony_cistatic constexpr size_t INIT_VRGE_ENV = -8; 1684514f5e3Sopenharmony_ci 1694514f5e3Sopenharmony_ci} 1704514f5e3Sopenharmony_ci 1714514f5e3Sopenharmony_ci#endif // ECMASCRIPT_COMPILER_SHARE_GATE_META_DATA_H 172