Commit d439b174 authored by Anirudh's avatar Anirudh
Browse files

Utility functions

parent 2e1e7b4e
......@@ -24,7 +24,7 @@ add_library (libsystemc-clang
####################################
#From here the files are for the reflection database
####################################
Utility.cpp
#Utility.cpp
EntryFunctionContainer.cpp
WaitContainer.cpp
NotifyContainer.cpp
......
......@@ -37,6 +37,7 @@ bool FindSimTime::VisitCallExpr (CallExpr * c)
return true;
}
/*
string FindSimTime::getArgumentName (Expr * arg)
{
if (arg == NULL)
......@@ -55,6 +56,7 @@ string FindSimTime::getArgumentName (Expr * arg)
// _os << ", argument: " << s.str() << "\n";
return s.str ();
}
*/
FindSimTime::simulationTimeMapType FindSimTime::returnSimTime ()
{
......
......@@ -6,28 +6,23 @@
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/PrettyPrinter.h"
#include <map>
#include "Utility.h"
namespace scpar {
using namespace clang;
using namespace std;
class FindSimTime:public RecursiveASTVisitor < FindSimTime > {
class FindSimTime:public RecursiveASTVisitor < FindSimTime >, public Utility {
public:
typedef pair < string, string > simulationTimePairType;
typedef map < string, string > simulationTimeMapType;
FindSimTime (FunctionDecl *, llvm::raw_ostream &
);
~FindSimTime (
);
virtual bool VisitCallExpr (CallExpr * C
);
string getArgumentName (Expr * arg
);
simulationTimeMapType returnSimTime (
);
FindSimTime (FunctionDecl *, llvm::raw_ostream &);
~FindSimTime ();
virtual bool VisitCallExpr (CallExpr * C);
simulationTimeMapType returnSimTime ();
private:
llvm::raw_ostream & _os;
......
......@@ -6,26 +6,13 @@ GlobalSuspensionAutomata::GlobalSuspensionAutomata(Model * systemCmodel,
ASTContext * a)
:_systemcModel(systemCmodel), _os(os), _a(a)
{
u = new Utility();
}
GlobalSuspensionAutomata::~GlobalSuspensionAutomata()
{
}
// ANI : Needs to be a template class
bool GlobalSuspensionAutomata::notInVector(vector<SusCFG*> vec, SusCFG* cand){
for (int i = 0; i<vec.size(); i++) {
if (vec.at(i) == cand) {
return 0;
}
}
return 1;
}
void GlobalSuspensionAutomata::initializeGpuMap() {
// GPU map algorithm.
......@@ -80,7 +67,7 @@ void GlobalSuspensionAutomata::initializeGpuMap() {
for (int k = 0; k<bCodeBlocks.size(); k++) {
if (_susCFGBlockGPUMacroMap.find(bCodeBlocks.at(k)) != _susCFGBlockGPUMacroMap.end()) {
// DP segment found
if(notInVector(tmpVec, bCodeBlocks.at(k))) {
if(!isElementPresent(tmpVec, bCodeBlocks.at(k))) {
susCFGBlockList.push_back(bCodeBlocks.at(k));
}
}
......@@ -96,7 +83,17 @@ void GlobalSuspensionAutomata::initializeGpuMap() {
// Actual gpu map algo starts here....
// use _commonTimeDPMap and for each timePair with more than one DP segment, do pseudo-knapsacking algo
for (commonTimeDPMapType::iterator cit = _commonTimeDPMap.begin(), cite = _commonTimeDPMap.end();
cit != cite;
cit++) {
_os <<"\n Time : " <<cit->first.first<<" " <<cit->first.second<<"\n";
for (int i = 0; i<cit->second.size(); i++) {
_os <<" "<<cit->second.at(i)<<" " <<cit->second.at(i)->getBlockID();
}
}
for (commonTimeDPMapType::iterator cit = _commonTimeDPMap.begin(), cite = _commonTimeDPMap.end();
cit != cite;
cit++) {
......
......@@ -3,11 +3,12 @@
#include "Model.h"
#include "FindGPUMacro.h"
#include "Utility.h"
namespace scpar {
using namespace clang;
using namespace std;
class GlobalSuspensionAutomata {
class GlobalSuspensionAutomata : public Utility{
public:
GlobalSuspensionAutomata (Model *, raw_ostream &, ASTContext *);
~GlobalSuspensionAutomata();
......@@ -42,7 +43,6 @@ namespace scpar {
typedef pair<timePairType, vector<SusCFG*> > commonTimeDPPairType;
typedef map<timePairType, vector<SusCFG*> > commonTimeDPMapType;
bool notInVector(vector<SusCFG*>, SusCFG*);
bool updateTransitionTime(Transition*);
void updateEventNotificationTime(Transition*);
void getTransportType();
......@@ -86,7 +86,7 @@ namespace scpar {
entryFunctionMacroMapType _entryFunctionGPUMacroMap;
susCFGBlockGPUMacroMapType _susCFGBlockGPUMacroMap;
commonTimeDPMapType _commonTimeDPMap;
Utility *u;
};
}
#endif
......@@ -884,7 +884,7 @@ bool SuspensionAutomata::isTimedWait(Stmt * stmt)
}
return false;
}
/*
string SuspensionAutomata::getArgumentName(Expr * arg)
{
if (arg == NULL)
......@@ -902,6 +902,7 @@ string SuspensionAutomata::getArgumentName(Expr * arg)
// _os << ", argument: " << s.str() << "\n";
return s.str();
}
*/
bool SuspensionAutomata::isDeltaWait(Stmt * stmt)
{
......
......@@ -115,7 +115,7 @@ namespace scpar {
//////////////////////////////////////////////////////////////////////////////
class SuspensionAutomata {
class SuspensionAutomata : public Utility{
public:
typedef vector < SusCFG * >susCFGVectorType;
......@@ -147,7 +147,7 @@ namespace scpar {
bool isEventWait(Stmt * stmt);
float getTime(Stmt *stmt);
string getEvent(Stmt *stmt);
string getArgumentName(Expr * arg);
//string getArgumentName(Expr * arg);
void addEvent(string);
void addSimTime(float);
susCFGVectorType getSusCFG();
......
......@@ -24,18 +24,77 @@ namespace scpar {
using namespace std;
class Utility {
public:
Utility (
);
Utility (){
}
/*
void tabit (llvm::raw_ostream &, int tabn);
string strip (string, string);
template < typename vec > vec removeDuplicate (vec);
template < typename vec, typename element > bool isElementPresent (vec, element);
template < typename element > string getArgumentName (element *);
*/
void tabit (raw_ostream & os, int tabn)
{
for (int i = 0; i < tabn; i++) {
os << " ";
}
}
template < typename vec > vec removeDuplicate (vec);
string strip (string s, string sub) {
// sub has "struct "
size_t pos = s.find (sub);
template < typename vec, typename element > bool isElementPresent (vec, element);
if (pos == string::npos) {
return s;
}
template < typename element > string getArgumentName (element *);
return s.erase (pos, sub.length ());
}
template < typename vec > vec removeDuplicate (vec vecInput) {
for (unsigned int i = 0; i < vecInput.size (); i++) {
for (unsigned int j = 0; j < vecInput.size (); j++)
{
if (i != j && vecInput.at (i) == vecInput.at (j))
{
vecInput.erase (vecInput.begin () + j);
}
}
}
return vecInput;
}
template < typename vec, typename element >
bool isElementPresent (vec vecInput, element elemInput) {
for (unsigned int i = 0; i < vecInput.size (); i++) {
if (elemInput == vecInput.at (i)) {
return true;
}
}
return false;
}
template < typename expressionArg > string getArgumentName (expressionArg * exp)
{
if (exp == NULL) {
return string ("NULL");
}
clang::LangOptions LangOpts;
LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy (LangOpts);
string TypeS;
llvm::raw_string_ostream s (TypeS);
exp->printPretty (s, 0, Policy);
return s.str ();
}
};
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment