OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
OperationSerializer Class Reference

#include <OperationSerializer.hh>

Inheritance diagram for OperationSerializer:
Inheritance graph
Collaboration diagram for OperationSerializer:
Collaboration graph

Public Member Functions

 OperationSerializer ()
 
virtual ~OperationSerializer ()
 
virtual void writeState (const ObjectState *state)
 
virtual ObjectStatereadState ()
 
void setSourceFile (const std::string &filename)
 
void setDestinationFile (const std::string &filename)
 
void setSchemaFile (const std::string &filename)
 
void setUseSchema (bool useSchema)
 
- Public Member Functions inherited from TCETools::Serializer
virtual ~Serializer ()
 

Private Member Functions

 OperationSerializer (const OperationSerializer &)
 Copying not allowed.
 
OperationSerializeroperator= (const OperationSerializer &)
 Assignment not allowed.
 
ObjectStateconvertToXMLFormat (const ObjectState *state)
 
ObjectStateconvertToOperationFormat (const ObjectState *state)
 
ObjectStatetoOperation (const ObjectState *state)
 
ObjectStatetoXMLFormat (const ObjectState *state)
 
void setOperandProperties (ObjectState *operand, ObjectState *source)
 

Private Attributes

XMLSerializer serializer_
 Constructs the ObjectState tree from the XML file.
 

Detailed Description

Class that constructs an ObjectState tree that represents the information contents of an operation module from a given external file.

Definition at line 49 of file OperationSerializer.hh.

Constructor & Destructor Documentation

◆ OperationSerializer() [1/2]

OperationSerializer::OperationSerializer ( )

Constructor.

If schema file is found it is used.

Definition at line 67 of file OperationSerializer.cc.

67 : Serializer() {
68
70 if (path != "") {
71 string schema = path + FileSystem::DIRECTORY_SEPARATOR +
73 if (FileSystem::fileExists(schema)) {
74 setSchemaFile(schema);
75 setUseSchema(true);
76 }
77 }
78}
const string SCHEMA_FILE_NAME
const string LIBRARY_NAME
Name of the library.
static std::string schemaDirPath(const std::string &prog)
static const std::string DIRECTORY_SEPARATOR
static bool fileExists(const std::string fileName)
void setUseSchema(bool useSchema)
void setSchemaFile(const std::string &filename)

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), LIBRARY_NAME, SCHEMA_FILE_NAME, Environment::schemaDirPath(), setSchemaFile(), and setUseSchema().

Here is the call graph for this function:

◆ ~OperationSerializer()

OperationSerializer::~OperationSerializer ( )
virtual

Destructor.

Definition at line 83 of file OperationSerializer.cc.

83 {
84}

◆ OperationSerializer() [2/2]

OperationSerializer::OperationSerializer ( const OperationSerializer )
private

Copying not allowed.

Member Function Documentation

◆ convertToOperationFormat()

ObjectState * OperationSerializer::convertToOperationFormat ( const ObjectState state)
private

Converts ObjectState to more easily parseable format.

More easily parseable format is such that there are less nodes. Only children of the main node are the operands, affects, and affected-by nodes.

Parameters
stateObjectState to be converted.
Exceptions
ObjectStateLoadingExceptionIf ObjectState conversion fails.
Returns
The converted ObjectState tree.

Definition at line 318 of file OperationSerializer.cc.

318 {
319 ObjectState* operation = new ObjectState(OPSER_OSAL);
320 for (int i = 0; i < state->childCount(); i++) {
321 ObjectState* child = state->child(i);
322 operation->addChild(toOperation(child));
323 }
324 return operation;
325}
const string OPSER_OSAL
XML tag for the module.
ObjectState * child(int index) const
void addChild(ObjectState *child)
int childCount() const
ObjectState * toOperation(const ObjectState *state)

References ObjectState::addChild(), ObjectState::child(), ObjectState::childCount(), OPSER_OSAL, and toOperation().

Referenced by readState().

Here is the call graph for this function:

◆ convertToXMLFormat()

