OpenASIP 2.2
Loading...
Searching...
No Matches
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
47using std::string;
48using std::cout;
49using std::cerr;
50using std::endl;
51using std::vector;
52
53const 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 */
88
89/**
90 * Prints the version of the application.
91 */
92void
94 cout << "buildopset - Operation behavior module builder "
96}
97
98/**
99 * Returns the value of the source-dir option.
100 *
101 * @return The value of the source-dir option.
102 */
103string
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 */
113bool
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 */
124int 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) {
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)) {
147 module = FileSystem::currentWorkingDir()
148 + FileSystem::DIRECTORY_SEPARATOR + 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 const&) {
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}
int main(int argc, char *argv[])
const string SCHEMA_FILE_NAME
Definition BuildOpset.cc:53
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static void setCmdLineOptions(CmdLineOptions *options_)
static std::string TCEVersionString()
static void initialize()
std::string sourceDir() const
virtual ~BuildOpsetOptions()
Definition BuildOpset.cc:86
bool ignore() const
virtual void printVersion() const
Definition BuildOpset.cc:93
virtual bool isFlagOn() const
virtual std::string String(int index=0) const
void parse(char *argv[], int argc)
CmdLineOptionParser * findOption(std::string name) const
virtual int numberOfArguments() const
void addOption(CmdLineOptionParser *opt)
static std::string toString(const T &source)
std::string fileName() const
std::string errorMessage() const
Definition Exception.cc:123
std::string procedureName() const
int lineNum() const
static bool isAbsolutePath(const std::string &pathName)
static const std::string DIRECTORY_SEPARATOR
static std::string fileOfPath(const std::string pathName)
static std::string directoryOfPath(const std::string fileName)
Definition FileSystem.cc:79
virtual void printHelp() const
static OperationBuilder & instance()
bool verifyXML(const std::string file)
bool buildObject(const std::string &baseName, const std::string &behaviorFile, const std::string &path, std::vector< std::string > &output)
std::string behaviorFile(const std::string &baseName, std::string &path)