1 /* 2 * Copyright (c) 2021 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_STUBS_H 17 #define ECMASCRIPT_COMPILER_COMMON_STUBS_H 18 19 #include "ecmascript/compiler/stub_builder.h" 20 #include "ecmascript/compiler/test_stubs.h" 21 22 namespace panda::ecmascript::kungfu { 23 #define COMMON_STUB_LIST(V) \ 24 V(Add) \ 25 V(Sub) \ 26 V(Mul) \ 27 V(Div) \ 28 V(Mod) \ 29 V(Equal) \ 30 V(NotEqual) \ 31 V(Less) \ 32 V(LessEq) \ 33 V(Greater) \ 34 V(GreaterEq) \ 35 V(Shl) \ 36 V(Shr) \ 37 V(Ashr) \ 38 V(And) \ 39 V(Or) \ 40 V(Xor) \ 41 V(Instanceof) \ 42 V(TypeOf) \ 43 V(Inc) \ 44 V(Dec) \ 45 V(Neg) \ 46 V(Not) \ 47 V(ToBoolean) \ 48 V(GetPropertyByName) \ 49 V(DeprecatedGetPropertyByName) \ 50 V(SetPropertyByName) \ 51 V(DeprecatedSetPropertyByName) \ 52 V(SetPropertyByNameWithOwn) \ 53 V(GetPropertyByIndex) \ 54 V(SetPropertyByIndex) \ 55 V(SetPropertyByIndexWithOwn) \ 56 V(GetPropertyByValue) \ 57 V(DeprecatedGetPropertyByValue) \ 58 V(SetPropertyByValue) \ 59 V(DeprecatedSetPropertyByValue) \ 60 V(TryLdGlobalByName) \ 61 V(TryStGlobalByName) \ 62 V(LdGlobalVar) \ 63 V(StGlobalVar) \ 64 V(SetPropertyByValueWithOwn) \ 65 V(TryLoadICByName) \ 66 V(TryLoadICByValue) \ 67 V(TryStoreICByName) \ 68 V(TryStoreICByValue) \ 69 V(SetValueWithBarrier) \ 70 V(NewLexicalEnv) \ 71 V(GetUnmapedArgs) \ 72 V(NewThisObjectChecked) \ 73 V(ConstructorCheck) \ 74 V(JsProxyCallInternal) 75 76 #define COMMON_STUB_ID_LIST(V) \ 77 COMMON_STUB_LIST(V) \ 78 TEST_STUB_SIGNATRUE_LIST(V) 79 80 #define DECLARE_STUB_CLASS(name) \ 81 class name##StubBuilder : public StubBuilder { \ 82 public: \ 83 explicit name##StubBuilder(CallSignature *callSignature, Environment *env) \ 84 : StubBuilder(callSignature, env) {} \ 85 ~name##StubBuilder() = default; \ 86 NO_MOVE_SEMANTIC(name##StubBuilder); \ 87 NO_COPY_SEMANTIC(name##StubBuilder); \ 88 void GenerateCircuit() override; \ 89 }; COMMON_STUB_LIST(DECLARE_STUB_CLASS)90 COMMON_STUB_LIST(DECLARE_STUB_CLASS) 91 #undef DECLARE_STUB_CLASS 92 93 class CommonStubCSigns { 94 public: 95 enum ID { 96 #define DEF_STUB_ID(name) name, 97 COMMON_STUB_ID_LIST(DEF_STUB_ID) 98 #undef DEF_STUB_ID 99 NUM_OF_STUBS 100 }; 101 102 static void Initialize(); 103 104 static void GetCSigns(std::vector<const CallSignature*>& callSigns); 105 106 static const CallSignature *Get(size_t index) 107 { 108 ASSERT(index < NUM_OF_STUBS); 109 return &callSigns_[index]; 110 } 111 private: 112 static CallSignature callSigns_[NUM_OF_STUBS]; 113 }; 114 } // namespace panda::ecmascript::kungfu 115 #endif // ECMASCRIPT_COMPILER_COMMON_STUBS_H 116