OpenASIP  2.0
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
CompiledSimCompiler Class Reference

#include <CompiledSimCompiler.hh>

Collaboration diagram for CompiledSimCompiler:
Collaboration graph

Public Member Functions

 CompiledSimCompiler ()
 
virtual ~CompiledSimCompiler ()
 
int compileDirectory (const std::string &dirName, const std::string &flags="", bool verbose=false) const
 
int compileFile (const std::string &path, const std::string &flags="", const std::string &outputExtension=".o", bool verbose=false) const
 
int compileToSO (const std::string &path, const std::string &flags="", bool verbose=false) const
 

Static Public Attributes

static const char * COMPILED_SIM_CPP_FLAGS
 cpp flags used for compiled simulation More...
 
static const char * COMPILED_SIM_SO_FLAGS = " -shared -fpic "
 flags used when compiling .so files More...
 

Private Member Functions

 CompiledSimCompiler (const CompiledSimCompiler &)
 Copying not allowed. More...
 
CompiledSimCompileroperator= (const CompiledSimCompiler &)
 Assignment not allowed. More...
 

Private Attributes

int threadCount_
 Number of threads to use while compiling through a Makefile. More...
 
std::string compiler_
 The compiler to use. More...
 
std::string globalCompileFlags_
 Global compile flags (from env variable) More...
 

Detailed Description

A class for compiling the dynamic libraries used by the compiled simulator

Definition at line 41 of file CompiledSimCompiler.hh.

Constructor & Destructor Documentation

◆ CompiledSimCompiler() [1/2]

CompiledSimCompiler::CompiledSimCompiler ( )

The constructor

Definition at line 79 of file CompiledSimCompiler.cc.

79  {
80 
81  // Get number of threads
82  threadCount_ = 3;
83  std::string USER_THREAD_COUNT =
84  Environment::environmentVariable("TTASIM_COMPILER_THREADS");
85  if (USER_THREAD_COUNT != "") {
86  threadCount_ = Conversion::toInt(string(USER_THREAD_COUNT));
87  }
88 
89  // Get compiler
90  compiler_ = "g++";
91  std::string USER_COMPILER =
92  Environment::environmentVariable("TTASIM_COMPILER");
93  if (USER_COMPILER != "") {
94  compiler_ = string(USER_COMPILER);
95  }
96 
97  // Get global compile flags
98  globalCompileFlags_ = " -O0 ";
99  std::string fl =
100  Environment::environmentVariable("TTASIM_COMPILER_FLAGS");
101  if (fl != "")
102  globalCompileFlags_ = std::string(fl);
103 }

References compiler_, Environment::environmentVariable(), globalCompileFlags_, threadCount_, and Conversion::toInt().

Here is the call graph for this function:

◆ ~CompiledSimCompiler()

CompiledSimCompiler::~CompiledSimCompiler ( )
virtual

The destructor

Definition at line 108 of file CompiledSimCompiler.cc.

108  {
109 }

◆ CompiledSimCompiler() [2/2]

CompiledSimCompiler::CompiledSimCompiler ( const CompiledSimCompiler )
private

Copying not allowed.

Member Function Documentation

◆ compileDirectory()

int CompiledSimCompiler::compileDirectory ( const std::string &  dirName,
const std::string &  flags = "",
bool  verbose = false 
) const

Compiles a directory with given flags using a pre-generated makefile

In case environment variable TTASIM_COMPILER is set, it is used to compile the simulation code, otherwise 'gcc' is used. The count of compiler threads is read from TTASIM_COMPILER_THREADS, and defaults to 3.

Parameters
dirNamea source directory containing the .cpp files and the Makefile
flagsadditional compile flags given by the user. for instance, "-O3"
verbosePrint information of the compilation progress.
Returns
Return value given by system(). 0 on success. !=0 on failure

Definition at line 125 of file CompiledSimCompiler.cc.

128  {
129 
130  string command =
131  "make -sC " + dirName + " CC=\"" + compiler_ + "\" opt_flags=\"" +
132  globalCompileFlags_ + " " + flags + " \" -j" +
134 
135  if (verbose) {
137  << "Compiling the simulation engine with command "
138  << command << endl;
139  }
140 
141  time_t startTime = std::time(NULL);
142  int retval = system(command.c_str());
143  time_t endTime = std::time(NULL);
144 
145  time_t elapsed = endTime - startTime;
146 
147  if (verbose) {
149  << "Compiling the simulation engine with opt. switches '"
150  << globalCompileFlags_ << " " << flags
151  << "' took " << elapsed / 60 << "m " << (elapsed % 60) << "s "
152  << endl;
153  }
154 
155  return retval;
156 }

References compiler_, globalCompileFlags_, Application::logStream(), threadCount_, and Conversion::toString().

Referenced by CompiledSimController::reset().

Here is the call graph for this function:

◆ compileFile()

int CompiledSimCompiler::compileFile ( const std::string &  path,
const std::string &  flags = "",
const std::string &  outputExtension = ".o",
bool  verbose = false 
) const

Compiles a single C++ file using the set flags

Parameters
pathPath to the file
flagscustom flags to be used for compiling
outputExtensionextension to append to the filename. default is ".o"
verbosePrint information of the compilation progress.
Returns
Return value given by system() call. 0 on success. !=0 on failure

Definition at line 168 of file CompiledSimCompiler.cc.

172  {
173 
174  std::string directory = FileSystem::directoryOfPath(path);
175  std::string fileNameBody = FileSystem::fileNameBody(path);
176  std::string fileName = FileSystem::fileOfPath(path);
177  std::string DS = FileSystem::DIRECTORY_SEPARATOR;
178 
179  // Get includes
180  vector<string> includePaths = Environment::includeDirPaths();
181  string includes;
182  for (vector<string>::const_iterator it = includePaths.begin();
183  it != includePaths.end(); ++it) {
184  includes += "-I" + *it + " ";
185  }
186 
187  if (verbose) {
188  Application::logStream() << "Compiling simulation file "
189  << path << endl;
190  }
191 
192  string command = compiler_ + " " + includes + COMPILED_SIM_CPP_FLAGS
193  + globalCompileFlags_ + " " + flags + " "
194  + path + " -o " + directory + DS + fileNameBody + outputExtension;
195 
196  return system(command.c_str());
197 }

References COMPILED_SIM_CPP_FLAGS, compiler_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::directoryOfPath(), DS, FileSystem::fileNameBody(), FileSystem::fileOfPath(), globalCompileFlags_, Environment::includeDirPaths(), and Application::logStream().

Referenced by compileToSO(), and CompiledSimController::reset().

Here is the call graph for this function:

◆ compileToSO()

int CompiledSimCompiler::compileToSO ( const std::string &  path,
const std::string &  flags = "",
bool  verbose = false 
) const

Compiles a single C++ file to a shared library (.so)

Used for generating .so files in dynamic compiled simulation

Parameters
pathPath to the file
flagscustom flags to be used for compiling
verbosePrint information of the compilation progress.
Returns
Return value given by system() call. 0 on success. !=0 on failure

Definition at line 210 of file CompiledSimCompiler.cc.

213  {
214 
215  return compileFile(path, COMPILED_SIM_SO_FLAGS + flags, ".so", verbose);
216 }

References COMPILED_SIM_SO_FLAGS, and compileFile().

Referenced by CompiledSimulation::compileAndLoadFunction(), and CompiledSimController::reset().

Here is the call graph for this function:

◆ operator=()

CompiledSimCompiler& CompiledSimCompiler::operator= ( const CompiledSimCompiler )
private

Assignment not allowed.

Member Data Documentation

◆ COMPILED_SIM_CPP_FLAGS

const char * CompiledSimCompiler::COMPILED_SIM_CPP_FLAGS
static
Initial value:
= " -fpic -std=c++11 "
" -fno-working-directory "
"-fno-enforce-eh-specs "
"-fno-rtti -DNDEBUG "

cpp flags used for compiled simulation

Definition at line 63 of file CompiledSimCompiler.hh.

Referenced by compileFile(), and CompiledSimCodeGenerator::generateMakefile().

◆ COMPILED_SIM_SO_FLAGS

const char * CompiledSimCompiler::COMPILED_SIM_SO_FLAGS = " -shared -fpic "
static

flags used when compiling .so files

Definition at line 66 of file CompiledSimCompiler.hh.

Referenced by compileToSO(), and CompiledSimCodeGenerator::generateMakefile().

◆ compiler_

std::string CompiledSimCompiler::compiler_
private

The compiler to use.

Definition at line 77 of file CompiledSimCompiler.hh.

Referenced by compileDirectory(), CompiledSimCompiler(), and compileFile().

◆ globalCompileFlags_

std::string CompiledSimCompiler::globalCompileFlags_
private

Global compile flags (from env variable)

Definition at line 79 of file CompiledSimCompiler.hh.

Referenced by compileDirectory(), CompiledSimCompiler(), and compileFile().

◆ threadCount_

int CompiledSimCompiler::threadCount_
private

Number of threads to use while compiling through a Makefile.

Definition at line 75 of file CompiledSimCompiler.hh.

Referenced by compileDirectory(), and CompiledSimCompiler().


The documentation for this class was generated from the following files:
CompiledSimCompiler::COMPILED_SIM_SO_FLAGS
static const char * COMPILED_SIM_SO_FLAGS
flags used when compiling .so files
Definition: CompiledSimCompiler.hh:66
CompiledSimCompiler::COMPILED_SIM_CPP_FLAGS
static const char * COMPILED_SIM_CPP_FLAGS
cpp flags used for compiled simulation
Definition: CompiledSimCompiler.hh:63
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
Conversion::toString
static std::string toString(const T &source)
CompiledSimCompiler::threadCount_
int threadCount_
Number of threads to use while compiling through a Makefile.
Definition: CompiledSimCompiler.hh:75
CompiledSimCompiler::compiler_
std::string compiler_
The compiler to use.
Definition: CompiledSimCompiler.hh:77
Environment::includeDirPaths
static std::vector< std::string > includeDirPaths()
Definition: Environment.cc:348
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
CompiledSimCompiler::compileFile
int compileFile(const std::string &path, const std::string &flags="", const std::string &outputExtension=".o", bool verbose=false) const
Definition: CompiledSimCompiler.cc:168
CompiledSimCompiler::globalCompileFlags_
std::string globalCompileFlags_
Global compile flags (from env variable)
Definition: CompiledSimCompiler.hh:79
Conversion::toInt
static int toInt(const T &source)
Environment::environmentVariable
static std::string environmentVariable(const std::string &variable)
Definition: Environment.cc:406
DS
#define DS
Definition: LLVMBackend.cc:124
FileSystem::fileNameBody
static std::string fileNameBody(const std::string &fileName)
Definition: FileSystem.cc:291