• 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_NEW_OBJECT_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H
18 
19 #include "ecmascript/compiler/profiler_operation.h"
20 #include "ecmascript/compiler/stub_builder.h"
21 
22 namespace panda::ecmascript::kungfu {
23 class NewObjectStubBuilder : public StubBuilder {
24 public:
NewObjectStubBuilder(StubBuilder * parent)25     explicit NewObjectStubBuilder(StubBuilder *parent)
26         : StubBuilder(parent) {}
NewObjectStubBuilder(Environment * env)27     explicit NewObjectStubBuilder(Environment *env)
28         : StubBuilder(env) {}
29     ~NewObjectStubBuilder() override = default;
30     NO_MOVE_SEMANTIC(NewObjectStubBuilder);
31     NO_COPY_SEMANTIC(NewObjectStubBuilder);
GenerateCircuit()32     void GenerateCircuit() override {}
33 
SetParameters(GateRef glue,GateRef size)34     void SetParameters(GateRef glue, GateRef size)
35     {
36         glue_ = glue;
37         size_ = size;
38     }
39 
SetGlue(GateRef glue)40     void SetGlue(GateRef glue)
41     {
42         glue_ = glue;
43     }
44 
45     void NewLexicalEnv(Variable *result, Label *exit, GateRef numSlots, GateRef parent);
46     void NewJSObject(Variable *result, Label *exit, GateRef hclass);
47     GateRef NewJSObject(GateRef glue, GateRef hclass);
48     GateRef NewJSArray(GateRef glue, GateRef hclass);
49     GateRef NewTaggedArray(GateRef glue, GateRef len);
50     GateRef NewJSArrayWithSize(GateRef hclass, GateRef size);
51     void NewArgumentsList(Variable *result, Label *exit, GateRef sp, GateRef startIdx, GateRef numArgs);
52     void NewArgumentsObj(Variable *result, Label *exit, GateRef argumentsList, GateRef numArgs);
53     void AllocLineStringObject(Variable *result, Label *exit, GateRef length, bool compressed);
54     void HeapAlloc(Variable *result, Label *exit, RegionSpaceFlag spaceType);
55     void NewJSArrayLiteral(Variable *result, Label *exit, RegionSpaceFlag spaceType, GateRef obj, GateRef hclass,
56                            bool isEmptyArray);
57     void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef value, GateRef start, GateRef end);
58     GateRef FastNewThisObject(GateRef glue, GateRef ctor);
59     GateRef NewThisObjectChecked(GateRef glue, GateRef ctor);
60     GateRef CreateEmptyArray(GateRef glue, ProfileOperation callback);
61     GateRef CreateArrayWithBuffer(GateRef glue, GateRef index, GateRef jsFunc, ProfileOperation callback);
62     void NewTaggedArrayChecked(Variable *result, GateRef len, Label *exit);
63 
64 private:
65     static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50;
66     void AllocateInYoung(Variable *result, Label *exit);
67     void InitializeTaggedArrayWithSpeicalValue(Label *exit,
68         GateRef array, GateRef value, GateRef start, GateRef length);
69     GateRef glue_ {Circuit::NullGate()};
70     GateRef size_ {0};
71 };
72 }  // namespace panda::ecmascript::kungfu
73 #endif  // ECMASCRIPT_COMPILER_NEW_OBJECT_STUB_BUILDER_H
74