Commit ac1d4b98 authored by Hiren Patel's avatar Hiren Patel

Merge branch 'code-cleanup' into 'master'

Code cleanup

See merge request !11
parents 52d34b6b 910e0a5d
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
project(systemc-clang) project(systemc-clang)
# Use C++ standard version to c++17
set(CMAKE_CXX_STANDARD 17)
# Always keep it on
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option (USE_SAUTO option (USE_SAUTO
"Use suspension-automata library." OFF "Use suspension-automata library." OFF
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
## It is important to use this script to set all the necessary paths. ## It is important to use this script to set all the necessary paths.
## ##
# Path for where the binaries are for clang # Path for where the binaries are for clang
# SET this. # SET this.
export LLVM_BUILD_DIR=/home/$USER/bin/clang-7.0.0/ export LLVM_BUILD_DIR=/home/$USER/bin/clang-7.0.0/
...@@ -26,10 +25,11 @@ LLVMCONFIG=$LLVM_BUILD_DIR/bin/llvm-config ...@@ -26,10 +25,11 @@ LLVMCONFIG=$LLVM_BUILD_DIR/bin/llvm-config
# Alternatively, you can use gcc and g++, but some flags don't work. # Alternatively, you can use gcc and g++, but some flags don't work.
export CC=clang export CC=clang
export CXX=clang++ export CXX=clang++
export LLVM_CXX_FLAGS=`$LLVMCONFIG --cxxflags` export LLVM_CXX_FLAGS="`$LLVMCONFIG --cxxflags` -fno-aligned-allocation"
# Generate all the flags. # Generate all the flags.
export LLVM_CXX_FLAGS="$LLVM_CXX_FLAGS -fvisibility-inlines-hidden" export LLVM_CXX_FLAGS="$LLVM_CXX_FLAGS -fvisibility-inlines-hidden"
export LLVM_LIBS=`$LLVMCONFIG --libs` export LLVM_LIBS=`$LLVMCONFIG --libs`
export LLVM_LD_FLAGS=`$LLVMCONFIG --ldflags` export LLVM_LD_FLAGS=`$LLVMCONFIG --ldflags`
export LLVM_LD_FLAGS=`echo $LLVM_LD_FLAGS | sed 's/ *$//g'` export LLVM_LD_FLAGS=`echo $LLVM_LD_FLAGS | sed 's/ *$//g'`
#! /usr/bin/fish
###===================================================================
##
## It is important to use this script to set all the necessary paths.
## This is a fish shell script.
##===================================================================
# Path for where the binaries are for clang
# SET this.
set -x LLVM_BUILD_DIR /home/$USER/bin/clang-7.0.0/
# Path where SystemC is installed
# SET this.
set -x SYSTEMC /home/$USER/code/systemc-2.3.3/systemc/
# Path for the systemc-clang build directory
# SET this.
set -x SYSTEMC_CLANG_BUILD_DIR /home/$USER/code/systemc-clang-build/
##===================================================================
set -x LLVMCOMPONENT cppbackend
set -x RTTIFLAG -fno-rtti
set -x LLVMCONFIG $LLVM_BUILD_DIR/bin/llvm-config
# New llvm/clang uses flags that are different than GNU gcc's
# Alternatively, you can use gcc and g++, but some flags don't work.
set -x CC clang
set -x CXX clang++
set -x LLVM_CXX_FLAGS (eval $LLVMCONFIG --cxxflags)
# Generate all the flags.
# -fno-aligned-allocation needed for c++17
set -x LLVM_CXX_FLAGS "$LLVM_CXX_FLAGS -fvisibility-inlines-hidden -fno-aligned-allocation"
set -x LLVM_LIBS (eval $LLVMCONFIG --libs)
set -x LLVM_LD_FLAGS (eval $LLVMCONFIG --ldflags)
set -x LLVM_LD_FLAGS (echo $LLVM_LD_FLAGS | sed 's/ *$//g')
add_library (libsystemc-clang add_library (libsystemc-clang
ModuleDecl.cpp ModuleDecl.cpp
FindModule.cpp FindModule.cpp
SCModules.cpp SCModules.cpp
FindSCMain.cpp FindSCMain.cpp
FindPorts.cpp FindPorts.cpp
FindTLMInterfaces.cpp FindTLMInterfaces.cpp
FindEvents.cpp FindEvents.cpp
FindGlobalEvents.cpp FindGlobalEvents.cpp
FindEntryFunctions.cpp FindEntryFunctions.cpp
FindSensitivity.cpp FindSensitivity.cpp
FindWait.cpp FindWait.cpp
FindNotify.cpp FindNotify.cpp
FindSignals.cpp FindSignals.cpp
FindSimTime.cpp FindSimTime.cpp
FindConstructor.cpp FindConstructor.cpp
SystemCClang.cpp SystemCClang.cpp
FindNetlist.cpp FindNetlist.cpp
FindArgument.cpp FindArgument.cpp
Automata.cpp Automata.cpp
SuspensionAutomata.cpp SuspensionAutomata.cpp
# SCuitable/GlobalSuspensionAutomata.cpp SCuitable/GlobalSuspensionAutomata.cpp
# SCuitable/FindGPUMacro.cpp SCuitable/FindGPUMacro.cpp
#################################### ####################################
#From here the files are for the reflection database #From here the files are for the reflection database
#################################### ####################################
#Utility.cpp #Utility.cpp
EntryFunctionContainer.cpp EntryFunctionContainer.cpp
WaitContainer.cpp WaitContainer.cpp
NotifyContainer.cpp NotifyContainer.cpp
EventDecl.cpp EventDecl.cpp
ProcessDecl.cpp ProcessDecl.cpp
Signal.cpp Signal.cpp
PortDecl.cpp PortDecl.cpp
InterfaceDecl.cpp InterfaceDecl.cpp
Model.cpp Model.cpp
WaitCalls.cpp WaitCalls.cpp
NotifyCalls.cpp NotifyCalls.cpp
EventContainer.cpp EventContainer.cpp
# AST MATCHERS # AST MATCHERS
# matchers/sc_module.cpp # matchers/sc_module.cpp
) )
...@@ -96,28 +96,24 @@ namespace scpar { ...@@ -96,28 +96,24 @@ namespace scpar {
return template_types_; return template_types_;
} }
void printTemplateArguments( llvm::raw_ostream &os, int tabn = 0 ) { void printTemplateArguments( llvm::raw_ostream &os ) {
vector < string > template_arguments; //{ getTemplateArguments() }; vector < string > template_arguments;
// type_vector_t::iterator
// for (auto mit = template_types_.begin(); mit != template_types_.end(); mit++) {
for ( auto const &mit: template_types_ ) { for ( auto const &mit: template_types_ ) {
for ( auto i{0}; i < tabn; ++i) { //os << "\n port type: " << mit.first << " ";
os << " "; //<< ", type ptr: " << mit.second;
} //os << "\n";
os << "- " << mit.first << ", type ptr: " << mit.second;
os << "\n";
template_arguments.push_back( mit.first ); template_arguments.push_back( mit.first );
} }
// Print the template arguments to the output stream // Print the template arguments to the output stream
os << "= "; os << ", " << template_arguments.size() << " arguments, ";
for ( auto const &targ: template_arguments ) { for ( auto const &targ: template_arguments ) {
os << targ << " "; os << targ << " ";
} }
} }
vector < string > getTemplateArguments() { vector<string> getTemplateArguments() {
vector < string > template_arguments; vector<string> template_arguments;
// type_vector_t::iterator // type_vector_t::iterator
// for ( auto mit = template_types_.begin(); mit != template_types_.end(); ++mit ) { // for ( auto mit = template_types_.begin(); mit != template_types_.end(); ++mit ) {
for ( auto const &mit: template_types_ ) { for ( auto const &mit: template_types_ ) {
......
...@@ -13,7 +13,7 @@ namespace scpar { ...@@ -13,7 +13,7 @@ namespace scpar {
class FindWait:public RecursiveASTVisitor < FindWait > { class FindWait:public RecursiveASTVisitor < FindWait > {
public: public:
typedef vector < CallExpr * >waitListType; typedef vector < CallExpr * > waitListType;
typedef pair < CXXMethodDecl *,vector < string > >processWaitEventPairType; typedef pair < CXXMethodDecl *,vector < string > >processWaitEventPairType;
typedef map < CXXMethodDecl *, vector < string > >processWaitEventMapType; typedef map < CXXMethodDecl *, vector < string > >processWaitEventMapType;
......
...@@ -44,5 +44,5 @@ void InterfaceDecl::dump(raw_ostream & os, int tabn) { ...@@ -44,5 +44,5 @@ void InterfaceDecl::dump(raw_ostream & os, int tabn) {
} }
os << "InterfaceDecl " << this << " '" << _name << "' FindTemplateTypes " << os << "InterfaceDecl " << this << " '" << _name << "' FindTemplateTypes " <<
_templateType; _templateType;
_templateType->printTemplateArguments(os, 1); _templateType->printTemplateArguments(os );
} }
...@@ -5,41 +5,42 @@ using namespace scpar; ...@@ -5,41 +5,42 @@ using namespace scpar;
using namespace std; using namespace std;
PortDecl::~PortDecl() { PortDecl::~PortDecl() {
if ( _templateType != nullptr ) { if ( template_type_ != nullptr ) {
delete _templateType; delete template_type_;
} }
} }
PortDecl::PortDecl():_name{"NONE"}, _templateType{nullptr} { PortDecl::PortDecl() :
port_name_{ "NONE" },
template_type_{ nullptr } {
} }
PortDecl::PortDecl(const string &name, FindTemplateTypes *tt):_name{name}, _templateType{tt} { PortDecl::PortDecl( const string &name, FindTemplateTypes *tt ) :
port_name_{ name },
template_type_{ tt } {
} }
PortDecl::PortDecl(const PortDecl &from) { PortDecl::PortDecl( const PortDecl &from ) {
_name = from._name; port_name_ = from.port_name_;
// This is necessary to allow FindPorts to go out of scope. // This is necessary to allow FindPorts to go out of scope.
_templateType = new FindTemplateTypes(*from._templateType); template_type_ = new FindTemplateTypes{ *from.template_type_ };
} }
void PortDecl::setModuleName(const string &name) { void PortDecl::setModuleName( const string &name ) {
_name = name; port_name_ = name;
} }
string PortDecl::getName() const { string PortDecl::getName() const {
return _name; return port_name_;
} }
FindTemplateTypes *PortDecl::getTemplateType() { FindTemplateTypes *PortDecl::getTemplateType() {
return _templateType; return template_type_;
} }
void PortDecl::dump(raw_ostream & os, int tabn) { void PortDecl::dump( llvm::raw_ostream & os, int tabn ) {
for ( auto i = 0; i < tabn; ++i ) { //os << "PortDecl " << this << " '" << port_name_ << "' FindTemplateTypes " << template_type_;
os << " "; os << "Port name: " << port_name_ << " ";
} template_type_->printTemplateArguments( os );
os << "PortDecl " << this << " '" << _name << "' FindTemplateTypes " <<
_templateType;
_templateType->printTemplateArguments(os, 1);
} }
...@@ -30,8 +30,8 @@ namespace scpar { ...@@ -30,8 +30,8 @@ namespace scpar {
void dump(raw_ostream &, int tabn = 0); void dump(raw_ostream &, int tabn = 0);
private: private:
string _name; string port_name_;
FindTemplateTypes *_templateType; FindTemplateTypes *template_type_;
}; };
} }
#endif #endif
...@@ -66,5 +66,5 @@ void ...@@ -66,5 +66,5 @@ void
} }
os << "Signal " << this << " '" << _name << "' FindTemplateTypes " << os << "Signal " << this << " '" << _name << "' FindTemplateTypes " <<
_sig->getTemplateTypes () << "' FieldDecl' " << _sig->getASTNode (); _sig->getTemplateTypes () << "' FieldDecl' " << _sig->getASTNode ();
_sig->getTemplateTypes ()->printTemplateArguments (os, tabn); _sig->getTemplateTypes ()->printTemplateArguments ( os );
} }
...@@ -130,8 +130,7 @@ namespace scpar { ...@@ -130,8 +130,7 @@ namespace scpar {
typedef pair<State*, vector<SusCFG*> > stateCommonCodeBlockPairType; typedef pair<State*, vector<SusCFG*> > stateCommonCodeBlockPairType;
typedef map<State *, vector<SusCFG*> > stateCommonCodeBlockMapType; typedef map<State *, vector<SusCFG*> > stateCommonCodeBlockMapType;
SuspensionAutomata(vector<WaitContainer*>, CXXMethodDecl *, ASTContext *, SuspensionAutomata(vector<WaitContainer*>, CXXMethodDecl *, ASTContext *, llvm::raw_ostream &);
raw_ostream &);
~SuspensionAutomata(); ~SuspensionAutomata();
void addRemainingBlocks(State*, vector<SusCFG*>&); void addRemainingBlocks(State*, vector<SusCFG*>&);
void checkInsert(vector<SusCFG*>, vector<SusCFG*>&); void checkInsert(vector<SusCFG*>, vector<SusCFG*>&);
......
...@@ -17,39 +17,37 @@ bool SystemCConsumer::postFire() { ...@@ -17,39 +17,37 @@ bool SystemCConsumer::postFire() {
bool SystemCConsumer::fire() { bool SystemCConsumer::fire() {
TranslationUnitDecl *tu = _context.getTranslationUnitDecl(); TranslationUnitDecl *tu{ _context.getTranslationUnitDecl() };
// Reflection database. // Reflection database.
_systemcModel = new Model(); _systemcModel = new Model{};
// Find the sc_modules // Find the sc_modules
SCModules scmod(tu, _os); SCModules scmod{ tu, _os };
// ANI : Do we need FindGlobalEvents? // ANI : Do we need FindGlobalEvents?
FindGlobalEvents fglobals(tu, _os); FindGlobalEvents fglobals{ tu, _os };
FindGlobalEvents::globalEventMapType eventMap = fglobals.getEventMap(); FindGlobalEvents::globalEventMapType eventMap { fglobals.getEventMap() };
_systemcModel->addGlobalEvents(eventMap); _systemcModel->addGlobalEvents(eventMap);
SCModules::moduleMapType scmodules = scmod.getSystemCModulesMap(); SCModules::moduleMapType scmodules{ scmod.getSystemCModulesMap() };
for ( SCModules::moduleMapType::iterator mit = scmodules.begin(), for ( SCModules::moduleMapType::iterator mit = scmodules.begin(),
mitend = scmodules.end(); mit != mitend; ++mit ) { mitend = scmodules.end(); mit != mitend; ++mit ) {
ModuleDecl *md = new ModuleDecl(mit->first, mit->second); ModuleDecl *md = new ModuleDecl{ mit->first, mit->second };
_systemcModel->addModuleDecl(md); _systemcModel->addModuleDecl(md);
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Find the sc_main // Find the sc_main
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
FindSCMain scmain(tu, _os); FindSCMain scmain{ tu, _os };
if ( scmain.isSCMainFound() ) { if ( scmain.isSCMainFound() ) {
FunctionDecl *fnDecl = scmain.getSCMainFunctionDecl(); FunctionDecl *fnDecl{ scmain.getSCMainFunctionDecl() };
FindSimTime scstart(fnDecl, _os); FindSimTime scstart{ fnDecl, _os };
_systemcModel->addSimulationTime(scstart.returnSimTime()); _systemcModel->addSimulationTime( scstart.returnSimTime() );
} else { } else {
_os <<"\n Could not find SCMain"; _os <<"\n Could not find SCMain";
} }
...@@ -57,81 +55,79 @@ bool SystemCConsumer::fire() { ...@@ -57,81 +55,79 @@ bool SystemCConsumer::fire() {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Find the netlist. // Find the netlist.
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
FindNetlist findNetlist(scmain.getSCMainFunctionDecl()); FindNetlist findNetlist{ scmain.getSCMainFunctionDecl() };
findNetlist.dump(); findNetlist.dump();
_systemcModel->addNetlist(findNetlist); _systemcModel->addNetlist(findNetlist);
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Figure out the module map. // Figure out the module map.
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
Model::moduleMapType moduleMap = _systemcModel->getModuleDecl(); Model::moduleMapType moduleMap{ _systemcModel->getModuleDecl() };
for (Model::moduleMapType::iterator mit = moduleMap.begin(), mitend = moduleMap.end(); mit != mitend; mit++) { for (Model::moduleMapType::iterator mit = moduleMap.begin(), mitend = moduleMap.end(); mit != mitend; mit++) {
ModuleDecl *mainmd = mit->second; ModuleDecl *mainmd{ mit->second };
int numInstances = mainmd->getNumInstances(); int numInstances{ mainmd->getNumInstances() };
vector<ModuleDecl*> moduleDeclVec; vector<ModuleDecl*> moduleDeclVec;
_os << "\n"; _os << "\n";
_os <<"For module: " << mit->first <<" num instance : " << numInstances; _os <<"For module: " << mit->first <<" num instance : " << numInstances;
for (unsigned int num {0}; num < numInstances; ++num ) { for (unsigned int num{0}; num < numInstances; ++num ) {
ModuleDecl *md = new ModuleDecl(); ModuleDecl *md = new ModuleDecl{};
vector < EntryFunctionContainer * >_entryFunctionContainerVector; vector <EntryFunctionContainer *> _entryFunctionContainerVector;
FindConstructor constructor(mainmd->getModuleClassDecl(), _os); FindConstructor constructor{ mainmd->getModuleClassDecl(), _os };
md->addConstructor(constructor.returnConstructorStmt()); md->addConstructor(constructor.returnConstructorStmt());
FindPorts ports(mainmd->getModuleClassDecl(), _os); FindPorts ports{ mainmd->getModuleClassDecl(), _os };
md->addInputPorts(ports.getInputPorts()); md->addInputPorts( ports.getInputPorts() );
md->addOutputPorts(ports.getOutputPorts()); md->addOutputPorts( ports.getOutputPorts() );
md->addInputOutputPorts(ports.getInputOutputPorts()); md->addInputOutputPorts( ports.getInputOutputPorts() );
FindTLMInterfaces findTLMInterfaces(mainmd->getModuleClassDecl(), _os); FindTLMInterfaces findTLMInterfaces{ mainmd->getModuleClassDecl(), _os };
md->addInputInterfaces(findTLMInterfaces.getInputInterfaces()); md->addInputInterfaces( findTLMInterfaces.getInputInterfaces() );
md->addOutputInterfaces(findTLMInterfaces.getOutputInterfaces()); md->addOutputInterfaces( findTLMInterfaces.getOutputInterfaces() );
md->addInputOutputInterfaces(findTLMInterfaces.getInputOutputInterfaces()); md->addInputOutputInterfaces( findTLMInterfaces.getInputOutputInterfaces() );
FindSignals signals(mainmd->getModuleClassDecl(), _os); FindSignals signals{ mainmd->getModuleClassDecl(), _os };
md->addSignals(signals.getSignals()); md->addSignals( signals.getSignals() );
FindEntryFunctions findEntries(mainmd->getModuleClassDecl(), _os); FindEntryFunctions findEntries{ mainmd->getModuleClassDecl(), _os };
FindEntryFunctions::entryFunctionVectorType * entryFunctions = findEntries.getEntryFunctions(); FindEntryFunctions::entryFunctionVectorType *entryFunctions{ findEntries.getEntryFunctions() };
md->addProcess(entryFunctions); md->addProcess( entryFunctions );
for (size_t i = 0; i < entryFunctions->size(); i++) { for (size_t i = 0; i < entryFunctions->size(); i++) {
EntryFunctionContainer *ef = (*entryFunctions)[i]; EntryFunctionContainer *ef{ (*entryFunctions)[i] };
FindSensitivity findSensitivity(constructor.returnConstructorStmt(), _os); FindSensitivity findSensitivity{ constructor.returnConstructorStmt(), _os };
ef->addSensitivityInfo(findSensitivity); ef->addSensitivityInfo(findSensitivity);
if (ef->getEntryMethod() == nullptr) { if ( ef->getEntryMethod() == nullptr ) {
_os << "ERROR"; _os << "ERROR";
continue; continue;
} }
FindWait findWaits(ef->getEntryMethod(), _os); FindWait findWaits{ ef->getEntryMethod(), _os };
ef->addWaits(findWaits); ef->addWaits(findWaits);
FindNotify findNotify(ef->_entryMethodDecl, _os); FindNotify findNotify{ ef->_entryMethodDecl, _os };
ef->addNotifys(findNotify); ef->addNotifys(findNotify);
/* /*
SuspensionAutomata suspensionAutomata(findWaits.getWaitCalls(), ef->getEntryMethod(), &_context, llvm::errs()); SuspensionAutomata suspensionAutomata(findWaits.getWaitCalls(), ef->getEntryMethod(), &_context, llvm::errs());
if (suspensionAutomata.initialize()) { if (suspensionAutomata.initialize()) {
suspensionAutomata.genSusCFG(); suspensionAutomata.genSusCFG();
//suspensionAutomata.dumpSusCFG(); //suspensionAutomata.dumpSusCFG();
suspensionAutomata.genSauto(); suspensionAutomata.genSauto();
//suspensionAutomata.dumpSauto(); //suspensionAutomata.dumpSauto();
ef->addSusCFGAuto(suspensionAutomata); ef->addSusCFGAuto(suspensionAutomata);
} }
*/ */
_entryFunctionContainerVector.push_back(ef); _entryFunctionContainerVector.push_back(ef);
} }
moduleDeclVec.push_back(md); moduleDeclVec.push_back(md);
} }
_systemcModel->addModuleDeclInstances(mainmd, moduleDeclVec); _systemcModel->addModuleDeclInstances(mainmd, moduleDeclVec);
} }
/* /*
FindSCMain scmain(tu, _os); FindSCMain scmain(tu, _os);
...@@ -205,11 +201,11 @@ void SystemCConsumer::HandleTranslationUnit(ASTContext & context) { ...@@ -205,11 +201,11 @@ void SystemCConsumer::HandleTranslationUnit(ASTContext & context) {
} }
SystemCConsumer::SystemCConsumer(CompilerInstance & ci) : SystemCConsumer::SystemCConsumer(CompilerInstance & ci) :
_os(llvm::errs()), _os{ llvm::errs() },
_sm(ci.getSourceManager()), _sm{ ci.getSourceManager() },
_context(ci.getASTContext()), _context{ ci.getASTContext() },
_ci(ci), _ci{ ci },
_systemcModel(nullptr) { _systemcModel{ nullptr } {
} }
......
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