• 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/pass_manager.h"
21 
22 namespace panda::ecmascript::kungfu {
23 class NTypeBytecodeLowering {
24 public:
NTypeBytecodeLowering(Circuit * circuit,PassContext * ctx,bool enableLog,const std::string & name,const CString & recordName)25     NTypeBytecodeLowering(Circuit *circuit, PassContext *ctx,
26                           bool enableLog, const std::string& name, const CString& recordName)
27         : circuit_(circuit),
28           acc_(circuit),
29           builder_(circuit, ctx->GetCompilerConfig()),
30           ptManager_(ctx->GetPTManager()),
31           jsPandaFile_(ctx->GetJSPandaFile()),
32           enableLog_(enableLog),
33           profiling_(ctx->GetCompilerConfig()->IsProfiling()),
34           traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
35           methodName_(name),
36           recordName_(recordName),
37           glue_(acc_.GetGlueFromArgList()),
38           argAcc_(circuit),
39           compilationEnv_(ctx->GetCompilationEnv()) {}
40 
41     ~NTypeBytecodeLowering() = default;
42 
43     void RunNTypeBytecodeLowering();
44 private:
45     void Lower(GateRef gate);
46     void LowerNTypedCreateEmptyArray(GateRef gate);
47     void LowerNTypedCreateArrayWithBuffer(GateRef gate);
48     void LowerNTypedCopyRestArgs(GateRef gate);
49     void LowerNTypedGetUnmappedArgs(GateRef gate);
50     void LowerNTypedStownByIndex(GateRef gate);
51     void LowerLdLexVar(GateRef gate);
52     void LowerStLexVar(GateRef gate);
53     void LowerThrowUndefinedIfHoleWithName(GateRef gate);
54     void LowerLdLocalMoudleVar(GateRef gate);
55     void LowerStModuleVar(GateRef gate);
56     void LowerNTypedStOwnByName(GateRef gate);
57     void LowerThrowIfSuperNotCorrectCall(GateRef gate);
58     void LowerThrowIfNotObject(GateRef gate);
59 
IsLogEnabled()60     bool IsLogEnabled() const
61     {
62         return enableLog_;
63     }
64 
IsProfiling()65     bool IsProfiling() const
66     {
67         return profiling_;
68     }
69 
IsTraceBC()70     bool IsTraceBC() const
71     {
72         return traceBc_;
73     }
74 
GetMethodName()75     const std::string& GetMethodName() const
76     {
77         return methodName_;
78     }
79 
GetConstantpoolValue(uint32_t cpId)80     JSTaggedValue GetConstantpoolValue(uint32_t cpId)
81     {
82         return compilationEnv_->FindConstpool(jsPandaFile_, cpId);
83     }
84 
GetArrayLiteralValue(uint32_t cpId,uint32_t cpIdx)85     JSTaggedValue GetArrayLiteralValue(uint32_t cpId, uint32_t cpIdx)
86     {
87         JSTaggedValue cp = GetConstantpoolValue(cpId);
88         JSTaggedValue unsharedCp = compilationEnv_->FindOrCreateUnsharedConstpool(cp);
89         return compilationEnv_->GetArrayLiteralFromCache(unsharedCp, cpIdx, recordName_);
90     }
91 
92     enum SuperCorrectCallCheck : uint8_t {
93         CALL_SUPER_BEFORE_THIS_CHECK = 0,
94         FORBIDDEN_SUPER_REBIND_THIS_CHECK,
95     };
96 
97     void AddProfiling(GateRef gate);
98     Circuit *circuit_ {nullptr};
99     GateAccessor acc_;
100     CircuitBuilder builder_;
101     PGOTypeManager *ptManager_ {nullptr};
102     const JSPandaFile *jsPandaFile_ {nullptr};
103     bool enableLog_ {false};
104     bool profiling_ {false};
105     bool traceBc_ {false};
106     std::string methodName_;
107     const CString recordName_;
108     GateRef glue_ {Circuit::NullGate()};
109     ArgumentAccessor argAcc_;
110     const CompilationEnv *compilationEnv_ {nullptr};
111 };
112 }  // panda::ecmascript::kungfu
113 #endif  // ECMASCRIPT_COMPILER_NTYPE_BYTECODE_LOWERING_H
114