ObjectState * OperationSerializer::convertToXMLFormat ( const ObjectState state)
private

Converts ObjectState to the format understood by XMLSerializer.

XMLSerializer needs an ObjectState tree in which each attribute is in its own node. ObjectState tree obtained form an operation is not in that format. This is why conversion is needed.

Parameters
stateObjectState to be converted.
Exceptions
ObjectStateLoadingExceptionIf ObjectState conversion fails.
Returns
The converted ObjectState tree.

Definition at line 147 of file OperationSerializer.cc.

147 {
148 ObjectState* operation = new ObjectState(OPSER_OSAL);
150 for (int i = 0; i < state->childCount(); i++) {
151 ObjectState* child = state->child(i);
152 operation->addChild(toXMLFormat(child));
153 }
154 return operation;
155}
const double VERSION_NUMBER
The version number.
const string OPSER_VERSION
XML tag for version.
void setAttribute(const std::string &name, const std::string &value)
ObjectState * toXMLFormat(const ObjectState *state)

References ObjectState::addChild(), ObjectState::child(), ObjectState::childCount(), OPSER_OSAL, OPSER_VERSION, ObjectState::setAttribute(), toXMLFormat(), and VERSION_NUMBER.

Referenced by writeState().

Here is the call graph for this function:

◆ operator=()

OperationSerializer & OperationSerializer::operator= ( const OperationSerializer )
private

Assignment not allowed.

◆ readState()

ObjectState * OperationSerializer::readState ( )
virtual

Reads the Operation property file and returns a corresponding ObjectState.

ObjectState is converted to more easily parseable format before returning.

Returns
The read ObjectState tree.

Implements TCETools::Serializer.

Definition at line 118 of file OperationSerializer.cc.

118 {
119 ObjectState* operationState = NULL;
120 try {
121 ObjectState* xmlState = serializer_.readState();
122 operationState = convertToOperationFormat(xmlState);
123 delete xmlState;
124 } catch (const Exception& e) {
125 string method = "OperationSerializer::readState()";
126 string msg = "Problems reading the state: " + e.errorMessage();
127 SerializerException error(__FILE__, __LINE__, __func__, msg);
128 error.setCause(e);
129 throw error;
130 }
131
132 return operationState;
133}
#define __func__
std::string errorMessage() const
Definition Exception.cc:123
ObjectState * convertToOperationFormat(const ObjectState *state)
XMLSerializer serializer_
Constructs the ObjectState tree from the XML file.
virtual ObjectState * readState()

References __func__, convertToOperationFormat(), Exception::errorMessage(), XMLSerializer::readState(), serializer_, and Exception::setCause().

Referenced by OSEdTreeView::constructTree(), OSEdPropertiesCmd::Do(), OSEdRemoveOperationCmd::Do(), OperationPropertyLoader::loadModule(), OperationContainer::operation(), OperationIndex::readOperations(), and OperationBuilder::verifyXML().

Here is the call graph for this function:

◆ setDestinationFile()

void OperationSerializer::setDestinationFile ( const std::string &  filename)

Sets destination file.

Parameters
filenameThe name of the file.

Definition at line 546 of file OperationSerializer.cc.

546 {
548}
void setDestinationFile(const std::string &fileName)

References serializer_, and XMLSerializer::setDestinationFile().

Referenced by OSEdAddOperationCmd::Do(), OSEdPropertiesCmd::Do(), and OSEdRemoveOperationCmd::Do().

Here is the call graph for this function:

◆ setOperandProperties()

void OperationSerializer::setOperandProperties ( ObjectState operand,
ObjectState source 
)
private

Set operand properties to right values.

Parameters
operandOperand which properties are set.
sourceOriginal ObjectState tree.

Definition at line 508 of file OperationSerializer.cc.

510 {
511
512 for (int childIndex = 0; childIndex < source->childCount();
513 childIndex++) {
514
515 ObjectState* child = source->child(childIndex);
516 if (child->name() == Operand::OPRND_MEM_ADDRESS) {
518 } else if (child->name() == Operand::OPRND_MEM_DATA) {
520 } else if (child->name() == Operand::OPRND_CAN_SWAP) {
521 ObjectState* canSwap = new ObjectState(*child);
522 operand->addChild(canSwap);
523 }
524 if (child->name() == Operand::OPRND_MEM_UNITS) {
526 }
527 }
528}
int intValue() const
std::string name() const
static const std::string OPRND_CAN_SWAP
Object state name for can swap.
Definition Operand.hh:92
static const std::string OPRND_MEM_UNITS
Object state name for memory unit count.
Definition Operand.hh:88
static const std::string OPRND_MEM_ADDRESS
Object state name for memory address.
Definition Operand.hh:86
static const std::string OPRND_MEM_DATA
Object state name for memory data.
Definition Operand.hh:90

References ObjectState::addChild(), ObjectState::child(), ObjectState::childCount(), ObjectState::intValue(), ObjectState::name(), Operand::OPRND_CAN_SWAP, Operand::OPRND_MEM_ADDRESS, Operand::OPRND_MEM_DATA, Operand::OPRND_MEM_UNITS, and ObjectState::setAttribute().

Referenced by toOperation().

Here is the call graph for this function:

◆ setSchemaFile()

void OperationSerializer::setSchemaFile ( const std::string &  filename)

Sets schema file.

Parameters
fileNameThe name of the file.

Definition at line 556 of file OperationSerializer.cc.

556 {
557 serializer_.setSchemaFile(filename);
558}
void setSchemaFile(const std::string &fileName)

References serializer_, and XMLSerializer::setSchemaFile().

Referenced by OperationSerializer().

Here is the call graph for this function:

◆ setSourceFile()

void OperationSerializer::setSourceFile ( const std::string &  filename)

Sets source file.

Parameters
filenameThe name of the file.

Definition at line 536 of file OperationSerializer.cc.

536 {
537 serializer_.setSourceFile(filename);
538}
void setSourceFile(const std::string &fileName)

References serializer_, and XMLSerializer::setSourceFile().

Referenced by OSEdTreeView::constructTree(), OSEdPropertiesCmd::Do(), OSEdRemoveOperationCmd::Do(), OperationPropertyLoader::loadModule(), OperationContainer::operation(), OperationIndex::readOperations(), and OperationBuilder::verifyXML().

Here is the call graph for this function:

◆ setUseSchema()

void OperationSerializer::setUseSchema ( bool  useSchema)

Sets whether schema is used or not.

Parameters
useSchemaTrue or false, depending on if schema is to be used or not.

Definition at line 566 of file OperationSerializer.cc.

566 {
567 serializer_.setUseSchema(useSchema);
568}
void setUseSchema(bool useSchema)

References serializer_, and XMLSerializer::setUseSchema().

Referenced by OperationSerializer().

Here is the call graph for this function:

◆ toOperation()

ObjectState * OperationSerializer::toOperation ( const ObjectState state)
private

Converts Operation ObjectState tree to more easily parsed format.

Parameters
stateObjectState to be converted.
Exceptions
ObjectStateLoadingExceptionIf ObjectState conversion fails.
Returns
The converted ObjectState tree.

Definition at line 335 of file OperationSerializer.cc.

335 {
337
338 try {
339 for (int i = 0; i < state->childCount(); i++) {
340
341 ObjectState* child = state->child(i);
342
343 if (child->name() == Operation::OPRN_NAME) {
344 root->setAttribute(
346 } else if (child->name() == Operation::OPRN_DESCRIPTION) {
348 } else if (child->name() == Operation::OPRN_INPUTS) {
350 } else if (child->name() == Operation::OPRN_OUTPUTS) {
352 } else if (child->name() == Operation::OPRN_READS_MEMORY) {
354 } else if (child->name() == Operation::OPRN_WRITES_MEMORY) {
356 } else if (child->name() == Operation::OPRN_TRAP) {
358 } else if (child->name() == Operation::OPRN_SIDE_EFFECTS) {
360 } else if (child->name() == Operation::OPRN_CLOCKED) {
362 } else if (child->name() == Operation::OPRN_CONTROL_FLOW) {
364 } else if (child->name() == Operation::OPRN_ISCALL) {
366 } else if (child->name() == Operation::OPRN_ISBRANCH) {
368
369// } else if (child->name() == Operation::OPRN_AFFECTED_BY) {
370// ObjectState* affectedBy = new ObjectState(*child);
371// root->addChild(affectedBy);
372
373// } else if (child->name() == Operation::OPRN_AFFECTS) {
374// ObjectState* affects = new ObjectState(*child);
375// root->addChild(affects);
376
377 } else if (child->name() == Operation::OPRN_IN) {
379
380 inOperand->setAttribute(
383
384 inOperand->setAttribute(
387
389 inOperand->setAttribute(
392 }
393
395 inOperand->setAttribute(
398 }
399
400 root->addChild(inOperand);
401
402 setOperandProperties(inOperand, child);
403
404 if (!inOperand->hasAttribute(Operand::OPRND_MEM_ADDRESS)) {
405 inOperand->setAttribute(Operand::OPRND_MEM_ADDRESS, false);
406 }
407
408 if (!inOperand->hasAttribute(Operand::OPRND_MEM_DATA)) {
409 inOperand->setAttribute(Operand::OPRND_MEM_DATA, false);
410 }
411
412 } else if (child->name() == Operation::OPRN_OUT) {
413
415
416 outOperand->setAttribute(
419
420 outOperand->setAttribute(
423
425 outOperand->setAttribute(
428 }
429
431 outOperand->setAttribute(
434 }
435
436 root->addChild(outOperand);
437 setOperandProperties(outOperand, child);
438
439 outOperand->setAttribute(Operand::OPRND_MEM_ADDRESS, false);
440
441 if (!outOperand->hasAttribute(Operand::OPRND_MEM_DATA)) {
442 outOperand->setAttribute(Operand::OPRND_MEM_DATA, false);
443 }
444
445 } else {
446 // just copy other elements
447 ObjectState* copyChild = new ObjectState(*child);
448 root->addChild(copyChild);
449 }
450 }
451
452 root->setAttribute(
455
457 root->setAttribute(Operation::OPRN_DESCRIPTION, std::string(""));
458 }
459
462 }
463
466 }
467
470 }
471
474 }
475
478 }
479
482 }
485 }
488 }
489
490 } catch (const Exception& e) {
491 string msg = "Error while constructing ObjectState tree" +
492 e.errorMessage();
493 ObjectStateLoadingException error(__FILE__, __LINE__, __func__, msg);
494 error.setCause(e);
495 throw error;
496 }
497
498 return root;
499}
bool hasAttribute(const std::string &name) const
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string stringValue() const
static const std::string OPRND_ELEM_WIDTH
Object state name for element width.
Definition Operand.hh:98
static const std::string OPRND_TYPE
Object state name for operand type.
Definition Operand.hh:84
static const std::string OPRND_ELEM_COUNT
Object state name for element count.
Definition Operand.hh:100
static const std::string OPRND_ID
Object state name for operand id.
Definition Operand.hh:82
void setOperandProperties(ObjectState *operand, ObjectState *source)
static const char * OPRN_CONTROL_FLOW
Object state name for control flow property.
Definition Operation.hh:81
static const char * OPRN_ISBRANCH
Object state name for branch property.
Definition Operation.hh:99
static const char * OPRN_DESCRIPTION
Object state name for description.
Definition Operation.hh:69
static const char * OPRN_IN
Object state name for input operand.
Definition Operation.hh:91
static const char * OPRN_CLOCKED
Object state name for clockedness.
Definition Operation.hh:79
static const char * OPRN_TRAP
Object state name for trap.
Definition Operation.hh:75
static const char * OPRN_OPERATION
Object state name for operation.
Definition Operation.hh:65
static const char * OPRN_ISCALL
Object state name for call property.
Definition Operation.hh:97
static const char * OPRN_SIDE_EFFECTS
Object state name for side effects.
Definition Operation.hh:77
static const char * OPRN_READS_MEMORY
Object state name for reads memory.
Definition Operation.hh:83
static const char * OPRN_OUT
Object state name for output operand.
Definition Operation.hh:93
static const char * OPRN_OUTPUTS
Object state name for outputs.
Definition Operation.hh:73
static const char * OPRN_NAME
Object state name for name.
Definition Operation.hh:67
static const char * OPRN_INPUTS
Object state name for inputs.
Definition Operation.hh:71
static const char * OPRN_WRITES_MEMORY
Object state name for writes memory.
Definition Operation.hh:85
static std::string stringToUpper(const std::string &source)

References __func__, ObjectState::addChild(), ObjectState::child(), ObjectState::childCount(), Exception::errorMessage(), ObjectState::hasAttribute(), ObjectState::intAttribute(), ObjectState::intValue(), ObjectState::name(), Operation::OPRN_CLOCKED, Operation::OPRN_CONTROL_FLOW, Operation::OPRN_DESCRIPTION, Operation::OPRN_IN, Operation::OPRN_INPUTS, Operation::OPRN_ISBRANCH, Operation::OPRN_ISCALL, Operation::OPRN_NAME, Operation::OPRN_OPERATION, Operation::OPRN_OUT, Operation::OPRN_OUTPUTS, Operation::OPRN_READS_MEMORY, Operation::OPRN_SIDE_EFFECTS, Operation::OPRN_TRAP, Operation::OPRN_WRITES_MEMORY, Operand::OPRND_ELEM_COUNT, Operand::OPRND_ELEM_WIDTH, Operand::OPRND_ID, Operand::OPRND_MEM_ADDRESS, Operand::OPRND_MEM_DATA, Operand::OPRND_TYPE, ObjectState::setAttribute(), Exception::setCause(), setOperandProperties(), ObjectState::stringAttribute(), StringTools::stringToUpper(), and ObjectState::stringValue().

Referenced by convertToOperationFormat().

Here is the call graph for this function:

◆ toXMLFormat()

ObjectState * OperationSerializer::toXMLFormat ( const ObjectState state)
private

Converts an individual operation to xml format.

Parameters
stateObjectState to be converted.
Exceptions
ObjectStateLoadingExceptionIf ObjectState conversion fails.
Returns
The converted ObjectState tree.

Definition at line 165 of file OperationSerializer.cc.

