1 /* 2 * Copyright (c) 2024 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 16 #ifndef ECMASCRIPT_COMPILER_COMMON_STUB_CSIGNS_H 17 #define ECMASCRIPT_COMPILER_COMMON_STUB_CSIGNS_H 18 19 #include "ecmascript/compiler/call_signature.h" 20 21 namespace panda::ecmascript::kungfu { 22 #define COMMON_STUB_LIST(V) \ 23 V(Add) \ 24 V(Sub) \ 25 V(Mul) \ 26 V(Div) \ 27 V(Mod) \ 28 V(Equal) \ 29 V(NotEqual) \ 30 V(StrictEqual) \ 31 V(StrictNotEqual) \ 32 V(Less) \ 33 V(LessEq) \ 34 V(Greater) \ 35 V(GreaterEq) \ 36 V(Shl) \ 37 V(Shr) \ 38 V(Ashr) \ 39 V(And) \ 40 V(Or) \ 41 V(Xor) \ 42 V(IsIn) \ 43 V(Instanceof) \ 44 V(OrdinaryHasInstance) \ 45 V(TypeOf) \ 46 V(Inc) \ 47 V(Dec) \ 48 V(Neg) \ 49 V(Not) \ 50 V(ToBooleanTrue) \ 51 V(ToBooleanFalse) \ 52 V(JSTaggedValueHasProperty) \ 53 V(GetPropertyByName) \ 54 V(SetPropertyByNameWithMega) \ 55 V(GetPropertyByNameWithMega) \ 56 V(DeprecatedGetPropertyByName) \ 57 V(SetPropertyByName) \ 58 V(DeprecatedSetPropertyByName) \ 59 V(SetPropertyByNameWithOwn) \ 60 V(GetPropertyByIndex) \ 61 V(SetPropertyByIndex) \ 62 V(SetPropertyByIndexWithOwn) \ 63 V(GetPropertyByValue) \ 64 V(DeprecatedGetPropertyByValue) \ 65 V(SetPropertyByValue) \ 66 V(DeprecatedSetPropertyByValue) \ 67 V(TryLdGlobalByName) \ 68 V(TryStGlobalByName) \ 69 V(LdGlobalVar) \ 70 V(LdObjByIndex) \ 71 V(StGlobalVar) \ 72 V(StObjByIndex) \ 73 V(StOwnByIndex) \ 74 V(StOwnByName) \ 75 V(StOwnByNameWithNameSet) \ 76 V(StOwnByValue) \ 77 V(StOwnByValueWithNameSet) \ 78 V(SetPropertyByValueWithOwn) \ 79 V(TryLoadICByName) \ 80 V(TryLoadICByValue) \ 81 V(TryStoreICByName) \ 82 V(TryStoreICByValue) \ 83 V(SetValueWithBarrier) \ 84 V(SetNonSValueWithBarrier) \ 85 V(SetSValueWithBarrier) \ 86 V(NewLexicalEnv) \ 87 V(CopyRestArgs) \ 88 V(GetUnmappedArgs) \ 89 V(GetCallSpreadArgs) \ 90 V(NewThisObjectChecked) \ 91 V(ConstructorCheck) \ 92 V(CreateEmptyArray) \ 93 V(CreateArrayWithBuffer) \ 94 V(CreateObjectHavingMethod) \ 95 V(NewJSObject) \ 96 V(FastNewThisObject) \ 97 V(FastSuperAllocateThis) \ 98 V(JsBoundCallInternal) \ 99 V(CreateStringBySingleCharCode) \ 100 V(Getpropiterator) \ 101 V(Getnextpropname) \ 102 V(CreateJSSetIterator) \ 103 V(JSSetEntries) \ 104 V(CreateJSMapIterator) \ 105 V(JSMapKeys) \ 106 V(JSMapValues) \ 107 V(JSMapGet) \ 108 V(JSMapHas) \ 109 V(JSSetHas) \ 110 V(JSSetAdd) \ 111 V(JSProxyGetProperty) \ 112 V(JSProxySetProperty) \ 113 V(JSProxySetPropertyNoThrow) \ 114 V(CreateJSTypedArrayEntries) \ 115 V(CreateJSTypedArrayKeys) \ 116 V(CreateJSTypedArrayValues) \ 117 V(JSMapDelete) \ 118 V(JSSetDelete) \ 119 V(GetSingleCharCodeByIndex) \ 120 V(FastStringEqual) \ 121 V(FastStringAdd) \ 122 V(StringAdd) \ 123 V(Definefunc) \ 124 V(DefineField) \ 125 V(CallArg0Stub) \ 126 V(CallArg1Stub) \ 127 V(CallArg2Stub) \ 128 V(CallArg3Stub) \ 129 V(CallThis0Stub) \ 130 V(CallThis1Stub) \ 131 V(CallThis2Stub) \ 132 V(CallThis3Stub) \ 133 V(NewFloat32ArrayWithNoArgs) \ 134 V(NewFloat32Array) \ 135 V(StringLoadElement) \ 136 V(GetStringFromConstPool) \ 137 V(GetPrototype) \ 138 V(FastCallSelector) \ 139 V(CheckSuperAndNew) \ 140 V(SuperCallAndConstructorCheck) \ 141 V(ConvertCharToInt32) \ 142 V(ConvertCharToDouble) \ 143 V(ConvertCharToString) \ 144 V(DeleteObjectProperty) \ 145 V(SameValue) \ 146 V(StringIteratorNext) \ 147 V(VerifyBarrier) \ 148 V(ArrayIteratorNext) \ 149 V(MapIteratorNext) \ 150 V(SetIteratorNext) \ 151 V(GetIterator) \ 152 V(GrowElementsCapacity) \ 153 V(BatchBarrier) \ 154 V(MoveBarrierInRegion) \ 155 V(MoveBarrierCrossRegion) \ 156 V(FindEntryFromNameDictionary) \ 157 V(ReverseBarrier) \ 158 V(DefineNormalFuncForJit) \ 159 V(DefineArrowFuncForJit) \ 160 V(DefineBaseConstructorForJit) \ 161 V(GetValueWithBarrier) \ 162 V(CMCSetValueWithBarrier) 163 164 #define COMMON_STUB_ID_LIST(V) \ 165 COMMON_STUB_LIST(V) 166 167 #define COMMON_STW_COPY_STUB_LIST(V) \ 168 COMMON_STUB_LIST(V) 169 170 class CommonStubCSigns { 171 public: 172 enum ID { 173 #define DEF_STUB_ID(name) name, 174 COMMON_STUB_ID_LIST(DEF_STUB_ID) 175 #undef DEF_STUB_ID 176 #define DEF_STUB_ID(name) name##StwCopy, 177 COMMON_STW_COPY_STUB_LIST(DEF_STUB_ID) 178 #undef DEF_STUB_ID 179 NUM_OF_STUBS, 180 NUM_OF_ALL_NORMAL_STUBS = CMCSetValueWithBarrier + 1, 181 }; 182 #define ASSERT_ID_EQUAL(name) \ 183 static_assert((static_cast<uint32_t>(ID::name##StwCopy)) == \ 184 (static_cast<uint32_t>(ID::name) + ID::NUM_OF_ALL_NORMAL_STUBS)); 185 186 COMMON_STUB_ID_LIST(ASSERT_ID_EQUAL) 187 #undef ASSERT_ID_EQUAL 188 189 static void Initialize(); 190 191 static void GetCSigns(std::vector<const CallSignature*>& callSigns); 192 Get(size_t index)193 static const CallSignature *Get(size_t index) 194 { 195 ASSERT(index < NUM_OF_STUBS); 196 return &callSigns_[index]; 197 } 198 GetName(size_t index)199 static const std::string &GetName(size_t index) 200 { 201 ASSERT(index < NUM_OF_STUBS); 202 return callSigns_[index].GetName(); 203 } 204 IsReadOnly(size_t index)205 static bool IsReadOnly(size_t index) 206 { 207 ASSERT(index < NUM_OF_STUBS); 208 switch (index) { 209 case GetValueWithBarrier: 210 return true; 211 default: 212 return false; 213 } 214 return false; 215 } 216 IsCold(size_t index)217 static bool IsCold(size_t index) 218 { 219 ASSERT(index < NUM_OF_STUBS); 220 switch (index) { 221 case GetValueWithBarrier: 222 return true; 223 default: 224 return false; 225 } 226 return false; 227 } 228 229 private: 230 static CallSignature callSigns_[NUM_OF_STUBS]; 231 }; 232 } // namespace panda::ecmascript::kungfu 233 #endif // ECMASCRIPT_COMPILER_COMMON_STUB_CSIGNS_H 234