• 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 #include "ecmascript/compiler/test_stubs.h"
21 
22 namespace panda::ecmascript::kungfu {
23 #define COMMON_STUB_LIST(V)           \
24     V(Add)                            \
25     V(Sub)                            \
26     V(Mul)                            \
27     V(Div)                            \
28     V(Mod)                            \
29     V(Equal)                          \
30     V(NotEqual)                       \
31     V(StrictEqual)                    \
32     V(StrictNotEqual)                 \
33     V(Less)                           \
34     V(LessEq)                         \
35     V(Greater)                        \
36     V(GreaterEq)                      \
37     V(Shl)                            \
38     V(Shr)                            \
39     V(Ashr)                           \
40     V(And)                            \
41     V(Or)                             \
42     V(Xor)                            \
43     V(Instanceof)                     \
44     V(TypeOf)                         \
45     V(Inc)                            \
46     V(Dec)                            \
47     V(Neg)                            \
48     V(Not)                            \
49     V(ToBoolean)                      \
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(StGlobalVar)                    \
66     V(SetPropertyByValueWithOwn)      \
67     V(TryLoadICByName)                \
68     V(TryLoadICByValue)               \
69     V(TryStoreICByName)               \
70     V(TryStoreICByValue)              \
71     V(SetValueWithBarrier)            \
72     V(NewLexicalEnv)                  \
73     V(GetUnmapedArgs)                 \
74     V(NewThisObjectChecked)           \
75     V(ConstructorCheck)               \
76     V(CreateEmptyArray)               \
77     V(CreateArrayWithBuffer)          \
78     V(NewJSObject)                    \
79     V(JsBoundCallInternal)            \
80     V(JsProxyCallInternal)
81 
82 #define COMMON_STUB_ID_LIST(V)          \
83     COMMON_STUB_LIST(V)                 \
84     TEST_STUB_SIGNATRUE_LIST(V)
85 
86 #define DECLARE_STUB_CLASS(name)                                                   \
87     class name##StubBuilder : public StubBuilder {                                 \
88     public:                                                                        \
89         explicit name##StubBuilder(CallSignature *callSignature, Environment *env) \
90             : StubBuilder(callSignature, env) {}                                   \
91         ~name##StubBuilder() = default;                                            \
92         NO_MOVE_SEMANTIC(name##StubBuilder);                                       \
93         NO_COPY_SEMANTIC(name##StubBuilder);                                       \
94         void GenerateCircuit() override;                                           \
95     };
COMMON_STUB_LIST(DECLARE_STUB_CLASS)96     COMMON_STUB_LIST(DECLARE_STUB_CLASS)
97 #undef DECLARE_STUB_CLASS
98 
99 class CommonStubCSigns {
100 public:
101     enum ID {
102 #define DEF_STUB_ID(name) name,
103         COMMON_STUB_ID_LIST(DEF_STUB_ID)
104 #undef DEF_STUB_ID
105         NUM_OF_STUBS
106     };
107 
108     static void Initialize();
109 
110     static void GetCSigns(std::vector<const CallSignature*>& callSigns);
111 
112     static const CallSignature *Get(size_t index)
113     {
114         ASSERT(index < NUM_OF_STUBS);
115         return &callSigns_[index];
116     }
117 
118     static const std::string &GetName(size_t index)
119     {
120         ASSERT(index < NUM_OF_STUBS);
121         return callSigns_[index].GetName();
122     }
123 
124 private:
125     static CallSignature callSigns_[NUM_OF_STUBS];
126 };
127 }  // namespace panda::ecmascript::kungfu
128 #endif  // ECMASCRIPT_COMPILER_COMMON_STUBS_H
129