1 /* 2 * Copyright (c) 2022-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 #include "ecmascript/compiler/bc_call_signature.h" 17 18 #include "ecmascript/compiler/call_signature.h" 19 #include "ecmascript/compiler/interpreter_stub.h" 20 21 namespace panda::ecmascript::kungfu { 22 CallSignature BytecodeStubCSigns::callSigns_[BytecodeStubCSigns::NUM_OF_VALID_STUBS]; 23 CallSignature BytecodeStubCSigns::bcHandlerCSign_; 24 CallSignature BytecodeStubCSigns::bcDebuggerHandlerCSign_; 25 Initialize()26void BytecodeStubCSigns::Initialize() 27 { 28 #define INIT_SIGNATURES(name) \ 29 BytecodeHandlerCallSignature::Initialize(&callSigns_[name]); \ 30 callSigns_[name].SetID(ID_##name); \ 31 callSigns_[name].SetName(std::string("BCStub_") + #name); \ 32 callSigns_[name].SetConstructor( \ 33 [](void* env) { \ 34 return static_cast<void*>( \ 35 new name##StubBuilder(&callSigns_[name], \ 36 static_cast<Environment*>(env))); \ 37 }); 38 39 INTERPRETER_BC_STUB_LIST(INIT_SIGNATURES) 40 #define INIT_SIGNATURES_DYN(name, ...) \ 41 INIT_SIGNATURES(name) \ 42 callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_PROFILE_HANDLER); 43 ASM_INTERPRETER_BC_PROFILER_STUB_LIST(INIT_SIGNATURES_DYN) 44 #undef INIT_SIGNATURES_DYN 45 46 #define INIT_SIGNATURES_DYN(name, ...) \ 47 INIT_SIGNATURES(name) \ 48 callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_JIT_PROFILE_HANDLER); 49 ASM_INTERPRETER_BC_JIT_PROFILER_STUB_LIST(INIT_SIGNATURES_DYN) 50 #undef INIT_SIGNATURES_DYN 51 #undef INIT_SIGNATURES 52 53 #define INIT_HELPER_SIGNATURES(name) \ 54 BytecodeHandlerCallSignature::Initialize(&callSigns_[name]); \ 55 callSigns_[name].SetID(ID_##name); \ 56 callSigns_[name].SetName(std::string("BCStub_") + #name); \ 57 callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_HELPER_HANDLER); \ 58 callSigns_[name].SetConstructor( \ 59 [](void* env) { \ 60 return static_cast<void*>( \ 61 new name##StubBuilder(&callSigns_[name], static_cast<Environment*>(env))); \ 62 }); 63 64 ASM_INTERPRETER_BC_HELPER_STUB_LIST(INIT_HELPER_SIGNATURES) 65 #undef INIT_HELPER_SIGNATURES 66 67 BytecodeHandlerCallSignature::Initialize(&bcHandlerCSign_); 68 BytecodeDebuggerHandlerCallSignature::Initialize(&bcDebuggerHandlerCSign_); 69 } 70 GetCSigns(std::vector<const CallSignature*>& outCSigns)71void BytecodeStubCSigns::GetCSigns(std::vector<const CallSignature*>& outCSigns) 72 { 73 for (size_t i = 0; i < NUM_OF_VALID_STUBS; i++) { 74 outCSigns.push_back(&callSigns_[i]); 75 } 76 } 77 } // namespace panda::ecmascript::kungfu 78