14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/builtins_string_stub_builder.h" 204514f5e3Sopenharmony_ci#include "ecmascript/compiler/profiler_operation.h" 214514f5e3Sopenharmony_ci#include "ecmascript/compiler/stub_builder.h" 224514f5e3Sopenharmony_ci 234514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu { 244514f5e3Sopenharmony_ci 254514f5e3Sopenharmony_cistruct TraceIdInfo { 264514f5e3Sopenharmony_ci GateRef pc = 0; 274514f5e3Sopenharmony_ci GateRef traceId = 0; 284514f5e3Sopenharmony_ci bool isPc = true; 294514f5e3Sopenharmony_ci}; 304514f5e3Sopenharmony_ci 314514f5e3Sopenharmony_ciclass NewObjectStubBuilder : public StubBuilder { 324514f5e3Sopenharmony_cipublic: 334514f5e3Sopenharmony_ci explicit NewObjectStubBuilder(StubBuilder *parent) 344514f5e3Sopenharmony_ci : StubBuilder(parent) {} 354514f5e3Sopenharmony_ci explicit NewObjectStubBuilder(Environment *env) 364514f5e3Sopenharmony_ci : StubBuilder(env) {} 374514f5e3Sopenharmony_ci ~NewObjectStubBuilder() override = default; 384514f5e3Sopenharmony_ci NO_MOVE_SEMANTIC(NewObjectStubBuilder); 394514f5e3Sopenharmony_ci NO_COPY_SEMANTIC(NewObjectStubBuilder); 404514f5e3Sopenharmony_ci void GenerateCircuit() override {} 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_ci void SetParameters(GateRef glue, GateRef size) 434514f5e3Sopenharmony_ci { 444514f5e3Sopenharmony_ci glue_ = glue; 454514f5e3Sopenharmony_ci size_ = size; 464514f5e3Sopenharmony_ci } 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_ci void SetGlue(GateRef glue) 494514f5e3Sopenharmony_ci { 504514f5e3Sopenharmony_ci glue_ = glue; 514514f5e3Sopenharmony_ci } 524514f5e3Sopenharmony_ci 534514f5e3Sopenharmony_ci void NewLexicalEnv(Variable *result, Label *exit, GateRef numSlots, GateRef parent); 544514f5e3Sopenharmony_ci void NewJSObject(Variable *result, Label *exit, GateRef hclass, GateRef size); 554514f5e3Sopenharmony_ci void NewJSObject(Variable *result, Label *exit, GateRef hclass); 564514f5e3Sopenharmony_ci void NewSObject(Variable *result, Label *exit, GateRef hclass); 574514f5e3Sopenharmony_ci GateRef NewJSObject(GateRef glue, GateRef hclass); 584514f5e3Sopenharmony_ci GateRef NewSObject(GateRef glue, GateRef hclass); 594514f5e3Sopenharmony_ci GateRef NewJSFunctionByHClass(GateRef glue, GateRef method, GateRef hclass, 604514f5e3Sopenharmony_ci FunctionKind targetKind = FunctionKind::LAST_FUNCTION_KIND); 614514f5e3Sopenharmony_ci GateRef NewSFunctionByHClass(GateRef glue, GateRef method, GateRef hclass, 624514f5e3Sopenharmony_ci FunctionKind targetKind = FunctionKind::LAST_FUNCTION_KIND); 634514f5e3Sopenharmony_ci GateRef CloneJSFunction(GateRef glue, GateRef value); 644514f5e3Sopenharmony_ci GateRef CloneProperties(GateRef glue, GateRef currentEnv, GateRef elements, GateRef obj); 654514f5e3Sopenharmony_ci GateRef NewAccessorData(GateRef glue); 664514f5e3Sopenharmony_ci GateRef CloneObjectLiteral(GateRef glue, GateRef literal, GateRef currentEnv); 674514f5e3Sopenharmony_ci GateRef CreateObjectHavingMethod(GateRef glue, GateRef literal, GateRef currentEnv); 684514f5e3Sopenharmony_ci GateRef NewJSProxy(GateRef glue, GateRef target, GateRef handler); 694514f5e3Sopenharmony_ci GateRef NewJSArray(GateRef glue, GateRef hclass); 704514f5e3Sopenharmony_ci GateRef NewTaggedArray(GateRef glue, GateRef len); 714514f5e3Sopenharmony_ci GateRef NewMutantTaggedArray(GateRef glue, GateRef len); 724514f5e3Sopenharmony_ci GateRef CopyArray(GateRef glue, GateRef elements, GateRef oldLen, GateRef newLen, 734514f5e3Sopenharmony_ci RegionSpaceFlag spaceType = RegionSpaceFlag::IN_YOUNG_SPACE); 744514f5e3Sopenharmony_ci GateRef ExtendArrayCheck(GateRef glue, GateRef elements, GateRef newLen, 754514f5e3Sopenharmony_ci RegionSpaceFlag spaceType = RegionSpaceFlag::IN_YOUNG_SPACE); 764514f5e3Sopenharmony_ci void ExtendArray(Variable *result, GateRef glue, GateRef elements, GateRef newLen, Label *exit, 774514f5e3Sopenharmony_ci RegionSpaceFlag spaceType = RegionSpaceFlag::IN_YOUNG_SPACE, bool isMutantArray = false); 784514f5e3Sopenharmony_ci void ExtendMutantArray(Variable *result, GateRef glue, GateRef elements, GateRef newLen, Label *exit, 794514f5e3Sopenharmony_ci RegionSpaceFlag spaceType = RegionSpaceFlag::IN_YOUNG_SPACE); 804514f5e3Sopenharmony_ci GateRef NewJSArrayWithSize(GateRef hclass, GateRef size); 814514f5e3Sopenharmony_ci GateRef NewJSForinIterator(GateRef glue, GateRef receiver, GateRef keys, GateRef cachedHclass); 824514f5e3Sopenharmony_ci GateRef LoadHClassFromMethod(GateRef glue, GateRef method); 834514f5e3Sopenharmony_ci GateRef LoadSHClassFromMethod(GateRef glue, GateRef method); 844514f5e3Sopenharmony_ci GateRef NewJSFunction(GateRef glue, GateRef method, 854514f5e3Sopenharmony_ci FunctionKind targetKind = FunctionKind::LAST_FUNCTION_KIND); 864514f5e3Sopenharmony_ci GateRef NewJSSendableFunction(GateRef glue, GateRef method, 874514f5e3Sopenharmony_ci FunctionKind targetKind = FunctionKind::LAST_FUNCTION_KIND); 884514f5e3Sopenharmony_ci void NewJSFunction(GateRef glue, GateRef jsFunc, GateRef index, GateRef length, GateRef lexEnv, 894514f5e3Sopenharmony_ci Variable *result, Label *success, Label *failed, GateRef slotId, 904514f5e3Sopenharmony_ci FunctionKind targetKind = FunctionKind::LAST_FUNCTION_KIND); 914514f5e3Sopenharmony_ci void SetProfileTypeInfoCellToFunction(GateRef jsFunc, GateRef definedFunc, GateRef slotId); 924514f5e3Sopenharmony_ci GateRef NewJSBoundFunction(GateRef glue, GateRef target, GateRef boundThis, GateRef args); 934514f5e3Sopenharmony_ci GateRef EnumerateObjectProperties(GateRef glue, GateRef obj); 944514f5e3Sopenharmony_ci void NewArgumentsList(Variable *result, Label *exit, GateRef sp, GateRef startIdx, GateRef numArgs); 954514f5e3Sopenharmony_ci void FillArgumentsList(GateRef argumentsList, GateRef sp, GateRef startIdx, GateRef numArgs); 964514f5e3Sopenharmony_ci GateRef NewArgumentsListObj(GateRef numArgs); 974514f5e3Sopenharmony_ci void NewArgumentsObj(Variable *result, Label *exit, GateRef argumentsList, GateRef numArgs); 984514f5e3Sopenharmony_ci void AssignRestArg(Variable *result, Label *exit, GateRef sp, GateRef startIdx, GateRef numArgs, 994514f5e3Sopenharmony_ci GateRef intialHClass); 1004514f5e3Sopenharmony_ci void AllocLineStringObject(Variable *result, Label *exit, GateRef length, bool compressed); 1014514f5e3Sopenharmony_ci void AllocSlicedStringObject(Variable *result, Label *exit, GateRef from, GateRef length, 1024514f5e3Sopenharmony_ci FlatStringStubBuilder *flatString); 1034514f5e3Sopenharmony_ci void AllocTreeStringObject(Variable *result, Label *exit, GateRef first, GateRef second, 1044514f5e3Sopenharmony_ci GateRef length, bool compressed); 1054514f5e3Sopenharmony_ci void HeapAlloc(Variable *result, Label *exit, RegionSpaceFlag spaceType, GateRef hclass); 1064514f5e3Sopenharmony_ci void NewJSArrayLiteral(Variable *result, Label *exit, RegionSpaceFlag spaceType, GateRef obj, GateRef hclass, 1074514f5e3Sopenharmony_ci GateRef trackInfo, bool isEmptyArray); 1084514f5e3Sopenharmony_ci GateRef NewTrackInfo(GateRef glue, GateRef cachedHClass, GateRef cachedFunc, RegionSpaceFlag spaceFlag, 1094514f5e3Sopenharmony_ci GateRef arraySize); 1104514f5e3Sopenharmony_ci // Note: The size is the num of bytes, it is required to be divisible by 8. 1114514f5e3Sopenharmony_ci void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef value, GateRef start, GateRef end, 1124514f5e3Sopenharmony_ci MemoryAttribute mAttr = MemoryAttribute::Default()); 1134514f5e3Sopenharmony_ci GateRef FastNewThisObject(GateRef glue, GateRef ctor); 1144514f5e3Sopenharmony_ci GateRef FastSuperAllocateThis(GateRef glue, GateRef superCtor, GateRef newTarget); 1154514f5e3Sopenharmony_ci GateRef NewThisObjectChecked(GateRef glue, GateRef ctor); 1164514f5e3Sopenharmony_ci GateRef CreateEmptyObject(GateRef glue); 1174514f5e3Sopenharmony_ci GateRef CreateEmptyArray(GateRef glue); 1184514f5e3Sopenharmony_ci GateRef CreateEmptyArray(GateRef glue, GateRef jsFunc, TraceIdInfo traceIdInfo, 1194514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef slotId, ProfileOperation callback); 1204514f5e3Sopenharmony_ci GateRef CreateArrayWithBuffer(GateRef glue, GateRef index, GateRef jsFunc, TraceIdInfo traceIdInfo, 1214514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef slotId, ProfileOperation callback); 1224514f5e3Sopenharmony_ci void NewTaggedArrayChecked(Variable *result, GateRef len, Label *exit); 1234514f5e3Sopenharmony_ci void NewMutantTaggedArrayChecked(Variable *result, GateRef len, Label *exit); 1244514f5e3Sopenharmony_ci template <typename IteratorType, typename CollectionType> 1254514f5e3Sopenharmony_ci void CreateJSCollectionIterator(Variable *result, Label *exit, GateRef set, GateRef kind); 1264514f5e3Sopenharmony_ci void CreateJSTypedArrayIterator(Variable *result, Label *exit, GateRef set, GateRef kind); 1274514f5e3Sopenharmony_ci GateRef NewTaggedSubArray(GateRef glue, GateRef srcTypedArray, GateRef elementSize, GateRef newLength, 1284514f5e3Sopenharmony_ci GateRef beginIndex, GateRef arrayCls, GateRef buffer); 1294514f5e3Sopenharmony_ci GateRef NewTypedArray(GateRef glue, GateRef srcTypedArray, GateRef srcType, GateRef length); 1304514f5e3Sopenharmony_ci GateRef NewJSObjectByConstructor(GateRef glue, GateRef constructor, GateRef newTarget); 1314514f5e3Sopenharmony_ci GateRef NewFloat32ArrayObj(GateRef glue, GateRef glueGlobalEnv); 1324514f5e3Sopenharmony_ci GateRef NewFloat32ArrayWithSize(GateRef glue, GateRef size); 1334514f5e3Sopenharmony_ci GateRef NewTypedArrayFromCtor(GateRef glue, GateRef ctor, GateRef length, Label *slowPath); 1344514f5e3Sopenharmony_ci void NewByteArray(Variable *result, Label *exit, GateRef elementSize, GateRef length); 1354514f5e3Sopenharmony_ci GateRef NewProfileTypeInfoCell(GateRef glue, GateRef value); 1364514f5e3Sopenharmony_ci GateRef GetElementSizeFromType(GateRef glue, GateRef type); 1374514f5e3Sopenharmony_ci GateRef GetOnHeapHClassFromType(GateRef glue, GateRef type); 1384514f5e3Sopenharmony_ciprivate: 1394514f5e3Sopenharmony_ci static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50; 1404514f5e3Sopenharmony_ci GateRef LoadTrackInfo(GateRef glue, GateRef jsFunc, TraceIdInfo traceIdInfo, 1414514f5e3Sopenharmony_ci GateRef profileTypeInfo, GateRef slotId, GateRef slotValue, GateRef arrayLiteral, ProfileOperation callback); 1424514f5e3Sopenharmony_ci GateRef LoadArrayHClassSlowPath( 1434514f5e3Sopenharmony_ci GateRef glue, GateRef jsFunc, TraceIdInfo traceIdInfo, GateRef arrayLiteral, ProfileOperation callback); 1444514f5e3Sopenharmony_ci GateRef CreateEmptyArrayCommon(GateRef glue, GateRef hclass, GateRef trackInfo); 1454514f5e3Sopenharmony_ci void AllocateInYoungPrologue(Variable *result, Label *callRuntime, Label *exit); 1464514f5e3Sopenharmony_ci void AllocateInYoung(Variable *result, Label *exit, GateRef hclass); 1474514f5e3Sopenharmony_ci void AllocateInYoung(Variable *result, Label *error, Label *noError, GateRef hclass); 1484514f5e3Sopenharmony_ci void AllocateInSOldPrologue(Variable *result, Label *callRuntime, Label *exit); 1494514f5e3Sopenharmony_ci void AllocateInSOld(Variable *result, Label *exit, GateRef hclass); 1504514f5e3Sopenharmony_ci void InitializeTaggedArrayWithSpeicalValue(Label *exit, 1514514f5e3Sopenharmony_ci GateRef array, GateRef value, GateRef start, GateRef length); 1524514f5e3Sopenharmony_ci GateRef glue_ {Circuit::NullGate()}; 1534514f5e3Sopenharmony_ci GateRef size_ {0}; 1544514f5e3Sopenharmony_ci}; 1554514f5e3Sopenharmony_ci} // namespace panda::ecmascript::kungfu 1564514f5e3Sopenharmony_ci#endif // ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H 157