• 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_HCR_LOWERING_H
17 #define ECMASCRIPT_COMPILER_NTYPE_HCR_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 
25 namespace panda::ecmascript::kungfu {
26 class NTypeHCRLowering {
27 public:
NTypeHCRLowering(Circuit * circuit,PassContext * ctx,TSManager * tsManager,const CString & recordName,bool enableLog,const std::string & name)28     NTypeHCRLowering(Circuit *circuit, PassContext *ctx, TSManager *tsManager,
29                      const CString &recordName, bool enableLog, const std::string& name)
30         : circuit_(circuit),
31           acc_(circuit),
32           builder_(circuit, ctx->GetCompilerConfig()),
33           recordName_(recordName),
34           tsManager_(tsManager),
35           enableLog_(enableLog),
36           profiling_(ctx->GetCompilerConfig()->IsProfiling()),
37           traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
38           methodName_(name),
39           glue_(acc_.GetGlueFromArgList()) {}
40 
41     ~NTypeHCRLowering() = default;
42 
43     void RunNTypeHCRLowering();
44 private:
45     void Lower(GateRef gate);
46     void LowerNTypedCreateEmptyArray(GateRef gate);
47     void LowerNTypedCreateArrayWithBuffer(GateRef gate);
48     void LowerNTypedStownByIndex(GateRef gate);
49     void LowerNTypedStOwnByName(GateRef gate);
50     void LowerLdLexVar(GateRef gate);
51     void LowerStLexVar(GateRef gate);
52     void LowerThrowUndefinedIfHoleWithName(GateRef gate);
53 
IsLogEnabled()54     bool IsLogEnabled() const
55     {
56         return enableLog_;
57     }
58 
IsProfiling()59     bool IsProfiling() const
60     {
61         return profiling_;
62     }
63 
IsTraceBC()64     bool IsTraceBC() const
65     {
66         return traceBc_;
67     }
68 
GetMethodName()69     const std::string& GetMethodName() const
70     {
71         return methodName_;
72     }
73 
74     void AddProfiling(GateRef gate);
75     Circuit *circuit_ {nullptr};
76     GateAccessor acc_;
77     CircuitBuilder builder_;
78     const CString &recordName_;
79     TSManager *tsManager_ {nullptr};
80     bool enableLog_ {false};
81     bool profiling_ {false};
82     bool traceBc_ {false};
83     std::string methodName_;
84     GateRef glue_ {Circuit::NullGate()};
85 };
86 }  // panda::ecmascript::kungfu
87 #endif  // ECMASCRIPT_COMPILER_NTYPE_HCR_LOWERING_H
88