OpenASIP  2.0
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 
37 using std::string;
38 
39 const string ProcessorConfigurationFile::ARCHITECTURE = "Architecture";
40 const string ProcessorConfigurationFile::ARCHITECTURE_SIZE = "ArchitectureSize";
42 "ArchitectureModified";
43 const string ProcessorConfigurationFile::ENCODING_MAP = "EncodingMap";
44 const string ProcessorConfigurationFile::ENCODING_MAP_SIZE = "EncodingSize";
46 "EncodingModified";
47 const string ProcessorConfigurationFile::IMPLEMENTATION = "Implementation";
49 "ImplementationSize";
51 "ImplementationModified";
52 
53 /**
54  * Constructor.
55  *
56  * @param inputStream Stream where configuration file is read from.
57  */
59  std::istream& inputStream) : ConfigurationFile(true), pcfDir_(".") {
60 
64  true);
65 
69  true);
70 
75 
76  load(inputStream);
77 }
78 
79 /**
80  * Destructor.
81  */
83 }
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  */
94 void
95 ProcessorConfigurationFile::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  */
106 string
108  return realPath(value(ARCHITECTURE));
109 }
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  */
117 unsigned int
119  return intValue(ARCHITECTURE_SIZE);
120 }
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  */
128 unsigned int
131 }
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  */
139 string
141  return realPath(value(IMPLEMENTATION));
142 }
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  */
150 unsigned int
153 }
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  */
161 unsigned int
164 }
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  */
172 string
174  return realPath(value(ENCODING_MAP));
175 }
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  */
183 unsigned int
185  return intValue(ENCODING_MAP_SIZE);
186 }
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  */
194 unsigned int
197 }
198 
199 /**
200  * Returns the number of errors.
201  *
202  * @return The number of errors.
203  */
204 int
206  return errors_.size();
207 }
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  */
216 string
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  */
230 bool
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  */
245 bool
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  */
283 std::string
284 ProcessorConfigurationFile::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 }
ProcessorConfigurationFile::ENCODING_MAP
static const std::string ENCODING_MAP
Definition: ProcessorConfigurationFile.hh:84
ProcessorConfigurationFile::ARCHITECTURE_MODIFIED
static const std::string ARCHITECTURE_MODIFIED
Definition: ProcessorConfigurationFile.hh:82
ProcessorConfigurationFile::ENCODING_MAP_SIZE
static const std::string ENCODING_MAP_SIZE
Definition: ProcessorConfigurationFile.hh:85
FileSystem.hh
ConfigurationFile::VT_STRING
@ VT_STRING
String value.
Definition: ConfigurationFile.hh:76
ProcessorConfigurationFile::architectureModified
unsigned int architectureModified()
Definition: ProcessorConfigurationFile.cc:129
ProcessorConfigurationFile::implementationSize
unsigned int implementationSize()
Definition: ProcessorConfigurationFile.cc:151
ProcessorConfigurationFile::architectureSize
unsigned int architectureSize()
Definition: ProcessorConfigurationFile.cc:118
ConfigurationFile
Definition: ConfigurationFile.hh:50
ProcessorConfigurationFile::IMPLEMENTATION_MODIFIED
static const std::string IMPLEMENTATION_MODIFIED
Definition: ProcessorConfigurationFile.hh:90
ConfigurationFile::VT_INTEGER
@ VT_INTEGER
Integer value.
Definition: ConfigurationFile.hh:74
ProcessorConfigurationFile::ARCHITECTURE_SIZE
static const std::string ARCHITECTURE_SIZE
Definition: ProcessorConfigurationFile.hh:81
ProcessorConfigurationFile::architectureName
std::string architectureName()
Definition: ProcessorConfigurationFile.cc:107
ProcessorConfigurationFile::realPath
std::string realPath(const std::string &pathInPCF) const
Definition: ProcessorConfigurationFile.cc:284
Conversion::toString
static std::string toString(const T &source)
ConfigurationFile::FE_UNKNOWN_KEY
@ FE_UNKNOWN_KEY
Unknown key error.
Definition: ConfigurationFile.hh:88
ProcessorConfigurationFile::ARCHITECTURE
static const std::string ARCHITECTURE
Definition: ProcessorConfigurationFile.hh:80
ConfigurationFile::value
std::string value(const std::string &key, int index=0)
Definition: ConfigurationFile.cc:114
ProcessorConfigurationFile::IMPLEMENTATION_SIZE
static const std::string IMPLEMENTATION_SIZE
Definition: ProcessorConfigurationFile.hh:89
ProcessorConfigurationFile::errors_
std::vector< std::string > errors_
Definition: ProcessorConfigurationFile.hh:92
ProcessorConfigurationFile::errors
bool errors()
Definition: ProcessorConfigurationFile.cc:231
ProcessorConfigurationFile::pcfDir_
std::string pcfDir_
Definition: ProcessorConfigurationFile.hh:98
ProcessorConfigurationFile::implementationModified
unsigned int implementationModified()
Definition: ProcessorConfigurationFile.cc:162
ProcessorConfigurationFile::setPCFDirectory
void setPCFDirectory(const std::string &path)
Definition: ProcessorConfigurationFile.cc:95
ProcessorConfigurationFile::implementationName
std::string implementationName()
Definition: ProcessorConfigurationFile.cc:140
Conversion.hh
ProcessorConfigurationFile::ENCODING_MAP_MODIFIED
static const std::string ENCODING_MAP_MODIFIED
Definition: ProcessorConfigurationFile.hh:86
ProcessorConfigurationFile::~ProcessorConfigurationFile
virtual ~ProcessorConfigurationFile()
Definition: ProcessorConfigurationFile.cc:82
ProcessorConfigurationFile::errorCount
int errorCount()
Definition: ProcessorConfigurationFile.cc:205
ProcessorConfigurationFile::errorString
std::string errorString(int index)
Definition: ProcessorConfigurationFile.cc:217
ConfigurationFile::FE_SYNTAX
@ FE_SYNTAX
Syntax error.
Definition: ConfigurationFile.hh:86
ConfigurationFile::ConfigurationFileError
ConfigurationFileError
Definition: ConfigurationFile.hh:85
ProcessorConfigurationFile::handleError
virtual bool handleError(int lineNumber, ConfigurationFile::ConfigurationFileError error, const std::string &line)
Definition: ProcessorConfigurationFile.cc:246
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
ConfigurationFile::FE_ILLEGAL_TYPE
@ FE_ILLEGAL_TYPE
Illegal type error.
Definition: ConfigurationFile.hh:87
ConfigurationFile::load
void load(std::istream &inputStream)
Definition: ConfigurationFile.cc:88
ConfigurationFile::intValue
int intValue(const std::string &key, int index=0)
Definition: ConfigurationFile.cc:146
ProcessorConfigurationFile.hh
ConfigurationFile::timeStampValue
unsigned int timeStampValue(const std::string &key)
Definition: ConfigurationFile.cc:228
ProcessorConfigurationFile::encodingMapModified
unsigned int encodingMapModified()
Definition: ProcessorConfigurationFile.cc:195
ProcessorConfigurationFile::ProcessorConfigurationFile
ProcessorConfigurationFile(std::istream &inputStream)
Definition: ProcessorConfigurationFile.cc:58
ProcessorConfigurationFile::IMPLEMENTATION
static const std::string IMPLEMENTATION
Definition: ProcessorConfigurationFile.hh:88
ConfigurationFile::addSupportedKey
void addSupportedKey(const std::string &key, ConfigurationValueType type, bool caseSensitive=false)
Definition: ConfigurationFile.cc:292
ProcessorConfigurationFile::encodingMapSize
unsigned int encodingMapSize()
Definition: ProcessorConfigurationFile.cc:184
FileSystem::isAbsolutePath
static bool isAbsolutePath(const std::string &pathName)
Definition: FileSystem.cc:234
ConfigurationFile::FE_MISSING_VALUE
@ FE_MISSING_VALUE
Missing value error.
Definition: ConfigurationFile.hh:89
ProcessorConfigurationFile::encodingMapName
std::string encodingMapName()
Definition: ProcessorConfigurationFile.cc:173
ConfigurationFile::VT_READABLE_TIME
@ VT_READABLE_TIME
Time in readable format.
Definition: ConfigurationFile.hh:78