1/*
2 * Copyright (c) 2024 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_STUB_CSIGNS_H
17#define ECMASCRIPT_COMPILER_COMMON_STUB_CSIGNS_H
18
19#include "ecmascript/compiler/call_signature.h"
20
21namespace 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(SetNonSValueWithBarrier)        \
80    V(SetValueWithEdenBarrier)        \
81    V(SetNonSValueWithEdenBarrier)    \
82    V(SetSValueWithBarrier)           \
83    V(NewLexicalEnv)                  \
84    V(CopyRestArgs)                   \
85    V(GetUnmappedArgs)                \
86    V(GetCallSpreadArgs)              \
87    V(NewThisObjectChecked)           \
88    V(ConstructorCheck)               \
89    V(CreateEmptyArray)               \
90    V(CreateArrayWithBuffer)          \
91    V(NewJSObject)                    \
92    V(JsBoundCallInternal)            \
93    V(CreateStringBySingleCharCode)   \
94    V(Getpropiterator)                \
95    V(Getnextpropname)                \
96    V(CreateJSSetIterator)            \
97    V(JSSetEntries)                   \
98    V(CreateJSMapIterator)            \
99    V(JSMapKeys)                      \
100    V(JSMapValues)                    \
101    V(JSMapGet)                       \
102    V(JSMapHas)                       \
103    V(JSSetHas)                       \
104    V(JSSetAdd)                       \
105    V(JSMapDelete)                    \
106    V(JSSetDelete)                    \
107    V(CreateJSTypedArrayEntries)      \
108    V(CreateJSTypedArrayKeys)         \
109    V(CreateJSTypedArrayValues)       \
110    V(GetSingleCharCodeByIndex)       \
111    V(FastStringEqual)                \
112    V(FastStringAdd)                  \
113    V(Definefunc)                     \
114    V(DefineField)                    \
115    V(ConvertCharToInt32)             \
116    V(ConvertCharToDouble)            \
117    V(DeleteObjectProperty)           \
118    V(SameValue)                      \
119    V(StringIteratorNext)             \
120    V(VerifyBarrier)
121
122#define COMMON_STUB_ID_LIST(V)          \
123    COMMON_STUB_LIST(V)
124
125class CommonStubCSigns {
126public:
127    enum ID {
128#define DEF_STUB_ID(name) name,
129        COMMON_STUB_ID_LIST(DEF_STUB_ID)
130#undef DEF_STUB_ID
131        NUM_OF_STUBS
132    };
133
134    static void Initialize();
135
136    static void GetCSigns(std::vector<const CallSignature*>& callSigns);
137
138    static const CallSignature *Get(size_t index)
139    {
140        ASSERT(index < NUM_OF_STUBS);
141        return &callSigns_[index];
142    }
143
144    static const std::string &GetName(size_t index)
145    {
146        ASSERT(index < NUM_OF_STUBS);
147        return callSigns_[index].GetName();
148    }
149
150private:
151    static CallSignature callSigns_[NUM_OF_STUBS];
152};
153}  // namespace panda::ecmascript::kungfu
154#endif  // ECMASCRIPT_COMPILER_COMMON_STUB_CSIGNS_H
155