OpenASIP 2.2
Loading...
Searching...
No Matches
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
 
static const char * COMPILED_SIM_SO_FLAGS = " -shared -fpic "
 flags used when compiling .so files
 

Private Member Functions

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

Private Attributes

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

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}
std::string globalCompileFlags_
Global compile flags (from env variable)
int threadCount_
Number of threads to use while compiling through a Makefile.
std::string compiler_
The compiler to use.
static int toInt(const T &source)
static std::string environmentVariable(const std::string &variable)

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}
static std::ostream & logStream()
static std::string toString(const T &source)

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);
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}
#define DS
static const char * COMPILED_SIM_CPP_FLAGS
cpp flags used for compiled simulation
static std::vector< std::string > includeDirPaths()
static const std::string DIRECTORY_SEPARATOR
static std::string fileNameBody(const std::string &fileName)
static std::string fileOfPath(const std::string pathName)
static std::string directoryOfPath(const std::string fileName)
Definition FileSystem.cc:79

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}
int compileFile(const std::string &path, const std::string &flags="", const std::string &outputExtension=".o", bool verbose=false) const
static const char * COMPILED_SIM_SO_FLAGS
flags used when compiling .so files

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: