OpenASIP  2.0
ADFSerializer.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2019 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 ADFSerializer.cc
26  *
27  * Implementation of ADFSerializer class.
28  *
29  * @author Lasse Laasonen 2004 (lasse.laasonen-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2009-2014 (pjaaskel-no.spam-cs tut.fi)
31  * @note reviewed 15 Jun 2004 by pj, vpj, ml, ll
32  * @note rating: red
33  */
34 
35 #include "ADFSerializer.hh"
36 #include "Bus.hh"
37 #include "Guard.hh"
38 #include "Segment.hh"
39 #include "Socket.hh"
40 #include "Bridge.hh"
41 #include "FunctionUnit.hh"
42 #include "HWOperation.hh"
43 #include "ExecutionPipeline.hh"
44 #include "FUPort.hh"
45 #include "SpecialRegisterPort.hh"
46 #include "RegisterFile.hh"
47 #include "ImmediateUnit.hh"
48 #include "AddressSpace.hh"
49 #include "ControlUnit.hh"
50 #include "Connection.hh"
51 #include "InstructionTemplate.hh"
52 #include "TemplateSlot.hh"
54 #include "Environment.hh"
55 #include "ObjectState.hh"
57 
58 using std::string;
59 using boost::format;
60 using namespace TTAMachine;
61 
62 // declaration of constant strings used in MDF file
63 const string MDF = "adf";
64 const string MDF_VERSION = "version";
65 // writes files according to ADF specs version 1.10.x
66 const string MDF_VERSION_NUMBER = "1.20";
67 // 1.8:
68 // - adf: little-endian
69 // 1.9 ??
70 // 1.10:
71 // - adf: bitness64
72 
73 const string TRIGGER_INVALIDATES_OLD_RESULTS = "trigger-invalidates-old-results";
74 const string LITTLE_ENDIAN_MACHINE = "little-endian";
75 const string BITNESS64 = "bitness64";
76 const string ALWAYS_WRITE_BACK_RESULTS = "always-write-back-results";
77 const string FUNCTION_UNITS_ORDERED = "fu-ordered";
78 const string BUS = "bus";
79 const string BUS_NAME = "name";
80 const string BUS_WIDTH = "width";
81 const string SHORT_IMMEDIATE = "short-immediate";
82 const string SHORT_IMM_WIDTH = "width";
83 const string SHORT_IMM_EXTENSION = "extension";
84 const string SIGN_EXTENSION = "sign";
85 const string ZERO_EXTENSION = "zero";
86 
87 const string GUARD = "guard";
88 const string INVERTED_EXPR = "inverted-expr";
89 const string SIMPLE_EXPR = "simple-expr";
90 const string GUARD_BOOL = "bool";
91 const string GUARD_REGFILE_NAME = "name";
92 const string GUARD_REGFILE_INDEX = "index";
93 const string GUARD_UNIT = "unit";
94 const string GUARD_UNIT_NAME = "name";
95 const string GUARD_UNIT_PORT = "port";
96 const string ALWAYS_FALSE_GUARD = "always-false";
97 const string ALWAYS_TRUE_GUARD = "always-true";
98 const string SEGMENT = "segment";
99 const string SEGMENT_NAME = "name";
100 const string SEGMENT_WRITES_TO = "writes-to";
101 
102 const string SOCKET = "socket";
103 const string SOCKET_NAME = "name";
104 const string SOCKET_READS_FROM = "reads-from";
105 const string SOCKET_WRITES_TO = "writes-to";
106 const string SOCKET_BUS = "bus";
107 const string SOCKET_SEGMENT = "segment";
108 
109 const string BRIDGE = "bridge";
110 const string BRIDGE_NAME = "name";
111 const string BRIDGE_READS_FROM = "reads-from";
112 const string BRIDGE_WRITES_TO = "writes-to";
113 
114 const string FUNCTION_UNIT = "function-unit";
115 const string FU_NAME = "name";
116 const string FU_ADDRESS_SPACE = "address-space";
117 const string FU_OPERATION = "operation";
118 const string FU_OP_NAME = "name";
119 const string FU_OP_BIND = "bind";
120 const string FU_OP_BIND_NAME = "name";
121 const string FU_OP_PIPELINE = "pipeline";
122 const string FU_OP_PL_RESOURCE = "resource";
123 const string FU_OP_PL_RES_NAME = "name";
124 const string FU_OP_PL_RES_START_CYCLE = "start-cycle";
125 const string FU_OP_PL_RES_CYCLES = "cycles";
126 const string FU_OP_PL_READS = "reads";
127 const string FU_OP_PL_READS_NAME = "name";
128 const string FU_OP_PL_WRITES = "writes";
129 const string FU_OP_PL_WRITES_NAME = "name";
130 
131 const string REGISTER_FILE = "register-file";
132 const string RF_NAME = "name";
133 const string RF_TYPE = "type";
134 const string RF_TYPE_NORMAL = "normal";
135 const string RF_TYPE_VOLATILE = "volatile";
136 const string RF_TYPE_RESERVED = "reserved";
137 const string RF_SIZE = "size";
138 const string RF_WIDTH = "width";
139 const string RF_MAX_READS = "max-reads";
140 const string RF_MAX_WRITES = "max-writes";
141 const string RF_GUARD_LATENCY = "guard-latency";
142 const string RF_ZERO_REGISTER = "zero-register";
143 
144 const string IMMEDIATE_UNIT = "immediate-unit";
145 const string IU_NAME = "name";
146 const string IU_TYPE = "type";
147 const string IU_TYPE_NORMAL = "normal";
148 const string IU_TYPE_VOLATILE = "volatile";
149 const string IU_TYPE_RESERVED = "reserved";
150 const string IU_SIZE = "size";
151 const string IU_LATENCY = "latency";
152 const string IU_WIDTH = "width";
153 const string IU_MAX_READS = "max-reads";
154 const string IU_MAX_WRITES = "max-writes";
155 const string IU_EXTENSION = "extension";
156 const string IU_GUARD_LATENCY = "guard-latency";
157 const string IU_TEMPLATE = "template";
158 const string IU_TEMPLATE_NAME = "name";
159 const string IU_TEMPLATE_SLOT = "slot";
160 const string IU_TEMPLATE_SLOT_NAME = "name";
161 const string IU_TEMPLATE_SLOT_WIDTH = "width";
162 const string IU_TEMPLATE_BUS = "bus";
163 
164 const string ADDRESS_SPACE = "address-space";
165 const string AS_NAME = "name";
166 const string AS_WIDTH = "width";
167 const string AS_MIN_ADDRESS = "min-address";
168 const string AS_MAX_ADDRESS = "max-address";
169 const string AS_NUMERICAL_ID = "numerical-id";
170 const string AS_SHARED_MEMORY = "shared-memory";
171 
172 const string CONTROL_UNIT = "global-control-unit";
173 const string CU_NAME = "name";
174 const string CU_ADDRESS_SPACE = "address-space";
175 const string CU_DELAY_SLOTS = "delay-slots";
176 const string CU_GUARD_LATENCY = "guard-latency";
177 const string CU_RETURN_ADDRESS = "return-address";
178 const string CU_CTRL_OPERATION = "ctrl-operation";
179 const string CU_SPECIAL_PORT = "special-port";
180 
181 const string PORT = "port";
182 const string PORT_NAME = "name";
183 const string PORT_CONNECTS_TO = "connects-to";
184 
185 const string FU_PORT_WIDTH = "width";
186 const string FU_PORT_TRIGGERS = "triggers";
187 const string FU_PORT_SETS_OPCODE = "sets-opcode";
188 const string FU_PORT_NO_REGISTER = "no-register";
189 
190 const string IMMEDIATE_SLOT = "immediate-slot";
191 const string IMMEDIATE_SLOT_NAME = "name";
192 
193 const string TEMPLATE_RF_READ = "register-file-read";
194 const string TEMPLATE_RF_WRITE = "register-file-write";
195 const string TEMPLATE_FU_READ = "function-unit-read";
196 const string TEMPLATE_FU_WRITE = "function-unit-write";
197 
198 const string ADF_SCHEMA_FILE = "mach/ADF_Schema.xsd";
199 
200 /**
201  * Constructor.
202  */
205  setUseSchema(true);
206 }
207 
208 
209 /**
210  * Destructor.
211  */
213 }
214 
215 
216 /**
217  * Writes the given ObjectState tree created by Machine::saveState to the
218  * destination file.
219  *
220  * @param machineState ObjectState tree created by Machine::saveState.
221  * @exception SerializerException If an error occurs while serializing.
222  */
223 void
225  ObjectState* converted = convertToMDFFormat(machineState);
226  XMLSerializer::writeState(converted);
227  delete converted;
228 }
229 
230 /**
231  * Reads the current MDF file set and creates an ObjectState tree which can
232  * be given to Machine::loadState to create a machine.
233  *
234  * @return The newly created ObjectState tree.
235  * @exception SerializerException If an error occurs while reading.
236  */
240  ObjectState* machineState;
241  try {
242  machineState = convertToMachineFormat(mdfState);
243  } catch (const SerializerException&) {
244  delete mdfState;
245  throw;
246  }
247 
248  delete mdfState;
249  return machineState;
250 }
251 
252 /**
253  * Serializes the given machine to mdf file.
254  *
255  * @param machine The machine to be serialized.
256  * @exception SerializerException If an error occurs while serializing.
257  */
258 void
260  ObjectState* machineState = machine.saveState();
261  writeState(machineState);
262  delete machineState;
263 }
264 
265 /**
266  * Reads the current MDF file set and creates a Machine according to it.
267  *
268  * @return The newly created machine.
269  * @exception SerializerException If an error occurs while reading the MDF
270  * file.
271  * @exception ObjectStateLoadingException If an error occurs while creating
272  * Machine.
273  */
274 Machine*
276  ObjectState* machineState = readState();
277  Machine* mach = new Machine();
278  mach->loadState(machineState);
279 
280  delete machineState;
281  return mach;
282 }
283 
284 /**
285  * Converts the given ObjectState tree created by Machine to correspond
286  * with MDF format.
287  *
288  * @param machineState Root of the ObjectState tree.
289  * @return The newly created ObjectState tree which matches with MDF format.
290  */
293 
294  ObjectState* root = new ObjectState(MDF);
296 
297  // Test for global attributes.
298  if (machineState->hasAttribute(
299  Machine::OSKEY_TRIGGER_INVALIDATES_OLD_RESULTS) &&
300  machineState->boolAttribute(
301  Machine::OSKEY_TRIGGER_INVALIDATES_OLD_RESULTS)) {
303  }
304  if (machineState->hasAttribute(Machine::OSKEY_ALWAYS_WRITE_BACK_RESULTS) &&
305  machineState->boolAttribute(Machine::OSKEY_ALWAYS_WRITE_BACK_RESULTS)) {
307  }
308  if (machineState->hasAttribute(Machine::OSKEY_FUNCTION_UNITS_ORDERED) &&
309  machineState->boolAttribute(Machine::OSKEY_FUNCTION_UNITS_ORDERED)) {
311  }
312  if (machineState->hasAttribute(LITTLE_ENDIAN_MACHINE) &&
313  machineState->boolAttribute(LITTLE_ENDIAN_MACHINE)) {
315  }
316 
317  if (machineState->hasAttribute(BITNESS64) &&
318  machineState->boolAttribute(BITNESS64)) {
319  root->addChild(new ObjectState(BITNESS64));
320  }
321 
322  // add buses
323  for (int i = 0; i < machineState->childCount(); i++) {
324  ObjectState* child = machineState->child(i);
325  if (child->name() == Bus::OSNAME_BUS) {
326  root->addChild(busToMDF(child));
327  }
328  }
329 
330  // add sockets
331  for (int i = 0; i < machineState->childCount(); i++) {
332  ObjectState* child = machineState->child(i);
333  if (child->name() == Socket::OSNAME_SOCKET) {
334  root->addChild(socketToMDF(child));
335  }
336  }
337 
338  // add bridges
339  for (int i = 0; i < machineState->childCount(); i++) {
340  ObjectState* child = machineState->child(i);
341  if (child->name() == Bridge::OSNAME_BRIDGE) {
342  root->addChild(bridgeToMDF(child));
343  }
344  }
345 
346  // add function units
347  for (int i = 0; i < machineState->childCount(); i++) {
348  ObjectState* child = machineState->child(i);
349  if (child->name() == FunctionUnit::OSNAME_FU) {
350  root->addChild(functionUnitToMDF(child));
351  }
352  }
353 
354  // add register files
355  for (int i = 0; i < machineState->childCount(); i++) {
356  ObjectState* child = machineState->child(i);
357  if (child->name() == RegisterFile::OSNAME_REGISTER_FILE) {
358  root->addChild(registerFileToMDF(child));
359  }
360  }
361 
362  // add address spaces
363  for (int i = 0; i < machineState->childCount(); i++) {
364  ObjectState* child = machineState->child(i);
365  if (child->name() == AddressSpace::OSNAME_ADDRESS_SPACE) {
366  root->addChild(addressSpaceToMDF(child));
367  }
368  }
369 
370  // add control unit
371  for (int i = 0; i < machineState->childCount(); i++) {
372  ObjectState* child = machineState->child(i);
373  if (child->name() == ControlUnit::OSNAME_CONTROL_UNIT) {
374  root->addChild(controlUnitToMDF(child));
375  }
376  }
377 
378  // add immediate units
379  for (int i = 0; i < machineState->childCount(); i++) {
380  ObjectState* child = machineState->child(i);
381  if (child->name() == ImmediateUnit::OSNAME_IMMEDIATE_UNIT) {
382  root->addChild(immediateUnitToMDF(child, machineState));
383  }
384  }
385 
386  // add immediate slots
387  for (int i = 0; i < machineState->childCount(); i++) {
388  ObjectState* child = machineState->child(i);
389  if (child->name() == ImmediateSlot::OSNAME_IMMEDIATE_SLOT) {
390  root->addChild(immediateSlotToMDF(child));
391  }
392  }
393 
394  // Add operation triggered formats
395  for (int i = 0; i < machineState->childCount(); i++) {
396  ObjectState* child = machineState->child(i);
397  if (child->name() == OperationTriggeredFormat::OSNAME_FORMAT) {
398  ObjectState* newChild = new ObjectState(*child);
399  root->addChild(newChild);
400  }
401  }
402 
403  return root;
404 }
405 
406 
407 /**
408  * Creates a new ObjectState tree which matches one-to-one with MDF specs
409  * syntax.
410  *
411  * The tree is created according to the given ObjectState tree created by
412  * Bus::saveState.
413  *
414  * @param busState Root node of the ObjectState tree created by
415  * Bus::saveState.
416  * @return The newly created ObjectState tree.
417  */
420 
421  ObjectState* root = new ObjectState(BUS);
422  root->setAttribute(BUS_NAME, busState->stringAttribute(Bus::OSKEY_NAME));
423 
424  // add width element
425  ObjectState* widthChild = new ObjectState(BUS_WIDTH);
426  widthChild->setValue(busState->stringAttribute(Bus::OSKEY_WIDTH));
427  root->addChild(widthChild);
428 
429  // add guards
430  for (int i = 0; i < busState->childCount(); i++) {
431  ObjectState* child = busState->child(i);
432 
433  if (child->name() == PortGuard::OSNAME_PORT_GUARD ||
434  child->name() == RegisterGuard::OSNAME_REGISTER_GUARD) {
435  string guardType;
436  string guardUnit;
437  string guardTarget;
438  string unitNameAttrib;
439  string targetNameAttrib;
440  if (child->name() == PortGuard::OSNAME_PORT_GUARD) {
441  guardType = GUARD_UNIT;
442  guardUnit = GUARD_UNIT_NAME;
443  guardTarget = GUARD_UNIT_PORT;
444  unitNameAttrib = PortGuard::OSKEY_FU;
445  targetNameAttrib = PortGuard::OSKEY_PORT;
446  } else if (child->name() ==
447  RegisterGuard::OSNAME_REGISTER_GUARD) {
448  guardType = GUARD_BOOL;
449  guardUnit = GUARD_REGFILE_NAME;
450  guardTarget = GUARD_REGFILE_INDEX;
451  unitNameAttrib = RegisterGuard::OSKEY_REGFILE;
452  targetNameAttrib = RegisterGuard::OSKEY_INDEX;
453  }
454 
455  ObjectState* guardChild = new ObjectState(GUARD);
456  root->addChild(guardChild);
457  ObjectState* conditionalChild;
458  if (child->intAttribute(Guard::OSKEY_INVERTED)) {
459  conditionalChild = new ObjectState(INVERTED_EXPR);
460  } else {
461  conditionalChild = new ObjectState(SIMPLE_EXPR);
462  }
463  guardChild->addChild(conditionalChild);
464  ObjectState* typeChild = new ObjectState(guardType);
465  conditionalChild->addChild(typeChild);
466  ObjectState* unitChild = new ObjectState(guardUnit);
467  typeChild->addChild(unitChild);
468  unitChild->setValue(child->stringAttribute(unitNameAttrib));
469  ObjectState* targetChild = new ObjectState(guardTarget);
470  typeChild->addChild(targetChild);
471  targetChild->setValue(child->stringAttribute(targetNameAttrib));
472 
473  } else if (child->name() ==
474  UnconditionalGuard::OSNAME_UNCONDITIONAL_GUARD) {
475 
476  // unconditional guards
477  ObjectState* guardChild = new ObjectState(GUARD);
478  root->addChild(guardChild);
479  if (child->boolAttribute(Guard::OSKEY_INVERTED)) {
480  guardChild->addChild(new ObjectState(ALWAYS_FALSE_GUARD));
481  } else {
482  guardChild->addChild(new ObjectState(ALWAYS_TRUE_GUARD));
483  }
484  }
485  }
486 
487  // add segments
488  for (int i = 0; i < busState->childCount(); i++) {
489  ObjectState* child = busState->child(i);
490 
491  if (child->name() == Segment::OSNAME_SEGMENT) {
492  ObjectState* segment = new ObjectState(SEGMENT);
493  root->addChild(segment);
494  segment->setAttribute(
495  SEGMENT_NAME, child->stringAttribute(Segment::OSKEY_NAME));
496  ObjectState* writesTo = new ObjectState(SEGMENT_WRITES_TO);
497  segment->addChild(writesTo);
498  if (child->hasAttribute(Segment::OSKEY_DESTINATION)) {
499  writesTo->setValue(
500  child->stringAttribute(Segment::OSKEY_DESTINATION));
501  }
502  }
503  }
504 
505  // add short immediate element
506  ObjectState* sImmChild = new ObjectState(SHORT_IMMEDIATE);
507  root->addChild(sImmChild);
508  ObjectState* extensionChild = new ObjectState(SHORT_IMM_EXTENSION);
509  string extension = busState->stringAttribute(Bus::OSKEY_EXTENSION);
510  if (extension == Bus::OSVALUE_SIGN) {
511  extensionChild->setValue(SIGN_EXTENSION);
512  } else if (extension == Bus::OSVALUE_ZERO) {
513  extensionChild->setValue(ZERO_EXTENSION);
514  } else {
515  string procName = "MDFSerialiser::busToMDF";
516  string errorMsg = "Unknown extension attribute value in ObjectState "
517  "instance.";
518  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
520  }
521 
522  sImmChild->addChild(extensionChild);
523  ObjectState* sImmWidthChild = new ObjectState(SHORT_IMM_WIDTH);
524  sImmChild->addChild(sImmWidthChild);
525  sImmWidthChild->setValue(busState->stringAttribute(Bus::OSKEY_IMMWIDTH));
526 
527  return root;
528 }
529 
530 
531 /**
532  * Creates a new ObjectState tree which matches one-to-one with MDF specs
533  * syntax.
534  *
535  * The tree is created according to the given ObjectState tree created by
536  * Socket::saveState.
537  *
538  * @param socketState Root node of the ObjectState tree created by
539  * Socket::saveState.
540  * @return The newly created ObjectState tree.
541  */
544 
545  ObjectState* socket = new ObjectState(SOCKET);
546  socket->setAttribute(
547  SOCKET_NAME, socketState->stringAttribute(Socket::OSKEY_NAME));
548 
549  bool input;
550  if (socketState->stringAttribute(Socket::OSKEY_DIRECTION) ==
551  Socket::OSVALUE_INPUT) {
552  input = true;
553  } else if (socketState->stringAttribute(Socket::OSKEY_DIRECTION) ==
554  Socket::OSVALUE_OUTPUT) {
555  input = false;
556  } else {
557  return socket;
558  }
559 
560  for (int i = 0; i < socketState->childCount(); i++) {
561  ObjectState* child = socketState->child(i);
562  ObjectState* conn;
563  if (input) {
564  conn = new ObjectState(SOCKET_READS_FROM);
565  } else {
566  conn = new ObjectState(SOCKET_WRITES_TO);
567  }
568  socket->addChild(conn);
569  ObjectState* bus = new ObjectState(SOCKET_BUS);
570  conn->addChild(bus);
571  bus->setValue(child->stringAttribute(Connection::OSKEY_BUS));
572 
573  ObjectState* segment = new ObjectState(SOCKET_SEGMENT);
574  conn->addChild(segment);
575  if (child->hasAttribute(Connection::OSKEY_SEGMENT)) {
576  segment->setValue(
577  child->stringAttribute(Connection::OSKEY_SEGMENT));
578  }
579  }
580 
581  return socket;
582 }
583 
584 
585 /**
586  * Creates a new ObjectState tree which matches one-to-one with MDF specs
587  * syntax.
588  *
589  * The tree is created according to the given ObjectState tree created by
590  * Bridge::saveState.
591  *
592  * @param bridgeState Root node of the ObjectState tree created by
593  * Bridge::saveState.
594  * @return The newly created ObjectState tree.
595  */
598 
599  ObjectState* bridge = new ObjectState(BRIDGE);
600  bridge->setAttribute(
601  BRIDGE_NAME, bridgeState->stringAttribute(Bridge::OSKEY_NAME));
602 
603  ObjectState* readsFrom = new ObjectState(BRIDGE_READS_FROM);
604  bridge->addChild(readsFrom);
605  readsFrom->setValue(
606  bridgeState->stringAttribute(Bridge::OSKEY_SOURCE_BUS));
607 
608  ObjectState* writesTo = new ObjectState(BRIDGE_WRITES_TO);
609  bridge->addChild(writesTo);
610  writesTo->setValue(
611  bridgeState->stringAttribute(Bridge::OSKEY_DESTINATION_BUS));
612 
613  return bridge;
614 }
615 
616 
617 /**
618  * Creates a new ObjectState tree which matches one-to-one with MDF specs
619  * syntax.
620  *
621  * The tree is created according to the given ObjectState tree created by
622  * FunctionUnit::saveState.
623  *
624  * @param fuState Root node of the ObjectState tree created by
625  * FunctionUnit::saveState.
626  * @return The newly created ObjectState tree.
627  */
630 
632  fu->setAttribute(
633  FU_NAME, fuState->stringAttribute(FunctionUnit::OSKEY_NAME));
634 
635  // add ports and operations
636  for (int i = 0; i < fuState->childCount(); i++) {
637  ObjectState* child = fuState->child(i);
638  if (child->name() == FUPort::OSNAME_FUPORT) {
639  fu->addChild(mdfFUPort(child));
640  } else if (child->name() == HWOperation::OSNAME_OPERATION) {
641  fu->addChild(mdfOperation(child));
642  }
643  }
644 
645  // add address space
646  ObjectState* addressSpace = new ObjectState(FU_ADDRESS_SPACE);
647  fu->addChild(addressSpace);
648 
649  // set address space name if it exists
650  if (fuState->hasAttribute(FunctionUnit::OSKEY_AS)) {
651  addressSpace->setValue(
652  fuState->stringAttribute(FunctionUnit::OSKEY_AS));
653  }
654 
655  return fu;
656 }
657 
658 
659 /**
660  * Creates a new ObjectState tree which matches one-to-one with MDF specs
661  * syntax.
662  *
663  * The tree is created according to the given ObjectState tree created by
664  * RegisterFile::saveState.
665  *
666  * @param rfState Root node of the ObjectState tree created by
667  * RegisterFile::saveState.
668  * @return The newly created ObjectState tree.
669  */
672 
673  ObjectState* regFile = new ObjectState(REGISTER_FILE);
674  regFile->setAttribute(
675  RF_NAME, rfState->stringAttribute(RegisterFile::OSKEY_NAME));
676 
677  ObjectState* type = new ObjectState(RF_TYPE);
678  regFile->addChild(type);
679  string typeValue = rfState->stringAttribute(RegisterFile::OSKEY_TYPE);
680  if (typeValue == RegisterFile::OSVALUE_NORMAL) {
681  type->setValue(RF_TYPE_NORMAL);
682  } else if (typeValue == RegisterFile::OSVALUE_RESERVED) {
683  type->setValue(RF_TYPE_RESERVED);
684  } else if (typeValue == RegisterFile::OSVALUE_VOLATILE) {
685  type->setValue(RF_TYPE_VOLATILE);
686  } else {
687  string procName = "ADFSerializer::registerFileToMDF";
688  string errorMsg = "Unknown register file type in ObjectState "
689  "instance.";
690  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
692  }
693 
694  ObjectState* size = new ObjectState(RF_SIZE);
695  regFile->addChild(size);
696  size->setValue(rfState->stringAttribute(RegisterFile::OSKEY_SIZE));
697 
698  ObjectState* width = new ObjectState(RF_WIDTH);
699  regFile->addChild(width);
700  width->setValue(rfState->stringAttribute(RegisterFile::OSKEY_WIDTH));
701 
702  ObjectState* maxReads = new ObjectState(RF_MAX_READS);
703  regFile->addChild(maxReads);
704  maxReads->setValue(
705  rfState->stringAttribute(RegisterFile::OSKEY_MAX_READS));
706 
707  ObjectState* maxWrites = new ObjectState(RF_MAX_WRITES);
708  regFile->addChild(maxWrites);
709  maxWrites->setValue(
710  rfState->stringAttribute(RegisterFile::OSKEY_MAX_WRITES));
711 
712  if (rfState->intAttribute(RegisterFile::OSKEY_GUARD_LATENCY) > 0) {
713  ObjectState* guardLatency = new ObjectState(RF_GUARD_LATENCY);
714  regFile->addChild(guardLatency);
715  guardLatency->setValue(
716  rfState->stringAttribute(RegisterFile::OSKEY_GUARD_LATENCY));
717  }
718 
719  // add ports
720  for (int i = 0; i < rfState->childCount(); i++) {
721  ObjectState* child = rfState->child(i);
722  regFile->addChild(mdfPort(child));
723  }
724 
725  if (rfState->hasAttribute(RegisterFile::OSKEY_ZERO_REGISTER)) {
726  ObjectState* zeroRegister = new ObjectState(RF_ZERO_REGISTER);
727  regFile->addChild(zeroRegister);
728  zeroRegister->setValue(
729  rfState->boolAttribute(RegisterFile::OSKEY_ZERO_REGISTER));
730  }
731 
732  return regFile;
733 }
734 
735 
736 /**
737  * Creates a new ObjectState tree which matches one-to-one with MDF specs
738  * syntax.
739  *
740  * The tree is created according to the given ObjectState tree created by
741  * ImmediateUnit::saveState. The whole ObjectState tree created by
742  * Machine::saveState must be given too because instruction templates are
743  * needed too to create the new ObjectState tree.
744  *
745  * @param iuState Root node of the ObjectState tree created by
746  * ImmediateUnit::saveState.
747  * @param machineState The ObjectState tree created by Machine::saveState.
748  * @return The newly created ObjectState tree.
749  */
752  const ObjectState* machineState) {
753 
754  ObjectState* iUnit = new ObjectState(IMMEDIATE_UNIT);
755  string iuName = iuState->stringAttribute(ImmediateUnit::OSKEY_NAME);
756  iUnit->setAttribute(IU_NAME, iuName);
757 
758  // type
759  ObjectState* type = new ObjectState(IU_TYPE);
760  iUnit->addChild(type);
761  string typeValue = iuState->stringAttribute(RegisterFile::OSKEY_TYPE);
762  if (typeValue == ImmediateUnit::OSVALUE_NORMAL) {
763  type->setValue(IU_TYPE_NORMAL);
764  } else if (typeValue == ImmediateUnit::OSVALUE_RESERVED) {
765  type->setValue(IU_TYPE_RESERVED);
766  } else if (typeValue == ImmediateUnit::OSVALUE_VOLATILE) {
767  type->setValue(IU_TYPE_VOLATILE);
768  } else {
769  string procName = "ADFSerializer::immediateUnitToMDF";
770  string errorMsg = "Unknown immediate unit type in ObjectState "
771  "instance.";
772  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
774  }
775 
776  // add size element
777  ObjectState* size = new ObjectState(IU_SIZE);
778  iUnit->addChild(size);
779  size->setValue(iuState->stringAttribute(ImmediateUnit::OSKEY_SIZE));
780 
781  // add width element
782  ObjectState* width = new ObjectState(IU_WIDTH);
783  iUnit->addChild(width);
784  width->setValue(iuState->stringAttribute(ImmediateUnit::OSKEY_WIDTH));
785 
786  // add max reads
787  ObjectState* maxReads = new ObjectState(RF_MAX_READS);
788  iUnit->addChild(maxReads);
789  maxReads->setValue(
790  iuState->stringAttribute(RegisterFile::OSKEY_MAX_READS));
791 
792  // add max writes
793  ObjectState* maxWrites = new ObjectState(IU_MAX_WRITES);
794  iUnit->addChild(maxWrites);
795  maxWrites->setValue(
796  iuState->stringAttribute(RegisterFile::OSKEY_MAX_WRITES));
797 
798  // add guard latency
799  if (iuState->intAttribute(ImmediateUnit::OSKEY_GUARD_LATENCY) > 0) {
800  ObjectState* guardLatency = new ObjectState(IU_GUARD_LATENCY);
801  iUnit->addChild(guardLatency);
802  guardLatency->setValue(
803  iuState->stringAttribute(ImmediateUnit::OSKEY_GUARD_LATENCY));
804  }
805 
806  // add read latency element
807  ObjectState* readLatency = new ObjectState(IU_LATENCY);
808  iUnit->addChild(readLatency);
809  readLatency->setValue(
810  iuState->stringAttribute(ImmediateUnit::OSKEY_LATENCY));
811 
812  // add extension element
813  ObjectState* extension = new ObjectState(IU_EXTENSION);
814  iUnit->addChild(extension);
815  extension->setValue(
816  iuState->stringAttribute(ImmediateUnit::OSKEY_EXTENSION));
817 
818  // add ports
819  for (int i = 0; i < iuState->childCount(); i++) {
820  ObjectState* child = iuState->child(i);
821  if (child->name() == RFPort::OSNAME_RFPORT) {
822  iUnit->addChild(mdfPort(child));
823  }
824  }
825 
826  // add instruction templates
827  for (int iTempIndex = 0; iTempIndex < machineState->childCount();
828  iTempIndex++) {
829  ObjectState* iTemp = machineState->child(iTempIndex);
830  if (iTemp->name() ==
831  InstructionTemplate::OSNAME_INSTRUCTION_TEMPLATE) {
832  instructionTemplateToMDF(iTemp, iUnit);
833  }
834  }
835 
836  return iUnit;
837 }
838 
839 
840 /**
841  * Creates a new ObjectState tree which matches one-to-one with MDF specs
842  * syntax.
843  *
844  * The tree is created according to the given ObjectState tree created by
845  * AddressSpace::saveState.
846  *
847  * @param asState Root node of the ObjectState tree created by
848  * AddressSpace::saveState.
849  * @return The newly created ObjectState tree.
850  */
853 
855  as->setAttribute(
856  AS_NAME, asState->stringAttribute(AddressSpace::OSKEY_NAME));
857 
858  // add width element
859  ObjectState* width = new ObjectState(AS_WIDTH);
860  as->addChild(width);
861  width->setValue(asState->stringAttribute(AddressSpace::OSKEY_WIDTH));
862 
863  // add min-address element
864  ObjectState* minAddress = new ObjectState(AS_MIN_ADDRESS);
865  as->addChild(minAddress);
866  minAddress->setValue(
867  asState->stringAttribute(AddressSpace::OSKEY_MIN_ADDRESS));
868 
869  // add max-address element
870  ObjectState* maxAddress = new ObjectState(AS_MAX_ADDRESS);
871  as->addChild(maxAddress);
872  maxAddress->setValue(
873  asState->stringAttribute(AddressSpace::OSKEY_MAX_ADDRESS));
874 
875  if (asState->hasAttribute(AddressSpace::OSKEY_SHARED_MEMORY)) {
877  as->addChild(shared);
878  shared->setValue(
879  asState->boolAttribute(AddressSpace::OSKEY_SHARED_MEMORY));
880  }
881  // the numerical ids
882  for (int i = 0; i < asState->childCount(); i++) {
883  ObjectState* child = asState->child(i);
884  if (child->name() == AddressSpace::OSKEY_NUMERICAL_ID) {
885  ObjectState* idObj = new ObjectState(AS_NUMERICAL_ID, as);
886  idObj->setValue(child->intValue());
887  }
888  }
889  return as;
890 }
891 
892 
893 /**
894  * Creates a new ObjectState tree which matches one-to-one with MDF specs
895  * syntax.
896  *
897  * The tree is created according to the given ObjectState tree created by
898  * ControlUnit::saveState.
899  *
900  * @param cuState Root node of the ObjectState tree created by
901  * ControlUnit::saveState.
902  * @return The newly created ObjectState tree.
903  */
906 
907  ObjectState* cUnit = new ObjectState(CONTROL_UNIT);
908  cUnit->setAttribute(
909  CU_NAME, cuState->stringAttribute(ControlUnit::OSKEY_NAME));
910 
911  // add operand ports
912  for (int i = 0; i < cuState->childCount(); i++) {
913  ObjectState* child = cuState->child(i);
914  if (child->name() == FUPort::OSNAME_FUPORT) {
915  cUnit->addChild(mdfFUPort(child));
916  }
917  }
918 
919  // add special ports
920  for (int i = 0; i < cuState->childCount(); i++) {
921  ObjectState* child = cuState->child(i);
922  if (child->name() == SpecialRegisterPort::OSNAME_SPECIAL_REG_PORT) {
923  cUnit->addChild(mdfSRPort(child));
924  }
925  }
926 
927  // add return-address element
928  ObjectState* raElement = new ObjectState(CU_RETURN_ADDRESS);
929  cUnit->addChild(raElement);
930  if (cuState->hasAttribute(ControlUnit::OSKEY_RA_PORT)) {
931  raElement->setValue(
932  cuState->stringAttribute(ControlUnit::OSKEY_RA_PORT));
933  }
934 
935  // add operations
936  for (int i = 0; i < cuState->childCount(); i++) {
937  ObjectState* child = cuState->child(i);
938  if (child->name() == HWOperation::OSNAME_OPERATION) {
939  ObjectState* ctrlOperation = mdfOperation(child);
940  ctrlOperation->setName(CU_CTRL_OPERATION);
941  cUnit->addChild(ctrlOperation);
942  }
943  }
944 
945  // add address space element
947  cUnit->addChild(as);
948  if (cuState->hasAttribute(FunctionUnit::OSKEY_AS)) {
949  as->setValue(cuState->stringAttribute(FunctionUnit::OSKEY_AS));
950  }
951 
952  // add delay-slots element
953  ObjectState* dSlots = new ObjectState(CU_DELAY_SLOTS);
954  cUnit->addChild(dSlots);
955  dSlots->setValue(
956  cuState->stringAttribute(ControlUnit::OSKEY_DELAY_SLOTS));
957 
958  // add guard latency element
959  ObjectState* gLatency = new ObjectState(CU_GUARD_LATENCY);
960  cUnit->addChild(gLatency);
961  gLatency->setValue(
962  cuState->stringAttribute(ControlUnit::OSKEY_GUARD_LATENCY));
963 
964  return cUnit;
965 }
966 
967 
968 /**
969  * Creates a new ObjectState instance that matches with the syntax of
970  * immediate-slot element in ADF file.
971  *
972  * @param isState ObjectState instance representing ImmediateSlot instance.
973  * @return The newly created ObjectState instance.
974  */
977  ObjectState* immediateSlot = new ObjectState(IMMEDIATE_SLOT);
978  immediateSlot->setAttribute(
980  isState->stringAttribute(ImmediateSlot::OSKEY_NAME));
981  return immediateSlot;
982 }
983 
984 
985 /**
986  * Creates a new ObjectState tree which can be read by Machine::loadState
987  * and which corresponds with the given ObjectState tree.
988  *
989  * @param mdfState An ObjectState tree whose structure matches with MDF file
990  * structure.
991  * @return The newly created ObjectState tree.
992  * @exception SerializerException If an error occurs while converting.
993  */
996  ObjectState* machine = new ObjectState(Machine::OSNAME_MACHINE);
997 
998  // Will count the number of function units and give sequential number
999  // to each of them.
1000  int orderNumber = 0;
1001 
1002  try {
1003  for (int i = 0; i < mdfState->childCount(); i++) {
1004  ObjectState* child = mdfState->child(i);
1005  if (child->name() == TRIGGER_INVALIDATES_OLD_RESULTS) {
1006  machine->setAttribute(
1007  Machine::OSKEY_TRIGGER_INVALIDATES_OLD_RESULTS, true);
1008  } else if (child->name() == ALWAYS_WRITE_BACK_RESULTS) {
1009  machine->setAttribute(
1010  Machine::OSKEY_ALWAYS_WRITE_BACK_RESULTS, true);
1011  } else if (child->name() == LITTLE_ENDIAN_MACHINE) {
1012  machine->setAttribute(LITTLE_ENDIAN_MACHINE, true);
1013  } else if (child->name() == BITNESS64) {
1014  machine->setAttribute(BITNESS64, true);
1015  } else if (child->name() == FUNCTION_UNITS_ORDERED) {
1016  machine->setAttribute(
1017  Machine::OSKEY_FUNCTION_UNITS_ORDERED, true);
1018  } else if (child->name() == BUS) {
1019  machine->addChild(busToMachine(child));
1020  } else if (child->name() == SOCKET) {
1021  machine->addChild(socketToMachine(child));
1022  } else if (child->name() == BRIDGE) {
1023  machine->addChild(bridgeToMachine(child));
1024  } else if (child->name() == FUNCTION_UNIT) {
1025  orderNumber++;
1026  machine->addChild(functionUnitToMachine(child, orderNumber));
1027  } else if (child->name() == REGISTER_FILE) {
1028  machine->addChild(registerFileToMachine(child));
1029  } else if (child->name() == ADDRESS_SPACE) {
1030  machine->addChild(addressSpaceToMachine(child));
1031  } else if (child->name() == CONTROL_UNIT) {
1032  machine->addChild(controlUnitToMachine(child));
1033  } else if (child->name() == IMMEDIATE_UNIT) {
1034  machine->addChild(immediateUnitToMachine(child, machine));
1035  } else if (child->name() == IMMEDIATE_SLOT) {
1036  machine->addChild(immediateSlotToMachine(child));
1037  } else if (child->name() == IU_TEMPLATE) {
1038  // the instruction template must not belong to any IU in case
1039  // one defines a template with implicit slots
1041  } else if (
1042  child->name() == OperationTriggeredFormat::OSNAME_FORMAT) {
1043  ObjectState* newChild = new ObjectState(*child);
1044  machine->addChild(newChild);
1045  }
1046  }
1047  } catch (const SerializerException&) {
1048  delete machine;
1049  throw;
1050  }
1051 
1052  return machine;
1053 }
1054 
1055 /**
1056  * Creates a new ObjectState tree which can be read by Bus::loadState and
1057  * which corresponds with the given ObjectState tree declaring a bus by
1058  * MDF syntax.
1059  *
1060  * @param busState The ObjectState tree declaring a bus by MDF syntax.
1061  * @return The newly created ObjectState tree.
1062  */
1063 ObjectState*
1065 
1066  ObjectState* bus = new ObjectState(Bus::OSNAME_BUS);
1067 
1068  // set name
1069  bus->setAttribute(
1070  Component::OSKEY_NAME, busState->stringAttribute(BUS_NAME));
1071 
1072  // set width
1073  ObjectState* width = busState->childByName(BUS_WIDTH);
1074  bus->setAttribute(Bus::OSKEY_WIDTH, width->stringValue());
1075 
1076  // set immediate width and extension
1077  ObjectState* shortImm = busState->childByName(SHORT_IMMEDIATE);
1078  ObjectState* shortImmWidth = shortImm->childByName(SHORT_IMM_WIDTH);
1079  bus->setAttribute(Bus::OSKEY_IMMWIDTH, shortImmWidth->stringValue());
1080  ObjectState* shortImmExt = shortImm->childByName(SHORT_IMM_EXTENSION);
1081  string extension = shortImmExt->stringValue();
1082  if (extension == SIGN_EXTENSION) {
1083  bus->setAttribute(Bus::OSKEY_EXTENSION, Bus::OSVALUE_SIGN);
1084  } else if (extension == ZERO_EXTENSION) {
1085  bus->setAttribute(Bus::OSKEY_EXTENSION, Bus::OSVALUE_ZERO);
1086  } else {
1087  string procName = "ADFSerializer::busToMachine";
1088  string errorMsg = "Unknown extension value in ObjectState.";
1089  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
1091  }
1092 
1093  // add segments and guards
1094  for (int i = 0; i < busState->childCount(); i++) {
1095  ObjectState* child = busState->child(i);
1096  if (child->name() == SEGMENT) {
1097  ObjectState* segment = new ObjectState(Segment::OSNAME_SEGMENT);
1098  bus->addChild(segment);
1099  segment->setAttribute(
1100  Segment::OSKEY_NAME, child->stringAttribute(SEGMENT_NAME));
1101  ObjectState* writesTo = child->childByName(SEGMENT_WRITES_TO);
1102  string destination = writesTo->stringValue();
1103  if (destination != "") {
1104  segment->setAttribute(
1105  Segment::OSKEY_DESTINATION, writesTo->stringValue());
1106  }
1107  } else if (child->name() == GUARD) {
1108  ObjectState* guardType = child->child(0);
1109  if (guardType->name() == ALWAYS_TRUE_GUARD) {
1110  ObjectState* ucGuard = new ObjectState(
1111  UnconditionalGuard::OSNAME_UNCONDITIONAL_GUARD);
1112  bus->addChild(ucGuard);
1113  ucGuard->setAttribute(Guard::OSKEY_INVERTED, false);
1114  } else if (guardType->name() == ALWAYS_FALSE_GUARD) {
1115  ObjectState* ucGuard = new ObjectState(
1116  UnconditionalGuard::OSNAME_UNCONDITIONAL_GUARD);
1117  bus->addChild(ucGuard);
1118  ucGuard->setAttribute(Guard::OSKEY_INVERTED, true);
1119  } else if (guardType->name() == SIMPLE_EXPR ||
1120  guardType->name() == INVERTED_EXPR) {
1121  ObjectState* boolOrUnit = guardType->child(0);
1122  string objectStateName;
1123  string unitNameElem;
1124  string unitNameAttrib;
1125  string targetNameElem;
1126  string targetNameAttrib;
1127  if (boolOrUnit->name() == GUARD_BOOL) {
1128  objectStateName = RegisterGuard::OSNAME_REGISTER_GUARD;
1129  unitNameElem = GUARD_REGFILE_NAME;
1130  unitNameAttrib = RegisterGuard::OSKEY_REGFILE;
1131  targetNameElem = GUARD_REGFILE_INDEX;
1132  targetNameAttrib = RegisterGuard::OSKEY_INDEX;
1133  } else if (boolOrUnit->name() == GUARD_UNIT) {
1134  objectStateName = PortGuard::OSNAME_PORT_GUARD;
1135  unitNameElem = GUARD_UNIT_NAME;
1136  unitNameAttrib = PortGuard::OSKEY_FU;
1137  targetNameElem = GUARD_UNIT_PORT;
1138  targetNameAttrib = PortGuard::OSKEY_PORT;
1139  } else {
1140  string procName = "ADFSerializer::busToMachine";
1141  string errorMsg = "Unknown ObjectState name.";
1143  __FILE__, __LINE__, procName, errorMsg);
1145  }
1146 
1147  ObjectState* guard = new ObjectState(objectStateName);
1148  bus->addChild(guard);
1149  if (guardType->name() == SIMPLE_EXPR) {
1150  guard->setAttribute(Guard::OSKEY_INVERTED, false);
1151  } else {
1152  guard->setAttribute(Guard::OSKEY_INVERTED, true);
1153  }
1154  ObjectState* unit = boolOrUnit->childByName(unitNameElem);
1155  guard->setAttribute(unitNameAttrib, unit->stringValue());
1156  ObjectState* target = boolOrUnit->childByName(
1157  targetNameElem);
1158  guard->setAttribute(targetNameAttrib, target->stringValue());
1159  }
1160  }
1161  }
1162 
1163  return bus;
1164 }
1165 
1166 
1167 /**
1168  * Creates a new ObjectState tree which can be read by Socket::loadState and
1169  * which corresponds with the given ObjectState tree declaring a socket by
1170  * MDF syntax.
1171  *
1172  * @param socketState The ObjectState tree declaring a socket by MDF syntax.
1173  * @return The newly created ObjectState tree.
1174  */
1175 ObjectState*
1177 
1178  ObjectState* socket = new ObjectState(Socket::OSNAME_SOCKET);
1179 
1180  // set name
1181  socket->setAttribute(
1182  Component::OSKEY_NAME, socketState->stringAttribute(SOCKET_NAME));
1183 
1184  // set direction
1185  if (socketState->hasChild(SOCKET_READS_FROM) ||
1186  socketState->hasChild(SOCKET_WRITES_TO)) {
1187 
1188  if (socketState->hasChild(SOCKET_READS_FROM)) {
1189  socket->setAttribute(
1190  Socket::OSKEY_DIRECTION, Socket::OSVALUE_INPUT);
1191  } else {
1192  socket->setAttribute(
1193  Socket::OSKEY_DIRECTION, Socket::OSVALUE_OUTPUT);
1194  }
1195 
1196  // add connections
1197  for (int i = 0; i < socketState->childCount(); i++) {
1198  ObjectState* srcOrDest = socketState->child(i);
1199  ObjectState* conn = new ObjectState(
1200  Connection::OSNAME_CONNECTION);
1201  socket->addChild(conn);
1202  conn->setAttribute(
1203  Connection::OSKEY_SOCKET,
1204  socketState->stringAttribute(SOCKET_NAME));
1205  ObjectState* bus = srcOrDest->childByName(SOCKET_BUS);
1206  conn->setAttribute(Connection::OSKEY_BUS, bus->stringValue());
1207  ObjectState* segment = srcOrDest->childByName(SOCKET_SEGMENT);
1208  conn->setAttribute(
1209  Connection::OSKEY_SEGMENT, segment->stringValue());
1210  }
1211 
1212  } else {
1213  socket->setAttribute(
1214  Socket::OSKEY_DIRECTION, Socket::OSVALUE_UNKNOWN);
1215  }
1216 
1217  return socket;
1218 }
1219 
1220 
1221 /**
1222  * Creates a new ObjectState tree which can be read by Bridge::loadState.
1223  *
1224  * The ObjectState tree is created according to the given ObjectState tree
1225  * which matches with the syntax of bridge declaration in MDF file.
1226  *
1227  * @param bridgeState The ObjectState tree which matches with the syntax of
1228  * bridge declaration in MDF file.
1229  * @return The newly created ObjectState tree.
1230  */
1231 ObjectState*
1233 
1234  ObjectState* bridge = new ObjectState(Bridge::OSNAME_BRIDGE);
1235  bridge->setAttribute(
1236  Component::OSKEY_NAME, bridgeState->stringAttribute(BRIDGE_NAME));
1237  ObjectState* readsFrom = bridgeState->childByName(BRIDGE_READS_FROM);
1238  bridge->setAttribute(Bridge::OSKEY_SOURCE_BUS, readsFrom->stringValue());
1239  ObjectState* writesTo = bridgeState->childByName(BRIDGE_WRITES_TO);
1240  bridge->setAttribute(
1241  Bridge::OSKEY_DESTINATION_BUS, writesTo->stringValue());
1242  return bridge;
1243 }
1244 
1245 
1246 /**
1247  * Creates a new ObjectState tree which can be read by
1248  * FunctionUnit::loadState.
1249  *
1250  * The ObjectState tree is created according to the given ObjectState tree
1251  * which matches with the syntax of function unit declaration in MDF file.
1252  *
1253  * @param fuState The ObjectState tree which matches with the syntax of
1254  * function unit declaration in MDF file.
1255  * @param orderNumber The number indicating sequential position of the FU
1256  * in the ADF.
1257  * @return The newly created ObjectState tree.
1258  */
1259 ObjectState*
1261  const ObjectState* fuState,
1262  const int orderNumber) {
1263 
1264  ObjectState* fu = new ObjectState(FunctionUnit::OSNAME_FU);
1265 
1266  // set name
1267  fu->setAttribute(
1268  Component::OSKEY_NAME, fuState->stringAttribute(FU_NAME));
1269  // each FU has own value of ordering
1270  fu->setAttribute(FunctionUnit::OSKEY_ORDER_NUMBER, orderNumber);
1271  // set address space
1272  ObjectState* as = fuState->childByName(FU_ADDRESS_SPACE);
1273  string asName = as->stringValue();
1274  if (asName != "") {
1275  fu->setAttribute(FunctionUnit::OSKEY_AS, asName);
1276  }
1277 
1278  // set ports and operations
1279  for (int i = 0; i < fuState->childCount(); i++) {
1280  ObjectState* child = fuState->child(i);
1281  if (child->name() == PORT) {
1282  fu->addChild(machineFUPort(child));
1283  } else if (child->name() == FU_OPERATION) {
1284  fu->addChild(machineOperation(child));
1285  }
1286  }
1287 
1288  return fu;
1289 }
1290 
1291 
1292 /**
1293  * Creates a new ObjectState tree which can be read by
1294  * RegisterFile::loadState.
1295  *
1296  * The ObjectState tree is created according to the given ObjectState tree
1297  * which matches with the syntax of register file declaration in MDF file.
1298  *
1299  * @param rfState The ObjectState tree which matches with the syntax of
1300  * register file declaration in MDF file.
1301  * @return The newly created ObjectState tree.
1302  */
1303 ObjectState*
1305 
1306  ObjectState* regFile =
1307  new ObjectState(RegisterFile::OSNAME_REGISTER_FILE);
1308 
1309  // set name
1310  regFile->setAttribute(
1311  Component::OSKEY_NAME, rfState->stringAttribute(RF_NAME));
1312 
1313  // set type
1314  ObjectState* typeChild = rfState->childByName(RF_TYPE);
1315  string type = typeChild->stringValue();
1316  if (type == RF_TYPE_NORMAL) {
1317  regFile->setAttribute(
1318  RegisterFile::OSKEY_TYPE, RegisterFile::OSVALUE_NORMAL);
1319  } else if (type == RF_TYPE_RESERVED) {
1320  regFile->setAttribute(
1321  RegisterFile::OSKEY_TYPE, RegisterFile::OSVALUE_RESERVED);
1322  } else if (type == RF_TYPE_VOLATILE) {
1323  regFile->setAttribute(
1324  RegisterFile::OSKEY_TYPE, RegisterFile::OSVALUE_VOLATILE);
1325  } else {
1326  string procName = "ADFSerializer::registerFileToMachine";
1327  string errorMsg = "Unknown register file type in ObjectState "
1328  "instance.";
1329  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
1331  }
1332 
1333  // set size
1334  ObjectState* size = rfState->childByName(RF_SIZE);
1335  regFile->setAttribute(BaseRegisterFile::OSKEY_SIZE, size->stringValue());
1336 
1337  // set width
1338  ObjectState* width = rfState->childByName(RF_WIDTH);
1339  regFile->setAttribute(
1340  BaseRegisterFile::OSKEY_WIDTH, width->stringValue());
1341 
1342  // set max reads
1343  ObjectState* maxReads = rfState->childByName(RF_MAX_READS);
1344  regFile->setAttribute(
1345  RegisterFile::OSKEY_MAX_READS, maxReads->stringValue());
1346 
1347  // set max writes
1348  ObjectState* maxWrites = rfState->childByName(RF_MAX_WRITES);
1349  regFile->setAttribute(
1350  RegisterFile::OSKEY_MAX_WRITES, maxWrites->stringValue());
1351 
1352  // set guard latency
1353  if (rfState->hasChild(RF_GUARD_LATENCY)) {
1354  ObjectState* latencyChild = rfState->childByName(RF_GUARD_LATENCY);
1355  regFile->setAttribute(
1356  RegisterFile::OSKEY_GUARD_LATENCY, latencyChild->stringValue());
1357  } else {
1358  regFile->setAttribute(RegisterFile::OSKEY_GUARD_LATENCY, 0);
1359  }
1360 
1361  // set ports
1362  for (int i = 0; i < rfState->childCount(); i++) {
1363  ObjectState* child = rfState->child(i);
1364  if (child->name() == PORT) {
1365  regFile->addChild(machineRFPort(child));
1366  }
1367  }
1368 
1369  if (rfState->hasChild(RF_ZERO_REGISTER)) {
1370  ObjectState* zeroRegister = rfState->childByName(RF_ZERO_REGISTER);
1371  regFile->setAttribute(
1372  RegisterFile::OSKEY_ZERO_REGISTER, zeroRegister->boolValue());
1373  }
1374 
1375  return regFile;
1376 }
1377 
1378 
1379 /**
1380  * Creates a new ObjectState tree which can be read by
1381  * AddressSpace::loadState.
1382  *
1383  * The ObjectState tree is created according to the given ObjectState tree
1384  * which matches with the syntax of address space declaration in MDF file.
1385  *
1386  * @param asState The ObjectState tree which matches with the syntax of
1387  * address space declaration in MDF file.
1388  * @return The newly created ObjectState tree.
1389  */
1390 ObjectState*
1392 
1393  ObjectState* as = new ObjectState(AddressSpace::OSNAME_ADDRESS_SPACE);
1394 
1395  // set name
1396  as->setAttribute(
1397  Component::OSKEY_NAME, asState->stringAttribute(AS_NAME));
1398 
1399  // set width
1400  ObjectState* width = asState->childByName(AS_WIDTH);
1401  as->setAttribute(AddressSpace::OSKEY_WIDTH, width->stringValue());
1402 
1403  // set min address
1404  ObjectState* minAddress = asState->childByName(AS_MIN_ADDRESS);
1405  as->setAttribute(
1406  AddressSpace::OSKEY_MIN_ADDRESS, minAddress->stringValue());
1407 
1408  // set max address
1409  ObjectState* maxAddress = asState->childByName(AS_MAX_ADDRESS);
1410  as->setAttribute(
1411  AddressSpace::OSKEY_MAX_ADDRESS, maxAddress->stringValue());
1412 
1413  if (asState->hasChild(AS_SHARED_MEMORY)) {
1414  ObjectState* shared = asState->childByName(AS_SHARED_MEMORY);
1415  as->setAttribute(
1416  AddressSpace::OSKEY_SHARED_MEMORY, shared->boolValue());
1417  }
1418 
1419  // the numerical ids
1420  for (int i = 0; i < asState->childCount(); i++) {
1421  ObjectState* child = asState->child(i);
1422  if (child->name() == AS_NUMERICAL_ID) {
1423  ObjectState* idObj =
1424  new ObjectState(AddressSpace::OSKEY_NUMERICAL_ID, as);
1425  idObj->setValue(child->intValue());
1426  as->addChild(idObj);
1427  }
1428  }
1429 
1430  return as;
1431 }
1432 
1433 
1434 /**
1435  * Creates a new ObjectState tree which can be read by
1436  * ControlUnit::loadState.
1437  *
1438  * The ObjectState tree is created according to the given ObjectState tree
1439  * which matches with the syntax of control unit declaration in MDF file.
1440  *
1441  * @param cuState The ObjectState tree which matches with the syntax of
1442  * control unit declaration in MDF file.
1443  * @return The newly created ObjectState tree.
1444  */
1445 ObjectState*
1447 
1448  ObjectState* cu = new ObjectState(ControlUnit::OSNAME_CONTROL_UNIT);
1449 
1450  // set name
1451  cu->setAttribute(
1452  Component::OSKEY_NAME, cuState->stringAttribute(CU_NAME));
1453 
1454  // set address space
1455  ObjectState* as = cuState->childByName(CU_ADDRESS_SPACE);
1456  string asName = as->stringValue();
1457  if (asName != "") {
1458  cu->setAttribute(FunctionUnit::OSKEY_AS, as->stringValue());
1459  }
1460 
1461  // set delay slots
1462  ObjectState* delaySlots = cuState->childByName(CU_DELAY_SLOTS);
1463  cu->setAttribute(
1464  ControlUnit::OSKEY_DELAY_SLOTS, delaySlots->stringValue());
1465 
1466  // set the guard latency
1467  ObjectState* gLatency = cuState->childByName(CU_GUARD_LATENCY);
1468  cu->setAttribute(
1469  ControlUnit::OSKEY_GUARD_LATENCY, gLatency->stringValue());
1470 
1471  // set ports
1472  for (int i = 0; i < cuState->childCount(); i++) {
1473  ObjectState* child = cuState->child(i);
1474  if (child->name() == PORT) {
1475  cu->addChild(machineFUPort(child));
1476  } else if (child->name() == CU_SPECIAL_PORT) {
1477  cu->addChild(machineSRPort(child));
1478  }
1479  }
1480 
1481  // set return address port binding
1482  ObjectState* raElem = cuState->childByName(CU_RETURN_ADDRESS);
1483  string raPortName = raElem->stringValue();
1484  if (raPortName != "") {
1485  cu->setAttribute(ControlUnit::OSKEY_RA_PORT, raPortName);
1486  }
1487 
1488  // set operations
1489  for (int i = 0; i < cuState->childCount(); i++) {
1490  ObjectState* child = cuState->child(i);
1491  if (child->name() == CU_CTRL_OPERATION) {
1492  cu->addChild(machineOperation(child));
1493  }
1494  }
1495 
1496  return cu;
1497 }
1498 
1499 
1500 /**
1501  * Creates a new ObjectState tree which can be read by
1502  * ImmediateUnit::loadState.
1503  *
1504  * The ObjectState tree is created according to the given ObjectState tree
1505  * which matches with the syntax of immediate unit declaration in MDF file.
1506  * Adds also instruction template ObjectStates to the given ObjectState tree
1507  * which contains the whole machine.
1508  *
1509  * @param iuState The ObjectState tree which matches with the syntax of
1510  * immediate unit declaration in MDF file.
1511  * @param machineState The ObjectState tree containing tree instruction
1512  * templates as child objects.
1513  * @return The newly created ObjectState tree.
1514  * @exception SerializerException If an error occurs while processing.
1515  */
1516 ObjectState*
1518  const ObjectState* iuState, ObjectState* machineState) {
1519  ObjectState* iu = new ObjectState(ImmediateUnit::OSNAME_IMMEDIATE_UNIT);
1520 
1521  // set name
1522  iu->setAttribute(
1523  Component::OSKEY_NAME, iuState->stringAttribute(IU_NAME));
1524 
1525  // set type
1526  ObjectState* typeChild = iuState->childByName(IU_TYPE);
1527  string type = typeChild->stringValue();
1528  if (type == IU_TYPE_NORMAL) {
1529  iu->setAttribute(
1530  ImmediateUnit::OSKEY_TYPE, ImmediateUnit::OSVALUE_NORMAL);
1531  } else if (type == IU_TYPE_RESERVED) {
1532  iu->setAttribute(
1533  ImmediateUnit::OSKEY_TYPE, ImmediateUnit::OSVALUE_RESERVED);
1534  } else if (type == IU_TYPE_VOLATILE) {
1535  iu->setAttribute(
1536  ImmediateUnit::OSKEY_TYPE, ImmediateUnit::OSVALUE_VOLATILE);
1537  } else {
1538  string procName = "ADFSerializer::registerFileToMachine";
1539  string errorMsg = "Unknown register file type in ObjectState "
1540  "instance.";
1541  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
1543  }
1544 
1545  // set size
1546  ObjectState* size = iuState->childByName(IU_SIZE);
1547  iu->setAttribute(BaseRegisterFile::OSKEY_SIZE, size->stringValue());
1548 
1549  // set width
1550  ObjectState* width = iuState->childByName(IU_WIDTH);
1551  iu->setAttribute(BaseRegisterFile::OSKEY_WIDTH, width->stringValue());
1552 
1553  // set max reads
1554  ObjectState* maxReads = iuState->childByName(IU_MAX_READS);
1555  iu->setAttribute(
1556  ImmediateUnit::OSKEY_MAX_READS, maxReads->stringValue());
1557 
1558  // set max writes
1559  ObjectState* maxWrites = iuState->childByName(IU_MAX_WRITES);
1560  iu->setAttribute(
1561  ImmediateUnit::OSKEY_MAX_WRITES, maxWrites->stringValue());
1562 
1563  // set guard latency
1564  if (iuState->hasChild(IU_GUARD_LATENCY)) {
1565  ObjectState* guardLatencyChild =
1566  iuState->childByName(IU_GUARD_LATENCY);
1567  iu->setAttribute(
1568  ImmediateUnit::OSKEY_GUARD_LATENCY,
1569  guardLatencyChild->stringValue());
1570  } else {
1571  iu->setAttribute(ImmediateUnit::OSKEY_GUARD_LATENCY, 0);
1572  }
1573 
1574  // set read latency
1575  if (iuState->hasChild(IU_LATENCY)) {
1576  ObjectState* readLatencyChild = iuState->childByName(IU_LATENCY);
1577  iu->setAttribute(
1578  ImmediateUnit::OSKEY_LATENCY, readLatencyChild->stringValue());
1579  } else {
1580  iu->setAttribute(ImmediateUnit::OSKEY_LATENCY, 1);
1581  }
1582 
1583  setIUExtensionMode(iuState, iu);
1584 
1585  // set ports and instruction templates
1586  for (int i = 0; i < iuState->childCount(); i++) {
1587  ObjectState* child = iuState->child(i);
1588  if (child->name() == PORT) {
1589  iu->addChild(machineRFPort(child));
1590  } else if (child->name() == IU_TEMPLATE) {
1591  try {
1593  child, machineState, iuState->stringAttribute(IU_NAME));
1594  } catch (const SerializerException&) {
1595  delete iu;
1596  throw;
1597  }
1598  }
1599  }
1600 
1601  // if machine has an empty instruction template, it must be found in the
1602  // immediate unit declaration
1603  if (hasEmptyInstructionTemplate(machineState)) {
1604  bool emptyFound = false;
1605  for (int i = 0; i < iuState->childCount(); i++) {
1606  ObjectState* child = iuState->child(i);
1607  if (child->name() == IU_TEMPLATE && child->childCount() == 0) {
1608  emptyFound = true;
1609  break;
1610  }
1611  }
1612  if (!emptyFound) {
1613  delete iu;
1615  format errorMsg = textGen.text(
1617  errorMsg % iuState->stringAttribute(IU_NAME);
1618  string procName = "ADFSerializer::immediateUnitToMachine";
1619  throw SerializerException(
1620  __FILE__, __LINE__, procName, errorMsg.str());
1621  }
1622  }
1623 
1624  return iu;
1625 }
1626 
1627 /**
1628  * Creates an ObjectState instance that can be loaded by ImmediateSlot
1629  * instance.
1630  *
1631  * @param isState An ObjectState instance that represents an immediate-slot
1632  * element of ADF file.
1633  * @return The newly created ObjectState instance.
1634  */
1635 ObjectState*
1637  ObjectState* immediateSlot = new ObjectState(
1638  ImmediateSlot::OSNAME_IMMEDIATE_SLOT);
1639  immediateSlot->setAttribute(
1640  ImmediateSlot::OSKEY_NAME,
1642  return immediateSlot;
1643 }
1644 
1645 
1646 /**
1647  * Creates an ObjectState instance that represents a special register port
1648  * in machine object model format.
1649  *
1650  * The ObjectState instance is created according to the given ObjectState
1651  * instance that represents a special register port in mdf format.
1652  *
1653  * @param mdfSRPortState ObjectState instance representing a special
1654  * register port in mdf format.
1655  * @return The newly created ObjectState instance representing a special
1656  * register port in machine object model format.
1657  */
1658 ObjectState*
1660 
1661  assert(mdfSRPortState->name() == CU_SPECIAL_PORT);
1662  ObjectState* machPort =
1663  new ObjectState(SpecialRegisterPort::OSNAME_SPECIAL_REG_PORT);
1664  machPort->setAttribute(
1665  SpecialRegisterPort::OSKEY_NAME,
1666  mdfSRPortState->stringAttribute(PORT_NAME));
1667 
1668  ObjectState* width = mdfSRPortState->childByName(FU_PORT_WIDTH);
1669  machPort->setAttribute(
1670  SpecialRegisterPort::OSKEY_WIDTH, width->stringValue());
1671 
1672  int connIndex = 0;
1673  for (int i = 0; i < mdfSRPortState->childCount(); i++) {
1674  ObjectState* child = mdfSRPortState->child(i);
1675  if (child->name() == PORT_CONNECTS_TO) {
1676  connIndex++;
1677  if (connIndex == 1) {
1678  machPort->setAttribute(
1679  Port::OSKEY_FIRST_SOCKET, child->stringValue());
1680  } else if (connIndex == 2) {
1681  machPort->setAttribute(
1682  Port::OSKEY_SECOND_SOCKET, child->stringValue());
1683  } else {
1684  string procName = "ADFSerializer::machineSRPort";
1685  string errorMsg = "Too many connects-to elements in SR "
1686  "port.";
1688  __FILE__, __LINE__, procName, errorMsg);
1690  }
1691  }
1692  }
1693 
1694  return machPort;
1695 }
1696 
1697 
1698 /**
1699  * Creates an ObjectState instance that represents a special register port
1700  * in mdf format.
1701  *
1702  * The ObjectState instance is created according to the given ObjectState
1703  * instance that represents a special register port in machine object model
1704  * format.
1705  *
1706  * @param machineSRPortState ObjectState instance representing a special
1707  * register port in machine object model format.
1708  * @return The newly created ObjectState instance representing a special
1709  * register port in mdf format.
1710  */
1711 ObjectState*
1712 ADFSerializer::mdfSRPort(const ObjectState* machineSRPortState) {
1713 
1714  assert(machineSRPortState->name() ==
1715  SpecialRegisterPort::OSNAME_SPECIAL_REG_PORT);
1716 
1718  string name =
1719  machineSRPortState->stringAttribute(SpecialRegisterPort::OSKEY_NAME);
1721 
1722  if (machineSRPortState->hasAttribute(FUPort::OSKEY_FIRST_SOCKET)) {
1724  mdfSRPort->addChild(conn);
1725  conn->setValue(machineSRPortState->stringAttribute(
1726  FUPort::OSKEY_FIRST_SOCKET));
1727  }
1728 
1729  if (machineSRPortState->hasAttribute(FUPort::OSKEY_SECOND_SOCKET)) {
1731  mdfSRPort->addChild(conn);
1732  conn->setValue(machineSRPortState->stringAttribute(
1733  FUPort::OSKEY_SECOND_SOCKET));
1734  }
1735 
1736  ObjectState* width = new ObjectState(FU_PORT_WIDTH);
1737  mdfSRPort->addChild(width);
1738  width->setValue(
1739  machineSRPortState->stringAttribute(
1740  SpecialRegisterPort::OSKEY_WIDTH));
1741 
1742  return mdfSRPort;
1743 }
1744 
1745 
1746 /**
1747  * Sets extension mode of immediate unit to the given ObjectState tree
1748  * representing immediate unit in machine object model format.
1749  *
1750  * @param mdfIUState ObjectState instance representing immediate unit in
1751  * mdf format.
1752  * @param momIUState ObjectState instance representing immediate unit in
1753  * machine object model format.
1754  */
1755 void
1757  const ObjectState* mdfIUState,
1758  ObjectState* momIUState) {
1759 
1760  ObjectState* extension = mdfIUState->childByName(IU_EXTENSION);
1761  string extensionValue = extension->stringValue();
1762  if (extensionValue == SIGN_EXTENSION) {
1763  momIUState->setAttribute(
1764  ImmediateUnit::OSKEY_EXTENSION, ImmediateUnit::OSVALUE_SIGN);
1765  } else if (extensionValue == ZERO_EXTENSION) {
1766  momIUState->setAttribute(
1767  ImmediateUnit::OSKEY_EXTENSION, ImmediateUnit::OSVALUE_ZERO);
1768  } else {
1769  string procName = "ADFSerializer::setIUExtensionMode";
1770  string errorMsg = "Unknown extension attribute value in ObjectState "
1771  "instance.";
1772  Application::writeToErrorLog(__FILE__, __LINE__, procName, errorMsg);
1774  }
1775 }
1776 
1777 
1778 /**
1779  * Creates an ObjectState instance that represents a register file port in
1780  * machine object model format.
1781  *
1782  * The ObjectState instance is created according to the given ObjectState
1783  * instance that represents a port in mdf format. The given instance must
1784  * have an attribute called 'name' and up to two 'connects-to' children.
1785  *
1786  * @param mdfPortState ObjectState instance representing a normal port in
1787  * mdf format.
1788  * @return The newly created ObjectState instance representing a normal
1789  * port in machine object model format.
1790  */
1791 ObjectState*
1793 
1794  ObjectState* port = new ObjectState(RFPort::OSNAME_RFPORT);
1795  port->setAttribute(
1796  RFPort::OSKEY_NAME, mdfPortState->stringAttribute(PORT_NAME));
1797 
1798  for (int i = 0; i < mdfPortState->childCount(); i++) {
1799  ObjectState* conn = mdfPortState->child(i);
1800  if (i == 0) {
1801  port->setAttribute(
1802  Port::OSKEY_FIRST_SOCKET, conn->stringValue());
1803  } else {
1804  port->setAttribute(
1805  Port::OSKEY_SECOND_SOCKET, conn->stringValue());
1806  }
1807  }
1808 
1809  return port;
1810 }
1811 
1812 
1813 /**
1814  * Creates an ObjectState instance that represents a normal port in mdf
1815  * format.
1816  *
1817  * The ObjectState instance is created according to the given ObjectState
1818  * instance that represents a port in machine object model format.
1819  *
1820  * @param machinePortState ObjectState instance representing a normal port in
1821  * machine object model format.
1822  * @return The newly created ObjectState instance representing a normal
1823  * port in mdf format.
1824  */
1825 ObjectState*
1826 ADFSerializer::mdfPort(const ObjectState* machinePortState) {
1827 
1829  mdfPort->setAttribute(PORT_NAME, machinePortState->stringAttribute(
1830  Port::OSKEY_NAME));
1831  if (machinePortState->hasAttribute(Port::OSKEY_FIRST_SOCKET)) {
1833  mdfPort->addChild(conn);
1834  conn->setValue(machinePortState->stringAttribute(
1835  Port::OSKEY_FIRST_SOCKET));
1836  }
1837  if (machinePortState->hasAttribute(Port::OSKEY_SECOND_SOCKET)) {
1839  mdfPort->addChild(conn);
1840  conn->setValue(machinePortState->stringAttribute(
1841  Port::OSKEY_SECOND_SOCKET));
1842  }
1843  return mdfPort;
1844 }
1845 
1846 
1847 /**
1848  * Creates an ObjectState instance that represent a function unit port in
1849  * machine object model format.
1850  *
1851  * The ObjectState instance is created according to the given ObjectState
1852  * instance that represents a function unit port in mdf format. The given
1853  * instance must have an attribute called 'name' and up to two 'connects-to'
1854  * children. It has also 'width' child and may also have 'triggers' and
1855  * 'setsOpcode' children.
1856  *
1857  * @param mdfFUPortState ObjectState instance representing a function port in
1858  * mdf format.
1859  * @return The newly created ObjectState instance representing a function
1860  * unit port in machine object model format.
1861  */
1862 ObjectState*
1864 
1865  ObjectState* fuPort = new ObjectState(FUPort::OSNAME_FUPORT);
1866  fuPort->setAttribute(Port::OSKEY_NAME, mdfFUPortState->stringAttribute(
1867  PORT_NAME));
1868 
1869  // set socket connections
1870  for (int i = 0; i < mdfFUPortState->childCount(); i++) {
1871  ObjectState* portChild = mdfFUPortState->child(i);
1872  if (portChild->name() == PORT_CONNECTS_TO) {
1873  if (!fuPort->hasAttribute(Port::OSKEY_FIRST_SOCKET)) {
1874  fuPort->setAttribute(
1875  Port::OSKEY_FIRST_SOCKET, portChild->stringValue());
1876  } else {
1877  fuPort->setAttribute(
1878  Port::OSKEY_SECOND_SOCKET, portChild->stringValue());
1879  }
1880  }
1881  }
1882 
1883  // set other attributes
1884  ObjectState* width = mdfFUPortState->childByName(FU_PORT_WIDTH);
1885  fuPort->setAttribute(FUPort::OSKEY_WIDTH, width->stringValue());
1886  fuPort->setAttribute(
1887  FUPort::OSKEY_TRIGGERING, mdfFUPortState->hasChild(
1888  FU_PORT_TRIGGERS));
1889  fuPort->setAttribute(
1890  FUPort::OSKEY_OPCODE_SETTING, mdfFUPortState->hasChild(
1892  fuPort->setAttribute(
1893  FUPort::OSKEY_NO_REGISTER, mdfFUPortState->hasChild(
1895 
1896  return fuPort;
1897 }
1898 
1899 
1900 /**
1901  * Creates an ObjectState instance that represents a function unit port in
1902  * mdf format.
1903  *
1904  * The ObjectState instance is created according to the given ObjectState
1905  * instance that represents a function unit port in machine object model
1906  * format.
1907  *
1908  * @param machineFUPortState ObjectState instance representing a function
1909  * unit port in machine object model format.
1910  * @return The newly created ObjectState instance representing a function
1911  * unit port in mdf format.
1912  */
1913 ObjectState*
1914 ADFSerializer::mdfFUPort(const ObjectState* machineFUPortState) {
1915 
1916  ObjectState* mdfFUPort = mdfPort(machineFUPortState);
1917  ObjectState* width = new ObjectState(FU_PORT_WIDTH);
1918  width->setValue(machineFUPortState->stringAttribute(
1919  FUPort::OSKEY_WIDTH));
1920  mdfFUPort->addChild(width);
1921  if (machineFUPortState->intAttribute(FUPort::OSKEY_TRIGGERING)) {
1923  }
1924  if (machineFUPortState->intAttribute(FUPort::OSKEY_OPCODE_SETTING)) {
1926  }
1927 
1928  if (machineFUPortState->intAttribute(FUPort::OSKEY_NO_REGISTER)) {
1930  }
1931 
1932  return mdfFUPort;
1933 }
1934 
1935 
1936 /**
1937  * Creates an ObjectState instance that represents an operation in machine
1938  * object model format.
1939  *
1940  * The ObjectState instance is created according to the given ObjectState
1941  * instance that represents an operation in mdf format.
1942  *
1943  * @param mdfOperationState ObjectState instance representing an operation
1944  * in mdf format.
1945  * @return The newly created ObjectState instance representing an operation
1946  * in machine object model format.
1947  */
1948 ObjectState*
1950 
1952  HWOperation::OSNAME_OPERATION);
1954  HWOperation::OSKEY_NAME,
1955  mdfOperationState->childByName(FU_OP_NAME)->stringValue());
1956 
1957  // set operand bindings
1958  for (int i = 0; i < mdfOperationState->childCount(); i++) {
1959  ObjectState* child = mdfOperationState->child(i);
1960  if (child->name() == FU_OP_BIND) {
1961  ObjectState* binding = new ObjectState(
1962  HWOperation::OSNAME_OPERAND_BINDING);
1963  machineOperation->addChild(binding);
1964  binding->setAttribute(
1965  HWOperation::OSKEY_OPERAND,
1967  binding->setAttribute(
1968  HWOperation::OSKEY_PORT, child->stringValue());
1969  }
1970  }
1971 
1972  // set pipeline
1973  ObjectState* mdfPipeline = mdfOperationState->childByName(
1974  FU_OP_PIPELINE);
1976 
1977  return machineOperation;
1978 }
1979 
1980 
1981 /**
1982  * Creates an ObjectState instance that represents an operation in mdf
1983  * format.
1984  *
1985  * The ObjectState instance is created according to the given ObjectState
1986  * instance that represents an operation in machine object model format.
1987  *
1988  * @param machineOperationState ObjectState instance representing an
1989  * operation in machine object model format.
1990  * @return The newly created ObjectState instance representing an operation
1991  * in mdf format.
1992  */
1993 ObjectState*
1994 ADFSerializer::mdfOperation(const ObjectState* machineOperationState) {
1995 
1997  ObjectState* name = new ObjectState(FU_OP_NAME);
1998  mdfOperation->addChild(name);
1999  name->setValue(machineOperationState->stringAttribute(
2000  HWOperation::OSKEY_NAME));
2001 
2002  // add bind elements
2003  for (int i = 0; i < machineOperationState->childCount(); i++) {
2004  ObjectState* child = machineOperationState->child(i);
2005  if (child->name() == HWOperation::OSNAME_OPERAND_BINDING) {
2006  ObjectState* bind = new ObjectState(FU_OP_BIND);
2007  mdfOperation->addChild(bind);
2008  bind->setAttribute(
2010  HWOperation::OSKEY_OPERAND));
2011  bind->setValue(child->stringAttribute(HWOperation::OSKEY_PORT));
2012  }
2013  }
2014 
2015  ObjectState* machPipeline = machineOperationState->childByName(
2016  ExecutionPipeline::OSNAME_PIPELINE);
2017  mdfOperation->addChild(mdfPipeline(machPipeline));
2018  return mdfOperation;
2019 }
2020 
2021 
2022 /**
2023  * Creates an ObjectState instance that represents a pipeline in machine
2024  * object model format.
2025  *
2026  * The ObjectState instance is created according to the given ObjectState
2027  * instance that represents a pipeline in mdf format.
2028  *
2029  * @param mdfPipelineState ObjectState instance representing a pipeline in
2030  * mdf format.
2031  * @return The newly created ObjectState instance representing a pipeline in
2032  * machine object model format.
2033  */
2034 ObjectState*
2036 
2038  ExecutionPipeline::OSNAME_PIPELINE);
2039 
2040  for (int i = 0; i < mdfPipelineState->childCount(); i++) {
2041  ObjectState* mdfResource = mdfPipelineState->child(i);
2042  ObjectState* machineResource = NULL;
2043  if (mdfResource->name() == FU_OP_PL_RESOURCE) {
2044  machineResource = new ObjectState(
2045  ExecutionPipeline::OSNAME_RESOURCE_USAGE);
2046  machineResource->setAttribute(
2047  ExecutionPipeline::OSKEY_RESOURCE_NAME,
2048  mdfResource->stringAttribute(FU_OP_PL_RES_NAME));
2049  } else if (mdfResource->name() == FU_OP_PL_READS) {
2050  machineResource = new ObjectState(
2051  ExecutionPipeline::OSNAME_OPERAND_READ);
2052  machineResource->setAttribute(
2053  ExecutionPipeline::OSKEY_OPERAND,
2054  mdfResource->stringAttribute(FU_OP_PL_READS_NAME));
2055  } else if (mdfResource->name() == FU_OP_PL_WRITES) {
2056  machineResource = new ObjectState(
2057  ExecutionPipeline::OSNAME_OPERAND_WRITE);
2058  machineResource->setAttribute(
2059  ExecutionPipeline::OSKEY_OPERAND,
2060  mdfResource->stringAttribute(FU_OP_PL_WRITES_NAME));
2061  } else {
2062  const string procName = "ADFSerializer::machinePipeline";
2063  const string errorMsg = "Given pipeline model is invalid.";
2065  __FILE__, __LINE__, procName, errorMsg);
2067  }
2068 
2069  machinePipeline->addChild(machineResource);
2070  machineResource->setAttribute(
2071  ExecutionPipeline::OSKEY_START_CYCLE,
2072  mdfResource->childByName(FU_OP_PL_RES_START_CYCLE)->
2073  stringValue());
2074  machineResource->setAttribute(
2075  ExecutionPipeline::OSKEY_CYCLES,
2076  mdfResource->childByName(FU_OP_PL_RES_CYCLES)->stringValue());
2077  }
2078 
2079  return machinePipeline;
2080 }
2081 
2082 
2083 /**
2084  * Creates an ObjectState instance that represents a pipeline in mdf format.
2085  *
2086  * The ObjectState instance is created according to the given ObjectState
2087  * instance that represents a pipeline in machine object model format.
2088  *
2089  * @param machinePipelineState ObjectState instance representing a pipeline
2090  * in machine object model format.
2091  * @return The newly created ObjectState instance representing a pipeline in
2092  * mdf format.
2093  */
2094 ObjectState*
2095 ADFSerializer::mdfPipeline(const ObjectState* machinePipelineState) {
2096 
2098 
2099  for (int i = 0; i < machinePipelineState->childCount(); i++) {
2100  ObjectState* resChild = machinePipelineState->child(i);
2101  ObjectState* mdfChild = NULL;
2102  if (resChild->name() == ExecutionPipeline::OSNAME_RESOURCE_USAGE) {
2103  mdfChild = new ObjectState(FU_OP_PL_RESOURCE);
2104  mdfChild->setAttribute(
2106  resChild->stringAttribute(
2107  ExecutionPipeline::OSKEY_RESOURCE_NAME));
2108  } else if (resChild->name() ==
2109  ExecutionPipeline::OSNAME_OPERAND_READ) {
2110  mdfChild = new ObjectState(FU_OP_PL_READS);
2111  mdfChild->setAttribute(
2113  resChild->stringAttribute(ExecutionPipeline::OSKEY_OPERAND));
2114  } else if (resChild->name() ==
2115  ExecutionPipeline::OSNAME_OPERAND_WRITE) {
2116  mdfChild = new ObjectState(FU_OP_PL_WRITES);
2117  mdfChild->setAttribute(
2119  resChild->stringAttribute(ExecutionPipeline::OSKEY_OPERAND));
2120  } else {
2121  assert(false);
2122  }
2123 
2124  mdfPipeline->addChild(mdfChild);
2126  mdfChild->addChild(startCycle);
2127  startCycle->setValue(
2128  resChild->stringAttribute(ExecutionPipeline::OSKEY_START_CYCLE));
2130  mdfChild->addChild(cycles);
2131  cycles->setValue(
2132  resChild->stringAttribute(ExecutionPipeline::OSKEY_CYCLES));
2133  }
2134 
2135  return mdfPipeline;
2136 }
2137 
2138 
2139 /**
2140  * Includes the given instruction template information to ObjectState tree
2141  * representing immediate unit in mdf format.
2142  *
2143  * @param momITState ObjectState instance representing an instruction
2144  * template in machine object model format.
2145  * @param mdfIUState ObjectState instance representing an immediate unit in
2146  * mdf format.
2147  */
2148 void
2150  const ObjectState* momITState,
2151  ObjectState* mdfIUState) {
2152 
2153  string iuName = mdfIUState->stringAttribute(IU_NAME);
2154  string iTempName = momITState->stringAttribute(Component::OSKEY_NAME);
2155  for (int slotIndex = 0; slotIndex < momITState->childCount();
2156  slotIndex++) {
2157  ObjectState* slot = momITState->child(slotIndex);
2158  if (slot->stringAttribute(TemplateSlot::OSKEY_DESTINATION) ==
2159  iuName) {
2160  ObjectState* correctTemplate = NULL;
2161 
2162  for (int iuChildIndex = 0;
2163  iuChildIndex < mdfIUState->childCount(); iuChildIndex++) {
2164  ObjectState* iuChild = mdfIUState->child(iuChildIndex);
2165  if (iuChild->name() == IU_TEMPLATE &&
2166  iuChild->stringAttribute(IU_TEMPLATE_NAME) == iTempName) {
2167  correctTemplate = iuChild;
2168  }
2169  }
2170 
2171  if (correctTemplate == NULL) {
2172  correctTemplate = new ObjectState(IU_TEMPLATE);
2173  mdfIUState->addChild(correctTemplate);
2174  correctTemplate->setAttribute(IU_TEMPLATE_NAME, iTempName);
2175  }
2176 
2177  ObjectState* slotElem = new ObjectState(IU_TEMPLATE_SLOT);
2178  correctTemplate->addChild(slotElem);
2180  slotElem->addChild(nameElem);
2181  nameElem->setValue(
2182  slot->stringAttribute(TemplateSlot::OSKEY_SLOT));
2184  slotElem->addChild(widthElem);
2185  widthElem->setValue(
2186  slot->stringAttribute(TemplateSlot::OSKEY_WIDTH));
2187  }
2188  }
2189 
2190 
2191  if (momITState->childCount() == 0) {
2192  ObjectState* emptyTemplate = new ObjectState(IU_TEMPLATE);
2193  mdfIUState->addChild(emptyTemplate);
2194  emptyTemplate->setAttribute(IU_TEMPLATE_NAME, iTempName);
2195  }
2196 }
2197 
2198 
2199 /**
2200  * Adds/modifies instruction templates to the given ObjectState instance
2201  * representing machine in machine object model format.
2202  *
2203  * Instruction templates are read from the given ObjectState instance
2204  * representing a template element inside immediate unit declaration of
2205  * mdf.
2206  *
2207  * @param mdfITState ObjectState instance representing a template element.
2208  * @param momMachineState ObjectState instance representing a machine in
2209  * machine object model format.
2210  * @param iuName Name of the immediate unit which contains the template
2211  * element.
2212  * @exception SerializerException If an error is occurred while processing.
2213  */
2214 void
2216  const ObjectState* mdfITState, ObjectState* momMachineState,
2217  const std::string& iuName) {
2218  const string procName = "ADFSerializer::instructionTemplateToMachine";
2219 
2220  string templateName = mdfITState->stringAttribute(IU_TEMPLATE_NAME);
2221  ObjectState* iTemp = NULL;
2222  bool iTempFound = false;
2223 
2224  for (int iTempIndex = 0; iTempIndex < momMachineState->childCount();
2225  iTempIndex++) {
2226  iTemp = momMachineState->child(iTempIndex);
2227  if (iTemp->name() ==
2228  InstructionTemplate::OSNAME_INSTRUCTION_TEMPLATE &&
2229  iTemp->stringAttribute(Component::OSKEY_NAME) ==
2230  templateName) {
2231  iTempFound = true;
2232  break;
2233  }
2234  }
2235 
2236  if (!iTempFound) {
2237  iTemp = new ObjectState(
2238  InstructionTemplate::OSNAME_INSTRUCTION_TEMPLATE);
2239  momMachineState->addChild(iTemp);
2240  iTemp->setAttribute(Component::OSKEY_NAME, templateName);
2241  }
2242 
2244 
2245  if ((mdfITState->childCount() == 0 && iTempFound &&
2246  iTemp->childCount() > 0) ||
2247  (mdfITState->childCount() > 0 && iTempFound &&
2248  iTemp->childCount() == 0)) {
2249  format errorMsg = textGen.text(
2251  errorMsg % templateName;
2252  throw SerializerException(
2253  __FILE__, __LINE__, procName, errorMsg.str());
2254  }
2255 
2256  for (int slotIndex = 0; slotIndex < mdfITState->childCount();
2257  slotIndex++) {
2258  ObjectState* slot = mdfITState->child(slotIndex);
2259  string slotName =
2261  string width =
2263 
2264  ObjectState* iTempSlot = momTemplateSlot(iTemp, slotName);
2265  if (iTempSlot == NULL) {
2266  iTempSlot = new ObjectState(TemplateSlot::OSNAME_TEMPLATE_SLOT);
2267  iTempSlot->setAttribute(TemplateSlot::OSKEY_SLOT, slotName);
2268  iTempSlot->setAttribute(TemplateSlot::OSKEY_WIDTH, width);
2269  iTempSlot->setAttribute(TemplateSlot::OSKEY_DESTINATION, iuName);
2270  iTemp->addChild(iTempSlot);
2271  } else {
2272  format errorMsg;
2273  if (iTempSlot->stringAttribute(TemplateSlot::OSKEY_DESTINATION) ==
2274  iuName) {
2275  errorMsg = textGen.text(
2277  errorMsg % slotName % iuName % templateName;
2278  } else {
2279  errorMsg = textGen.text(
2281  TXT_MULTIPLE_DESTINATIONS_IN_TEMPLATE_SLOT);
2282  errorMsg % slotName % templateName % iuName %
2283  iTempSlot->stringAttribute(
2284  TemplateSlot::OSKEY_DESTINATION);
2285  }
2286  throw SerializerException(
2287  __FILE__, __LINE__, procName, errorMsg.str());
2288  }
2289  }
2290 }
2291 
2292 /**
2293  * Looks for an ObjectState instance which represents a template slot in
2294  * machine object model format.
2295  *
2296  * The ObjectState instance is searched from inside the given ObjectState
2297  * instance that represents an instruction template in machine object model
2298  * format. The instance is seached by the given slot name. Returns NULL if
2299  * such an instance is not found.
2300  *
2301  * @param momITState An ObjectState instance representing an instruction
2302  * template in machine object model format.
2303  * @param busName The name of the slot to look the template slot for.
2304  * @return ObjectState instance representing a template slot in machine
2305  * object model format or NULL.
2306  */
2307 ObjectState*
2309  const ObjectState* momITState,
2310  const std::string& slotName) {
2311 
2312  for (int i = 0; i < momITState->childCount(); i++) {
2313  ObjectState* slot = momITState->child(i);
2314  if (slot->stringAttribute(TemplateSlot::OSKEY_SLOT) == slotName) {
2315  return slot;
2316  }
2317  }
2318 
2319  return NULL;
2320 }
2321 
2322 
2323 /**
2324  * Checks whether the machine represented by the given ObjectState tree
2325  * contains an empty instruction template.
2326  *
2327  * @param momMachineState The ObjectState tree.
2328  * @return True if it contains an empty instruction template, otherwise
2329  * false.
2330  */
2331 bool
2333  const ObjectState* momMachineState) {
2334 
2335  for (int i = 0; i < momMachineState->childCount(); i++) {
2336  ObjectState* child = momMachineState->child(i);
2337  if (child->name() ==
2338  InstructionTemplate::OSNAME_INSTRUCTION_TEMPLATE &&
2339  child->childCount() == 0) {
2340  return true;
2341  }
2342  }
2343 
2344  return false;
2345 }
BRIDGE_NAME
const string BRIDGE_NAME
Definition: ADFSerializer.cc:110
CU_RETURN_ADDRESS
const string CU_RETURN_ADDRESS
Definition: ADFSerializer.cc:177
ZERO_EXTENSION
const string ZERO_EXTENSION
Definition: ADFSerializer.cc:85
RF_MAX_WRITES
const string RF_MAX_WRITES
Definition: ADFSerializer.cc:140
ObjectState::hasAttribute
bool hasAttribute(const std::string &name) const
Definition: ObjectState.cc:205
ADDRESS_SPACE
const string ADDRESS_SPACE
Definition: ADFSerializer.cc:164
FU_OP_BIND_NAME
const string FU_OP_BIND_NAME
Definition: ADFSerializer.cc:120
AS_NAME
const string AS_NAME
Definition: ADFSerializer.cc:165
FU_OP_BIND
const string FU_OP_BIND
Definition: ADFSerializer.cc:119
PORT_CONNECTS_TO
const string PORT_CONNECTS_TO
Definition: ADFSerializer.cc:183
FU_OP_PL_RESOURCE
const string FU_OP_PL_RESOURCE
Definition: ADFSerializer.cc:122
SIGN_EXTENSION
const string SIGN_EXTENSION
Definition: ADFSerializer.cc:84
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ADFSerializer::mdfPipeline
static ObjectState * mdfPipeline(const ObjectState *machinePipelineState)
Definition: ADFSerializer.cc:2095
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ADFSerializerTextGenerator
Definition: ADFSerializerTextGenerator.hh:41
ExecutionPipeline.hh
IMMEDIATE_SLOT
const string IMMEDIATE_SLOT
Definition: ADFSerializer.cc:190
CU_SPECIAL_PORT
const string CU_SPECIAL_PORT
Definition: ADFSerializer.cc:179
SHORT_IMMEDIATE
const string SHORT_IMMEDIATE
Definition: ADFSerializer.cc:81
IU_TYPE
const string IU_TYPE
Definition: ADFSerializer.cc:146
IU_EXTENSION
const string IU_EXTENSION
Definition: ADFSerializer.cc:155
ADFSerializer::socketToMachine
static ObjectState * socketToMachine(const ObjectState *socketState)
Definition: ADFSerializer.cc:1176
SOCKET
const string SOCKET
Definition: ADFSerializer.cc:102
ObjectState::intValue
int intValue() const
ADFSerializer::machinePipeline
static ObjectState * machinePipeline(const ObjectState *mdfPipelineState)
Definition: ADFSerializer.cc:2035
CU_DELAY_SLOTS
const string CU_DELAY_SLOTS
Definition: ADFSerializer.cc:175
Application::writeToErrorLog
static void writeToErrorLog(const std::string fileName, const int lineNumber, const std::string functionName, const std::string message, const int neededVerbosity=0)
Definition: Application.cc:224
Connection.hh
ADFSerializer::functionUnitToMDF
static ObjectState * functionUnitToMDF(const ObjectState *fuState)
Definition: ADFSerializer.cc:629
MDF
const string MDF
Definition: ADFSerializer.cc:63
ADFSerializer::mdfSRPort
static ObjectState * mdfSRPort(const ObjectState *machineSRPortState)
Definition: ADFSerializer.cc:1712
ADFSerializer::mdfPort
static ObjectState * mdfPort(const ObjectState *machinePortState)
Definition: ADFSerializer.cc:1826
IU_LATENCY
const string IU_LATENCY
Definition: ADFSerializer.cc:151
RF_TYPE_NORMAL
const string RF_TYPE_NORMAL
Definition: ADFSerializer.cc:134
MDF_VERSION_NUMBER
const string MDF_VERSION_NUMBER
Definition: ADFSerializer.cc:66
CONTROL_UNIT
const string CONTROL_UNIT
Definition: ADFSerializer.cc:172
IMMEDIATE_UNIT
const string IMMEDIATE_UNIT
Definition: ADFSerializer.cc:144
AddressSpace.hh
IU_TYPE_VOLATILE
const string IU_TYPE_VOLATILE
Definition: ADFSerializer.cc:148
IMMEDIATE_SLOT_NAME
const string IMMEDIATE_SLOT_NAME
Definition: ADFSerializer.cc:191
IU_TYPE_NORMAL
const string IU_TYPE_NORMAL
Definition: ADFSerializer.cc:147
PORT_NAME
const string PORT_NAME
Definition: ADFSerializer.cc:182
BUS_NAME
const string BUS_NAME
Definition: ADFSerializer.cc:79
AS_WIDTH
const string AS_WIDTH
Definition: ADFSerializer.cc:166
ObjectState
Definition: ObjectState.hh:59
ADFSerializer::machineRFPort
static ObjectState * machineRFPort(const ObjectState *mdfPortState)
Definition: ADFSerializer.cc:1792
INVERTED_EXPR
const string INVERTED_EXPR
Definition: ADFSerializer.cc:88
IU_WIDTH
const string IU_WIDTH
Definition: ADFSerializer.cc:152
ImmediateUnit.hh
CU_ADDRESS_SPACE
const string CU_ADDRESS_SPACE
Definition: ADFSerializer.cc:174
TEMPLATE_RF_READ
const string TEMPLATE_RF_READ
Definition: ADFSerializer.cc:193
ADFSerializer::busToMDF
static ObjectState * busToMDF(const ObjectState *busState)
Definition: ADFSerializer.cc:419
SEGMENT_WRITES_TO
const string SEGMENT_WRITES_TO
Definition: ADFSerializer.cc:100
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ObjectState::setName
void setName(const std::string &name)
IU_TEMPLATE_BUS
const string IU_TEMPLATE_BUS
Definition: ADFSerializer.cc:162
SHORT_IMM_WIDTH
const string SHORT_IMM_WIDTH
Definition: ADFSerializer.cc:82
Socket.hh
ADFSerializer::controlUnitToMachine
static ObjectState * controlUnitToMachine(const ObjectState *cuState)
Definition: ADFSerializer.cc:1446
IU_TYPE_RESERVED
const string IU_TYPE_RESERVED
Definition: ADFSerializer.cc:149
RF_MAX_READS
const string RF_MAX_READS
Definition: ADFSerializer.cc:139
FU_OP_PL_WRITES
const string FU_OP_PL_WRITES
Definition: ADFSerializer.cc:128
TTAMachine::Machine::loadState
virtual void loadState(const ObjectState *state)
Definition: Machine.cc:728
ObjectState::childByName
ObjectState * childByName(const std::string &name) const
Definition: ObjectState.cc:443
AS_MAX_ADDRESS
const string AS_MAX_ADDRESS
Definition: ADFSerializer.cc:168
FU_PORT_SETS_OPCODE
const string FU_PORT_SETS_OPCODE
Definition: ADFSerializer.cc:187
ADFSerializer::controlUnitToMDF
static ObjectState * controlUnitToMDF(const ObjectState *cuState)
Definition: ADFSerializer.cc:905
assert
#define assert(condition)
Definition: Application.hh:86
TemplateSlot.hh
ADFSerializer::bridgeToMachine
static ObjectState * bridgeToMachine(const ObjectState *bridgeState)
Definition: ADFSerializer.cc:1232
FU_NAME
const string FU_NAME
Definition: ADFSerializer.cc:115
SIMPLE_EXPR
const string SIMPLE_EXPR
Definition: ADFSerializer.cc:89
FU_OPERATION
const string FU_OPERATION
Definition: ADFSerializer.cc:117
FU_PORT_TRIGGERS
const string FU_PORT_TRIGGERS
Definition: ADFSerializer.cc:186
FU_OP_PL_READS_NAME
const string FU_OP_PL_READS_NAME
Definition: ADFSerializer.cc:127
Segment.hh
IU_TEMPLATE_NAME
const string IU_TEMPLATE_NAME
Definition: ADFSerializer.cc:158
CU_GUARD_LATENCY
const string CU_GUARD_LATENCY
Definition: ADFSerializer.cc:176
AS_MIN_ADDRESS
const string AS_MIN_ADDRESS
Definition: ADFSerializer.cc:167
HWOperation.hh
XMLSerializer::setSchemaFile
void setSchemaFile(const std::string &fileName)
Definition: XMLSerializer.cc:168
GUARD
const string GUARD
Definition: ADFSerializer.cc:87
ADFSerializer::convertToMDFFormat
static ObjectState * convertToMDFFormat(const ObjectState *machineState)
Definition: ADFSerializer.cc:292
RF_TYPE_VOLATILE
const string RF_TYPE_VOLATILE
Definition: ADFSerializer.cc:135
ADFSerializer::hasEmptyInstructionTemplate
static bool hasEmptyInstructionTemplate(const ObjectState *momMachineState)
Definition: ADFSerializer.cc:2332
IU_GUARD_LATENCY
const string IU_GUARD_LATENCY
Definition: ADFSerializer.cc:156
GUARD_UNIT_NAME
const string GUARD_UNIT_NAME
Definition: ADFSerializer.cc:94
ADFSerializerTextGenerator::TXT_IT_EMPTY_AND_NON_EMPTY
@ TXT_IT_EMPTY_AND_NON_EMPTY
Definition: ADFSerializerTextGenerator.hh:50
InstructionTemplate.hh
ADFSerializer::setIUExtensionMode
static void setIUExtensionMode(const ObjectState *mdfIUState, ObjectState *momIUState)
Definition: ADFSerializer.cc:1756
SOCKET_SEGMENT
const string SOCKET_SEGMENT
Definition: ADFSerializer.cc:107
GUARD_UNIT
const string GUARD_UNIT
Definition: ADFSerializer.cc:93
IU_TEMPLATE_SLOT_WIDTH
const string IU_TEMPLATE_SLOT_WIDTH
Definition: ADFSerializer.cc:161
ADFSerializerTextGenerator::TXT_SAME_TEMPLATE_SLOT
@ TXT_SAME_TEMPLATE_SLOT
Definition: ADFSerializerTextGenerator.hh:49
XMLSerializer::readState
virtual ObjectState * readState()
Definition: XMLSerializer.cc:200
ADFSerializer::functionUnitToMachine
static ObjectState * functionUnitToMachine(const ObjectState *fuState, const int orderNumber)
Definition: ADFSerializer.cc:1260
RF_NAME
const string RF_NAME
Definition: ADFSerializer.cc:132
ALWAYS_TRUE_GUARD
const string ALWAYS_TRUE_GUARD
Definition: ADFSerializer.cc:97
SEGMENT
const string SEGMENT
Definition: ADFSerializer.cc:98
ObjectState.hh
TEMPLATE_RF_WRITE
const string TEMPLATE_RF_WRITE
Definition: ADFSerializer.cc:194
GUARD_REGFILE_NAME
const string GUARD_REGFILE_NAME
Definition: ADFSerializer.cc:91
SOCKET_BUS
const string SOCKET_BUS
Definition: ADFSerializer.cc:106
ADFSerializer::addressSpaceToMDF
static ObjectState * addressSpaceToMDF(const ObjectState *asState)
Definition: ADFSerializer.cc:852
TEMPLATE_FU_READ
const string TEMPLATE_FU_READ
Definition: ADFSerializer.cc:195
ADFSerializer::addressSpaceToMachine
static ObjectState * addressSpaceToMachine(const ObjectState *asState)
Definition: ADFSerializer.cc:1391
Guard.hh
Environment::schemaDirPath
static std::string schemaDirPath(const std::string &prog)
Definition: Environment.cc:151
ADFSerializer::mdfFUPort
static ObjectState * mdfFUPort(const ObjectState *machineFUPortState)
Definition: ADFSerializer.cc:1914
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
RF_TYPE
const string RF_TYPE
Definition: ADFSerializer.cc:133
Environment.hh
AS_NUMERICAL_ID
const string AS_NUMERICAL_ID
Definition: ADFSerializer.cc:169
ADFSerializer::immediateSlotToMachine
static ObjectState * immediateSlotToMachine(const ObjectState *isState)
Definition: ADFSerializer.cc:1636
ALWAYS_WRITE_BACK_RESULTS
const string ALWAYS_WRITE_BACK_RESULTS
Definition: ADFSerializer.cc:76
ObjectState::childCount
int childCount() const
FUNCTION_UNITS_ORDERED
const string FUNCTION_UNITS_ORDERED
Definition: ADFSerializer.cc:77
ADFSerializer::ADFSerializer
ADFSerializer()
Definition: ADFSerializer.cc:203
SEGMENT_NAME
const string SEGMENT_NAME
Definition: ADFSerializer.cc:99
TTAMachine::Machine::saveState
virtual ObjectState * saveState() const
Definition: Machine.cc:686
RF_WIDTH
const string RF_WIDTH
Definition: ADFSerializer.cc:138
CU_CTRL_OPERATION
const string CU_CTRL_OPERATION
Definition: ADFSerializer.cc:178
SerializerException
Definition: Exception.hh:675
GUARD_UNIT_PORT
const string GUARD_UNIT_PORT
Definition: ADFSerializer.cc:95
ObjectState::hasChild
bool hasChild(const std::string &name) const
Definition: ObjectState.cc:358
BITNESS64
const string BITNESS64
Definition: ADFSerializer.cc:75
ADFSerializer::machineOperation
static ObjectState * machineOperation(const ObjectState *mdfOperationState)
Definition: ADFSerializer.cc:1949
ADFSerializer::machineFUPort
static ObjectState * machineFUPort(const ObjectState *mdfFUPortState)
Definition: ADFSerializer.cc:1863
Bus.hh
ADFSerializer::~ADFSerializer
virtual ~ADFSerializer()
Definition: ADFSerializer.cc:212
ADFSerializer::instructionTemplateToMDF
static void instructionTemplateToMDF(const ObjectState *momITState, ObjectState *mdfIUState)
Definition: ADFSerializer.cc:2149
ADFSerializer::machineSRPort
static ObjectState * machineSRPort(const ObjectState *mdfSRPortState)
Definition: ADFSerializer.cc:1659
FU_OP_PL_RES_NAME
const string FU_OP_PL_RES_NAME
Definition: ADFSerializer.cc:123
ObjectState::name
std::string name() const
XMLSerializer::setUseSchema
void setUseSchema(bool useSchema)
Definition: XMLSerializer.cc:179
IU_NAME
const string IU_NAME
Definition: ADFSerializer.cc:145
GUARD_BOOL
const string GUARD_BOOL
Definition: ADFSerializer.cc:90
ADF_SCHEMA_FILE
const string ADF_SCHEMA_FILE
Definition: ADFSerializer.cc:198
ADFSerializer::bridgeToMDF
static ObjectState * bridgeToMDF(const ObjectState *bridgeState)
Definition: ADFSerializer.cc:597
ADFSerializer::readState
ObjectState * readState()
Definition: ADFSerializer.cc:238
RF_SIZE
const string RF_SIZE
Definition: ADFSerializer.cc:137
SOCKET_WRITES_TO
const string SOCKET_WRITES_TO
Definition: ADFSerializer.cc:105
ALWAYS_FALSE_GUARD
const string ALWAYS_FALSE_GUARD
Definition: ADFSerializer.cc:96
SOCKET_READS_FROM
const string SOCKET_READS_FROM
Definition: ADFSerializer.cc:104
FUNCTION_UNIT
const string FUNCTION_UNIT
Definition: ADFSerializer.cc:114
FU_OP_PL_RES_CYCLES
const string FU_OP_PL_RES_CYCLES
Definition: ADFSerializer.cc:125
RF_ZERO_REGISTER
const string RF_ZERO_REGISTER
Definition: ADFSerializer.cc:142
RF_GUARD_LATENCY
const string RF_GUARD_LATENCY
Definition: ADFSerializer.cc:141
IU_MAX_WRITES
const string IU_MAX_WRITES
Definition: ADFSerializer.cc:154
IU_TEMPLATE
const string IU_TEMPLATE
Definition: ADFSerializer.cc:157
ADFSerializer.hh
FU_OP_PIPELINE
const string FU_OP_PIPELINE
Definition: ADFSerializer.cc:121
FU_OP_PL_RES_START_CYCLE
const string FU_OP_PL_RES_START_CYCLE
Definition: ADFSerializer.cc:124
BRIDGE
const string BRIDGE
Definition: ADFSerializer.cc:109
FU_PORT_NO_REGISTER
const string FU_PORT_NO_REGISTER
Definition: ADFSerializer.cc:188
IU_MAX_READS
const string IU_MAX_READS
Definition: ADFSerializer.cc:153
ADFSerializer::immediateSlotToMDF
static ObjectState * immediateSlotToMDF(const ObjectState *isState)
Definition: ADFSerializer.cc:976
RegisterFile.hh
FU_ADDRESS_SPACE
const string FU_ADDRESS_SPACE
Definition: ADFSerializer.cc:116
ObjectState::boolAttribute
bool boolAttribute(const std::string &name) const
Definition: ObjectState.cc:338
FUPort.hh
ADFSerializer::writeState
void writeState(const ObjectState *machineState)
Definition: ADFSerializer.cc:224
SHORT_IMM_EXTENSION
const string SHORT_IMM_EXTENSION
Definition: ADFSerializer.cc:83
ControlUnit.hh
REGISTER_FILE
const string REGISTER_FILE
Definition: ADFSerializer.cc:131
FU_OP_PL_WRITES_NAME
const string FU_OP_PL_WRITES_NAME
Definition: ADFSerializer.cc:129
ADFSerializer::convertToMachineFormat
static ObjectState * convertToMachineFormat(const ObjectState *mdfState)
Definition: ADFSerializer.cc:995
AS_SHARED_MEMORY
const string AS_SHARED_MEMORY
Definition: ADFSerializer.cc:170
SpecialRegisterPort.hh
ADFSerializer::mdfOperation
static ObjectState * mdfOperation(const ObjectState *machineOperationState)
Definition: ADFSerializer.cc:1994
BRIDGE_READS_FROM
const string BRIDGE_READS_FROM
Definition: ADFSerializer.cc:111
ObjectState::boolValue
bool boolValue() const
ADFSerializer::writeMachine
void writeMachine(const TTAMachine::Machine &machine)
Definition: ADFSerializer.cc:259
PORT
const string PORT
Definition: ADFSerializer.cc:181
ObjectState::stringValue
std::string stringValue() const
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
LITTLE_ENDIAN_MACHINE
const string LITTLE_ENDIAN_MACHINE
Definition: ADFSerializer.cc:74
ADFSerializer::busToMachine
static ObjectState * busToMachine(const ObjectState *busState)
Definition: ADFSerializer.cc:1064
FU_OP_NAME
const string FU_OP_NAME
Definition: ADFSerializer.cc:118
TEMPLATE_FU_WRITE
const string TEMPLATE_FU_WRITE
Definition: ADFSerializer.cc:196
OperationTriggeredFormat.hh
IU_SIZE
const string IU_SIZE
Definition: ADFSerializer.cc:150
BUS_WIDTH
const string BUS_WIDTH
Definition: ADFSerializer.cc:80
CU_NAME
const string CU_NAME
Definition: ADFSerializer.cc:173
TTAMachine
Definition: Assembler.hh:48
Application::abortProgram
static void abortProgram() __attribute__((noreturn))
Definition: Application.cc:266
ADFSerializerTextGenerator::TXT_EMPTY_IT_NOT_DECLARED
@ TXT_EMPTY_IT_NOT_DECLARED
Definition: ADFSerializerTextGenerator.hh:51
SOCKET_NAME
const string SOCKET_NAME
Definition: ADFSerializer.cc:103
ADFSerializer::registerFileToMDF
static ObjectState * registerFileToMDF(const ObjectState *rfState)
Definition: ADFSerializer.cc:671
GUARD_REGFILE_INDEX
const string GUARD_REGFILE_INDEX
Definition: ADFSerializer.cc:92
BRIDGE_WRITES_TO
const string BRIDGE_WRITES_TO
Definition: ADFSerializer.cc:112
MDF_VERSION
const string MDF_VERSION
Definition: ADFSerializer.cc:64
ADFSerializer::registerFileToMachine
static ObjectState * registerFileToMachine(const ObjectState *rfState)
Definition: ADFSerializer.cc:1304
XMLSerializer
Definition: XMLSerializer.hh:62
IU_TEMPLATE_SLOT
const string IU_TEMPLATE_SLOT
Definition: ADFSerializer.cc:159
IU_TEMPLATE_SLOT_NAME
const string IU_TEMPLATE_SLOT_NAME
Definition: ADFSerializer.cc:160
ObjectState::setValue
void setValue(const std::string &value)
ADFSerializer::instructionTemplateToMachine
static void instructionTemplateToMachine(const ObjectState *mdfITState, ObjectState *momMachineState, const std::string &iuName=std::string(""))
Definition: ADFSerializer.cc:2215
TRIGGER_INVALIDATES_OLD_RESULTS
const string TRIGGER_INVALIDATES_OLD_RESULTS
Definition: ADFSerializer.cc:73
RF_TYPE_RESERVED
const string RF_TYPE_RESERVED
Definition: ADFSerializer.cc:136
BUS
const string BUS
Definition: ADFSerializer.cc:78
ADFSerializer::momTemplateSlot
static ObjectState * momTemplateSlot(const ObjectState *momITState, const std::string &busName)
Definition: ADFSerializer.cc:2308
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
ADFSerializer::immediateUnitToMachine
static ObjectState * immediateUnitToMachine(const ObjectState *iuState, ObjectState *machineState)
Definition: ADFSerializer.cc:1517
Bridge.hh
ADFSerializer::immediateUnitToMDF
static ObjectState * immediateUnitToMDF(const ObjectState *iuState, const ObjectState *machineState)
Definition: ADFSerializer.cc:751
TTAMachine::Machine
Definition: Machine.hh:73
FunctionUnit.hh
FU_PORT_WIDTH
const string FU_PORT_WIDTH
Definition: ADFSerializer.cc:185
XMLSerializer::writeState
virtual void writeState(const ObjectState *rootState)
Definition: XMLSerializer.cc:219
ADFSerializerTextGenerator.hh
FU_OP_PL_READS
const string FU_OP_PL_READS
Definition: ADFSerializer.cc:126
ADFSerializer::socketToMDF
static ObjectState * socketToMDF(const ObjectState *socketState)
Definition: ADFSerializer.cc:543