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