• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()27 void 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 #undef INIT_SIGNATURES
42 
43 #define INIT_HELPER_SIGNATURES(name)                                                        \
44     BytecodeHandlerCallSignature::Initialize(&callSigns_[name]);                            \
45     callSigns_[name].SetID(ID_##name);                                                      \
46     callSigns_[name].SetName(std::string("BCStub_") + #name);                               \
47     callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_HELPER_HANDLER);     \
48     callSigns_[name].SetConstructor(                                                        \
49     [](void* env) {                                                                         \
50         return static_cast<void*>(                                                          \
51             new name##StubBuilder(&callSigns_[name], static_cast<Environment*>(env)));      \
52     });
53 
54     ASM_INTERPRETER_BC_HELPER_STUB_LIST(INIT_HELPER_SIGNATURES)
55 #undef INIT_HELPER_SIGNATURES
56 
57     BytecodeHandlerCallSignature::Initialize(&bcHandlerCSign_);
58     BytecodeDebuggerHandlerCallSignature::Initialize(&bcDebuggerHandlerCSign_);
59 }
60 
GetCSigns(std::vector<const CallSignature * > & outCSigns)61 void BytecodeStubCSigns::GetCSigns(std::vector<const CallSignature*>& outCSigns)
62 {
63     for (size_t i = 0; i < NUM_OF_VALID_STUBS; i++) {
64         outCSigns.push_back(&callSigns_[i]);
65     }
66 }
67 }  // namespace panda::ecmascript::kungfu
68