OpenASIP  2.0
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. More...
 

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 }

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 + " ";
151  TCEString LDFLAGS = Environment::environmentVariable("LDFLAGS")
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 
172  if (Application::isInstalled()) {
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  CXXFLAGS += " -L" + Application::installationDir() + "/lib -lopenasip ";
180  }
181 
182  // Add user defined CXXFLAGS + CPPFLAGS to the end because they
183  // might point to paths with incompatible TCE headers.
184  string COMPILE_FLAGS = \
185  INCLUDES + " " +
186  CONFIGURE_CPPFLAGS + " " + CONFIGURE_LDFLAGS + " " +
187  CXXFLAGS + " " + CPPFLAGS + " ";
188 
189  string module = path + FileSystem::DIRECTORY_SEPARATOR +
190  baseName + ".opb";
191 
192  string command = (CXXCOMPILER == "") ? (string(CXX)) : (CXXCOMPILER);
193  command += " " + COMPILE_FLAGS + " " + behaviorFile + " " +
194  string(SHARED_CXX_FLAGS) + " " + LDFLAGS + " -o " + module + " 2>&1";
195 
197  Application::logStream() << command << std::endl;
198  }
199 
200  if (Application::runShellCommandAndGetOutput(command, output) != 0) {
201  return false;
202  }
203  }
204  return true;
205 }

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(), OSEdBuildCmd::Do(), OSEdBuildAllCmd::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 224 of file OperationBuilder.cc.

227  {
228 
229  const string source =
230  sourcePath + FileSystem::DIRECTORY_SEPARATOR + xmlFile;
231 
232  // an unreadable or nonexisting file should have been caught earlier on
233  // (for example, during validation)
234  assert(FileSystem::fileExists(source) &&
236 
237  if (!FileSystem::fileExists(destinationPath)) {
238  if (!FileSystem::createDirectory(destinationPath)) {
239  return false;
240  }
241  }
242 
243  const string dest =
244  destinationPath + FileSystem::DIRECTORY_SEPARATOR + xmlFile;
245 
246  if (FileSystem::fileExists(dest)) {
248  return false;
249  }
250  }
251 
252  FileSystem::copy(source, dest);
253  return true;
254 }

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 }

References instance_, and OperationBuilder().

Referenced by OperationIndex::addPath(), OSEdBuildCmd::Do(), OSEdBuildAllCmd::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 284 of file OperationBuilder.cc.

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

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 263 of file OperationBuilder.cc.

263  {
264  OperationSerializer serializer;
265  serializer.setSourceFile(file);
266 
267  try {
268  ObjectState* root = serializer.readState();
269  delete root;
270  } catch (const SerializerException& s) {
271  cerr << "Invalid XML file: " << s.errorMessage() << endl;
272  return false;
273  }
274  return true;
275 }

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 }

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:
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
FileSystem::createDirectory
static bool createDirectory(const std::string &path)
Definition: FileSystem.cc:400
Application::runShellCommandAndGetOutput
static int runShellCommandAndGetOutput(const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)
Definition: Application.cc:338
Application::VERBOSE_LEVEL_DEFAULT
static const int VERBOSE_LEVEL_DEFAULT
Default verbose level - do not print anything unnecessary.
Definition: Application.hh:222
ObjectState
Definition: ObjectState.hh:59
Application::verboseLevel
static int verboseLevel()
Definition: Application.hh:176
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
assert
#define assert(condition)
Definition: Application.hh:86
OperationBuilder::behaviorFile
std::string behaviorFile(const std::string &baseName, std::string &path)
Definition: OperationBuilder.cc:115
Environment::opsetIncludeDir
static std::vector< std::string > opsetIncludeDir()
Definition: Environment.cc:384
Environment::includeDirPaths
static std::vector< std::string > includeDirPaths()
Definition: Environment.cc:348
OperationSerializer::readState
virtual ObjectState * readState()
Definition: OperationSerializer.cc:118
FileSystem::copy
static void copy(const std::string &source, const std::string &target)
Definition: FileSystem.cc:524
OperationSerializer
Definition: OperationSerializer.hh:49
OperationBuilder::makeIncludeString
std::string makeIncludeString(const std::vector< std::string > &paths)
Definition: OperationBuilder.cc:284
SerializerException
Definition: Exception.hh:675
OperationSerializer::setSourceFile
void setSourceFile(const std::string &filename)
Definition: OperationSerializer.cc:536
Environment::osalPaths
static std::vector< std::string > osalPaths()
Definition: Environment.cc:519
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
Application::isInstalled
static bool isInstalled()
Definition: Application.cc:522
FileSystem::fileExists
static bool fileExists(const std::string fileName)
Application::installationDir
static std::string installationDir()
Definition: Application.cc:537
TCEString
Definition: TCEString.hh:53
FileSystem::currentWorkingDir
static std::string currentWorkingDir()
Definition: FileSystem.cc:142
Environment::developerMode
static bool developerMode()
Definition: Environment.cc:1166
Environment::environmentVariable
static std::string environmentVariable(const std::string &variable)
Definition: Environment.cc:406
DS
#define DS
Definition: LLVMBackend.cc:124
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
OperationBuilder::instance_
static OperationBuilder * instance_
Static unique instance.
Definition: OperationBuilder.hh:70
OperationBuilder::OperationBuilder
OperationBuilder()
Definition: OperationBuilder.cc:56