OpenASIP 2.2
Loading...
Searching...
No Matches
DictionaryTool.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 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 DictionaryTool.cc
26 *
27 * DictionaryTool main application.
28 *
29 * @author Jari M�ntyneva 2006 (jari.mantyneva-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <cstdlib>
34#include <iostream>
35#include <fstream>
36#include <string>
37#include <vector>
38
39#include "ADFSerializer.hh"
40#include "Application.hh"
41#include "Machine.hh"
44#include "CmdLineOptions.hh"
45#include "Exception.hh"
46#include "Binary.hh"
47#include "TPEFWriter.hh"
48#include "TPEFProgramFactory.hh"
49#include "ProgramWriter.hh"
50#include "BinaryStream.hh"
51#include "MoveElement.hh"
52#include "tce_config.h"
53
54using std::cout;
55using std::cerr;
56using std::endl;
57using std::string;
58using std::ofstream;
59using std::vector;
60using namespace TTAMachine;
61using namespace TTAProgram;
62using namespace TPEF;
63
64/**
65 * DictionaryTool commandline options.
66 */
68public:
70 CmdLineOptions("Usage: dictionary_tool [options] adffile") {
71
74 "primitive",
75 "Print missing operations from primitive operation set",
76 "p");
77
79
81 new BoolCmdLineOptionParser("connections",
82 "Print all connections in adf.",
83 "c");
84
86
89 "global_register",
90 "Print the name of global connection register", "g");
91
93
96 "missing",
97 "Print missing connections to connection register",
98 "m");
99
101
104 "reg_connections",
105 "Print all connections to the connection register.", "r");
106
108
111 "no_errors",
112 "Don't print any error messages.", "e");
113
115
118 "binary",
119 "Write binary program as output.", "w");
120
122 }
123
125 return findOption("primitive")->isFlagOn();
126 }
127
129 return findOption("connections")->isFlagOn();
130 }
131
133 return findOption("global_register")->isFlagOn();
134 }
135
137 return findOption("missing")->isFlagOn();
138 }
139
141 return findOption("reg_connections")->isFlagOn();
142 }
143
145 return findOption("no_errors")->isFlagOn();
146 }
147
148 bool writeBinary() {
149 return findOption("binary")->isFlagOn();
150 }
151
152 void printVersion() const {
153 cout << "dictionary_tool - Dictionary Tool "
155 }
156};
157
158
159/**
160 * The dictionary_tool main function.
161 */
162int main(int argc, char* argv[]) {
163
165
166 try {
167 options.parse(argv, argc);
168 } catch (ParserStopRequest const&) {
169 return EXIT_SUCCESS;
170 } catch (const IllegalCommandLine& e) {
171 cerr << e.errorMessage() << endl;
172 return EXIT_FAILURE;
173 }
174
175 if (options.numberOfArguments() == 0) {
177 return EXIT_SUCCESS;
178 } else if (options.numberOfArguments() > 1) {
179 cerr << "Illegal number of arguments" << endl;
180 return EXIT_FAILURE;
181 }
182
183 string adfFileName = options.argument(1);
184
185 ADFSerializer adfSerializer;
186 adfSerializer.setSourceFile(adfFileName);
187
189
190 try {
191 mach = adfSerializer.readMachine();
192 } catch (...) {
193 cout.flush();
194 cerr << "Error opening ADF file:" << endl
195 << "- Is the filename correct?" << endl
196 << "- Is the machine legal?" << endl;
197 return EXIT_FAILURE;
198 }
199
200 ProgrammabilityValidator* validator;
201
202 try {
203 validator = new ProgrammabilityValidator(*mach);
204 } catch (IllegalMachine& e) {
205 cerr << e.errorMessage() << endl;
206 return EXIT_FAILURE;
207 }
208
209 ProgrammabilityValidatorResults booleanResults;
210 validator->checkBooleanRegister(booleanResults);
211 if (booleanResults.errorCount() != 0) {
212 for (int i = 0; i < booleanResults.errorCount(); i++) {
214 booleanResults.error(i);
215
216 cerr << error.second << endl;
217 }
218 cerr << "Execution stopped." << endl;
219 return EXIT_SUCCESS;
220 }
221
222 bool gcrError = false;
223
225 TPEF::Binary* binaryProgram = NULL;
226 try {
227 binaryProgram = validator->profile(results);
228 } catch (NotAvailable& e) {
229 cerr << e.errorMessage() << endl;
230 cerr << "Check that all operations are found in OSAL." << endl;
231 cerr << "Create new ones with OSEd." << endl;
232 cerr << "Execution stopped." << endl;
233 return EXIT_FAILURE;
234 } catch (InstanceNotFound& e) {
235 cerr << e.errorMessage() << endl;
236 }
237
238 if (options.writeBinary()) {
239 string outputFile = adfFileName.append("_profiled.tpef");
240 BinaryStream tpefOut(outputFile);
241 TPEFWriter::instance().writeBinary(tpefOut, binaryProgram);
242 }
243
244 if (!options.doNotPrintErrors()) {
245 for (int i = 0; i < results.errorCount(); i++) {
247 if (error.first ==
249 OPERATION_MISSING_FROM_THE_PRIMITIVE_OPERATION_SET) {
250 if (options.printPrimitive()) {
251 cerr << error.second << endl;
252 }
253 }
254 else if (error.first ==
256 GLOBAL_CONNECTION_REGISTER_NOT_FOUND) {
257 if (options.printGlobalRegister()) {
258 gcrError = true;
259 cerr << error.second << endl;
260 }
261 }
262 else if (error.first ==
264 MISSING_CONNECTION) {
265 if (options.printMissingConnections()) {
266 cerr << error.second << endl;
267 }
268 }
269 else {
270 cerr << error.second << endl;
271 }
272 }
273 }
274
275 if (options.printGlobalRegister() && !gcrError) {
276 cout << "* The global connection register in the machine is: "
277 << validator->findGlobalConnectionRegister()->name()
278 << endl;
279 }
280
281 if (options.printConnections()) {
282 validator->printConnections();
283 }
284
285 if (options.printRFConnections()) {
286 validator->printRegisterConnections();
287 }
288
289 return EXIT_SUCCESS;
290}
int main(int argc, char *argv[])
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
TTAMachine::Machine * readMachine()
static std::string TCEVersionString()
virtual bool isFlagOn() const
void parse(char *argv[], int argc)
CmdLineOptionParser * findOption(std::string name) const
virtual std::string argument(int index) const
virtual int numberOfArguments() const
void addOption(CmdLineOptionParser *opt)
std::string errorMessage() const
Definition Exception.cc:123
virtual void printHelp() const
std::pair< ProgrammabilityValidator::ErrorCode, std::string > Error
Typedef for an error (error code + error message).
bool checkBooleanRegister(ProgrammabilityValidatorResults &results)
const RegisterFile * findGlobalConnectionRegister()
TPEF::Binary * profile(ProgrammabilityValidatorResults &results)
void writeBinary(BinaryStream &stream, const Binary *bin) const
static const BinaryWriter & instance()
Definition TPEFWriter.cc:70
virtual TCEString name() const
void setSourceFile(const std::string &fileName)