Commit 361d99c1 authored by Hiren Patel's avatar Hiren Patel

Merge branch 'code-cleanup' into 'master'

Code cleanup

See merge request !9
parents 3302c59f be634884
#!/bin/bash
##===================================================================
##
## It is important to use this script to set all the necessary paths.
......@@ -10,7 +11,7 @@ export LLVM_BUILD_DIR=/home/$USER/clang-7.0.0/
# Path where SystemC is installed
# SET this.
export SYSTEMC=/home/$USER/sw/systemc-2.3.3/
export SYSTEMC=/home/$USER/code/systemc-2.3.3/systemc/
# Path for the systemc-clang build directory
# SET this.
......
......@@ -2,39 +2,39 @@
using namespace scpar;
FindSCMain::FindSCMain ( TranslationUnitDecl *tuDecl, llvm::raw_ostream &os ):
os_{os},
sc_main_function_declaration_{nullptr} {
assert (!( tuDecl == nullptr ));
TraverseDecl( tuDecl );
}
FindSCMain::FindSCMain ( TranslationUnitDecl *tuDecl, llvm::raw_ostream &os ) :
os_{os},
sc_main_function_declaration_{nullptr} {
assert (!( tuDecl == nullptr ));
TraverseDecl( tuDecl );
}
FindSCMain::~FindSCMain() {
sc_main_function_declaration_ = nullptr;
sc_main_function_declaration_ = nullptr;
}
bool FindSCMain::VisitFunctionDecl( FunctionDecl *function_declaration ) {
/// Find sc_main.
/// There are three conditions to satisfy this:
/// 1. Must have sc_main in its name.
/// 2. Must have a body
/// 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")
|| (!function_declaration->hasBody ()) || (function_declaration->isMain ())) {
return true;
}
sc_main_function_declaration_ = function_declaration;
return true;
/// Find sc_main.
/// There are three conditions to satisfy this:
/// 1. Must have sc_main in its name.
/// 2. Must have a body
/// 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")
|| (!function_declaration->hasBody ()) || (function_declaration->isMain ())) {
return true;
}
sc_main_function_declaration_ = function_declaration;
return true;
}
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 {
return ( sc_main_function_declaration_ != nullptr );
return ( sc_main_function_declaration_ != nullptr );
}
#include "FindSimTime.h"
using namespace scpar;
FindSimTime::FindSimTime (FunctionDecl * tuDecl, llvm::raw_ostream & os):
_os (os), _sigInst (NULL), _callexpr (NULL)
{
assert (!(tuDecl == NULL));
FindSimTime::FindSimTime ( FunctionDecl * tuDecl, llvm::raw_ostream & os ) :
os_ (os) {
// _sigInst{nullptr},
// call_expr_{nullptr} {
TraverseDecl (tuDecl);
assert (!(tuDecl == nullptr ));
TraverseDecl (tuDecl);
}
FindSimTime::~FindSimTime ()
{
_simTime.clear ();
FindSimTime::~FindSimTime() {
simulation_time_.clear ();
}
bool FindSimTime::VisitCallExpr (CallExpr * c)
{
if (c->getDirectCallee ()->getNameInfo ().getAsString () != "sc_start")
{
bool FindSimTime::VisitCallExpr( CallExpr * c ) {
if (c->getDirectCallee ()->getNameInfo ().getAsString () != "sc_start") {
return true;
}
// _os << "Found sc_start";
if (c->getNumArgs () > 0)
{
// _os <<"\n Simulation time is :" << getArgumentName(c->getArg(0));
if (c->getNumArgs () > 1)
{
// _os << " " << getArgumentName(c->getArg(1));
_simTime.insert (simulationTimePairType
// os_ << "Found sc_start";
if (c->getNumArgs () > 0) {
// os_ <<"\n Simulation time is :" << getArgumentName(c->getArg(0));
if (c->getNumArgs () > 1) {
// os_ << " " << getArgumentName(c->getArg(1));
simulation_time_.insert (simulationTimePairType
(getArgumentName (c->getArg (0)),
getArgumentName (c->getArg (1))));
}
......@@ -38,27 +34,25 @@ bool FindSimTime::VisitCallExpr (CallExpr * c)
}
/*
string FindSimTime::getArgumentName (Expr * arg)
{
string FindSimTime::getArgumentName (Expr * arg)
{
if (arg == NULL)
return string ("NULL");
return string ("NULL");
clang::LangOptions LangOpts;
LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy (LangOpts);
string
TypeS;
TypeS;
llvm::raw_string_ostream s (TypeS);
arg->printPretty (s, 0, Policy);
// _os << ", argument: " << s.str() << "\n";
// os_ << ", argument: " << s.str() << "\n";
return s.str ();
}
}
*/
FindSimTime::simulationTimeMapType FindSimTime::returnSimTime ()
{
return _simTime;
FindSimTime::simulationTimeMapType FindSimTime::returnSimTime() {
return simulation_time_;
}
......@@ -12,23 +12,25 @@ namespace scpar {
using namespace clang;
using namespace std;
class FindSimTime:public RecursiveASTVisitor < FindSimTime >, public Utility {
class FindSimTime :
public RecursiveASTVisitor < FindSimTime >,
public Utility {
public:
typedef pair < string, string > simulationTimePairType;
typedef map < string, string > simulationTimeMapType;
typedef pair <string, string> simulationTimePairType;
typedef map <string, string> simulationTimeMapType;
FindSimTime (FunctionDecl *, llvm::raw_ostream &);
FindSimTime( FunctionDecl *, llvm::raw_ostream & );
virtual ~FindSimTime();
virtual bool VisitCallExpr(CallExpr * C);
virtual bool VisitCallExpr( CallExpr * c );
simulationTimeMapType returnSimTime ();
simulationTimeMapType returnSimTime();
private:
llvm::raw_ostream & _os;
FunctionDecl *_sigInst;
simulationTimeMapType _simTime;
CallExpr *_callexpr;
llvm::raw_ostream & os_;
// FunctionDecl *_sigInst;
simulationTimeMapType simulation_time_;
// CallExpr *call_expr_;
};
}
#endif
......@@ -5,9 +5,6 @@
using namespace scpar;
using namespace std;
//#include "json.hpp"
//using json = nlohmann:json;
Model::Model() {
}
......@@ -15,34 +12,34 @@ Model::Model() {
Model::~Model() {
// llvm::errs() << "\n[[ Destructor Model ]]\n";
// Delete all ModuleDecl pointers.
for (Model::moduleMapType::iterator mit = _modules.begin();
mit != _modules.end(); mit++) {
for (Model::moduleMapType::iterator mit = modules_.begin();
mit != modules_.end(); mit++) {
// Second is the ModuleDecl type.
delete mit->second;
}
_modules.clear();
modules_.clear();
}
Model::Model( const Model & from ) {
_modules = from._modules;
modules_ = from.modules_;
}
void Model::addModuleDecl( ModuleDecl * md ) {
_modules.insert( Model::modulePairType( md->getName(), md ) );
modules_.insert( Model::modulePairType( md->getName(), md ) );
}
void Model::addModuleDeclInstances( ModuleDecl* md, vector<ModuleDecl*> mdVec ) {
_moduleInstanceMap.insert(moduleInstancePairType(md, mdVec));
module_instance_map_.insert(moduleInstancePairType(md, mdVec));
}
void Model::addSimulationTime(FindSimTime::simulationTimeMapType simTime) {
_simTime = simTime;
simulation_time_ = simTime;
}
void Model::addEntryFunctionGPUMacroMap(entryFunctionGPUMacroMapType e) {
//_entryFunctionGPUMacroMap.insert(e.begin(), e.end());
_entryFunctionGPUMacroMap = e;
llvm::errs()<<" \n Size : " <<_entryFunctionGPUMacroMap.size()<<" " <<e.size();
//entry_function_gpu_macro_map_.insert(e.begin(), e.end());
entry_function_gpu_macro_map_ = e;
llvm::errs()<<" \n Size : " <<entry_function_gpu_macro_map_.size()<<" " <<e.size();
}
......@@ -52,34 +49,34 @@ void Model::addGlobalEvents(FindGlobalEvents::globalEventMapType eventMap) {
string eventName = it->first;
EventContainer *event = new EventContainer(eventName, it->second);
_eventMap.insert(eventPairType(eventName, event));
event_map_.insert(eventPairType(eventName, event));
}
}
void Model::addSCMain(FunctionDecl *fnDecl) {
_scmainFcDecl = fnDecl;
scmain_function_decl_ = fnDecl;
}
void Model::addNetlist( FindNetlist &n ) {
_instanceModuleMap = n.getInstanceModuleMap();
_portSignalMap = n.getPortSignalMap();
_instancePortSignalMap = n.getInstancePortSignalMap();
_instanceListModuleMap = n.getInstanceListModuleMap();
instance_module_map_ = n.getInstanceModuleMap();
port_signal_map_ = n.getPortSignalMap();
port_signal_instance_map_ = n.getInstancePortSignalMap();
module_instance_list_ = n.getInstanceListModuleMap();
updateModuleDecl();
}
void Model::updateModuleDecl() {
for (moduleMapType::iterator it = _modules.begin(), eit = _modules.end();
for (moduleMapType::iterator it = modules_.begin(), eit = modules_.end();
it != eit; it++) {
string moduleName = it->first;
ModuleDecl *md = it->second;
vector<string> instanceList;
llvm::errs() << "Finding instances for " << moduleName << " declaration: ";
if ( _instanceListModuleMap.find(moduleName) != _instanceListModuleMap.end() ) {
FindNetlist::instanceListModuleMapType::iterator instanceListModuleMapFind = _instanceListModuleMap.find(moduleName);
if ( module_instance_list_.find(moduleName) != module_instance_list_.end() ) {
FindNetlist::instanceListModuleMapType::iterator instanceListModuleMapFind = module_instance_list_.find(moduleName);
md->addInstances(instanceListModuleMapFind->second);
// Print the names of all the instances
......@@ -89,8 +86,8 @@ void Model::updateModuleDecl() {
llvm::errs() << "\n";
for (size_t i = 0 ; i < instanceListModuleMapFind->second.size(); i++) {
if (_instancePortSignalMap.find(instanceListModuleMapFind->second.at(i)) != _instancePortSignalMap.end()) {
FindNetlist::instancePortSignalMapType::iterator portSignalMapFound = _instancePortSignalMap.find(instanceListModuleMapFind->second.at(i));
if (port_signal_instance_map_.find(instanceListModuleMapFind->second.at(i)) != port_signal_instance_map_.end()) {
FindNetlist::instancePortSignalMapType::iterator portSignalMapFound = port_signal_instance_map_.find(instanceListModuleMapFind->second.at(i));
FindNetlist::portSignalMapType portSignalMap = portSignalMapFound->second;
md->addSignalBinding(portSignalMap);
......@@ -116,36 +113,36 @@ void Model::addSCModules(SCModules * m)
Model::moduleMapType Model::getModuleDecl()
{
return _modules;
return modules_;
}
Model::entryFunctionGPUMacroMapType Model::getEntryFunctionGPUMacroMap() {
llvm::errs()<<"\n return Size : " <<_entryFunctionGPUMacroMap.size();
return _entryFunctionGPUMacroMap;
llvm::errs()<<"\n return Size : " <<entry_function_gpu_macro_map_.size();
return entry_function_gpu_macro_map_;
}
Model::moduleInstanceMapType Model::getModuleInstanceMap() {
return _moduleInstanceMap;
return module_instance_map_;
}
Model::eventMapType Model::getEventMapType()
{
return _eventMap;
return event_map_;
}
unsigned int Model::getNumEvents() {
return (_eventMap.size() - 3);
return (event_map_.size() - 3);
}
void Model::dump( llvm::raw_ostream & os ) {
os << "\n# Number of modules : " << _modules.size();
os << "\n# Number of modules : " << modules_.size();
for (Model::moduleMapType::iterator mit = _modules.begin();
mit != _modules.end(); mit++) {
for (Model::moduleMapType::iterator mit = modules_.begin();
mit != modules_.end(); mit++) {
// Second is the ModuleDecl type.
vector<ModuleDecl*> instanceVec = _moduleInstanceMap[mit->second];
vector<ModuleDecl*> instanceVec = module_instance_map_[mit->second];
os << "\n# Module " << mit->first << ": " << instanceVec.size() << " instances.";
for (size_t i = 0; i < instanceVec.size(); i++) {
// os <<", instance: " << i + 1 << " ";
......@@ -154,28 +151,28 @@ void Model::dump( llvm::raw_ostream & os ) {
}
os << "\n\n";
os << "# Global events:\n";
for (Model::eventMapType::iterator it = _eventMap.begin(), ite =
_eventMap.end(); it != ite; it++) {
for (Model::eventMapType::iterator it = event_map_.begin(), ite =
event_map_.end(); it != ite; it++) {
os << " Event: " << it->first << " VarDecl: " << it->second << "\n";
}
os << "\n";
os << "# Simulation time: ";
for (FindSimTime::simulationTimeMapType::iterator it =
_simTime.begin(), eit = _simTime.end(); it != eit; it++) {
simulation_time_.begin(), eit = simulation_time_.end(); it != eit; it++) {
os << it->first << " " << it->second;
}
os << "\n\n";
os <<"# Netlist: " ;
for (FindNetlist::instanceModuleMapType::iterator it = _instanceModuleMap.begin(), eit = _instanceModuleMap.end(); it != eit; it++) {
for (FindNetlist::instanceModuleMapType::iterator it = instance_module_map_.begin(), eit = instance_module_map_.end(); it != eit; it++) {
os << "\n";
os << "Instance Name: " << it->first << ", module name : " << it->second;
string instanceName = it->first;
if (_instancePortSignalMap.find(instanceName) !=
_instancePortSignalMap.end()) {
if (port_signal_instance_map_.find(instanceName) !=
port_signal_instance_map_.end()) {
FindNetlist::instancePortSignalMapType::iterator instancePortSignalMapFound =
_instancePortSignalMap.find(instanceName);
port_signal_instance_map_.find(instanceName);
FindNetlist::portSignalMapType portSignalMap =
instancePortSignalMapFound->second;
for (FindNetlist::portSignalMapType::iterator pit =
......
......@@ -20,14 +20,14 @@ namespace scpar {
class Model {
public:
typedef pair < string, ModuleDecl * >modulePairType;
typedef map < string, ModuleDecl * >moduleMapType;
typedef pair < string, ModuleDecl * > modulePairType;
typedef map < string, ModuleDecl * > moduleMapType;
typedef pair < string, EventContainer * >eventPairType;
typedef map < string, EventContainer * >eventMapType;
typedef pair < string, EventContainer * > eventPairType;
typedef map < string, EventContainer * > eventMapType;
typedef pair<ModuleDecl*, vector<ModuleDecl*> >moduleInstancePairType;
typedef map<ModuleDecl*, vector<ModuleDecl*> >moduleInstanceMapType;
typedef pair<ModuleDecl*, vector<ModuleDecl*> > moduleInstancePairType;
typedef map<ModuleDecl*, vector<ModuleDecl*> > moduleInstanceMapType;
typedef pair<EntryFunctionContainer*, FindGPUMacro::forStmtGPUMacroMapType> entryFunctionGPUMacroPairType;
typedef map<EntryFunctionContainer*, FindGPUMacro::forStmtGPUMacroMapType> entryFunctionGPUMacroMapType;
......@@ -57,16 +57,16 @@ namespace scpar {
Model(const Model &);
protected:
moduleMapType _modules;
moduleInstanceMapType _moduleInstanceMap;
FindSimTime::simulationTimeMapType _simTime;
eventMapType _eventMap;
FunctionDecl *_scmainFcDecl;
FindNetlist::instanceModuleMapType _instanceModuleMap;
FindNetlist::portSignalMapType _portSignalMap;
FindNetlist::instancePortSignalMapType _instancePortSignalMap;
FindNetlist::instanceListModuleMapType _instanceListModuleMap;
entryFunctionGPUMacroMapType _entryFunctionGPUMacroMap;
moduleMapType modules_;
moduleInstanceMapType module_instance_map_;
FindSimTime::simulationTimeMapType simulation_time_;
eventMapType event_map_;
FunctionDecl *scmain_function_decl_;
FindNetlist::instanceModuleMapType instance_module_map_;
FindNetlist::portSignalMapType port_signal_map_;
FindNetlist::instancePortSignalMapType port_signal_instance_map_;
FindNetlist::instanceListModuleMapType module_instance_list_;
entryFunctionGPUMacroMapType entry_function_gpu_macro_map_;
};
}
#endif
......@@ -29,7 +29,8 @@ public:
);
//FrontendActionFactory *fe = newFrontendActionFactory < LightsCameraAction < A > >();
//Tool.run (fe);
Tool.run ( newFrontendActionFactory< LightsCameraAction<SystemCConsumer> >().get());
//Tool.run ( newFrontendActionFactory< LightsCameraAction<SystemCConsumer> >().get());
Tool.run ( newFrontendActionFactory< LightsCameraAction<A> >().get());
};
......
......@@ -51,8 +51,6 @@ using namespace clang::tooling;
#include "SCuitable/GlobalSuspensionAutomata.h"
#include "SCuitable/FindGPUMacro.h"
//#include "matchers/sc_module.h"
using namespace clang;
namespace scpar {
......@@ -60,9 +58,6 @@ namespace scpar {
class SystemCConsumer :
public ASTConsumer,
public RecursiveASTVisitor < SystemCConsumer > {
private:
public:
llvm::raw_ostream & _os;
SourceManager & _sm;
......@@ -77,7 +72,7 @@ namespace scpar {
Model *getSystemCModel();
virtual void HandleTranslationUnit(ASTContext & context);
virtual void HandleTranslationUnit(ASTContext & context);
ASTContext & _context;
private:
......@@ -89,22 +84,23 @@ namespace scpar {
}; // End class SystemCConsumer
class SystemCClang : public SystemCConsumer {
public:
SystemCClang( CompilerInstance &ci) :
SystemCConsumer(ci) {
}
bool postFire() {
return true;
}
};
template < typename A > class LightsCameraAction:
template <typename A> class LightsCameraAction:
public clang::ASTFrontendAction {
protected:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(CompilerInstance & ci, llvm::StringRef inFile) {
// virtual ASTConsumer * CreateASTConsumer(CompilerInstance & ci, StringRef) {
return std::unique_ptr<clang::ASTConsumer>(new SystemCConsumer(ci));
//return new A(ci);
return std::unique_ptr<clang::ASTConsumer>(new A(ci));
};
}; // End class LightsCameraAction
} // End namespace scpar
#endif
......@@ -16,24 +16,24 @@ namespace scpar {
// typedefs
typedef vector < string > waitArgVectorType;
WaitContainer ();
WaitContainer (CXXMethodDecl *, CallExpr *);
WaitContainer();
WaitContainer(CXXMethodDecl *, CallExpr *);
~WaitContainer ();
~WaitContainer();
// Copy constructor.
WaitContainer (const WaitContainer &);
WaitContainer(const WaitContainer &);
unsigned int getNumArgs ();
CXXMethodDecl *getEntryMethod ();
CallExpr *getASTNode ();
waitArgVectorType getArgList ();
unsigned int getNumArgs();
CXXMethodDecl *getEntryMethod();
CallExpr *getASTNode();
waitArgVectorType getArgList();
void dump (raw_ostream &, int tabn = 0);
void dump(raw_ostream &, int tabn = 0);
private:
void populateArgMap ();
string getArgString (Expr * e);
void populateArgMap();
string getArgString(Expr * e);
private:
CXXMethodDecl * _entryMethodDecl;
......
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