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_RT_CALL_SIGNATURE_H 17 #define ECMASCRIPT_COMPILER_RT_CALL_SIGNATURE_H 18 19 #include "ecmascript/compiler/call_signature.h" 20 #include "ecmascript/stubs/runtime_stubs.h" 21 22 namespace panda::ecmascript::kungfu { 23 class RuntimeStubCSigns { 24 public: 25 enum ID { 26 #define DEF_RUNTIME_STUB_ID(name) ID_##name, 27 RUNTIME_STUB_LIST(DEF_RUNTIME_STUB_ID) 28 #undef DEF_RUNTIME_STUB_ID 29 NUM_OF_STUBS 30 }; 31 32 enum NoGCStubID { 33 #define DEF_RUNTIME_STUB_ID(name) NOGCSTUB_ID_##name, 34 RUNTIME_ASM_STUB_LIST(DEF_RUNTIME_STUB_ID) 35 RUNTIME_STUB_WITHOUT_GC_LIST(DEF_RUNTIME_STUB_ID) 36 #undef DEF_RUNTIME_STUB_ID 37 NUM_OF_RTSTUBS_WITHOUT_GC 38 }; 39 40 enum AsmStubID { 41 #define DEF_RUNTIME_STUB_ID(name) ASM_STUB_ID_##name, 42 RUNTIME_ASM_STUB_LIST(DEF_RUNTIME_STUB_ID) 43 #undef DEF_RUNTIME_STUB_ID 44 NUM_OF_ASM_STUBS 45 }; 46 47 static void Initialize(); 48 IsAsmStub(uint32_t index)49 static bool IsAsmStub(uint32_t index) 50 { 51 return index < AsmStubID::NUM_OF_ASM_STUBS; 52 } 53 54 static void GetASMCSigns(std::vector<const CallSignature*>& callSigns); 55 Get(size_t index)56 static const CallSignature *Get(size_t index) 57 { 58 ASSERT(index < NUM_OF_RTSTUBS_WITHOUT_GC); 59 return &callSigns_[index]; 60 } 61 GetRTName(int index)62 static std::string GetRTName(int index) 63 { 64 ASSERT(index < NUM_OF_STUBS); 65 switch (index) { 66 #define DEF_STUB_NAME(name) case ID_##name: { return std::string("RTStub_") + #name; } 67 RUNTIME_STUB_LIST(DEF_STUB_NAME) 68 #undef DEF_STUB_NAME 69 default: 70 return "unknown"; 71 } 72 return "unknown"; 73 } 74 GetOptimizedCallSign()75 static const CallSignature* GetOptimizedCallSign() 76 { 77 return &optimizedCallSign_; 78 } 79 GetOptimizedFastCallSign()80 static const CallSignature* GetOptimizedFastCallSign() 81 { 82 return &optimizedFastCallSign_; 83 } 84 85 private: 86 static CallSignature callSigns_[NUM_OF_RTSTUBS_WITHOUT_GC]; 87 static CallSignature optimizedCallSign_; 88 static CallSignature optimizedFastCallSign_; 89 }; 90 static_assert(static_cast<int>(kungfu::RuntimeStubCSigns::ID_CallRuntime) == 91 static_cast<int>(kungfu::RuntimeStubCSigns::ASM_STUB_ID_CallRuntime)); 92 static_assert(static_cast<int>(kungfu::RuntimeStubCSigns::ID_AsmInterpreterEntry) == 93 static_cast<int>(kungfu::RuntimeStubCSigns::ASM_STUB_ID_AsmInterpreterEntry)); 94 #define RTSTUB_ID(name) kungfu::RuntimeStubCSigns::ID_##name 95 } // namespace panda::ecmascript::kungfu 96 #endif // ECMASCRIPT_COMPILER_RT_CALL_SIGNATURE_H