OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
OperationBuilder Class Reference

#include <OperationBuilder.hh>

Collaboration diagram for OperationBuilder:
Collaboration graph

Public Member Functions

std::string xmlFilePath (const std::string &xmlFile)
 
std::string behaviorFile (const std::string &baseName, std::string &path)
 
bool buildObject (const std::string &baseName, const std::string &behaviorFile, const std::string &path, std::vector< std::string > &output)
 
bool installDataFile (const std::string &path, const std::string &xmlFile, const std::string &destination)
 
bool verifyXML (const std::string file)
 

Static Public Member Functions

static OperationBuilderinstance ()
 

Private Member Functions

 OperationBuilder ()
 
virtual ~OperationBuilder ()
 
std::string makeIncludeString (const std::vector< std::string > &paths)
 

Static Private Attributes

static OperationBuilderinstance_ = NULL
 Static unique instance.
 

Detailed Description

Class that handles building the operation behavior.

Definition at line 42 of file OperationBuilder.hh.

Constructor & Destructor Documentation

◆ OperationBuilder()

OperationBuilder::OperationBuilder ( )
private

Constructor.

Definition at line 56 of file OperationBuilder.cc.

56 {
57}

Referenced by instance().

◆ ~OperationBuilder()

OperationBuilder::~OperationBuilder ( )
privatevirtual

Destructor.

Definition at line 62 of file OperationBuilder.cc.

62 {
63}

Member Function Documentation

◆ behaviorFile()

string OperationBuilder::behaviorFile ( const std::string &  baseName,
std::string &  path 
)

Searches for the path of behavior file.

If path for the file is not given, it is searched from the current working directory. If file is not found, an empty string is returned.

Parameters
baseNameThe name of behavior file.
pathThe path where the file is located.

Definition at line 115 of file OperationBuilder.cc.

117 {
118
119 string behFile = baseName + ".cc";
120 if (path == "") {
122 }
123 string pathToFile = path + FileSystem::DIRECTORY_SEPARATOR + behFile;
124 if (FileSystem::fileExists(pathToFile)) {
125 return pathToFile;
126 }
127 return "";
128}
static const std::string DIRECTORY_SEPARATOR
static std::string currentWorkingDir()
static bool fileExists(const std::string fileName)

References FileSystem::currentWorkingDir(), FileSystem::DIRECTORY_SEPARATOR, and FileSystem::fileExists().

Referenced by buildObject(), and main().

Here is the call graph for this function:

◆ buildObject()

bool OperationBuilder::buildObject ( const std::string &  baseName,
const std::string &  behaviorFile,
const std::string &  path,
std::vector< std::string > &  output 
)

Builds dynamic module and copies it to the same location where XML property file is located.

Parameters
baseNameThe base name for the module.
behaviorFileThe full path for behavior file.
pathPath where built module is put.
outputOutput of compilation.
Returns
True if everything is successful, false otherwise.

Definition at line 141 of file OperationBuilder.cc.

