Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templateissue #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions llvm/include/llvm/DataFlowAnalysis/FlowSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#ifndef LLVM_DFA_FLOWSET_H
#define LLVM_DFA_FLOWSET_H
#include <iostream>

using namespace std;
namespace llvm{

template <class T>
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 T>
typename FlowSet<T>::Node* FlowSet<T>::m_spRoot = nullptr;
/*
template <typename T>
void FlowSet<T>::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
1 change: 1 addition & 0 deletions llvm/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/DataFlowAnalysis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_llvm_library(LLVMDFA
Hello.cpp
FlowSet.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/DataFlowAnalysis

DEPENDS
intrinsics_gen
)
25 changes: 25 additions & 0 deletions llvm/lib/DataFlowAnalysis/FlowSet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "llvm/DataFlowAnalysis/FlowSet.h"

using namespace llvm;

template <typename T>
void FlowSet<T>::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<int>;