• 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 
24 namespace panda::ecmascript::kungfu {
25 class AsyncFunctionLowering {
26 public:
AsyncFunctionLowering(BytecodeCircuitBuilder * bcBuilder,Circuit * circuit,CompilationConfig * cmpCfg,bool enableLog,const std::string & name)27     AsyncFunctionLowering(BytecodeCircuitBuilder *bcBuilder, Circuit *circuit, CompilationConfig *cmpCfg,
28                           bool enableLog, const std::string& name)
29         : bcBuilder_(bcBuilder), circuit_(circuit), builder_(circuit, cmpCfg), enableLog_(enableLog),
30           stateEntry_(circuit->GetStateRoot()),
31           dependEntry_(circuit->GetDependRoot()),
32           accessor_(circuit), argAccessor_(circuit), methodName_(name)
33     {
34     }
35 
36     ~AsyncFunctionLowering() = default;
37 
38     void ProcessAll();
39 
40     bool IsAsyncRelated() const;
41 
GetMethodName()42     const std::string& GetMethodName() const
43     {
44         return methodName_;
45     }
46 
47 private:
IsLogEnabled()48     bool IsLogEnabled() const
49     {
50         return enableLog_;
51     }
52 
53     void ProcessJumpTable();
54 
55     void RebuildGeneratorCfg(GateRef resumeGate, GateRef restoreOffsetGate, GateRef ifFalseCondition, GateRef newTarget,
56                              GateRef &firstState);
57 
58     void UpdateValueSelector(GateRef prevLoopBeginGate, GateRef controlStateGate, GateRef prevBcOffsetPhiGate);
59 
60     GateRef GetFirstRestoreRegister(GateRef gate) const;
61 
62     BytecodeCircuitBuilder *bcBuilder_;
63     Circuit *circuit_;
64     CircuitBuilder builder_;
65     [[maybe_unused]] bool enableLog_ {false};
66     GateRef stateEntry_ {Circuit::NullGate()};
67     GateRef dependEntry_ {Circuit::NullGate()};
68     GateAccessor accessor_;
69     ArgumentAccessor argAccessor_;
70     std::string methodName_;
71 };
72 }  // panda::ecmascript::kungfu
73 
74 #endif // ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_
75