145 {
146
147 if (behaviorFile != "") {
148 TCEString CPPFLAGS = Environment::environmentVariable("CPPFLAGS");
149 TCEString CXXFLAGS = Environment::environmentVariable("CXXFLAGS")
150 + " " + CONFIGURE_CPPFLAGS + " ";
152 + " " + CONFIGURE_LDFLAGS + " ";
153 TCEString CXXCOMPILER = Environment::environmentVariable("CXX");
154 vector<string> includes = Environment::includeDirPaths();
155
156 TCEString INCLUDES = makeIncludeString(includes);
157
158 // Ugly fix. When compiling TCE the base opset is compiled in the
159 // source directory. When distributed version is enabled buildopset
160 // needs to know some include paths from the source tree because these
161 // headers aren't resident in places that includeDirPaths() returns.
163 string cwd = FileSystem::currentWorkingDir();
165 string srcOpsetDir = TCE_SRC_ROOT + DS + "opset" + DS + "base";
166 if (cwd == srcOpsetDir) {
167 vector<string> extraIncludes = Environment::opsetIncludeDir();
168 INCLUDES += makeIncludeString(extraIncludes);
169 }
170 }
171
173 /* Add a dependency to the installed libopenasip.so just in case
174 the .opb will be loaded through a libopenasip.so that is loaded
175 through a dlopen() with the RTLD_LOCAL flag. In that case
176 it can happen the loading of libopenasip.so to access some
177 specific functionality might not import all the symbols
178 required by the .opb loaded by libopenasip later. */
179 LDFLAGS += " -L" + Application::installationDir() + "/lib -lopenasip ";
180 } else {
181 LDFLAGS += " -L" + string(TCE_SRC_ROOT) + "/src/.libs -lopenasip ";
182 }
183
184 // Add user defined CXXFLAGS + CPPFLAGS to the end because they
185 // might point to paths with incompatible TCE headers.
186 string COMPILE_FLAGS = \
187 INCLUDES + " " +
188 CONFIGURE_CPPFLAGS + " " + CONFIGURE_LDFLAGS + " " +
189 CXXFLAGS + " " + CPPFLAGS + " ";
190
191 string module = path + FileSystem::DIRECTORY_SEPARATOR +
192 baseName + ".opb";
193
194 string command = (CXXCOMPILER == "") ? (string(CXX)) : (CXXCOMPILER);
195 command += " " + COMPILE_FLAGS + " " + behaviorFile + " " +
196 string(SHARED_CXX_FLAGS) + " " + LDFLAGS + " -o " + module + " 2>&1";
197
199 Application::logStream() << command << std::endl;
200 }
201
202 if (Application::runShellCommandAndGetOutput(command, output) != 0) {
203 return false;
204 }
205 }
206 return true;
207}
#define DS
static bool isInstalled()
static int runShellCommandAndGetOutput(const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)
static std::string installationDir()
static const int VERBOSE_LEVEL_DEFAULT
Default verbose level - do not print anything unnecessary.
static int verboseLevel()
static std::ostream & logStream()
static std::string environmentVariable(const std::string &variable)
static std::vector< std::string > includeDirPaths()
static bool developerMode()
static std::vector< std::string > opsetIncludeDir()
std::string makeIncludeString(const std::vector< std::string > &paths)
std::string behaviorFile(const std::string &baseName, std::string &path)

References behaviorFile(), FileSystem::currentWorkingDir(), Environment::developerMode(), FileSystem::DIRECTORY_SEPARATOR, DS, Environment::environmentVariable(), Environment::includeDirPaths(), Application::installationDir(), Application::isInstalled(), Application::logStream(), makeIncludeString(), Environment::opsetIncludeDir(), Application::runShellCommandAndGetOutput(), Application::VERBOSE_LEVEL_DEFAULT, and Application::verboseLevel().

Referenced by OperationIndex::addPath(), OSEdBuildAllCmd::Do(), OSEdBuildCmd::Do(), and main().

Here is the call graph for this function:

◆ installDataFile()

bool OperationBuilder::installDataFile ( const std::string &  sourcePath,
const std::string &  xmlFile,
const std::string &  destinationPath 
)

Installs the data file containing operation property declarations.

Creates the destination path if it does not exist. Overwrites the existing file, if it is already installed in given destination.

Installation can fail for several reasons: no rights to create destination directory, no rights to overwrite a previously installed version of the data file, no rights to read the source data file.

Parameters
pathSource path of data file.
xmlFileName of the data file.
destinationDestination path where the data file is to be installed.
Returns
True, if installation is completed successfully, false otherwise.

Definition at line 226 of file OperationBuilder.cc.

