• 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_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_STUB_BUILDER_H
18 
19 #include "ecmascript/base/config.h"
20 #include "ecmascript/compiler/call_signature.h"
21 #include "ecmascript/compiler/circuit_builder-inl.h"
22 #include "ecmascript/compiler/variable_type.h"
23 
24 namespace panda::ecmascript::kungfu {
25 using namespace panda::ecmascript;
26 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
27 #define DEFVARIABLE(varname, type, val) Variable varname(GetEnvironment(), type, NextVariableId(), val)
28 
29 #define SUBENTRY(messageId, condition)                                              \
30     GateRef glueArg = PtrArgument(0);                                               \
31     auto env = GetEnvironment();                                                    \
32     Label subEntry(env);                                                            \
33     env->SubCfgEntry(&subEntry);                                                    \
34     Label nextLabel(env);                                                           \
35     Assert(messageId, __LINE__, glueArg, condition, &nextLabel);                    \
36     Bind(&nextLabel)
37 #define SUBENTRY_WITH_GLUE(messageId, condition, glueArg)                           \
38     auto env = GetEnvironment();                                                    \
39     Label subEntry(env);                                                            \
40     env->SubCfgEntry(&subEntry);                                                    \
41     Label nextLabel(env);                                                           \
42     Assert(messageId, __LINE__, glueArg, condition, &nextLabel);                    \
43     Bind(&nextLabel)
44 
45 #ifndef NDEBUG
46 #define ASM_ASSERT(messageId, condition)                                            \
47     SUBENTRY(messageId, condition)
48 #define ASM_ASSERT_WITH_GLUE(messageId, condition, glue)                            \
49     SUBENTRY_WITH_GLUE(messageId, condition, glue)
50 #elif defined(ENABLE_ASM_ASSERT)
51 #define ASM_ASSERT(messageId, condition)                                            \
52     SUBENTRY(messageId, condition)
53 #define ASM_ASSERT_WITH_GLUE(messageId, condition, glue)                            \
54     SUBENTRY_WITH_GLUE(messageId, condition, glue)
55 #else
56 #define ASM_ASSERT(messageId, ...) ((void)0)
57 #define ASM_ASSERT_WITH_GLUE(messageId, ...) ((void)0)
58 #endif
59 
60 #ifndef NDEBUG
61 #define EXITENTRY()                                                                 \
62     env->SubCfgExit()
63 #elif defined(ENABLE_ASM_ASSERT)
64 #define EXITENTRY()                                                                 \
65     env->SubCfgExit()
66 #else
67 #define EXITENTRY() ((void)0)
68 #endif
69 
70 class StubBuilder {
71 public:
StubBuilder(StubBuilder * parent)72     explicit StubBuilder(StubBuilder *parent)
73         : callSignature_(parent->GetCallSignature()), env_(parent->GetEnvironment()) {}
StubBuilder(CallSignature * callSignature,Environment * env)74     explicit StubBuilder(CallSignature *callSignature, Environment *env)
75         : callSignature_(callSignature), env_(env) {}
StubBuilder(Environment * env)76     explicit StubBuilder(Environment *env)
77         : env_(env) {}
78     virtual ~StubBuilder() = default;
79     NO_MOVE_SEMANTIC(StubBuilder);
80     NO_COPY_SEMANTIC(StubBuilder);
81     virtual void GenerateCircuit() = 0;
GetEnvironment()82     Environment *GetEnvironment() const
83     {
84         return env_;
85     }
GetCallSignature()86     CallSignature *GetCallSignature() const
87     {
88         return callSignature_;
89     }
NextVariableId()90     int NextVariableId()
91     {
92         return env_->NextVariableId();
93     }
94     // constant
95     GateRef Int8(int8_t value);
96     GateRef Int16(int16_t value);
97     GateRef Int32(int32_t value);
98     GateRef Int64(int64_t value);
99     GateRef IntPtr(int64_t value);
100     GateRef IntPtrSize();
101     GateRef RelocatableData(uint64_t value);
102     GateRef True();
103     GateRef False();
104     GateRef Boolean(bool value);
105     GateRef Double(double value);
106     GateRef Undefined();
107     GateRef Hole();
108     GateRef Null();
109     GateRef Exception();
110     // parameter
111     GateRef Argument(size_t index);
112     GateRef Int1Argument(size_t index);
113     GateRef Int32Argument(size_t index);
114     GateRef Int64Argument(size_t index);
115     GateRef TaggedArgument(size_t index);
116     GateRef TaggedPointerArgument(size_t index);
117     GateRef PtrArgument(size_t index);
118     GateRef Float32Argument(size_t index);
119     GateRef Float64Argument(size_t index);
120     GateRef Alloca(int size);
121     // control flow
122     GateRef Return(GateRef value);
123     GateRef Return();
124     void Bind(Label *label);
125     void Jump(Label *label);
126     void Branch(GateRef condition, Label *trueLabel, Label *falseLabel);
127     void Switch(GateRef index, Label *defaultLabel, int64_t *keysValue, Label *keysLabel, int numberOfKeys);
128     void LoopBegin(Label *loopHead);
129     void LoopEnd(Label *loopHead);
130     // call operation
131     GateRef CallRuntime(GateRef glue, int index, const std::initializer_list<GateRef>& args);
132     GateRef CallRuntime(GateRef glue, int index, GateRef argc, GateRef argv);
133     GateRef CallNGCRuntime(GateRef glue, int index, const std::initializer_list<GateRef>& args);
134     GateRef CallStub(GateRef glue, int index, const std::initializer_list<GateRef>& args);
135     GateRef CallBuiltinRuntime(GateRef glue, const std::initializer_list<GateRef>& args, bool isNew = false);
136     void DebugPrint(GateRef thread, std::initializer_list<GateRef> args);
137     void FatalPrint(GateRef thread, std::initializer_list<GateRef> args);
138     // memory
139     GateRef Load(VariableType type, GateRef base, GateRef offset);
140     GateRef Load(VariableType type, GateRef base);
141     void Store(VariableType type, GateRef glue, GateRef base, GateRef offset, GateRef value);
142     // arithmetic
143     GateRef TaggedCastToIntPtr(GateRef x);
144     GateRef Int16Add(GateRef x, GateRef y);
145     GateRef Int32Add(GateRef x, GateRef y);
146     GateRef Int64Add(GateRef x, GateRef y);
147     GateRef DoubleAdd(GateRef x, GateRef y);
148     GateRef PtrAdd(GateRef x, GateRef y);
149     GateRef PtrSub(GateRef x, GateRef y);
150     GateRef PtrMul(GateRef x, GateRef y);
151     GateRef IntPtrEqual(GateRef x, GateRef y);
152     GateRef Int16Sub(GateRef x, GateRef y);
153     GateRef Int32Sub(GateRef x, GateRef y);
154     GateRef Int64Sub(GateRef x, GateRef y);
155     GateRef DoubleSub(GateRef x, GateRef y);
156     GateRef Int32Mul(GateRef x, GateRef y);
157     GateRef Int64Mul(GateRef x, GateRef y);
158     GateRef DoubleMul(GateRef x, GateRef y);
159     GateRef DoubleDiv(GateRef x, GateRef y);
160     GateRef Int32Div(GateRef x, GateRef y);
161     GateRef Int32Mod(GateRef x, GateRef y);
162     GateRef DoubleMod(GateRef x, GateRef y);
163     GateRef Int64Div(GateRef x, GateRef y);
164     GateRef IntPtrDiv(GateRef x, GateRef y);
165     // bit operation
166     GateRef Int32Or(GateRef x, GateRef y);
167     GateRef Int8And(GateRef x, GateRef y);
168     GateRef Int32And(GateRef x, GateRef y);
169     GateRef IntPtrAnd(GateRef x, GateRef y);
170     GateRef BoolAnd(GateRef x, GateRef y);
171     GateRef BoolOr(GateRef x, GateRef y);
172     GateRef Int32Not(GateRef x);
173     GateRef IntPtrNot(GateRef x);
174     GateRef BoolNot(GateRef x);
175     GateRef Int32Xor(GateRef x, GateRef y);
176     GateRef FixLoadType(GateRef x);
177     GateRef Int64Or(GateRef x, GateRef y);
178     GateRef IntPtrOr(GateRef x, GateRef y);
179     GateRef Int64And(GateRef x, GateRef y);
180     GateRef Int64Xor(GateRef x, GateRef y);
181     GateRef Int64Not(GateRef x);
182     GateRef Int16LSL(GateRef x, GateRef y);
183     GateRef Int32LSL(GateRef x, GateRef y);
184     GateRef Int64LSL(GateRef x, GateRef y);
185     GateRef IntPtrLSL(GateRef x, GateRef y);
186     GateRef Int8LSR(GateRef x, GateRef y);
187     GateRef Int32LSR(GateRef x, GateRef y);
188     GateRef Int64LSR(GateRef x, GateRef y);
189     GateRef IntPtrLSR(GateRef x, GateRef y);
190     GateRef Int32ASR(GateRef x, GateRef y);
191     GateRef TaggedIsInt(GateRef x);
192     GateRef TaggedIsDouble(GateRef x);
193     GateRef TaggedIsObject(GateRef x);
194     GateRef TaggedIsNumber(GateRef x);
195     GateRef TaggedIsNumeric(GateRef x);
196     GateRef TaggedIsHole(GateRef x);
197     GateRef TaggedIsNotHole(GateRef x);
198     GateRef TaggedIsUndefined(GateRef x);
199     GateRef TaggedIsException(GateRef x);
200     GateRef TaggedIsSpecial(GateRef x);
201     GateRef TaggedIsHeapObject(GateRef x);
202     GateRef TaggedIsAccessor(GateRef x);
203     GateRef ObjectAddressToRange(GateRef x);
204     GateRef InYoungGeneration(GateRef region);
205     GateRef TaggedIsGeneratorObject(GateRef x);
206     GateRef TaggedIsAsyncGeneratorObject(GateRef x);
207     GateRef TaggedIsWeak(GateRef x);
208     GateRef TaggedIsPrototypeHandler(GateRef x);
209     GateRef TaggedIsStoreTSHandler(GateRef x);
210     GateRef TaggedIsTransWithProtoHandler(GateRef x);
211     GateRef TaggedIsTransitionHandler(GateRef x);
212     GateRef TaggedIsString(GateRef obj);
213     GateRef BothAreString(GateRef x, GateRef y);
214     GateRef TaggedIsStringOrSymbol(GateRef obj);
215     GateRef GetNextPositionForHash(GateRef last, GateRef count, GateRef size);
216     GateRef DoubleIsNAN(GateRef x);
217     GateRef DoubleIsINF(GateRef x);
218     GateRef TaggedIsNull(GateRef x);
219     GateRef TaggedIsUndefinedOrNull(GateRef x);
220     GateRef TaggedIsTrue(GateRef x);
221     GateRef TaggedIsFalse(GateRef x);
222     GateRef TaggedIsBoolean(GateRef x);
223     GateRef TaggedGetInt(GateRef x);
224     GateRef Int8ToTaggedInt(GateRef x);
225     GateRef Int16ToTaggedInt(GateRef x);
226     GateRef IntToTaggedPtr(GateRef x);
227     GateRef IntToTaggedInt(GateRef x);
228     GateRef Int64ToTaggedInt(GateRef x);
229     GateRef DoubleToTaggedDoublePtr(GateRef x);
230     GateRef CastDoubleToInt64(GateRef x);
231     GateRef TaggedTrue();
232     GateRef TaggedFalse();
233     // compare operation
234     GateRef Int8Equal(GateRef x, GateRef y);
235     GateRef Equal(GateRef x, GateRef y);
236     GateRef Int32Equal(GateRef x, GateRef y);
237     GateRef Int32NotEqual(GateRef x, GateRef y);
238     GateRef Int64Equal(GateRef x, GateRef y);
239     GateRef DoubleEqual(GateRef x, GateRef y);
240     GateRef DoubleNotEqual(GateRef x, GateRef y);
241     GateRef Int64NotEqual(GateRef x, GateRef y);
242     GateRef DoubleLessThan(GateRef x, GateRef y);
243     GateRef DoubleLessThanOrEqual(GateRef x, GateRef y);
244     GateRef DoubleGreaterThan(GateRef x, GateRef y);
245     GateRef DoubleGreaterThanOrEqual(GateRef x, GateRef y);
246     GateRef Int32GreaterThan(GateRef x, GateRef y);
247     GateRef Int32LessThan(GateRef x, GateRef y);
248     GateRef Int32GreaterThanOrEqual(GateRef x, GateRef y);
249     GateRef Int32LessThanOrEqual(GateRef x, GateRef y);
250     GateRef Int32UnsignedGreaterThan(GateRef x, GateRef y);
251     GateRef Int32UnsignedLessThan(GateRef x, GateRef y);
252     GateRef Int32UnsignedGreaterThanOrEqual(GateRef x, GateRef y);
253     GateRef Int64GreaterThan(GateRef x, GateRef y);
254     GateRef Int64LessThan(GateRef x, GateRef y);
255     GateRef Int64LessThanOrEqual(GateRef x, GateRef y);
256     GateRef Int64GreaterThanOrEqual(GateRef x, GateRef y);
257     GateRef Int64UnsignedLessThanOrEqual(GateRef x, GateRef y);
258     GateRef IntPtrGreaterThan(GateRef x, GateRef y);
259     // cast operation
260     GateRef ChangeInt64ToIntPtr(GateRef val);
261     GateRef ZExtInt32ToPtr(GateRef val);
262     GateRef ChangeIntPtrToInt32(GateRef val);
263     // math operation
264     GateRef Sqrt(GateRef x);
265     GateRef GetSetterFromAccessor(GateRef accessor);
266     GateRef GetElementsArray(GateRef object);
267     void SetElementsArray(VariableType type, GateRef glue, GateRef object, GateRef elementsArray);
268     GateRef GetPropertiesArray(GateRef object);
269     // SetProperties in js_object.h
270     void SetPropertiesArray(VariableType type, GateRef glue, GateRef object, GateRef propsArray);
271     void SetHash(GateRef glue, GateRef object, GateRef hash);
272     GateRef GetLengthOfTaggedArray(GateRef array);
273     // object operation
274     GateRef IsJSHClass(GateRef obj);
275     GateRef LoadHClass(GateRef object);
276     void StoreHClass(GateRef glue, GateRef object, GateRef hClass);
277     void CopyAllHClass(GateRef glue, GateRef dstHClass, GateRef scrHClass);
278     GateRef GetObjectType(GateRef hClass);
279     GateRef IsDictionaryMode(GateRef object);
280     GateRef IsDictionaryModeByHClass(GateRef hClass);
281     GateRef IsDictionaryElement(GateRef hClass);
282     GateRef IsClassConstructorFromBitField(GateRef bitfield);
283     GateRef IsClassConstructor(GateRef object);
284     GateRef IsClassPrototype(GateRef object);
285     GateRef IsExtensible(GateRef object);
286     GateRef TaggedObjectIsEcmaObject(GateRef obj);
287     GateRef IsEcmaObject(GateRef obj);
288     GateRef IsSymbol(GateRef obj);
289     GateRef IsString(GateRef obj);
290     GateRef TaggedIsBigInt(GateRef obj);
291     GateRef TaggedIsPropertyBox(GateRef obj);
292     GateRef TaggedObjectIsBigInt(GateRef obj);
293     GateRef IsJsProxy(GateRef obj);
294     GateRef IsJSFunctionBase(GateRef obj);
295     GateRef IsConstructor(GateRef object);
296     GateRef IsBase(GateRef func);
297     GateRef IsJsArray(GateRef obj);
298     GateRef IsJsCOWArray(GateRef obj);
299     GateRef IsCOWArray(GateRef obj);
300     GateRef IsJSObject(GateRef obj);
301     GateRef IsWritable(GateRef attr);
302     GateRef IsAccessor(GateRef attr);
303     GateRef IsInlinedProperty(GateRef attr);
304     GateRef IsField(GateRef attr);
305     GateRef IsNonExist(GateRef attr);
306     GateRef IsJSAPIVector(GateRef attr);
307     GateRef IsJSAPIStack(GateRef obj);
308     GateRef IsJSAPIPlainArray(GateRef obj);
309     GateRef IsJSAPIQueue(GateRef obj);
310     GateRef IsJSAPIDeque(GateRef obj);
311     GateRef IsJSAPILightWeightMap(GateRef obj);
312     GateRef IsJSAPILightWeightSet(GateRef obj);
313     GateRef IsLinkedNode(GateRef obj);
314     GateRef IsJSAPIHashMap(GateRef obj);
315     GateRef IsJSAPIHashSet(GateRef obj);
316     GateRef IsJSAPILinkedList(GateRef obj);
317     GateRef IsJSAPIList(GateRef obj);
318     GateRef IsJSAPIArrayList(GateRef obj);
319     GateRef GetTarget(GateRef proxyObj);
320     GateRef HandlerBaseIsAccessor(GateRef attr);
321     GateRef HandlerBaseIsJSArray(GateRef attr);
322     GateRef HandlerBaseIsInlinedProperty(GateRef attr);
323     GateRef HandlerBaseGetOffset(GateRef attr);
324     GateRef IsInvalidPropertyBox(GateRef obj);
325     GateRef GetValueFromPropertyBox(GateRef obj);
326     void SetValueToPropertyBox(GateRef glue, GateRef obj, GateRef value);
327     GateRef GetTransitionHClass(GateRef obj);
328     GateRef GetTransitionHandlerInfo(GateRef obj);
329     GateRef GetTransWithProtoHClass(GateRef obj);
330     GateRef GetTransWithProtoHandlerInfo(GateRef obj);
331     GateRef IsInternalAccessor(GateRef attr);
332     GateRef GetProtoCell(GateRef object);
333     GateRef GetPrototypeHandlerHolder(GateRef object);
334     GateRef GetPrototypeHandlerHandlerInfo(GateRef object);
335     GateRef GetStoreTSHandlerHolder(GateRef object);
336     GateRef GetStoreTSHandlerHandlerInfo(GateRef object);
337     GateRef GetPrototype(GateRef glue, GateRef object);
338     GateRef GetHasChanged(GateRef object);
339     GateRef HclassIsPrototypeHandler(GateRef hClass);
340     GateRef HclassIsTransitionHandler(GateRef hClass);
341     GateRef HclassIsPropertyBox(GateRef hClass);
342     GateRef PropAttrGetOffset(GateRef attr);
343     GateRef InstanceOf(GateRef glue, GateRef object, GateRef target);
344     GateRef OrdinaryHasInstance(GateRef glue, GateRef target, GateRef obj);
345     GateRef SameValue(GateRef glue, GateRef left, GateRef right);
346 
347     // SetDictionaryOrder func in property_attribute.h
348     GateRef SetDictionaryOrderFieldInPropAttr(GateRef attr, GateRef value);
349     GateRef GetPrototypeFromHClass(GateRef hClass);
350     GateRef GetLayoutFromHClass(GateRef hClass);
351     GateRef GetBitFieldFromHClass(GateRef hClass);
352     GateRef GetLengthFromString(GateRef value);
353     GateRef GetHashcodeFromString(GateRef glue, GateRef value);
354     void SetBitFieldToHClass(GateRef glue, GateRef hClass, GateRef bitfield);
355     void SetPrototypeToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef proto);
356     void SetProtoChangeDetailsToHClass(VariableType type, GateRef glue, GateRef hClass,
357                                        GateRef protoChange);
358     void SetLayoutToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef attr);
359     void SetEnumCacheToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef key);
360     void SetTransitionsToHClass(VariableType type, GateRef glue, GateRef hClass, GateRef transition);
361     void SetIsProtoTypeToHClass(GateRef glue, GateRef hClass, GateRef value);
362     GateRef IsProtoTypeHClass(GateRef hClass);
363     void SetPropertyInlinedProps(GateRef glue, GateRef obj, GateRef hClass,
364         GateRef value, GateRef attrOffset, VariableType type = VariableType::JS_ANY());
365     GateRef GetPropertyInlinedProps(GateRef obj, GateRef hClass,
366         GateRef index);
367 
368     void IncNumberOfProps(GateRef glue, GateRef hClass);
369     GateRef GetNumberOfPropsFromHClass(GateRef hClass);
370     GateRef IsTSHClass(GateRef hClass);
371     void SetNumberOfPropsToHClass(GateRef glue, GateRef hClass, GateRef value);
372     GateRef GetObjectSizeFromHClass(GateRef hClass);
373     GateRef GetInlinedPropsStartFromHClass(GateRef hClass);
374     GateRef GetInlinedPropertiesFromHClass(GateRef hClass);
375     void ThrowTypeAndReturn(GateRef glue, int messageId, GateRef val);
376     GateRef GetValueFromTaggedArray(GateRef elements, GateRef index);
377     void SetValueToTaggedArray(VariableType valType, GateRef glue, GateRef array, GateRef index, GateRef val);
378     void UpdateValueAndAttributes(GateRef glue, GateRef elements, GateRef index, GateRef value, GateRef attr);
379     GateRef IsSpecialIndexedObj(GateRef jsType);
380     GateRef IsSpecialContainer(GateRef jsType);
381     GateRef IsAccessorInternal(GateRef value);
382     template<typename DictionaryT>
383     GateRef GetAttributesFromDictionary(GateRef elements, GateRef entry);
384     template<typename DictionaryT>
385     GateRef GetValueFromDictionary(GateRef elements, GateRef entry);
386     template<typename DictionaryT>
387     GateRef GetKeyFromDictionary(GateRef elements, GateRef entry);
388     GateRef GetPropAttrFromLayoutInfo(GateRef layout, GateRef entry);
389     GateRef GetPropertiesAddrFromLayoutInfo(GateRef layout);
390     GateRef GetPropertyMetaDataFromAttr(GateRef attr);
391     GateRef GetKeyFromLayoutInfo(GateRef layout, GateRef entry);
392     GateRef FindElementWithCache(GateRef glue, GateRef layoutInfo, GateRef hClass,
393         GateRef key, GateRef propsNum);
394     GateRef FindElementFromNumberDictionary(GateRef glue, GateRef elements, GateRef index);
395     GateRef FindEntryFromNameDictionary(GateRef glue, GateRef elements, GateRef key);
396     GateRef IsMatchInTransitionDictionary(GateRef element, GateRef key, GateRef metaData, GateRef attr);
397     GateRef FindEntryFromTransitionDictionary(GateRef glue, GateRef elements, GateRef key, GateRef metaData);
398     GateRef JSObjectGetProperty(GateRef obj, GateRef hClass, GateRef propAttr);
399     void JSObjectSetProperty(GateRef glue, GateRef obj, GateRef hClass, GateRef attr, GateRef value);
400     GateRef ShouldCallSetter(GateRef receiver, GateRef holder, GateRef accessor, GateRef attr);
401     GateRef CallSetterHelper(GateRef glue, GateRef holder, GateRef accessor,  GateRef value);
402     GateRef SetHasConstructorCondition(GateRef glue, GateRef receiver, GateRef key);
403     GateRef AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, GateRef value, GateRef propertyAttributes);
404     GateRef IsUtf16String(GateRef string);
405     GateRef IsUtf8String(GateRef string);
406     GateRef IsInternalString(GateRef string);
407     GateRef IsDigit(GateRef ch);
408     GateRef StringToElementIndex(GateRef string);
409     GateRef TryToElementsIndex(GateRef key);
410     GateRef ComputePropertyCapacityInJSObj(GateRef oldLength);
411     GateRef FindTransitions(GateRef glue, GateRef receiver, GateRef hClass, GateRef key, GateRef attr);
412     GateRef TaggedToRepresentation(GateRef value);
413     GateRef LdGlobalRecord(GateRef glue, GateRef key);
414     GateRef LoadFromField(GateRef receiver, GateRef handlerInfo);
415     GateRef LoadGlobal(GateRef cell);
416     GateRef LoadElement(GateRef receiver, GateRef key);
417     GateRef TryToElementsIndex(GateRef glue, GateRef key);
418     GateRef CheckPolyHClass(GateRef cachedValue, GateRef hClass);
419     GateRef LoadICWithHandler(GateRef glue, GateRef receiver, GateRef holder, GateRef handler);
420     GateRef StoreICWithHandler(GateRef glue, GateRef receiver, GateRef holder,
421                                  GateRef value, GateRef handler);
422     GateRef ICStoreElement(GateRef glue, GateRef receiver, GateRef key,
423                              GateRef value, GateRef handlerInfo);
424     GateRef GetArrayLength(GateRef object);
425     GateRef DoubleToInt(GateRef glue, GateRef x);
426     void StoreField(GateRef glue, GateRef receiver, GateRef value, GateRef handler);
427     void StoreWithTransition(GateRef glue, GateRef receiver, GateRef value, GateRef handler,
428                              bool withPrototype = false);
429     GateRef StoreGlobal(GateRef glue, GateRef value, GateRef cell);
430     void JSHClassAddProperty(GateRef glue, GateRef receiver, GateRef key, GateRef attr);
431     void NotifyHClassChanged(GateRef glue, GateRef oldHClass, GateRef newHClass);
432     GateRef GetInt64OfTInt(GateRef x);
433     GateRef GetInt32OfTInt(GateRef x);
434     GateRef GetDoubleOfTDouble(GateRef x);
435     GateRef GetDoubleOfTNumber(GateRef x);
436     GateRef LoadObjectFromWeakRef(GateRef x);
437     GateRef ChangeInt32ToFloat64(GateRef x);
438     GateRef ChangeUInt32ToFloat64(GateRef x);
439     GateRef ChangeFloat64ToInt32(GateRef x);
440     GateRef ChangeTaggedPointerToInt64(GateRef x);
441     GateRef Int64ToTaggedPtr(GateRef x);
442     GateRef TruncInt16ToInt8(GateRef x);
443     GateRef CastInt64ToFloat64(GateRef x);
444     GateRef SExtInt32ToInt64(GateRef x);
445     GateRef SExtInt16ToInt64(GateRef x);
446     GateRef SExtInt8ToInt64(GateRef x);
447     GateRef SExtInt1ToInt64(GateRef x);
448     GateRef SExtInt1ToInt32(GateRef x);
449     GateRef ZExtInt8ToInt16(GateRef x);
450     GateRef ZExtInt32ToInt64(GateRef x);
451     GateRef ZExtInt1ToInt64(GateRef x);
452     GateRef ZExtInt1ToInt32(GateRef x);
453     GateRef ZExtInt8ToInt32(GateRef x);
454     GateRef ZExtInt8ToInt64(GateRef x);
455     GateRef ZExtInt8ToPtr(GateRef x);
456     GateRef ZExtInt16ToPtr(GateRef x);
457     GateRef SExtInt32ToPtr(GateRef x);
458     GateRef ZExtInt16ToInt32(GateRef x);
459     GateRef ZExtInt16ToInt64(GateRef x);
460     GateRef TruncInt64ToInt32(GateRef x);
461     GateRef TruncPtrToInt32(GateRef x);
462     GateRef TruncInt64ToInt1(GateRef x);
463     GateRef TruncInt32ToInt1(GateRef x);
464     GateRef GetGlobalConstantAddr(GateRef index);
465     GateRef GetGlobalConstantString(ConstantIndex index);
466     GateRef IsCallableFromBitField(GateRef bitfield);
467     GateRef IsCallable(GateRef obj);
468     GateRef GetOffsetFieldInPropAttr(GateRef attr);
469     GateRef SetOffsetFieldInPropAttr(GateRef attr, GateRef value);
470     GateRef SetIsInlinePropsFieldInPropAttr(GateRef attr, GateRef value);
471     void SetHasConstructorToHClass(GateRef glue, GateRef hClass, GateRef value);
472     void UpdateValueInDict(GateRef glue, GateRef elements, GateRef index, GateRef value);
473     GateRef GetBitMask(GateRef bitoffset);
474     GateRef IntPtrEuqal(GateRef x, GateRef y);
475     void SetValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRef value);
476     GateRef GetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index);
477     GateRef GetPropertyByName(GateRef glue, GateRef receiver, GateRef key);
478     GateRef FastGetPropertyByName(GateRef glue, GateRef obj, GateRef key);
479     GateRef GetPropertyByValue(GateRef glue, GateRef receiver, GateRef keyValue);
480     GateRef SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index, GateRef value, bool useOwn);
481     GateRef SetPropertyByName(GateRef glue, GateRef receiver, GateRef key,
482         GateRef value, bool useOwn); // Crawl prototype chain
483     GateRef SetPropertyByValue(GateRef glue, GateRef receiver, GateRef key, GateRef value, bool useOwn);
484     GateRef GetParentEnv(GateRef object);
485     GateRef GetPropertiesFromLexicalEnv(GateRef object, GateRef index);
486     void SetPropertiesToLexicalEnv(GateRef glue, GateRef object, GateRef index, GateRef value);
487     GateRef GetHomeObjectFromJSFunction(GateRef object);
488     GateRef GetCallFieldFromMethod(GateRef method);
489     inline GateRef GetBuiltinId(GateRef method);
490     void SetLexicalEnvToFunction(GateRef glue, GateRef object, GateRef lexicalEnv);
491     GateRef GetGlobalObject(GateRef glue);
492     GateRef GetEntryIndexOfGlobalDictionary(GateRef entry);
493     GateRef GetBoxFromGlobalDictionary(GateRef object, GateRef entry);
494     GateRef GetValueFromGlobalDictionary(GateRef object, GateRef entry);
495     GateRef GetPropertiesFromJSObject(GateRef object);
496     template<OpCode Op, MachineType Type>
497     GateRef BinaryOp(GateRef x, GateRef y);
498     GateRef GetGlobalOwnProperty(GateRef glue, GateRef receiver, GateRef key);
499 
500     inline GateRef GetObjectFromConstPool(GateRef constpool, GateRef index);
501     GateRef GetStringFromConstPool(GateRef glue, GateRef constpool, GateRef index);
502     GateRef GetMethodFromConstPool(GateRef glue, GateRef constpool, GateRef index);
503     GateRef GetArrayLiteralFromConstPool(GateRef glue, GateRef constpool, GateRef index, GateRef module);
504     GateRef GetObjectLiteralFromConstPool(GateRef glue, GateRef constpool, GateRef index, GateRef module);
505     void SetExtensibleToBitfield(GateRef glue, GateRef obj, bool isExtensible);
506 
507     // fast path
508     GateRef FastEqual(GateRef left, GateRef right);
509     GateRef FastStrictEqual(GateRef glue, GateRef left, GateRef right);
510     GateRef FastStringEqual(GateRef glue, GateRef left, GateRef right);
511     GateRef FastMod(GateRef gule, GateRef left, GateRef right);
512     GateRef FastTypeOf(GateRef left, GateRef right);
513     GateRef FastMul(GateRef left, GateRef right);
514     GateRef FastDiv(GateRef left, GateRef right);
515     GateRef FastAdd(GateRef left, GateRef right);
516     GateRef FastSub(GateRef left, GateRef right);
517     GateRef FastToBoolean(GateRef value);
518 
519     // Add SpecialContainer
520     GateRef GetContainerProperty(GateRef glue, GateRef receiver, GateRef index, GateRef jsType);
521     GateRef JSAPIContainerGet(GateRef glue, GateRef receiver, GateRef index);
522 
523     // Exception handle
524     GateRef HasPendingException(GateRef glue);
525     void ReturnExceptionIfAbruptCompletion(GateRef glue);
526 
527     // method operator
528     GateRef IsJSFunction(GateRef obj);
529     GateRef IsBoundFunction(GateRef obj);
530     GateRef GetMethodFromJSFunction(GateRef jsfunc);
531     GateRef IsNativeMethod(GateRef method);
532     GateRef HasAotCode(GateRef method);
533     GateRef GetExpectedNumOfArgs(GateRef method);
534     GateRef GetMethod(GateRef glue, GateRef obj, GateRef key);
535     // proxy operator
536     GateRef GetMethodFromJSProxy(GateRef proxy);
537     GateRef GetHandlerFromJSProxy(GateRef proxy);
538     GateRef GetTargetFromJSProxy(GateRef proxy);
539     inline void SetHotnessCounter(GateRef glue, GateRef method, GateRef value);
540     inline void SaveHotnessCounterIfNeeded(GateRef glue, GateRef sp, GateRef hotnessCounter, JSCallMode mode);
541     inline void SavePcIfNeeded(GateRef glue);
542     inline void SaveJumpSizeIfNeeded(GateRef glue, GateRef jumpSize);
543     inline GateRef ComputeTaggedArraySize(GateRef length);
544     inline GateRef GetGlobalConstantValue(
545         VariableType type, GateRef glue, ConstantIndex index);
546     inline GateRef GetGlobalEnvValue(VariableType type, GateRef env, size_t index);
547     GateRef CallGetterHelper(GateRef glue, GateRef receiver, GateRef holder, GateRef accessor);
548     GateRef ConstructorCheck(GateRef glue, GateRef ctor, GateRef outPut, GateRef thisObj);
549     GateRef JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, GateRef jumpSize, GateRef hotnessCounter,
550                            JSCallMode mode, std::initializer_list<GateRef> args);
551     GateRef IsFastTypeArray(GateRef jsType);
552     GateRef GetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef jsType);
553     GateRef SetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef value,
554                                        GateRef jsType);
555     GateRef TryStringOrSymbelToElementIndex(GateRef string);
556     inline GateRef DispatchBuiltins(GateRef glue, GateRef builtinsId, const std::initializer_list<GateRef>& args);
557     inline GateRef DispatchBuiltinsWithArgv(GateRef glue, GateRef builtinsId,
558                                             const std::initializer_list<GateRef>& args);
559     GateRef ComputeSizeUtf8(GateRef length);
560     GateRef ComputeSizeUtf16(GateRef length);
561     GateRef AlignUp(GateRef x, GateRef alignment);
562     void CallFastPath(GateRef glue, GateRef nativeCode, GateRef func, GateRef thisValue, GateRef actualNumArgs,
563                       GateRef callField, GateRef method, Label* notFastBuiltins, Label* exit, Variable* result,
564                       std::initializer_list<GateRef> args, JSCallMode mode);
565     inline void SetLength(GateRef glue, GateRef str, GateRef length, bool compressed);
566     inline void SetRawHashcode(GateRef glue, GateRef str, GateRef rawHashcode);
567     inline void PGOProfiler(GateRef glue, GateRef func);
568     void Assert(int messageId, int line, GateRef glue, GateRef condition, Label *nextLabel);
569 private:
570     using BinaryOperation = std::function<GateRef(Environment*, GateRef, GateRef)>;
571     template<OpCode Op>
572     GateRef FastAddSubAndMul(GateRef left, GateRef right);
573     GateRef FastBinaryOp(GateRef left, GateRef right,
574                          const BinaryOperation& intOp, const BinaryOperation& floatOp);
575     void InitializeArguments();
576     CallSignature *callSignature_ {nullptr};
577     Environment *env_;
578 };
579 }  // namespace panda::ecmascript::kungfu
580 #endif  // ECMASCRIPT_COMPILER_STUB_BUILDER_H
581