OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Private Member Functions | List of all members
IDF::IDFSerializer Class Reference

#include <IDFSerializer.hh>

Inheritance diagram for IDF::IDFSerializer:
Inheritance graph
Collaboration diagram for IDF::IDFSerializer:
Collaboration graph

Public Member Functions

 IDFSerializer ()
 
virtual ~IDFSerializer ()
 
virtual ObjectStatereadState ()
 
virtual void writeState (const ObjectState *state)
 
MachineImplementationreadMachineImplementation ()
 
void writeMachineImplementation (const MachineImplementation &implementation)
 
- Public Member Functions inherited from XMLSerializer
 XMLSerializer ()
 
virtual ~XMLSerializer ()
 
void setSourceFile (const std::string &fileName)
 
void setSourceString (const std::string &source)
 
void setDestinationFile (const std::string &fileName)
 
void setDestinationString (std::string &destination)
 
void setSchemaFile (const std::string &fileName)
 
void setUseSchema (bool useSchema)
 
void setXMLNamespace (std::string nsUri)
 
- Public Member Functions inherited from TCETools::Serializer
virtual ~Serializer ()
 

Static Private Member Functions

static ObjectStateconvertToOMFormat (const ObjectState *fileState)
 
static ObjectStateconvertToFileFormat (const ObjectState *omState)
 

Additional Inherited Members

- Protected Member Functions inherited from XMLSerializer
std::string sourceFile () const
 

Detailed Description

Writer and reader for IDF files.

Definition at line 45 of file IDFSerializer.hh.

Constructor & Destructor Documentation

◆ IDFSerializer()

IDF::IDFSerializer::IDFSerializer ( )

The constructor.

Definition at line 90 of file IDFSerializer.cc.

90 : XMLSerializer() {
92 setUseSchema(true);
93}
const string IDF_SCHEMA_FILE
static std::string schemaDirPath(const std::string &prog)
void setUseSchema(bool useSchema)
void setSchemaFile(const std::string &fileName)

References IDF_SCHEMA_FILE, Environment::schemaDirPath(), XMLSerializer::setSchemaFile(), and XMLSerializer::setUseSchema().

Here is the call graph for this function:

◆ ~IDFSerializer()

IDF::IDFSerializer::~IDFSerializer ( )
virtual

The destructor.

Definition at line 99 of file IDFSerializer.cc.

99 {
100}

Member Function Documentation

◆ convertToFileFormat()

ObjectState * IDF::IDFSerializer::convertToFileFormat ( const ObjectState omState)
staticprivate

Converts the given ObjectState tree that represents state of a MachineImplementation instance to IDF file format.

Parameters
omStateObjectState tree that represents state of a MachineImplementation instance.
Returns
The newly created ObjectState tree.

Definition at line 352 of file IDFSerializer.cc.

