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