• 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 #ifndef ECMASCRIPT_COMPILER_BUILTINS_CALL_SIGNATURE_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_CALL_SIGNATURE_H
18 
19 #include "ecmascript/base/config.h"
20 #include "ecmascript/compiler/rt_call_signature.h"
21 
22 namespace panda::ecmascript::kungfu {
23 
24 #define PADDING_BUILTINS_STUB_LIST(V)               \
25     V(NONE)
26 
27 // BUILTINS_STUB_LIST is shared both ASM Interpreter and AOT.
28 // AOT_BUILTINS_STUB_LIST is used in AOT only.
29 #define BUILTINS_STUB_LIST(V)                       \
30     BUILTINS_METHOD_STUB_LIST(V)                    \
31     BUILTINS_CONSTRUCTOR_STUB_LIST(V)
32 
33 #define BUILTINS_METHOD_STUB_LIST(V)                \
34     V(CharCodeAt)                                   \
35     V(IndexOf)                                      \
36     V(Substring)                                    \
37     V(CharAt)                                       \
38     V(VectorForEach)                                \
39     V(VectorReplaceAllElements)                     \
40     V(StackForEach)                                 \
41     V(PlainArrayForEach)                            \
42     V(QueueForEach)                                 \
43     V(DequeForEach)                                 \
44     V(LightWeightMapForEach)                        \
45     V(LightWeightSetForEach)                        \
46     V(HashMapForEach)                               \
47     V(HashSetForEach)                               \
48     V(LinkedListForEach)                            \
49     V(ListForEach)                                  \
50     V(ArrayListForEach)                             \
51     V(ArrayListReplaceAllElements)                  \
52 
53 #define BUILTINS_CONSTRUCTOR_STUB_LIST(V)           \
54     V(BooleanConstructor)                           \
55     V(DateConstructor)                              \
56     V(ArrayConstructor)                             \
57 
58 #define AOT_BUILTINS_STUB_LIST(V)                   \
59     V(SQRT)                                         \
60     V(COS)                                          \
61     V(SIN)                                          \
62     V(ACOS)                                         \
63     V(ATAN)                                         \
64     V(ABS)                                          \
65     V(FLOOR)                                        \
66 
67 class BuiltinsStubCSigns {
68 public:
69     enum ID {
70 #define DEF_STUB_ID(name) name,
71         PADDING_BUILTINS_STUB_LIST(DEF_STUB_ID)
72         BUILTINS_STUB_LIST(DEF_STUB_ID)
73 #undef DEF_STUB_ID
74         NUM_OF_BUILTINS_STUBS,
75 #define DEF_STUB_ID(name) name,
76         AOT_BUILTINS_STUB_LIST(DEF_STUB_ID)
77 #undef DEF_STUB_ID
78         BUILTINS_CONSTRUCTOR_STUB_FIRST = BooleanConstructor,
79         INVALID = 0xFF,
80     };
81 
82     static void Initialize();
83 
84     static void GetCSigns(std::vector<const CallSignature*>& callSigns);
85 
Get(size_t index)86     static const CallSignature *Get(size_t index)
87     {
88         ASSERT(index < NUM_OF_BUILTINS_STUBS);
89         return &callSigns_[index];
90     }
91 
BuiltinsCSign()92     static const CallSignature* BuiltinsCSign()
93     {
94         return &builtinsCSign_;
95     }
96 
BuiltinsWithArgvCSign()97     static const CallSignature* BuiltinsWithArgvCSign()
98     {
99         return &builtinsWithArgvCSign_;
100     }
101 
IsFastBuiltin(ID builtinId)102     static bool IsFastBuiltin(ID builtinId)
103     {
104         return builtinId > NONE && builtinId < NUM_OF_BUILTINS_STUBS;
105     }
106 private:
107     static CallSignature callSigns_[NUM_OF_BUILTINS_STUBS];
108     static CallSignature builtinsCSign_;
109     static CallSignature builtinsWithArgvCSign_;
110 };
111 
112 enum class BuiltinsArgs : size_t {
113     GLUE = 0,
114     NATIVECODE,
115     FUNC,
116     NEWTARGET,
117     THISVALUE,
118     NUMARGS,
119     ARG0_OR_ARGV,
120     ARG1,
121     ARG2,
122     NUM_OF_INPUTS,
123 };
124 
125 #define BUILTINS_STUB_ID(name) kungfu::BuiltinsStubCSigns::name
126 }  // namespace panda::ecmascript::kungfu
127 #endif  // ECMASCRIPT_COMPILER_BUILTINS_CALL_SIGNATURE_H
128