229 {
230
231 const string source =
232 sourcePath + FileSystem::DIRECTORY_SEPARATOR + xmlFile;
233
234 // an unreadable or nonexisting file should have been caught earlier on
235 // (for example, during validation)
238
239 if (!FileSystem::fileExists(destinationPath)) {
240 if (!FileSystem::createDirectory(destinationPath)) {
241 return false;
242 }
243 }
244
245 const string dest =
246 destinationPath + FileSystem::DIRECTORY_SEPARATOR + xmlFile;
247
248 if (FileSystem::fileExists(dest)) {
250 return false;
251 }
252 }
253
254 FileSystem::copy(source, dest);
255 return true;
256}
#define assert(condition)
static bool fileIsReadable(const std::string fileName)
static bool createDirectory(const std::string &path)
static bool removeFileOrDirectory(const std::string &path)
static void copy(const std::string &source, const std::string &target)

References assert, FileSystem::copy(), FileSystem::createDirectory(), FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::fileIsReadable(), and FileSystem::removeFileOrDirectory().

Here is the call graph for this function:

◆ instance()

OperationBuilder & OperationBuilder::instance ( )
static

Returns an instance of OperationBuilder.

Returns
An instance of OperationBuilder.

Definition at line 71 of file OperationBuilder.cc.

71 {
72 if (instance_ == NULL) {
74 }
75 return *instance_;
76}
static OperationBuilder * instance_
Static unique instance.

References instance_, and OperationBuilder().

Referenced by OperationIndex::addPath(), OSEdBuildAllCmd::Do(), OSEdBuildCmd::Do(), and main().

Here is the call graph for this function:

◆ makeIncludeString()

string OperationBuilder::makeIncludeString ( const std::vector< std::string > &  paths)
private

Makes an include string for compiler (-I<path1> -I<path2> etc) from the paths in the vector

Parameters
Vectorcontaining the include paths

Definition at line 286 of file OperationBuilder.cc.

286 {
287 string includes = "";
288 for (size_t i = 0; i < paths.size(); i++) {
289 includes += "-I" + paths.at(i) + " ";
290 }
291 return includes;
292}

Referenced by buildObject().

◆ verifyXML()

bool OperationBuilder::verifyXML ( const std::string  file)

Verifies the correctness of XML file.

Parameters
fileAbsolute path of XML file.

Definition at line 265 of file OperationBuilder.cc.

265 {
266 OperationSerializer serializer;
267 serializer.setSourceFile(file);
268
269 try {
270 ObjectState* root = serializer.readState();
271 delete root;
272 } catch (const SerializerException& s) {
273 cerr << "Invalid XML file: " << s.errorMessage() << endl;
274 return false;
275 }
276 return true;
277}
std::string errorMessage() const
Definition Exception.cc:123
void setSourceFile(const std::string &filename)
virtual ObjectState * readState()

References Exception::errorMessage(), OperationSerializer::readState(), and OperationSerializer::setSourceFile().

Referenced by main().

Here is the call graph for this function:

◆ xmlFilePath()

string OperationBuilder::xmlFilePath ( const std::string &  xmlFile)

Finds the path for XML file.

File is searched only from certain locations. If file is not found, returns an empty string.

Parameters
xmlFileThe name of the XML file.
Returns
The path to XML file.

Definition at line 88 of file OperationBuilder.cc.

88 {
89
90 vector<string> searchPaths = Environment::osalPaths();
91 searchPaths.push_back(FileSystem::currentWorkingDir());
92
93 string filePath = "";
94 for (unsigned int i = 0; i < searchPaths.size(); i++) {
95 string file = searchPaths[i] + FileSystem::DIRECTORY_SEPARATOR +
96 xmlFile;
97 if (FileSystem::fileExists(file)) {
98 filePath = searchPaths[i];
99 break;
100 }
101 }
102 return filePath;
103}
static std::vector< std::string > osalPaths()

References FileSystem::currentWorkingDir(), FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), and Environment::osalPaths().

Here is the call graph for this function:

Member Data Documentation

◆ instance_

OperationBuilder * OperationBuilder::instance_ = NULL
staticprivate

Static unique instance.

Definition at line 70 of file OperationBuilder.hh.

Referenced by instance().


The documentation for this class was generated from the following files: