• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_NTYPE_MCR_LOWERING_H
17 #define ECMASCRIPT_COMPILER_NTYPE_MCR_LOWERING_H
18 
19 #include "ecmascript/compiler/argument_accessor.h"
20 #include "ecmascript/compiler/builtins/builtins_call_signature.h"
21 #include "ecmascript/compiler/bytecode_circuit_builder.h"
22 #include "ecmascript/compiler/circuit_builder-inl.h"
23 #include "ecmascript/compiler/pass_manager.h"
24 namespace panda::ecmascript::kungfu {
25 class NTypeMCRLowering {
26 public:
NTypeMCRLowering(Circuit * circuit,PassContext * ctx,const CString & recordName,bool enableLog,const std::string & name)27     NTypeMCRLowering(Circuit *circuit, PassContext *ctx, const CString &recordName,
28                      bool enableLog, const std::string& name)
29         : circuit_(circuit),
30           acc_(circuit),
31           builder_(circuit, ctx->GetCompilerConfig()),
32           dependEntry_(circuit->GetDependRoot()),
33           tsManager_(ctx->GetTSManager()),
34           recordName_(recordName),
35           enableLog_(enableLog),
36           profiling_(ctx->GetCompilerConfig()->IsProfiling()),
37           traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
38           methodName_(name),
39           glue_(acc_.GetGlueFromArgList()) {}
40 
41     ~NTypeMCRLowering() = default;
42 
43     void RunNTypeMCRLowering();
44 private:
45     static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50;
46     void Lower(GateRef gate);
47     void LowerCreateArray(GateRef gate, GateRef glue);
48     void LowerCreateArrayWithBuffer(GateRef gate);
49     void LowerCreateEmptyArray(GateRef gate);
50     void LowerCreateArrayWithOwn(GateRef gate, GateRef glue);
51     void LowerStLexVar(GateRef gate);
52     void LowerLdLexVar(GateRef gate);
53 
54     GateRef LoadFromConstPool(GateRef jsFunc, size_t index);
55     GateRef NewJSArrayLiteral(GateRef elements, GateRef length);
56     GateRef NewTaggedArray(size_t length);
57     GateRef LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
58                              bool useLabel = false);
59 
GetFrameState(GateRef gate)60     GateRef GetFrameState(GateRef gate) const
61     {
62         return acc_.GetFrameState(gate);
63     }
64 
IsLogEnabled()65     bool IsLogEnabled() const
66     {
67         return enableLog_;
68     }
69 
GetMethodName()70     const std::string& GetMethodName() const
71     {
72         return methodName_;
73     }
74 
75     Circuit *circuit_ {nullptr};
76     GateAccessor acc_;
77     CircuitBuilder builder_;
78     GateRef dependEntry_;
79     TSManager *tsManager_ {nullptr};
80     const CString &recordName_;
81     panda_file::File::EntityId methodId_ {0};
82     bool enableLog_ {false};
83     bool profiling_ {false};
84     bool traceBc_ {false};
85     std::string methodName_;
86     GateRef glue_ {Circuit::NullGate()};
87 };
88 }  // panda::ecmascript::kungfu
89 #endif  // ECMASCRIPT_COMPILER_NTYPE_MCR_LOWERING_H
90