• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_BUILTINS_ARRAY_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_ARRAY_STUB_BUILDER_H
18 #include "ecmascript/compiler/circuit_builder.h"
19 #include "ecmascript/compiler/gate.h"
20 #include "ecmascript/compiler/share_gate_meta_data.h"
21 #include "ecmascript/compiler/stub_builder-inl.h"
22 #include "ecmascript/compiler/builtins/builtins_stubs.h"
23 
24 namespace panda::ecmascript::kungfu {
25 class BuiltinsArrayStubBuilder : public BuiltinsStubBuilder {
26 public:
BuiltinsArrayStubBuilder(StubBuilder * parent)27     explicit BuiltinsArrayStubBuilder(StubBuilder *parent)
28         : BuiltinsStubBuilder(parent) {}
BuiltinsArrayStubBuilder(Environment * env)29     explicit BuiltinsArrayStubBuilder(Environment* env): BuiltinsStubBuilder(env) {}
30     ~BuiltinsArrayStubBuilder() override = default;
31     NO_MOVE_SEMANTIC(BuiltinsArrayStubBuilder);
32     NO_COPY_SEMANTIC(BuiltinsArrayStubBuilder);
GenerateCircuit()33     void GenerateCircuit() override {}
34 
35 #define DECLARE_BUILTINS_ARRAY_STUB_BUILDER(method, ...)           \
36     void method(GateRef glue, GateRef thisValue, GateRef numArgs, Variable *result, Label *exit, Label *slowPath);
37 BUILTINS_WITH_ARRAY_STUB_BUILDER(DECLARE_BUILTINS_ARRAY_STUB_BUILDER)
38 #undef DECLARE_BUILTINS_ARRAY_STUB_BUILDER
39 
40     void Sort(GateRef glue, GateRef thisValue, GateRef numArgs, Variable *result, Label *exit, Label *slowPath);
41 
42     void SortAfterArgs(GateRef glue, GateRef thisValue, GateRef callbackFnHandle,
43                        Variable *result, Label *exit, Label *slowPath, GateRef hir = Circuit::NullGate());
44 
45     void GenArrayConstructor(GateRef glue, GateRef nativeCode, GateRef func,
46         GateRef newTarget, GateRef thisValue, GateRef numArgs);
47 
48     void FastCreateArrayWithArgv(GateRef glue, Variable *res, GateRef argc, GateRef hclass, Label *exit);
49 
50     void ElementsKindHclassCompare(GateRef glue, GateRef arrayCls, Label *matchCls, Label *slowPath);
51 
52     GateRef IsConcatSpreadable(GateRef glue, GateRef obj);
53 
54     GateRef NewArray(GateRef glue, GateRef count);
55 
56     GateRef CalculatePositionWithLength(GateRef position, GateRef length);
57 
58     GateRef DoReverse(GateRef glue, GateRef thisValue, GateRef receiver, GateRef receiverState,
59         Variable *result, Label *exit);
60 
61     GateRef DoSort(GateRef glue, GateRef receiver, GateRef receiverState,
62         Variable *result, Label *exit, Label *slowPath, GateRef hir = Circuit::NullGate());
63 
64     void FastReverse(GateRef glue, GateRef thisValue, GateRef len,
65                      ElementsKind kind, Variable *result, Label *exit);
66 private:
67     static constexpr uint32_t MAX_LENGTH_ZERO = 0;
68     static constexpr uint32_t MAX_LENGTH_ONE = 1;
69     struct JsArrayRequirements {
70         bool stable = false;
71         bool defaultConstructor = false;
72     };
73     GateRef IsJsArrayWithLengthLimit(GateRef glue, GateRef object,
74         uint32_t maxLength, JsArrayRequirements requirements);
75     GateRef CreateSpliceDeletedArray(GateRef glue, GateRef thisValue, GateRef actualDeleteCount,
76         GateRef intialHClass, GateRef start);
77 };
78 }  // namespace panda::ecmascript::kungfu
79 #endif  // ECMASCRIPT_COMPILER_BUILTINS_ARRAY_STUB_BUILDER_H
80