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_NEW_OBJECT_STUB_BUILDER_H 17 #define ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H 18 19 #include "ecmascript/compiler/builtins/builtins_string_stub_builder.h" 20 #include "ecmascript/compiler/profiler_operation.h" 21 #include "ecmascript/compiler/stub_builder.h" 22 23 namespace panda::ecmascript::kungfu { 24 class NewObjectStubBuilder : public StubBuilder { 25 public: NewObjectStubBuilder(StubBuilder * parent)26 explicit NewObjectStubBuilder(StubBuilder *parent) 27 : StubBuilder(parent) {} NewObjectStubBuilder(Environment * env)28 explicit NewObjectStubBuilder(Environment *env) 29 : StubBuilder(env) {} 30 ~NewObjectStubBuilder() override = default; 31 NO_MOVE_SEMANTIC(NewObjectStubBuilder); 32 NO_COPY_SEMANTIC(NewObjectStubBuilder); GenerateCircuit()33 void GenerateCircuit() override {} 34 SetParameters(GateRef glue,GateRef size)35 void SetParameters(GateRef glue, GateRef size) 36 { 37 glue_ = glue; 38 size_ = size; 39 } 40 SetGlue(GateRef glue)41 void SetGlue(GateRef glue) 42 { 43 glue_ = glue; 44 } 45 46 void NewLexicalEnv(Variable *result, Label *exit, GateRef numSlots, GateRef parent); 47 void NewJSObject(Variable *result, Label *exit, GateRef hclass); 48 GateRef NewJSObject(GateRef glue, GateRef hclass); 49 GateRef NewJSArray(GateRef glue, GateRef hclass); 50 GateRef NewTaggedArray(GateRef glue, GateRef len); 51 GateRef CopyArray(GateRef glue, GateRef elements, GateRef oldLen, GateRef newLen); 52 GateRef ExtendArray(GateRef glue, GateRef elements, GateRef newLen); 53 GateRef NewJSArrayWithSize(GateRef hclass, GateRef size); 54 GateRef NewJSForinIterator(GateRef glue, GateRef receiver, GateRef keys, GateRef cachedHclass); 55 GateRef LoadHClassFromMethod(GateRef glue, GateRef method); 56 GateRef NewJSFunction(GateRef glue, GateRef constpool, GateRef module, GateRef index); 57 void NewJSFunction(GateRef glue, GateRef jsFunc, GateRef index, GateRef length, GateRef lexEnv, 58 Variable *result, Label *success, Label *failed); 59 void InitializeJSFunction(GateRef glue, GateRef func, GateRef kind); 60 GateRef EnumerateObjectProperties(GateRef glue, GateRef obj); 61 void NewArgumentsList(Variable *result, Label *exit, GateRef sp, GateRef startIdx, GateRef numArgs); 62 void NewArgumentsObj(Variable *result, Label *exit, GateRef argumentsList, GateRef numArgs); 63 void AllocLineStringObject(Variable *result, Label *exit, GateRef length, bool compressed); 64 void AllocSlicedStringObject(Variable *result, Label *exit, GateRef from, GateRef length, 65 FlatStringStubBuilder *flatString); 66 void AllocTreeStringObject(Variable *result, Label *exit, GateRef first, GateRef second, 67 GateRef length, bool compressed); 68 void HeapAlloc(Variable *result, Label *exit, RegionSpaceFlag spaceType); 69 void NewJSArrayLiteral(Variable *result, Label *exit, RegionSpaceFlag spaceType, GateRef obj, GateRef hclass, 70 GateRef trackInfo, bool isEmptyArray); 71 GateRef NewTrackInfo(GateRef glue, GateRef cachedHClass, GateRef cachedFunc, RegionSpaceFlag spaceFlag, 72 GateRef arraySize); 73 void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef value, GateRef start, GateRef end); 74 GateRef FastNewThisObject(GateRef glue, GateRef ctor); 75 GateRef FastSuperAllocateThis(GateRef glue, GateRef superCtor, GateRef newTarget); 76 GateRef NewThisObjectChecked(GateRef glue, GateRef ctor); 77 GateRef CreateEmptyObject(GateRef glue); 78 GateRef CreateEmptyArray(GateRef glue); 79 GateRef CreateEmptyArray(GateRef glue, GateRef jsFunc, GateRef pc, GateRef profileTypeInfo, GateRef slotId, 80 ProfileOperation callback); 81 GateRef CreateArrayWithBuffer(GateRef glue, GateRef index, GateRef jsFunc, GateRef pc, 82 GateRef profileTypeInfo, GateRef slotId, ProfileOperation callback); 83 void NewTaggedArrayChecked(Variable *result, GateRef len, Label *exit); 84 template <typename IteratorType, typename CollectionType> 85 void CreateJSCollectionIterator(Variable *result, Label *exit, GateRef set, GateRef kind); 86 GateRef NewTaggedSubArray(GateRef glue, GateRef srcTypedArray, GateRef elementSize, GateRef newLength, 87 GateRef beginIndex, GateRef arrayCls, GateRef buffer); 88 89 private: 90 static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50; 91 GateRef LoadTrackInfo(GateRef glue, GateRef jsFunc, GateRef pc, GateRef profileTypeInfo, GateRef slotId, 92 GateRef arrayLiteral, ProfileOperation callback); 93 GateRef LoadArrayHClassSlowPath( 94 GateRef glue, GateRef jsFunc, GateRef pc, GateRef arrayLiteral, ProfileOperation callback); 95 GateRef CreateEmptyArrayCommon(GateRef glue, GateRef hclass, GateRef trackInfo); 96 void AllocateInYoung(Variable *result, Label *exit); 97 void InitializeTaggedArrayWithSpeicalValue(Label *exit, 98 GateRef array, GateRef value, GateRef start, GateRef length); 99 GateRef glue_ {Circuit::NullGate()}; 100 GateRef size_ {0}; 101 }; 102 } // namespace panda::ecmascript::kungfu 103 #endif // ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H 104