165 {
167 try {
170 oper->addChild(nameChild);
171
172 ObjectState* descriptionChild = new ObjectState(Operation::OPRN_DESCRIPTION);
173 descriptionChild->setValue(state->stringAttribute(Operation::OPRN_DESCRIPTION));
174 oper->addChild(descriptionChild);
175
177 inputChild->setValue(state->intAttribute(Operation::OPRN_INPUTS));
178 oper->addChild(inputChild);
179
181 outputChild->setValue(state->intAttribute(Operation::OPRN_OUTPUTS));
182 oper->addChild(outputChild);
183
186 }
187
190 }
191
194 }
195
198 }
199
202 }
203
206 }
207
210 }
211
214 }
215
216 for (int i = 0; i < state->childCount(); i++) {
217
218 ObjectState* child = state->child(i);
219 if (child->name() == Operation::OPRN_IN ||
220 child->name() == Operation::OPRN_OUT) {
221
222 ObjectState* operandChild = NULL;
223 if (child->name() == Operation::OPRN_IN) {
224 operandChild = new ObjectState(Operation::OPRN_IN);
225 } else {
226 operandChild = new ObjectState(Operation::OPRN_OUT);
227 }
228
229 operandChild->setAttribute(
232
233 operandChild->setAttribute(
236
238 operandChild->setAttribute(
241 }
242
244 operandChild->setAttribute(
247 }
248
250 operandChild->
252 }
253
255 operandChild->addChild(
257 }
258
260 ObjectState* units = new ObjectState(
262 units->setValue(child->intAttribute(
264 operandChild->addChild(units);
265 }
266
267 // can swap list
268 if (child->childCount() > 0) {
269 ObjectState* swap =
271 ObjectState* canSwap = child->child(0);
272
273 for (int j = 0; j < canSwap->childCount(); j++) {
274 ObjectState* swapChild = canSwap->child(j);
275
276 ObjectState* newSwap =
278
279 newSwap->setAttribute(
281 swapChild->intAttribute(Operand::OPRND_ID));
282 swap->addChild(newSwap);
283
284 }
285 operandChild->addChild(swap);
286 }
287
288 oper->addChild(operandChild);
289 } else {
290
291 ObjectState* newChild = new ObjectState(*child);
292 oper->addChild(newChild);
293 }
294 }
295
296 } catch (const Exception& e) {
297 string msg = "Error while constructing ObjectState tree: " +
298 e.errorMessage();
299 ObjectStateLoadingException error(__FILE__, __LINE__, __func__, msg);
300 error.setCause(e);
301 throw error;
302 }
303 return oper;
304}
void setValue(const std::string &value)
bool boolAttribute(const std::string &name) const
static const std::string OPRND_IN
Object state name for input operand.
Definition Operand.hh:94

References __func__, ObjectState::addChild(), ObjectState::boolAttribute(), ObjectState::child(), ObjectState::childCount(), Exception::errorMessage(), ObjectState::hasAttribute(), ObjectState::intAttribute(), ObjectState::name(), Operation::OPRN_CLOCKED, Operation::OPRN_CONTROL_FLOW, Operation::OPRN_DESCRIPTION, Operation::OPRN_IN, Operation::OPRN_INPUTS, Operation::OPRN_ISBRANCH, Operation::OPRN_ISCALL, Operation::OPRN_NAME, Operation::OPRN_OPERATION, Operation::OPRN_OUT, Operation::OPRN_OUTPUTS, Operation::OPRN_READS_MEMORY, Operation::OPRN_SIDE_EFFECTS, Operation::OPRN_TRAP, Operation::OPRN_WRITES_MEMORY, Operand::OPRND_CAN_SWAP, Operand::OPRND_ELEM_COUNT, Operand::OPRND_ELEM_WIDTH, Operand::OPRND_ID, Operand::OPRND_IN, Operand::OPRND_MEM_ADDRESS, Operand::OPRND_MEM_DATA, Operand::OPRND_MEM_UNITS, Operand::OPRND_TYPE, ObjectState::setAttribute(), Exception::setCause(), ObjectState::setValue(), and ObjectState::stringAttribute().

Referenced by convertToXMLFormat().

Here is the call graph for this function:

◆ writeState()

void OperationSerializer::writeState ( const ObjectState state)
virtual

Writes the state of operations to XML file.

The states of operations are first converted to the format understood by XMLSerializer and then written.

Parameters
stateObjectState to be written.
Exceptions
SerializerExceptionIf error occurs.

Implements TCETools::Serializer.

Definition at line 96 of file OperationSerializer.cc.

96 {
97 try {
98 ObjectState* converted = convertToXMLFormat(state);
99 serializer_.writeState(converted);
100 delete converted;
101 } catch (const Exception& e) {
102 string method = "OperationSerializer::writeState()";
103 string msg = "Problems writing the state: " + e.errorMessage();
104 SerializerException error(__FILE__, __LINE__, __func__, msg);
105 error.setCause(e);
106 throw error;
107 }
108}
ObjectState * convertToXMLFormat(const ObjectState *state)
virtual void writeState(const ObjectState *rootState)

References __func__, convertToXMLFormat(), Exception::errorMessage(), serializer_, Exception::setCause(), and XMLSerializer::writeState().

Referenced by OSEdAddOperationCmd::Do(), OSEdPropertiesCmd::Do(), and OSEdRemoveOperationCmd::Do().

Here is the call graph for this function:

Member Data Documentation

◆ serializer_

XMLSerializer OperationSerializer::serializer_
private

Constructs the ObjectState tree from the XML file.

Definition at line 77 of file OperationSerializer.hh.

Referenced by readState(), setDestinationFile(), setSchemaFile(), setSourceFile(), setUseSchema(), and writeState().


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