diff --git a/llvm/include/llvm/DataFlowAnalysis/FlowSet.h b/llvm/include/llvm/DataFlowAnalysis/FlowSet.h new file mode 100644 index 00000000000000..48993b624d5686 --- /dev/null +++ b/llvm/include/llvm/DataFlowAnalysis/FlowSet.h @@ -0,0 +1,129 @@ +#ifndef LLVM_DFA_FLOWSET_H +#define LLVM_DFA_FLOWSET_H +#include + +using namespace std; +namespace llvm{ + +template +class FlowSet +{ + class Node; +public: + FlowSet() noexcept + { + m_spRoot = nullptr; + } + + class Iterator; + + Iterator begin() + { + return Iterator(m_spRoot); + } + + Iterator end() + { + return Iterator(nullptr); + } + + void push_back(T data); + + class Iterator + { + public: + Iterator() noexcept: + m_pCurrentNode(m_spRoot){ } + + Iterator(const Node* pNode) noexcept: + m_pCurrentNode(pNode){ } + + Iterator& operator=(Node* pNode) + { + this->m_pCurrentNode = pNode; + return *this; + } + + bool operator!=(const Iterator& it) + { + return this->m_pCurrentNode != it.m_pCurrentNode; + } + + bool operator==(const Iterator& it) + { + return this->m_pCurrentNode == it.m_pCurrentNode; + } + + Iterator& operator++() + { + if(m_pCurrentNode) + m_pCurrentNode = m_pCurrentNode->pNext; + return *this; + } + + // post increment (must be non reference) + Iterator operator++(int) + { + Iterator it = *this; + ++(*this); + return it; + } + + int operator*() + { + return m_pCurrentNode->data; + } + private: + const Node* m_pCurrentNode; + }; +private: + class Node + { + T data; + Node* pNext; + + friend class FlowSet; + }; + + Node* getNode(T data) + { + Node* pNewNode = new Node; + pNewNode->data = data; + pNewNode->pNext = nullptr; + + return pNewNode; + } + + Node*& getRootNode() + { + return m_spRoot; + } + + static Node* m_spRoot; +}; + +template +typename FlowSet::Node* FlowSet::m_spRoot = nullptr; +/* +template +void FlowSet::push_back(T data) +{ + Node* pTemp = getNode(data); + if(!getRootNode()) + { + getRootNode() = pTemp; + } + else + { + Node* pC = getRootNode(); + while(pC->pNext) + { + pC = pC->pNext; + } + pC->pNext = pTemp; + } +} +*/ +} // end namepspace llvm + +#endif // LLVM_DFA_FLOWSET_H diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt index 5a41d65b0cf377..42330a2ad3a5dc 100644 --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -28,6 +28,7 @@ add_subdirectory(Passes) add_subdirectory(TextAPI) add_subdirectory(ToolDrivers) add_subdirectory(XRay) +add_subdirectory(DataFlowAnalysis) if (LLVM_INCLUDE_TESTS) add_subdirectory(Testing) endif() diff --git a/llvm/lib/DataFlowAnalysis/CMakeLists.txt b/llvm/lib/DataFlowAnalysis/CMakeLists.txt new file mode 100644 index 00000000000000..360b3a31afc78b --- /dev/null +++ b/llvm/lib/DataFlowAnalysis/CMakeLists.txt @@ -0,0 +1,10 @@ +add_llvm_library(LLVMDFA + Hello.cpp + FlowSet.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/DataFlowAnalysis + + DEPENDS + intrinsics_gen + ) diff --git a/llvm/lib/DataFlowAnalysis/FlowSet.cpp b/llvm/lib/DataFlowAnalysis/FlowSet.cpp new file mode 100644 index 00000000000000..94be0ce7ffdf81 --- /dev/null +++ b/llvm/lib/DataFlowAnalysis/FlowSet.cpp @@ -0,0 +1,25 @@ +#include "llvm/DataFlowAnalysis/FlowSet.h" + +using namespace llvm; + +template +void FlowSet::push_back(T data) +{ + Node* pTemp = getNode(data); + if(!getRootNode()) + { + getRootNode() = pTemp; + } + else + { + Node* pC = getRootNode(); + while(pC->pNext) + { + pC = pC->pNext; + } + pC->pNext = pTemp; + } +} + + +template class llvm::FlowSet;