352 {
353
355
356 // the IC&decoder plugin data
358 ObjectState* child = omState->childByName(
360 ObjectState* icdecState = new ObjectState(IC_DECODER_PLUGIN);
361
362 if (child->hasAttribute(
365 newChild->setValue(
366 child->stringAttribute(
368 icdecState->addChild(newChild);
369 }
370
371 if (child->hasAttribute(
373 ObjectState* newChild = new ObjectState(
375 newChild->setValue(
376 child->stringAttribute(
378 icdecState->addChild(newChild);
379 }
380
381 if (child->hasAttribute(
383 ObjectState* newChild = new ObjectState(HDB_FILE);
384 newChild->setValue(
385 child->stringAttribute(
387 icdecState->addChild(newChild);
388 }
389
390
391 // Parameters
392 for (int i = 0; i < child->childCount(); i++) {
393 ObjectState* parameter = child->child(i);
394 assert(parameter->name() ==
396
398 icdecState->addChild(fileParam);
399 fileParam->setAttribute(
401 parameter->stringAttribute(
403
404 if (parameter->hasAttribute(
406
407 ObjectState* value =
409
410 value->setValue(parameter->stringAttribute(
412
413 fileParam->addChild(value);
414 }
415 }
416
417 fileState->addChild(icdecState);
418 }
419
420 // decompressor file
421 if (omState->hasAttribute(
424 fileState->addChild(newChild);
425 newChild->setValue(
426 omState->stringAttribute(
428
429 }
430
431 // add generated FUs.
432 ObjectState* fuGens =
434 for (int i = fuGens->childCount() - 1; i >= 0; --i) {
435 ObjectState* child = fuGens->child(i);
436 fileState->addChild(new ObjectState(*child));
437 }
438
439 // add FU implementations
440 ObjectState* fuImpls = omState->childByName(
442 for (int i = 0; i < fuImpls->childCount(); i++) {
443 ObjectState* child = fuImpls->child(i);
444 ObjectState* fu = new ObjectState(FU);
445 fileState->addChild(fu);
446 fu->setAttribute(
447 FU_NAME,
448 child->stringAttribute(
450 ObjectState* hdbFile = new ObjectState(HDB_FILE);
451 fu->addChild(hdbFile);
452 hdbFile->setValue(
453 child->stringAttribute(
455 ObjectState* id = new ObjectState(FU_ID);
456 fu->addChild(id);
457 id->setValue(
459 }
460
461 // add RF implementations
462 ObjectState* rfImpls = omState->childByName(
464 for (int i = 0; i < rfImpls->childCount(); i++) {
465 ObjectState* child = rfImpls->child(i);
466 ObjectState* rf = new ObjectState(RF);
467 fileState->addChild(rf);
468 rf->setAttribute(
469 RF_NAME,
470 child->stringAttribute(
472 ObjectState* hdbFile = new ObjectState(HDB_FILE);
473 rf->addChild(hdbFile);
474 hdbFile->setValue(
475 child->stringAttribute(
477 ObjectState* id = new ObjectState(RF_ID);
478 rf->addChild(id);
479 id->setValue(
481 }
482
483 // add IU implementations
484 ObjectState* iuImpls = omState->childByName(
486 for (int i = 0; i < iuImpls->childCount(); i++) {
487 ObjectState* child = iuImpls->child(i);
488 ObjectState* iu = new ObjectState(IU);
489 fileState->addChild(iu);
490 iu->setAttribute(
491 IU_NAME,
492 child->stringAttribute(
494 ObjectState* hdbFile = new ObjectState(HDB_FILE);
495 iu->addChild(hdbFile);
496 hdbFile->setValue(
497 child->stringAttribute(
499 ObjectState* id = new ObjectState(RF_ID);
500 iu->addChild(id);
501 id->setValue(
503 }
504
505 // add bus implementations
506 ObjectState* busImpls = omState->childByName(
508 for (int i = 0; i < busImpls->childCount(); i++) {
509 ObjectState* child = busImpls->child(i);
510 ObjectState* bus = new ObjectState(BUS);
511 fileState->addChild(bus);
512 bus->setAttribute(
513 BUS_NAME,
514 child->stringAttribute(
516 ObjectState* hdbFile = new ObjectState(HDB_FILE);
517 bus->addChild(hdbFile);
518 hdbFile->setValue(
519 child->stringAttribute(
521 ObjectState* id = new ObjectState(BUS_ID);
522 bus->addChild(id);
523 id->setValue(
525 }
526
527 // add socket implementations
528 ObjectState* socketImpls = omState->childByName(
530 for (int i = 0; i < socketImpls->childCount(); i++) {
531 ObjectState* child = socketImpls->child(i);
532 ObjectState* socket = new ObjectState(SOCKET);
533 fileState->addChild(socket);
534 socket->setAttribute(
535 IU_NAME,
536 child->stringAttribute(
538 ObjectState* hdbFile = new ObjectState(HDB_FILE);
539 socket->addChild(hdbFile);
540 hdbFile->setValue(
541 child->stringAttribute(
544 socket->addChild(id);
545 id->setValue(
547 }
548
549
550 return fileState;
551}
#define assert(condition)
const string SOCKET
const string FU
const string RF_NAME
const string FU_ID
const string RF_ID
const string DECOMPRESSOR_FILE
const string SOCKET_ID
const string IC_DECODER_PARAMETER
const string BUS
const string HDB_FILE
const string IC_DECODER_PLUGIN
const string ADF_IMPLEMENTATION
const string BUS_ID
const string IU
const string BUS_NAME
const string IC_DECODER_PARAMETER_VALUE
const string IC_DECODER_PLUGIN_NAME
const string IU_NAME
const string RF
const string IC_DECODER_PLUGIN_FILE
const string IC_DECODER_PARAMETER_NAME
#define FU_NAME
Definition OSAL.hh:494
static const std::string OSKEY_DECOMPRESSOR_FILE
ObjectState attribute key for the name of the decompressor file.
static const std::string OSNAME_IC_DECODER_PLUGIN
ObjectState name for the name of the IC/decoder plugin file.
static const std::string OSKEY_IC_DECODER_HDB
ObjectState attribute name for ic&decoder HDB.
static const std::string OSNAME_IU_IMPLEMENTATIONS
ObjectState name for IU implementation container.
static const std::string OSKEY_IC_DECODER_NAME
ObjectState attribute name for ic&decoder name.
static const std::string OSNAME_BUS_IMPLEMENTATIONS
ObjectState name for bus implementation container.
static const std::string OSNAME_FU_GENERATED
ObjectState name for FU generations container.
static const std::string OSKEY_IC_DECODER_FILE
ObjectState attribute name for ic&decoder file.
static const std::string OSNAME_IC_DECODER_PARAMETER
ObjectState attribute name for ic&decoder parameter.
static const std::string OSNAME_SOCKET_IMPLEMENTATIONS
ObjectState name for socket implementation container.
static const std::string OSKEY_IC_DECODER_PARAMETER_NAME
ObjectState attribute name for ic&decoder parameter name.
static const std::string OSNAME_RF_IMPLEMENTATIONS
ObjectState name for RF implementation container.
static const std::string OSNAME_FU_IMPLEMENTATIONS
ObjectState name for FU implementation container.
static const std::string OSKEY_IC_DECODER_PARAMETER_VALUE
ObjectState attribute name for ic&decoder parameter value.
static const std::string OSKEY_ID
ObjectState attribute key for the entry ID.
static const std::string OSKEY_UNIT_NAME
Objectstate attribute key for the name of the unit.
static const std::string OSKEY_HDB_FILE
ObjectState attribute key for the name of the HDB file.
bool hasAttribute(const std::string &name) const
ObjectState * childByName(const std::string &name) const
void setAttribute(const std::string &name, const std::string &value)
void setValue(const std::string &value)
bool hasChild(const std::string &name) const
ObjectState * child(int index) const
void addChild(ObjectState *child)
std::string stringAttribute(const std::string &name) const
std::string name() const
int childCount() const

References ObjectState::addChild(), ADF_IMPLEMENTATION, assert, BUS, BUS_ID, BUS_NAME, ObjectState::child(), ObjectState::childByName(), ObjectState::childCount(), DECOMPRESSOR_FILE, FU, FU_ID, FU_NAME, ObjectState::hasAttribute(), ObjectState::hasChild(), HDB_FILE, IC_DECODER_PARAMETER, IC_DECODER_PARAMETER_NAME, IC_DECODER_PARAMETER_VALUE, IC_DECODER_PLUGIN, IC_DECODER_PLUGIN_FILE, IC_DECODER_PLUGIN_NAME, IU, IU_NAME, ObjectState::name(), IDF::MachineImplementation::OSKEY_DECOMPRESSOR_FILE, IDF::UnitImplementationLocation::OSKEY_HDB_FILE, IDF::MachineImplementation::OSKEY_IC_DECODER_FILE, IDF::MachineImplementation::OSKEY_IC_DECODER_HDB, IDF::MachineImplementation::OSKEY_IC_DECODER_NAME, IDF::MachineImplementation::OSKEY_IC_DECODER_PARAMETER_NAME, IDF::MachineImplementation::OSKEY_IC_DECODER_PARAMETER_VALUE, IDF::UnitImplementationLocation::OSKEY_ID, IDF::UnitImplementationLocation::OSKEY_UNIT_NAME, IDF::MachineImplementation::OSNAME_BUS_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_FU_GENERATED, IDF::MachineImplementation::OSNAME_FU_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_IC_DECODER_PARAMETER, IDF::MachineImplementation::OSNAME_IC_DECODER_PLUGIN, IDF::MachineImplementation::OSNAME_IU_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_RF_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_SOCKET_IMPLEMENTATIONS, RF, RF_ID, RF_NAME, ObjectState::setAttribute(), ObjectState::setValue(), SOCKET, SOCKET_ID, and ObjectState::stringAttribute().

Referenced by writeState().

Here is the call graph for this function:

◆ convertToOMFormat()

ObjectState * IDF::IDFSerializer::convertToOMFormat ( const ObjectState fileState)
staticprivate

Converts the given ObjectState tree that represents an IDF file to format that can be loaded by MachineImplementation instance.

Parameters
fileStateObjectState tree that represents an IDF file.
Returns
The newly created ObjectState tree.

Definition at line 178 of file IDFSerializer.cc.

178 {
179
180 ObjectState* omState = new ObjectState(
182
183 // add unit implementations
184 ObjectState* fuGenerated =
186 ObjectState* fuImpls = new ObjectState(
188 ObjectState* rfImpls = new ObjectState(
190 ObjectState* iuImpls = new ObjectState(
192 ObjectState* busImpls = new ObjectState(
194 ObjectState* socketImpls = new ObjectState(
196
197 omState->addChild(fuImpls);
198 omState->addChild(rfImpls);
199 omState->addChild(iuImpls);
200 omState->addChild(busImpls);
201 omState->addChild(socketImpls);
202 omState->addChild(fuGenerated);
203
204 // the IC&decoder plugin data
205 if (fileState->hasChild(IC_DECODER_PLUGIN)) {
206 ObjectState* child = fileState->childByName(IC_DECODER_PLUGIN);
207 ObjectState* icdecState = new ObjectState(
209
210 std::string name = "";
211 std::string fileName = "";
212 std::string hdbFile = "";
213
214 for (int i = 0; i < child->childCount(); i++) {
215 ObjectState* attr = child->child(i);
216 if (attr->name() == IC_DECODER_PLUGIN_NAME) {
217 name = attr->stringValue();
218 } else if (attr->name() == IC_DECODER_PLUGIN_FILE) {
219 fileName = attr->stringValue();
220 } else if (attr->name() == HDB_FILE) {
221 hdbFile = attr->stringValue();
222 } else if (attr->name() == IC_DECODER_PARAMETER) {
223
224 // IC&decoder parameter.
225 ObjectState* parameterState = new ObjectState(
227
228 std::string parameterName = attr->stringAttribute(
230
231 parameterState->setAttribute(
233 parameterName);
234
235 std::string parameterValue = "";
236
238 parameterValue = attr->childByName(
240 }
241
242 parameterState->setAttribute(
244 parameterValue);
245
246 icdecState->addChild(parameterState);
247 }
248 }
249
250
251 icdecState->setAttribute(
253 icdecState->setAttribute(
255 icdecState->setAttribute(
257 omState->addChild(icdecState);
258 }
259
260 // decompressor file
261 if (fileState->hasChild(DECOMPRESSOR_FILE)) {
262 ObjectState* child = fileState->childByName(DECOMPRESSOR_FILE);
263 omState->setAttribute(
265 child->stringValue());
266 }
267
268 // Generated FUs.
269 for (int i = 0; i < fileState->childCount(); i++) {
270 ObjectState* child = fileState->child(i);
271
272 if (child->name() != FU_GENERATE) {
273 continue;
274 }
275
276 ObjectState* impl = new ObjectState(*child);
277 fuGenerated->addChild(impl);
278 }
279
280 const std::set<std::string> handledElements{FU, RF, IU, SOCKET, BUS};
281 for (int i = 0; i < fileState->childCount(); i++) {
282 ObjectState* child = fileState->child(i);
283
284 if (!handledElements.count(child->name())) {
285 continue;
286 }
287
288 ObjectState* impl = new ObjectState(
290 impl->setAttribute(
292 child->childByName(HDB_FILE)->stringValue());
293
294 if (child->name() == FU) {
295 fuImpls->addChild(impl);
296 impl->setAttribute(
298 child->stringAttribute(FU_NAME));
299 impl->setAttribute(
301 child->childByName(FU_ID)->stringValue());
302 } else if (child->name() == RF) {
303 rfImpls->addChild(impl);
304 impl->setAttribute(
306 child->stringAttribute(RF_NAME));
307 impl->setAttribute(
309 child->childByName(RF_ID)->stringValue());
310 } else if (child->name() == IU) {
311 iuImpls->addChild(impl);
312 impl->setAttribute(
314 child->stringAttribute(IU_NAME));
315 impl->setAttribute(
317 child->childByName(RF_ID)->stringValue());
318 } else if (child->name() == BUS) {
319 busImpls->addChild(impl);
320 impl->setAttribute(
322 child->stringAttribute(BUS_NAME));
323 impl->setAttribute(
325 child->childByName(BUS_ID)->stringValue());
326 } else if (child->name() == SOCKET) {
327 socketImpls->addChild(impl);
328 impl->setAttribute(
331 impl->setAttribute(
334 } else {
335 assert(false);
336 }
337 }
338
339 return omState;
340}
const string SOCKET_NAME
const string FU_GENERATE
static const std::string OSNAME_MACHINE_IMPLEMENTATION
ObjectState name for machine implementation.
static const std::string OSNAME_UNIT_IMPLEMENTATION
ObjectState name for unit implementation.
std::string stringValue() const

References ObjectState::addChild(), assert, BUS, BUS_ID, BUS_NAME, ObjectState::child(), ObjectState::childByName(), ObjectState::childCount(), DECOMPRESSOR_FILE, FU, FU_GENERATE, FU_ID, FU_NAME, ObjectState::hasChild(), HDB_FILE, IC_DECODER_PARAMETER, IC_DECODER_PARAMETER_NAME, IC_DECODER_PARAMETER_VALUE, IC_DECODER_PLUGIN, IC_DECODER_PLUGIN_FILE, IC_DECODER_PLUGIN_NAME, IU, IU_NAME, ObjectState::name(), IDF::MachineImplementation::OSKEY_DECOMPRESSOR_FILE, IDF::UnitImplementationLocation::OSKEY_HDB_FILE, IDF::MachineImplementation::OSKEY_IC_DECODER_FILE, IDF::MachineImplementation::OSKEY_IC_DECODER_HDB, IDF::MachineImplementation::OSKEY_IC_DECODER_NAME, IDF::MachineImplementation::OSKEY_IC_DECODER_PARAMETER_NAME, IDF::MachineImplementation::OSKEY_IC_DECODER_PARAMETER_VALUE, IDF::UnitImplementationLocation::OSKEY_ID, IDF::UnitImplementationLocation::OSKEY_UNIT_NAME, IDF::MachineImplementation::OSNAME_BUS_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_FU_GENERATED, IDF::MachineImplementation::OSNAME_FU_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_IC_DECODER_PARAMETER, IDF::MachineImplementation::OSNAME_IC_DECODER_PLUGIN, IDF::MachineImplementation::OSNAME_IU_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_MACHINE_IMPLEMENTATION, IDF::MachineImplementation::OSNAME_RF_IMPLEMENTATIONS, IDF::MachineImplementation::OSNAME_SOCKET_IMPLEMENTATIONS, IDF::UnitImplementationLocation::OSNAME_UNIT_IMPLEMENTATION, RF, RF_ID, RF_NAME, ObjectState::setAttribute(), SOCKET, SOCKET_ID, SOCKET_NAME, ObjectState::stringAttribute(), and ObjectState::stringValue().

Referenced by readState().

Here is the call graph for this function:

◆ readMachineImplementation()

MachineImplementation * IDF::IDFSerializer::readMachineImplementation ( )

Reads the source IDF file that is set and creates a MachineImplementation instance from it.

Returns
The newly created MachineImplementation instance.
Exceptions
SerializerExceptionIf an error occurs while reading the file.
ObjectStateLoadingExceptionIf an error occurs while loading the state of MachineImplementation instance.

Definition at line 148 of file IDFSerializer.cc.

148 {
149 ObjectState* omState = readState();
150 MachineImplementation* implementation = new MachineImplementation(
151 omState);
152 delete omState;
153 return implementation;
154}
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
virtual ObjectState * readState()

References implementation, and readState().

Referenced by IDF::MachineImplementation::loadFromIDF(), loadInputs(), ProGe::ProGeUI::loadMachineImplementation(), ProGe::ProGeUI::loadProcessorConfiguration(), and readIdf().

Here is the call graph for this function:

◆ readState()

ObjectState * IDF::IDFSerializer::readState ( )
virtual

Reads the source file that is set and creates an ObjectState tree that can be loaded by MachineImplementation instance.

Returns
The newly created ObjectState tree.
Exceptions
SerializerExceptionIf an error occurs while reading the file.

Reimplemented from XMLSerializer.

Definition at line 111 of file IDFSerializer.cc.

111 {
113 ObjectState* omState = convertToOMFormat(fileState);
114
115 // set the source IDF
116 omState->setAttribute(
118 delete fileState;
119 return omState;
120}
static ObjectState * convertToOMFormat(const ObjectState *fileState)
static const std::string OSKEY_SOURCE_IDF
ObjectState attribute name for the source IDF.
std::string sourceFile() const
virtual ObjectState * readState()

References convertToOMFormat(), IDF::MachineImplementation::OSKEY_SOURCE_IDF, XMLSerializer::readState(), ObjectState::setAttribute(), and XMLSerializer::sourceFile().

Referenced by DSDBManager::implementation(), ProcessorImplementationWindow::onLoadIDF(), readMachineImplementation(), and DSDBManager::writeImplementationToFile().

Here is the call graph for this function:

◆ writeMachineImplementation()

void IDF::IDFSerializer::writeMachineImplementation ( const MachineImplementation implementation)

Writes the given machine implementation to the destination IDF file.

Parameters
implementationThe implementation to be written.
Exceptions
SerializerExceptionIf an error occurs while writing file.

Definition at line 163 of file IDFSerializer.cc.

164 {
166 writeState(omState);
167 delete omState;
168}
virtual void writeState(const ObjectState *state)
virtual ObjectState * saveState() const

References implementation, IDF::MachineImplementation::saveState(), and writeState().

Referenced by ProcessorImplementationWindow::doSaveIDF().

Here is the call graph for this function:

◆ writeState()

void IDF::IDFSerializer::writeState ( const ObjectState state)
virtual

Writes the given ObjectState tree created by MachineImplementation::saveState to an IDF file.

Parameters
stateObjectState tree that represents the MachineImplementation instance.
Exceptions
SerializerExceptionIf an error occurs while writing the file.

Reimplemented from XMLSerializer.

Definition at line 131 of file IDFSerializer.cc.

131 {
132 ObjectState* fileState = convertToFileFormat(state);
133 XMLSerializer::writeState(fileState);
134 delete fileState;
135}
static ObjectState * convertToFileFormat(const ObjectState *omState)
virtual void writeState(const ObjectState *rootState)

References convertToFileFormat(), and XMLSerializer::writeState().

Referenced by DSDBManager::addImplementation(), DSDBManager::writeImplementationToFile(), and writeMachineImplementation().

Here is the call graph for this function:

The documentation for this class was generated from the following files: