OpenASIP  2.0
BuildOpset.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2013 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file BuildOpset.cc
26  *
27  * Program that builds operation behavior module and locates
28  * them to the target directory.
29  *
30  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
31  * @author Pekka Jääskeläinen 2013
32  * @note rating: red
33  */
34 
35 #include <string>
36 #include <iostream>
37 #include <vector>
38 
39 #include "BuildOpset.hh"
40 #include "FileSystem.hh"
41 #include "CmdLineOptions.hh"
42 #include "Environment.hh"
43 #include "Conversion.hh"
44 #include "tce_config.h"
45 #include "OperationBuilder.hh"
46 
47 using std::string;
48 using std::cout;
49 using std::cerr;
50 using std::endl;
51 using std::vector;
52 
53 const string SCHEMA_FILE_NAME = "Operation_Schema.xsd";
54 
55 //////////////////////////////////////////////////////////////////////////////
56 // BuildOpsetOptions
57 //////////////////////////////////////////////////////////////////////////////
58 
59 /**
60  * Constructor.
61  */
63  CmdLineOptions("Usage: buildopset [options] module_name") {
64 
65  TCEString desc;
66  desc += "\n\tIgnore the case whereby the source file containing the\n";
67  desc += "\toperation behavior model code are not found. By default, the\n";
68  desc += "\tOSAL Builder aborts if it cannot build the dynamic module.\n";
69  desc += "\tThis option may be used in combination with install option\n";
70  desc += "\tto install XML data even if operation behavior definitions\n";
71  desc += "\tdo not exist.";
73  new BoolCmdLineOptionParser("ignore", desc, "b");
75 
76  desc = "\n\tEnter explicit directory where the behavior definition\n";
77  desc += "\tsource file to be used is found.\n";
79  new StringCmdLineOptionParser("source-dir", desc, "s");
81 }
82 
83 /**
84  * Destructor
85  */
87 }
88 
89 /**
90  * Prints the version of the application.
91  */
92 void
94  cout << "buildopset - Operation behavior module builder "
95  << Application::TCEVersionString() << endl;
96 }
97 
98 /**
99  * Returns the value of the source-dir option.
100  *
101  * @return The value of the source-dir option.
102  */
103 string
105  return findOption("source-dir")->String();
106 }
107 
108 /**
109  * Returns the value of the ignore option.
110  *
111  * @return The value of the ignore option.
112  */
113 bool
115  return findOption("ignore")->isFlagOn();
116 }
117 
118 /**
119  * Main program.
120  *
121  * Searches for XML file given to it as a parameter. Then searches for a
122  * corresponding operation behavior source file and compiles it.
123  */
124 int main(int argc, char* argv[]) {
125 
126  Application::initialize(argc, argv);
127 
128  try {
131 
132  options->parse(argv, argc);
134 
135  int arguments = options->numberOfArguments();
136  string module = "";
137  // first argument is XML data file
138  if (arguments == 0 || arguments > 1) {
139  options->printHelp();
140  return EXIT_FAILURE;
141  } else {
142  module = options->argument(1);
143  }
144 
145  // get the path for the files
146  if (!FileSystem::isAbsolutePath(module)) {
149  }
150  string path = FileSystem::directoryOfPath(module);
151 
152  // get the base name of the module
153  string moduleName = FileSystem::fileOfPath(module);
154 
155  // get the path for the behavior file
156  string behaviorPath = options->sourceDir();
157  if (behaviorPath == "") {
158  behaviorPath = path;
159  }
160 
161  // verify that the operation properties file is legal
162  if (!builder.verifyXML(module + ".opp")) {
163  return EXIT_FAILURE;
164  }
165 
166 
167  // find the behavior source file and check if it should be ignored
168  // if it's not found
169  string behFile = builder.behaviorFile(moduleName, behaviorPath);
170  if (behFile == "" && !options->ignore()) {
171  string errorMessage = "Behavior source file '";
172  errorMessage += behaviorPath + FileSystem::DIRECTORY_SEPARATOR
173  + moduleName + ".cc" + "' not found";
174  cerr << errorMessage << endl;
175  return EXIT_FAILURE;
176  }
177 
178  // build and install the behavior module
179  vector<string> output;
180  builder.buildObject(moduleName, behFile, path, output);
181  if (output.size() > 0) {
182  cerr << "Error building shared objects:" << endl;
183  for (size_t i = 0; i < output.size(); i++) {
184  cerr << output[i] << endl;
185  }
186  return EXIT_FAILURE;
187  }
188 
189  } catch (ParserStopRequest) {
190  return EXIT_SUCCESS;
191  } catch (const IllegalCommandLine& i) {
192  cerr << i.errorMessage() << endl;
193  return EXIT_FAILURE;
194  } catch (const Exception& e) {
195  string linenum = Conversion::toString(e.lineNum());
196  cerr << "Exception thrown: " << e.fileName() << ": "
197  << linenum << ": " << e.procedureName() << ": "
198  << e.errorMessage() << endl;
199  return EXIT_FAILURE;
200  }
201 
202  return EXIT_SUCCESS;
203 }
BuildOpsetOptions
Definition: BuildOpset.hh:42
MachInfoCmdLineOptions::printHelp
virtual void printHelp() const
Definition: MachInfoCmdLineOptions.cc:89
Exception::procedureName
std::string procedureName() const
FileSystem.hh
Exception::lineNum
int lineNum() const
ParserStopRequest
Definition: Exception.hh:491
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
BuildOpsetOptions::BuildOpsetOptions
BuildOpsetOptions()
Definition: BuildOpset.cc:62
CmdLineOptions.hh
Application::setCmdLineOptions
static void setCmdLineOptions(CmdLineOptions *options_)
Definition: Application.cc:381
IllegalCommandLine
Definition: Exception.hh:438
CmdLineOptionParser::isFlagOn
virtual bool isFlagOn() const
Definition: CmdLineOptionParser.cc:126
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
Conversion::toString
static std::string toString(const T &source)
Exception::fileName
std::string fileName() const
SCHEMA_FILE_NAME
const string SCHEMA_FILE_NAME
Definition: BuildOpset.cc:53
main
int main(int argc, char *argv[])
Definition: BuildOpset.cc:124
OperationBuilder::behaviorFile
std::string behaviorFile(const std::string &baseName, std::string &path)
Definition: OperationBuilder.cc:115
OperationBuilder
Definition: OperationBuilder.hh:42
CmdLineParser::addOption
void addOption(CmdLineOptionParser *opt)
BuildOpset.hh
BuildOpsetOptions::printVersion
virtual void printVersion() const
Definition: BuildOpset.cc:93
Conversion.hh
CmdLineOptions
Definition: CmdLineOptions.hh:54
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
BoolCmdLineOptionParser
Definition: CmdLineOptionParser.hh:278
Environment.hh
BuildOpsetOptions::~BuildOpsetOptions
virtual ~BuildOpsetOptions()
Definition: BuildOpset.cc:86
Exception
Definition: Exception.hh:54
BuildOpsetOptions::ignore
bool ignore() const
Definition: BuildOpset.cc:114
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
BuildOpsetOptions::sourceDir
std::string sourceDir() const
Definition: BuildOpset.cc:104
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
CmdLineOptionParser::String
virtual std::string String(int index=0) const
Definition: CmdLineOptionParser.cc:102
OperationBuilder::buildObject
bool buildObject(const std::string &baseName, const std::string &behaviorFile, const std::string &path, std::vector< std::string > &output)
Definition: OperationBuilder.cc:141
OperationBuilder::verifyXML
bool verifyXML(const std::string file)
Definition: OperationBuilder.cc:263
Application::initialize
static void initialize()
Definition: Application.cc:99
TCEString
Definition: TCEString.hh:53
FileSystem::currentWorkingDir
static std::string currentWorkingDir()
Definition: FileSystem.cc:142
CmdLineParser::findOption
CmdLineOptionParser * findOption(std::string name) const
Definition: CmdLineParser.cc:160
FileSystem::isAbsolutePath
static bool isAbsolutePath(const std::string &pathName)
Definition: FileSystem.cc:234
CmdLineParser::argument
virtual std::string argument(int index) const
Application::TCEVersionString
static std::string TCEVersionString()
Definition: Application.cc:510
OperationBuilder.hh
StringCmdLineOptionParser
Definition: CmdLineOptionParser.hh:180
OperationBuilder::instance
static OperationBuilder & instance()
Definition: OperationBuilder.cc:71