• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_ASYNC_FUNCTION_LOWRING_H_
17 #define ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_
18 
19 #include "ecmascript/compiler/bytecode_circuit_builder.h"
20 #include "ecmascript/compiler/circuit.h"
21 #include "ecmascript/compiler/circuit_builder-inl.h"
22 #include "ecmascript/compiler/circuit_builder.h"
23 #include "ecmascript/compiler/graph_visitor.h"
24 #include "ecmascript/mem/chunk_containers.h"
25 
26 namespace panda::ecmascript::kungfu {
27 class AsyncFunctionLowering {
28 public:
AsyncFunctionLowering(BytecodeCircuitBuilder * bcBuilder,Circuit * circuit,CompilationConfig * cmpCfg,bool enableLog,const std::string & name)29     AsyncFunctionLowering(BytecodeCircuitBuilder *bcBuilder, Circuit *circuit, CompilationConfig *cmpCfg,
30                           bool enableLog, const std::string& name)
31         : bcBuilder_(bcBuilder), circuit_(circuit), builder_(circuit, cmpCfg), enableLog_(enableLog),
32           accessor_(circuit), argAccessor_(circuit), stateEntry_(GetEntryBBStateOut()),
33           dependEntry_(GetEntryBBDependOut()), methodName_(name)
34     {
35     }
36 
37     ~AsyncFunctionLowering() = default;
38 
39     void ProcessAll();
40 
41     bool IsAsyncRelated() const;
42 
GetMethodName()43     const std::string& GetMethodName() const
44     {
45         return methodName_;
46     }
47 
48 private:
IsLogEnabled()49     bool IsLogEnabled() const
50     {
51         return enableLog_;
52     }
53 
54     void ProcessJumpTable();
55 
56     void RebuildGeneratorCfg(GateRef resumeGate, GateRef restoreOffsetGate, GateRef ifFalseCondition, GateRef newTarget,
57                              GateRef &firstState);
58 
59     void UpdateValueSelector(GateRef prevLoopBeginGate, GateRef controlStateGate, GateRef prevBcOffsetPhiGate,
60                              bool genNewValuePhiGate = true);
61 
62     void CheckResumeInLoopBody(GateRef stateInGate, bool &resumeInLoopBody);
63 
64     void ModifyStateInput(GateRef stateInGate, GateRef ifBranch, GateRef ifFalse);
65 
66     GateRef GetDependPhiFromLoopBegin(GateRef loopbegin) const;
67 
68     GateRef GetEntryBBStateOut() const;
69 
70     GateRef GetEntryBBDependOut() const;
71 
72     BytecodeCircuitBuilder *bcBuilder_;
73     Circuit *circuit_;
74     CircuitBuilder builder_;
75     bool enableLog_ {false};
76     GateAccessor accessor_;
77     ArgumentAccessor argAccessor_;
78     GateRef stateEntry_ {Circuit::NullGate()};
79     GateRef dependEntry_ {Circuit::NullGate()};
80     std::string methodName_;
81 };
82 }  // panda::ecmascript::kungfu
83 
84 #endif // ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_
85