• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ecmascript/compiler/interpreter_stub.h"
18 
19 namespace panda::ecmascript::kungfu {
20 CallSignature BytecodeStubCSigns::callSigns_[BytecodeStubCSigns::NUM_OF_VALID_STUBS];
21 CallSignature BytecodeStubCSigns::bcHandlerCSign_;
22 CallSignature BytecodeStubCSigns::bcDebuggerHandlerCSign_;
23 
Initialize()24 void BytecodeStubCSigns::Initialize()
25 {
26 #define INIT_SIGNATURES(name)                                               \
27     BytecodeHandlerCallSignature::Initialize(&callSigns_[name]);            \
28     callSigns_[name].SetID(ID_##name);                                      \
29     callSigns_[name].SetName(std::string("BCStub_") + #name);               \
30     callSigns_[name].SetConstructor(                                        \
31     [](void* env) {                                                         \
32         return static_cast<void*>(                                          \
33             new name##StubBuilder(&callSigns_[name],                        \
34                 static_cast<Environment*>(env)));                           \
35     });
36 
37     INTERPRETER_BC_STUB_LIST(INIT_SIGNATURES)
38 #define INIT_SIGNATURES_DYN(name, ...) \
39     INIT_SIGNATURES(name)              \
40     callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_PROFILE_HANDLER);
41     ASM_INTERPRETER_BC_PROFILER_STUB_LIST(INIT_SIGNATURES_DYN)
42 #undef INIT_SIGNATURES_DYN
43 
44 #define INIT_SIGNATURES_DYN(name, ...) \
45     INIT_SIGNATURES(name)              \
46     callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_JIT_PROFILE_HANDLER);
47     ASM_INTERPRETER_BC_JIT_PROFILER_STUB_LIST(INIT_SIGNATURES_DYN)
48 #undef INIT_SIGNATURES_DYN
49 
50 #define INIT_SIGNATURES_DYN(name, ...)              \
51     INIT_SIGNATURES(name##StwCopy)                  \
52     callSigns_[name##StwCopy].SetStwCopyStub(true); \
53     callSigns_[name##StwCopy].SetTargetKind(CallSignature::TargetKind::BYTECODE_STW_COPY_HANDLER);
54     ASM_INTERPRETER_BC_STW_COPY_STUB_LIST(INIT_SIGNATURES_DYN)
55 #undef INIT_SIGNATURES_DYN
56 #undef INIT_SIGNATURES
57 
58 #define INIT_HELPER_SIGNATURES(name)                                                        \
59     BytecodeHandlerCallSignature::Initialize(&callSigns_[name]);                            \
60     callSigns_[name].SetID(ID_##name);                                                      \
61     callSigns_[name].SetName(std::string("BCStub_") + #name);                               \
62     callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_HELPER_HANDLER);     \
63     callSigns_[name].SetConstructor(                                                        \
64     [](void* env) {                                                                         \
65         return static_cast<void*>(                                                          \
66             new name##StubBuilder(&callSigns_[name], static_cast<Environment*>(env)));      \
67     });
68 
69     ASM_INTERPRETER_BC_HELPER_STUB_LIST(INIT_HELPER_SIGNATURES)
70 #undef INIT_HELPER_SIGNATURES
71 
72     BytecodeHandlerCallSignature::Initialize(&bcHandlerCSign_);
73     BytecodeDebuggerHandlerCallSignature::Initialize(&bcDebuggerHandlerCSign_);
74 }
75 
GetCSigns(std::vector<const CallSignature * > & outCSigns)76 void BytecodeStubCSigns::GetCSigns(std::vector<const CallSignature*>& outCSigns)
77 {
78     for (size_t i = 0; i < NUM_OF_VALID_STUBS; i++) {
79         outCSigns.push_back(&callSigns_[i]);
80     }
81 }
82 
GetNormalCSigns(std::vector<const CallSignature * > & outCSigns)83 void BytecodeStubCSigns::GetNormalCSigns(std::vector<const CallSignature*>& outCSigns)
84 {
85     for (size_t i = VID_NORMAL_START; i < VID_NORMAL_END; i++) {
86         outCSigns.push_back(&callSigns_[i]);
87     }
88 }
89 
GetStwCopyCSigns(std::vector<const CallSignature * > & outCSigns)90 void BytecodeStubCSigns::GetStwCopyCSigns(std::vector<const CallSignature*>& outCSigns)
91 {
92     for (size_t i = VID_STW_COPY_START; i < VID_STW_COPY_END; i++) {
93         outCSigns.push_back(&callSigns_[i]);
94     }
95 }
96 }  // namespace panda::ecmascript::kungfu
97