OpenASIP 2.2
Loading...
Searching...
No Matches
ProcessorConfigurationFile.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 ProcessorConfigurationFile.cc
26 *
27 * Definition of ProcessorConfigurationFile class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
34#include "Conversion.hh"
35#include "FileSystem.hh"
36
37using std::string;
38
39const string ProcessorConfigurationFile::ARCHITECTURE = "Architecture";
40const string ProcessorConfigurationFile::ARCHITECTURE_SIZE = "ArchitectureSize";
42"ArchitectureModified";
43const string ProcessorConfigurationFile::ENCODING_MAP = "EncodingMap";
44const string ProcessorConfigurationFile::ENCODING_MAP_SIZE = "EncodingSize";
46"EncodingModified";
47const string ProcessorConfigurationFile::IMPLEMENTATION = "Implementation";
49"ImplementationSize";
51"ImplementationModified";
52
53/**
54 * Constructor.
55 *
56 * @param inputStream Stream where configuration file is read from.
57 */
78
79/**
80 * Destructor.
81 */
84
85
86/**
87 * Sets the directory of PCF file itself.
88 *
89 * Path of the ADF, IDF and BEM files are constructed relative to the
90 * PCF directory if a relative path is given in PCF.
91 *
92 * @param directory The directory of the PCF file.
93 */
94void
95ProcessorConfigurationFile::setPCFDirectory(const std::string& directory) {
96 pcfDir_ = directory;
97}
98
99
100/**
101 * Returns the name of the architecture.
102 *
103 * @return The name of the architecture.
104 * @exception KeyNotFound If architecture is not found.
105 */
106string
110
111/**
112 * Returns the size of the architecture.
113 *
114 * @return The size of the architecture.
115 * @exception KeyNotFound If architecture size is not found.
116 */
117unsigned int
121
122/**
123 * Returns the timestamp of the architecture modified time.
124 *
125 * @return Architecture modified timestamp.
126 * @exception KeyNotFound If architecture modified time is not found.
127 */
128unsigned int
132
133/**
134 * Returns the name of the implementation.
135 *
136 * @return The name of the implementation.
137 * @exception KeyNotFound If implementation is not found.
138 */
139string
143
144/**
145 * Returns the size of the implementation.
146 *
147 * @return The size of the implementation.
148 * @exception KeyNotFound If implementation size is not found.
149 */
150unsigned int
154
155/**
156 * Returns the implementation modified timestamp.
157 *
158 * @return Timestamp of implementation modified time.
159 * @exception KeyNotFound If implementation modified timestamp is not found.
160 */
161unsigned int
165
166/**
167 * Returns the name of the encoding map.
168 *
169 * @return The name of the encoding map.
170 * @exception KeyNotFound If encoding map is not found.
171 */
172string
176
177/**
178 * Returns the size of the encoding map.
179 *
180 * @return The size of the encoding map.
181 * @exception KeyNotFound If encoding map size is not found.
182 */
183unsigned int
187
188/**
189 * Returns the timestamp of encoding map modified time.
190 *
191 * @return The timestamp of encoding map modified time.
192 * @exception KeyNotFound If timestamp is not found.
193 */
194unsigned int
198
199/**
200 * Returns the number of errors.
201 *
202 * @return The number of errors.
203 */
204int
208
209/**
210 * Returns the error string with a given index.
211 *
212 * If such error string is not found, returns empty string.
213 *
214 * @return Error string with a given index.
215 */
216string
218
219 if (index < 0 || index > static_cast<int>(errors_.size()) - 1) {
220 return "";
221 }
222 return errors_[index];
223}
224
225/**
226 * Returns true if errors were found.
227 *
228 * @return True if errors were found.
229 */
230bool
232 return !errors_.empty();
233}
234
235/**
236 * Handles the errors.
237 *
238 * Error string are added in internal data structure.
239 *
240 * @param lineNumber The line number.
241 * @param error The type of the error.
242 * @param line The line in which error occurred.
243 * @return True.
244 */
245bool
247 int lineNumber,
249 const std::string& line) {
250
251 string errorString;
252 switch (error) {
254 errorString += "Syntax error ";
255 break;
257 errorString += "Illegal type error ";
258 break;
260 errorString += "Unknown key error ";
261 break;
263 errorString += "Missing value error ";
264 break;
265 }
266 errorString += "in line " + Conversion::toString(lineNumber) +
267 ": " + line;
268
269 errors_.push_back(errorString);
270 return true;
271}
272
273
274/**
275 * Creates real path to the file referred to in PCF.
276 *
277 * The path is constructed assuming the PCF is in the directory set with
278 * setPCFDirectory method.
279 *
280 * @param pathInPCF The path that reads in the PCF.
281 * @return Real path to the file.
282 */
283std::string
284ProcessorConfigurationFile::realPath(const std::string& pathInPCF) const {
285 if (FileSystem::isAbsolutePath(pathInPCF) || pcfDir_ == "") {
286 return pathInPCF;
287 } else {
288 return pcfDir_ + FileSystem::DIRECTORY_SEPARATOR + pathInPCF;
289 }
290}
void addSupportedKey(const std::string &key, ConfigurationValueType type, bool caseSensitive=false)
void load(std::istream &inputStream)
unsigned int timeStampValue(const std::string &key)
int intValue(const std::string &key, int index=0)
@ FE_UNKNOWN_KEY
Unknown key error.
@ FE_SYNTAX
Syntax error.
@ FE_MISSING_VALUE
Missing value error.
@ FE_ILLEGAL_TYPE
Illegal type error.
@ VT_STRING
String value.
@ VT_READABLE_TIME
Time in readable format.
@ VT_INTEGER
Integer value.
std::string value(const std::string &key, int index=0)
static std::string toString(const T &source)
static bool isAbsolutePath(const std::string &pathName)
static const std::string DIRECTORY_SEPARATOR
std::vector< std::string > errors_
static const std::string IMPLEMENTATION_SIZE
static const std::string IMPLEMENTATION
static const std::string ENCODING_MAP_MODIFIED
static const std::string ARCHITECTURE_SIZE
std::string realPath(const std::string &pathInPCF) const
ProcessorConfigurationFile(std::istream &inputStream)
void setPCFDirectory(const std::string &path)
static const std::string IMPLEMENTATION_MODIFIED
static const std::string ARCHITECTURE_MODIFIED
static const std::string ENCODING_MAP_SIZE
virtual bool handleError(int lineNumber, ConfigurationFile::ConfigurationFileError error, const std::string &line)
static const std::string ARCHITECTURE
static const std::string ENCODING_MAP