• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_COMMON_STUBS_H
17 #define ECMASCRIPT_COMPILER_COMMON_STUBS_H
18 
19 #include "ecmascript/compiler/stub_builder.h"
20 
21 namespace panda::ecmascript::kungfu {
22 #define COMMON_STUB_LIST(V)           \
23     V(Add)                            \
24     V(Sub)                            \
25     V(Mul)                            \
26     V(Div)                            \
27     V(Mod)                            \
28     V(Equal)                          \
29     V(NotEqual)                       \
30     V(StrictEqual)                    \
31     V(StrictNotEqual)                 \
32     V(Less)                           \
33     V(LessEq)                         \
34     V(Greater)                        \
35     V(GreaterEq)                      \
36     V(Shl)                            \
37     V(Shr)                            \
38     V(Ashr)                           \
39     V(And)                            \
40     V(Or)                             \
41     V(Xor)                            \
42     V(Instanceof)                     \
43     V(TypeOf)                         \
44     V(Inc)                            \
45     V(Dec)                            \
46     V(Neg)                            \
47     V(Not)                            \
48     V(ToBooleanTrue)                  \
49     V(ToBooleanFalse)                 \
50     V(GetPropertyByName)              \
51     V(DeprecatedGetPropertyByName)    \
52     V(SetPropertyByName)              \
53     V(DeprecatedSetPropertyByName)    \
54     V(SetPropertyByNameWithOwn)       \
55     V(GetPropertyByIndex)             \
56     V(SetPropertyByIndex)             \
57     V(SetPropertyByIndexWithOwn)      \
58     V(GetPropertyByValue)             \
59     V(DeprecatedGetPropertyByValue)   \
60     V(SetPropertyByValue)             \
61     V(DeprecatedSetPropertyByValue)   \
62     V(TryLdGlobalByName)              \
63     V(TryStGlobalByName)              \
64     V(LdGlobalVar)                    \
65     V(LdObjByIndex)                   \
66     V(StGlobalVar)                    \
67     V(StObjByIndex)                   \
68     V(StOwnByIndex)                   \
69     V(StOwnByName)                    \
70     V(StOwnByNameWithNameSet)         \
71     V(StOwnByValue)                   \
72     V(StOwnByValueWithNameSet)        \
73     V(SetPropertyByValueWithOwn)      \
74     V(TryLoadICByName)                \
75     V(TryLoadICByValue)               \
76     V(TryStoreICByName)               \
77     V(TryStoreICByValue)              \
78     V(SetValueWithBarrier)            \
79     V(NewLexicalEnv)                  \
80     V(GetUnmapedArgs)                 \
81     V(NewThisObjectChecked)           \
82     V(ConstructorCheck)               \
83     V(CreateEmptyArray)               \
84     V(CreateArrayWithBuffer)          \
85     V(NewJSObject)                    \
86     V(JsBoundCallInternal)            \
87     V(JsProxyCallInternal)            \
88     V(CreateStringBySingleCharCode)   \
89     V(Getpropiterator)                \
90     V(Getnextpropname)                \
91     V(CreateJSSetIterator)            \
92     V(CreateJSMapIterator)            \
93     V(GetSingleCharCodeByIndex)       \
94     V(FastStringEqual)                \
95     V(FastStringAdd)                  \
96     V(DeleteObjectProperty)
97 
98 #define COMMON_STUB_ID_LIST(V)          \
99     COMMON_STUB_LIST(V)
100 
101 #define DECLARE_STUB_CLASS(name)                                                   \
102     class name##StubBuilder : public StubBuilder {                                 \
103     public:                                                                        \
104         explicit name##StubBuilder(CallSignature *callSignature, Environment *env) \
105             : StubBuilder(callSignature, env) {}                                   \
106         ~name##StubBuilder() = default;                                            \
107         NO_MOVE_SEMANTIC(name##StubBuilder);                                       \
108         NO_COPY_SEMANTIC(name##StubBuilder);                                       \
109         void GenerateCircuit() override;                                           \
110     };
COMMON_STUB_LIST(DECLARE_STUB_CLASS)111     COMMON_STUB_LIST(DECLARE_STUB_CLASS)
112 #undef DECLARE_STUB_CLASS
113 
114 class CommonStubCSigns {
115 public:
116     enum ID {
117 #define DEF_STUB_ID(name) name,
118         COMMON_STUB_ID_LIST(DEF_STUB_ID)
119 #undef DEF_STUB_ID
120         NUM_OF_STUBS
121     };
122 
123     static void Initialize();
124 
125     static void GetCSigns(std::vector<const CallSignature*>& callSigns);
126 
127     static const CallSignature *Get(size_t index)
128     {
129         ASSERT(index < NUM_OF_STUBS);
130         return &callSigns_[index];
131     }
132 
133     static const std::string &GetName(size_t index)
134     {
135         ASSERT(index < NUM_OF_STUBS);
136         return callSigns_[index].GetName();
137     }
138 
139 private:
140     static CallSignature callSigns_[NUM_OF_STUBS];
141 };
142 }  // namespace panda::ecmascript::kungfu
143 #endif  // ECMASCRIPT_COMPILER_COMMON_STUBS_H
144