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/mem/chunk_containers.h" 24 25 namespace panda::ecmascript::kungfu { 26 class AsyncFunctionLowering { 27 public: AsyncFunctionLowering(BytecodeCircuitBuilder * bcBuilder,Circuit * circuit,CompilationConfig * cmpCfg,bool enableLog,const std::string & name)28 AsyncFunctionLowering(BytecodeCircuitBuilder *bcBuilder, Circuit *circuit, CompilationConfig *cmpCfg, 29 bool enableLog, const std::string& name) 30 : bcBuilder_(bcBuilder), circuit_(circuit), builder_(circuit, cmpCfg), enableLog_(enableLog), 31 accessor_(circuit), argAccessor_(circuit), stateEntry_(GetEntryBBStateOut()), 32 dependEntry_(GetEntryBBDependOut()), 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 bool genNewValuePhiGate = true); 60 61 void CheckResumeInLoopBody(GateRef stateInGate, bool &resumeInLoopBody); 62 63 void ModifyStateInput(GateRef stateInGate, GateRef ifBranch, GateRef ifFalse); 64 65 GateRef GetDependPhiFromLoopBegin(GateRef loopbegin) const; 66 67 GateRef GetEntryBBStateOut() const; 68 69 GateRef GetEntryBBDependOut() const; 70 71 BytecodeCircuitBuilder *bcBuilder_; 72 Circuit *circuit_; 73 CircuitBuilder builder_; 74 bool enableLog_ {false}; 75 GateAccessor accessor_; 76 ArgumentAccessor argAccessor_; 77 GateRef stateEntry_ {Circuit::NullGate()}; 78 GateRef dependEntry_ {Circuit::NullGate()}; 79 std::string methodName_; 80 }; 81 } // panda::ecmascript::kungfu 82 83 #endif // ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_ 84