• 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_BYTECODE_LOWERING_H
17 #define ECMASCRIPT_COMPILER_NTYPE_BYTECODE_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 NTypeBytecodeLowering {
27 public:
NTypeBytecodeLowering(Circuit * circuit,PassContext * ctx,TSManager * tsManager,bool enableLog,const std::string & name)28     NTypeBytecodeLowering(Circuit *circuit, PassContext *ctx, TSManager *tsManager,
29                           bool enableLog, const std::string& name)
30         : circuit_(circuit),
31           acc_(circuit),
32           builder_(circuit, ctx->GetCompilerConfig()),
33           tsManager_(tsManager),
34           ptManager_(ctx->GetPTManager()),
35           jsPandaFile_(ctx->GetJSPandaFile()),
36           enableLog_(enableLog),
37           profiling_(ctx->GetCompilerConfig()->IsProfiling()),
38           traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
39           methodName_(name),
40           glue_(acc_.GetGlueFromArgList()),
41           argAcc_(circuit),
42           thread_(ctx->GetEcmaVM()->GetJSThread()) {}
43 
44     ~NTypeBytecodeLowering() = default;
45 
46     void RunNTypeBytecodeLowering();
47 private:
48     void Lower(GateRef gate);
49     void LowerNTypedCreateEmptyArray(GateRef gate);
50     void LowerNTypedCreateArrayWithBuffer(GateRef gate);
51     void LowerNTypedStownByIndex(GateRef gate);
52     void LowerLdLexVar(GateRef gate);
53     void LowerStLexVar(GateRef gate);
54     void LowerThrowUndefinedIfHoleWithName(GateRef gate);
55     void LowerLdLocalMoudleVar(GateRef gate);
56     void LowerStModuleVar(GateRef gate);
57     void LowerNTypedStOwnByName(GateRef gate);
58 
IsLogEnabled()59     bool IsLogEnabled() const
60     {
61         return enableLog_;
62     }
63 
IsProfiling()64     bool IsProfiling() const
65     {
66         return profiling_;
67     }
68 
IsTraceBC()69     bool IsTraceBC() const
70     {
71         return traceBc_;
72     }
73 
GetMethodName()74     const std::string& GetMethodName() const
75     {
76         return methodName_;
77     }
78 
79     void AddProfiling(GateRef gate);
80     Circuit *circuit_ {nullptr};
81     GateAccessor acc_;
82     CircuitBuilder builder_;
83     TSManager *tsManager_ {nullptr};
84     PGOTypeManager *ptManager_ {nullptr};
85     const JSPandaFile *jsPandaFile_ {nullptr};
86     bool enableLog_ {false};
87     bool profiling_ {false};
88     bool traceBc_ {false};
89     std::string methodName_;
90     GateRef glue_ {Circuit::NullGate()};
91     ArgumentAccessor argAcc_;
92     const JSThread *thread_ {nullptr};
93 };
94 }  // panda::ecmascript::kungfu
95 #endif  // ECMASCRIPT_COMPILER_NTYPE_BYTECODE_LOWERING_H
96