• 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 #include "ecmascript/compiler/builtins/builtins_call_signature.h"
16 #include "ecmascript/compiler/builtins/builtins_stubs.h"
17 #include "ecmascript/compiler/call_signature.h"
18 #include "ecmascript/stubs/runtime_stubs.h"
19 
20 namespace panda::ecmascript::kungfu {
21 CallSignature BuiltinsStubCSigns::callSigns_[BuiltinsStubCSigns::NUM_OF_BUILTINS_STUBS];
22 CallSignature BuiltinsStubCSigns::builtinsCSign_;
23 CallSignature BuiltinsStubCSigns::builtinsWithArgvCSign_;
24 
Initialize()25 void BuiltinsStubCSigns::Initialize()
26 {
27 #define COMMON_INIT(name)                                            \
28     callSigns_[name].SetID(name);                                    \
29     callSigns_[name].SetName(std::string("BuiltinStub_") + #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 #define INIT_BUILTINS_METHOD(name)                                   \
38     BuiltinsCallSignature::Initialize(&callSigns_[name]);            \
39     COMMON_INIT(name)
40 
41     BUILTINS_METHOD_STUB_LIST(INIT_BUILTINS_METHOD)
42 #undef INIT_BUILTINS_METHOD
43 
44 #define INIT_BUILTINS_CONSTRUCTOR(name)                              \
45     BuiltinsWithArgvCallSignature::Initialize(&callSigns_[name]);    \
46     COMMON_INIT(name)
47 
48     BUILTINS_CONSTRUCTOR_STUB_LIST(INIT_BUILTINS_CONSTRUCTOR)
49 #undef INIT_BUILTINS_CONSTRUCTOR
50 #undef COMMON_INIT
51     BuiltinsCallSignature::Initialize(&builtinsCSign_);
52     BuiltinsWithArgvCallSignature::Initialize(&builtinsWithArgvCSign_);
53 }
54 
GetCSigns(std::vector<const CallSignature * > & outCSigns)55 void BuiltinsStubCSigns::GetCSigns(std::vector<const CallSignature*>& outCSigns)
56 {
57     const size_t firstStubId = BUILTINS_STUB_ID(NONE) + 1;
58     for (size_t i = firstStubId; i < NUM_OF_BUILTINS_STUBS; i++) {
59         outCSigns.push_back(&callSigns_[i]);
60     }
61 }
62 }  // namespace panda::ecmascript::kungfu
63