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_DEPEND_CHAIN_HELPER_H 17 #define ECMASCRIPT_COMPILER_DEPEND_CHAIN_HELPER_H 18 19 #include "ecmascript/compiler/circuit_builder.h" 20 #include "ecmascript/compiler/gate_accessor.h" 21 #include "ecmascript/mem/chunk_containers.h" 22 23 namespace panda::ecmascript::kungfu { 24 class DependChains : public ChunkObject { 25 public:struct Node { NodeNode26 Node(GateRef gate, Node* next) : gate(gate), next(next) {} 27 GateRef gate; 28 Node *next; 29 }; 30 31 struct DependChainIterator { 32 public: DependChainIteratorDependChainIterator33 DependChainIterator(Node* node) : node_(node) {} 34 35 DependChainIterator& operator++() 36 { 37 ASSERT(node_ != nullptr); 38 node_ = node_->next; 39 return *this; 40 } 41 42 bool operator!=(const DependChainIterator& that) const 43 { 44 return node_ != that.node_; 45 } 46 GetCurrentGateDependChainIterator47 GateRef GetCurrentGate() 48 { 49 return node_->gate; 50 } 51 private: 52 Node* node_; 53 }; 54 DependChains(Chunk * chunk)55 DependChains(Chunk* chunk) : chunk_(chunk) {} 56 ~DependChains() = default; 57 58 DependChains* UpdateNode(GateRef gate); 59 bool Equals(DependChains* that); 60 void Merge(DependChains* that); CopyFrom(DependChains * other)61 void CopyFrom(DependChains *other) 62 { 63 head_ = other->head_; 64 size_ = other->size_; 65 } 66 GetHeadGate()67 GateRef GetHeadGate() 68 { 69 return head_->gate; 70 } 71 begin()72 DependChainIterator begin() 73 { 74 return DependChainIterator(head_); 75 } 76 end()77 DependChainIterator end() 78 { 79 return DependChainIterator(nullptr); 80 } 81 82 private: 83 Node *head_{nullptr}; 84 size_t size_ {0}; 85 Chunk* chunk_; 86 }; 87 } // panda::ecmascript::kungfu 88 #endif // ECMASCRIPT_COMPILER_DEPEND_CHAIN_HELPER_H