Commit 054dc72e authored by rmrf's avatar rmrf
Browse files

Cleanup code.

parent 9a814f4b
...@@ -2,39 +2,39 @@ ...@@ -2,39 +2,39 @@
using namespace scpar; using namespace scpar;
FindSCMain::FindSCMain ( TranslationUnitDecl *tuDecl, llvm::raw_ostream &os ): FindSCMain::FindSCMain ( TranslationUnitDecl *tuDecl, llvm::raw_ostream &os ) :
os_{os}, os_{os},
sc_main_function_declaration_{nullptr} { sc_main_function_declaration_{nullptr} {
assert (!( tuDecl == nullptr )); assert (!( tuDecl == nullptr ));
TraverseDecl( tuDecl ); TraverseDecl( tuDecl );
} }
FindSCMain::~FindSCMain() { FindSCMain::~FindSCMain() {
sc_main_function_declaration_ = nullptr; sc_main_function_declaration_ = nullptr;
} }
bool FindSCMain::VisitFunctionDecl( FunctionDecl *function_declaration ) { bool FindSCMain::VisitFunctionDecl( FunctionDecl *function_declaration ) {
/// Find sc_main. /// Find sc_main.
/// There are three conditions to satisfy this: /// There are three conditions to satisfy this:
/// 1. Must have sc_main in its name. /// 1. Must have sc_main in its name.
/// 2. Must have a body /// 2. Must have a body
/// 3. Must *not* be a first declaration. (This is becuase systemc.h includes a null definition of sc_main. /// 3. Must *not* be a first declaration. (This is becuase systemc.h includes a null definition of sc_main.
if ((function_declaration->getNameInfo ().getAsString () != "sc_main") if ((function_declaration->getNameInfo ().getAsString () != "sc_main")
|| (!function_declaration->hasBody ()) || (function_declaration->isMain ())) { || (!function_declaration->hasBody ()) || (function_declaration->isMain ())) {
return true; return true;
} }
sc_main_function_declaration_ = function_declaration; sc_main_function_declaration_ = function_declaration;
return true; return true;
} }
FunctionDecl *FindSCMain::getSCMainFunctionDecl() const { FunctionDecl *FindSCMain::getSCMainFunctionDecl() const {
assert ( sc_main_function_declaration_ != nullptr ); assert ( sc_main_function_declaration_ != nullptr );
return sc_main_function_declaration_; return sc_main_function_declaration_;
} }
bool FindSCMain::isSCMainFound() const { bool FindSCMain::isSCMainFound() const {
return ( sc_main_function_declaration_ != nullptr ); return ( sc_main_function_declaration_ != nullptr );
} }
#include "FindSimTime.h" #include "FindSimTime.h"
using namespace scpar; using namespace scpar;
FindSimTime::FindSimTime (FunctionDecl * tuDecl, llvm::raw_ostream & os): FindSimTime::FindSimTime ( FunctionDecl * tuDecl, llvm::raw_ostream & os ) :
_os (os), _sigInst (NULL), _callexpr (NULL) os_ (os) {
{ // _sigInst{nullptr},
assert (!(tuDecl == NULL)); // call_expr_{nullptr} {
TraverseDecl (tuDecl); assert (!(tuDecl == nullptr ));
TraverseDecl (tuDecl);
} }
FindSimTime::~FindSimTime () FindSimTime::~FindSimTime() {
{ simulation_time_.clear ();
_simTime.clear ();
} }
bool FindSimTime::VisitCallExpr (CallExpr * c) bool FindSimTime::VisitCallExpr( CallExpr * c ) {
{ if (c->getDirectCallee ()->getNameInfo ().getAsString () != "sc_start") {
if (c->getDirectCallee ()->getNameInfo ().getAsString () != "sc_start")
{
return true; return true;
} }
// _os << "Found sc_start"; // os_ << "Found sc_start";
if (c->getNumArgs () > 0) if (c->getNumArgs () > 0) {
{ // os_ <<"\n Simulation time is :" << getArgumentName(c->getArg(0));
// _os <<"\n Simulation time is :" << getArgumentName(c->getArg(0)); if (c->getNumArgs () > 1) {
if (c->getNumArgs () > 1) // os_ << " " << getArgumentName(c->getArg(1));
{ simulation_time_.insert (simulationTimePairType
// _os << " " << getArgumentName(c->getArg(1));
_simTime.insert (simulationTimePairType
(getArgumentName (c->getArg (0)), (getArgumentName (c->getArg (0)),
getArgumentName (c->getArg (1)))); getArgumentName (c->getArg (1))));
} }
...@@ -38,27 +34,25 @@ bool FindSimTime::VisitCallExpr (CallExpr * c) ...@@ -38,27 +34,25 @@ bool FindSimTime::VisitCallExpr (CallExpr * c)
} }
/* /*
string FindSimTime::getArgumentName (Expr * arg) string FindSimTime::getArgumentName (Expr * arg)
{ {
if (arg == NULL) if (arg == NULL)
return string ("NULL"); return string ("NULL");
clang::LangOptions LangOpts; clang::LangOptions LangOpts;
LangOpts.CPlusPlus = true; LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy (LangOpts); clang::PrintingPolicy Policy (LangOpts);
string string
TypeS; TypeS;
llvm::raw_string_ostream s (TypeS); llvm::raw_string_ostream s (TypeS);
arg->printPretty (s, 0, Policy); arg->printPretty (s, 0, Policy);
// _os << ", argument: " << s.str() << "\n"; // os_ << ", argument: " << s.str() << "\n";
return s.str (); return s.str ();
} }
*/ */
FindSimTime::simulationTimeMapType FindSimTime::returnSimTime () FindSimTime::simulationTimeMapType FindSimTime::returnSimTime() {
{ return simulation_time_;
return _simTime;
} }
...@@ -12,23 +12,25 @@ namespace scpar { ...@@ -12,23 +12,25 @@ namespace scpar {
using namespace clang; using namespace clang;
using namespace std; using namespace std;
class FindSimTime:public RecursiveASTVisitor < FindSimTime >, public Utility { class FindSimTime :
public RecursiveASTVisitor < FindSimTime >,
public Utility {
public: public:
typedef pair < string, string > simulationTimePairType; typedef pair <string, string> simulationTimePairType;
typedef map < string, string > simulationTimeMapType; typedef map <string, string> simulationTimeMapType;
FindSimTime (FunctionDecl *, llvm::raw_ostream &); FindSimTime( FunctionDecl *, llvm::raw_ostream & );
virtual ~FindSimTime(); virtual ~FindSimTime();
virtual bool VisitCallExpr(CallExpr * C); virtual bool VisitCallExpr( CallExpr * c );
simulationTimeMapType returnSimTime (); simulationTimeMapType returnSimTime();
private: private:
llvm::raw_ostream & _os; llvm::raw_ostream & os_;
FunctionDecl *_sigInst; // FunctionDecl *_sigInst;
simulationTimeMapType _simTime; simulationTimeMapType simulation_time_;
CallExpr *_callexpr; // CallExpr *call_expr_;
}; };
} }
#endif #endif
Markdown is supported
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