OpenASIP 2.2
Loading...
Searching...
No Matches
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"
46#include "RegisterFile.hh"
47#include "ImmediateUnit.hh"
48#include "AddressSpace.hh"
49#include "ControlUnit.hh"
50#include "Connection.hh"
52#include "TemplateSlot.hh"
54#include "Environment.hh"
55#include "ObjectState.hh"
57
58using std::string;
59using boost::format;
60using namespace TTAMachine;
61
62// declaration of constant strings used in MDF file
63const string MDF = "adf";
64const string MDF_VERSION = "version";
65// writes files according to ADF specs version 1.10.x
66const string MDF_VERSION_NUMBER = "1.20";
67// 1.8:
68// - adf: little-endian
69// 1.9 ??
70// 1.10:
71// - adf: bitness64
72
73const string TRIGGER_INVALIDATES_OLD_RESULTS = "trigger-invalidates-old-results";
74const string LITTLE_ENDIAN_MACHINE = "little-endian";
75const string BITNESS64 = "bitness64";
76const string ALWAYS_WRITE_BACK_RESULTS = "always-write-back-results";
77const string FUNCTION_UNITS_ORDERED = "fu-ordered";
78const string BUS = "bus";
79const string BUS_NAME = "name";
80const string BUS_WIDTH = "width";
81const string SHORT_IMMEDIATE = "short-immediate";
82const string SHORT_IMM_WIDTH = "width";
83const string SHORT_IMM_EXTENSION = "extension";
84const string SIGN_EXTENSION = "sign";
85const string ZERO_EXTENSION = "zero";
86
87const string GUARD = "guard";
88const string INVERTED_EXPR = "inverted-expr";
89const string SIMPLE_EXPR = "simple-expr";
90const string GUARD_BOOL = "bool";
91const string GUARD_REGFILE_NAME = "name";
92const string GUARD_REGFILE_INDEX = "index";
93const string GUARD_UNIT = "unit";
94const string GUARD_UNIT_NAME = "name";
95const string GUARD_UNIT_PORT = "port";
96const string ALWAYS_FALSE_GUARD = "always-false";
97const string ALWAYS_TRUE_GUARD = "always-true";
98const string SEGMENT = "segment";
99const string SEGMENT_NAME = "name";
100const string SEGMENT_WRITES_TO = "writes-to";
101
102const string SOCKET = "socket";
103const string SOCKET_NAME = "name";
104const string SOCKET_READS_FROM = "reads-from";
105const string SOCKET_WRITES_TO = "writes-to";
106const string SOCKET_BUS = "bus";
107const string SOCKET_SEGMENT = "segment";
108
109const string BRIDGE = "bridge";
110const string BRIDGE_NAME = "name";
111const string BRIDGE_READS_FROM = "reads-from";
112const string BRIDGE_WRITES_TO = "writes-to";
113
114const string FUNCTION_UNIT = "function-unit";
115const string FU_NAME = "name";
116const string FU_ADDRESS_SPACE = "address-space";
117const string FU_OPERATION = "operation";
118const string FU_OP_NAME = "name";
119const string FU_OP_BIND = "bind";
120const string FU_OP_BIND_NAME = "name";
121const string FU_OP_PIPELINE = "pipeline";
122const string FU_OP_PL_RESOURCE = "resource";
123const string FU_OP_PL_RES_NAME = "name";
124const string FU_OP_PL_RES_START_CYCLE = "start-cycle";
125const string FU_OP_PL_RES_CYCLES = "cycles";
126const string FU_OP_PL_READS = "reads";
127const string FU_OP_PL_READS_NAME = "name";
128const string FU_OP_PL_WRITES = "writes";
129const string FU_OP_PL_WRITES_NAME = "name";
130
131const string REGISTER_FILE = "register-file";
132const string RF_NAME = "name";
133const string RF_TYPE = "type";
134const string RF_TYPE_NORMAL = "normal";
135const string RF_TYPE_VOLATILE = "volatile";
136const string RF_TYPE_RESERVED = "reserved";
137const string RF_SIZE = "size";
138const string RF_WIDTH = "width";
139const string RF_MAX_READS = "max-reads";
140const string RF_MAX_WRITES = "max-writes";
141const string RF_GUARD_LATENCY = "guard-latency";
142const string RF_ZERO_REGISTER = "zero-register";
143
144const string IMMEDIATE_UNIT = "immediate-unit";
145const string IU_NAME = "name";
146const string IU_TYPE = "type";
147const string IU_TYPE_NORMAL = "normal";
148const string IU_TYPE_VOLATILE = "volatile";
149const string IU_TYPE_RESERVED = "reserved";
150const string IU_SIZE = "size";
151const string IU_LATENCY = "latency";
152const string IU_WIDTH = "width";
153const string IU_MAX_READS = "max-reads";
154const string IU_MAX_WRITES = "max-writes";
155const string IU_EXTENSION = "extension";
156const string IU_GUARD_LATENCY = "guard-latency";
157const string IU_TEMPLATE = "template";
158const string IU_TEMPLATE_NAME = "name";
159const string IU_TEMPLATE_SLOT = "slot";
160const string IU_TEMPLATE_SLOT_NAME = "name";
161const string IU_TEMPLATE_SLOT_WIDTH = "width";
162const string IU_TEMPLATE_BUS = "bus";
163
164const string ADDRESS_SPACE = "address-space";
165const string AS_NAME = "name";
166const string AS_WIDTH = "width";
167const string AS_MIN_ADDRESS = "min-address";
168const string AS_MAX_ADDRESS = "max-address";
169const string AS_NUMERICAL_ID = "numerical-id";
170const string AS_SHARED_MEMORY = "shared-memory";
171
172const string CONTROL_UNIT = "global-control-unit";
173const string CU_NAME = "name";
174const string CU_ADDRESS_SPACE = "address-space";
175const string CU_DELAY_SLOTS = "delay-slots";
176const string CU_GUARD_LATENCY = "guard-latency";
177const string CU_RETURN_ADDRESS = "return-address";
178const string CU_CTRL_OPERATION = "ctrl-operation";
179const string CU_SPECIAL_PORT = "special-port";
180
181const string PORT = "port";
182const string PORT_NAME = "name";
183const string PORT_CONNECTS_TO = "connects-to";
184
185const string FU_PORT_WIDTH = "width";
186const string FU_PORT_TRIGGERS = "triggers";
187const string FU_PORT_SETS_OPCODE = "sets-opcode";
188const string FU_PORT_NO_REGISTER = "no-register";
189
190const string IMMEDIATE_SLOT = "immediate-slot";
191const string IMMEDIATE_SLOT_NAME = "name";
192
193const string TEMPLATE_RF_READ = "register-file-read";
194const string TEMPLATE_RF_WRITE = "register-file-write";
195const string TEMPLATE_FU_READ = "function-unit-read";
196const string TEMPLATE_FU_WRITE = "function-unit-write";
197
198const string ADF_SCHEMA_FILE = "mach/ADF_Schema.xsd";
199
200/**
201 * Constructor.
202 */
207
208
209/**
210 * Destructor.
211 */
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 */
223void
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 */
258void
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 */
274Machine*
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(
300 machineState->boolAttribute(
303 }
307 }
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);
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);
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);
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);
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);
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 ||
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() ==
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;
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() ==
475
476 // unconditional guards
477 ObjectState* guardChild = new ObjectState(GUARD);
478 root->addChild(guardChild);
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(
497 segment->addChild(writesTo);
499 writesTo->setValue(
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) ==
552 input = true;
553 } else if (socketState->stringAttribute(Socket::OSKEY_DIRECTION) ==
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);
570 conn->addChild(bus);
572
573 ObjectState* segment = new ObjectState(SOCKET_SEGMENT);
574 conn->addChild(segment);
576 segment->setValue(
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(
607
609 bridge->addChild(writesTo);
610 writesTo->setValue(
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(
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) {
682 } else if (typeValue == RegisterFile::OSVALUE_RESERVED) {
684 } else if (typeValue == RegisterFile::OSVALUE_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(
706
707 ObjectState* maxWrites = new ObjectState(RF_MAX_WRITES);
708 regFile->addChild(maxWrites);
709 maxWrites->setValue(
711
713 ObjectState* guardLatency = new ObjectState(RF_GUARD_LATENCY);
714 regFile->addChild(guardLatency);
715 guardLatency->setValue(
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
726 ObjectState* zeroRegister = new ObjectState(RF_ZERO_REGISTER);
727 regFile->addChild(zeroRegister);
728 zeroRegister->setValue(
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
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) {
764 } else if (typeValue == ImmediateUnit::OSVALUE_RESERVED) {
766 } else if (typeValue == ImmediateUnit::OSVALUE_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(
791
792 // add max writes
793 ObjectState* maxWrites = new ObjectState(IU_MAX_WRITES);
794 iUnit->addChild(maxWrites);
795 maxWrites->setValue(
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(
811
812 // add extension element
813 ObjectState* extension = new ObjectState(IU_EXTENSION);
814 iUnit->addChild(extension);
815 extension->setValue(
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() ==
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);
862
863 // add min-address element
864 ObjectState* minAddress = new ObjectState(AS_MIN_ADDRESS);
865 as->addChild(minAddress);
866 minAddress->setValue(
868
869 // add max-address element
870 ObjectState* maxAddress = new ObjectState(AS_MAX_ADDRESS);
871 as->addChild(maxAddress);
872 maxAddress->setValue(
874
877 as->addChild(shared);
878 shared->setValue(
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
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);
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);
931 raElement->setValue(
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)) {
950 }
951
952 // add delay-slots element
954 cUnit->addChild(dSlots);
955 dSlots->setValue(
957
958 // add guard latency element
960 cUnit->addChild(gLatency);
961 gLatency->setValue(
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 */
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(
1008 } else if (child->name() == ALWAYS_WRITE_BACK_RESULTS) {
1009 machine->setAttribute(
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(
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 (
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 */
1065
1067
1068 // set name
1069 bus->setAttribute(
1071
1072 // set width
1073 ObjectState* width = busState->childByName(BUS_WIDTH);
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) {
1084 } else if (extension == ZERO_EXTENSION) {
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) {
1098 bus->addChild(segment);
1099 segment->setAttribute(
1101 ObjectState* writesTo = child->childByName(SEGMENT_WRITES_TO);
1102 string destination = writesTo->stringValue();
1103 if (destination != "") {
1104 segment->setAttribute(
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(
1112 bus->addChild(ucGuard);
1113 ucGuard->setAttribute(Guard::OSKEY_INVERTED, false);
1114 } else if (guardType->name() == ALWAYS_FALSE_GUARD) {
1115 ObjectState* ucGuard = new ObjectState(
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 */
1177
1179
1180 // set name
1181 socket->setAttribute(
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(
1191 } else {
1192 socket->setAttribute(
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(
1201 socket->addChild(conn);
1202 conn->setAttribute(
1204 socketState->stringAttribute(SOCKET_NAME));
1205 ObjectState* bus = srcOrDest->childByName(SOCKET_BUS);
1207 ObjectState* segment = srcOrDest->childByName(SOCKET_SEGMENT);
1208 conn->setAttribute(
1210 }
1211
1212 } else {
1213 socket->setAttribute(
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 */
1233
1235 bridge->setAttribute(
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(
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 */
1261 const ObjectState* fuState,
1262 const int orderNumber) {
1263
1265
1266 // set name
1267 fu->setAttribute(
1269 // each FU has own value of ordering
1271 // set address space
1273 string asName = as->stringValue();
1274 if (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 */
1305
1306 ObjectState* regFile =
1308
1309 // set name
1310 regFile->setAttribute(
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(
1319 } else if (type == RF_TYPE_RESERVED) {
1320 regFile->setAttribute(
1322 } else if (type == RF_TYPE_VOLATILE) {
1323 regFile->setAttribute(
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);
1336
1337 // set width
1338 ObjectState* width = rfState->childByName(RF_WIDTH);
1339 regFile->setAttribute(
1341
1342 // set max reads
1343 ObjectState* maxReads = rfState->childByName(RF_MAX_READS);
1344 regFile->setAttribute(
1346
1347 // set max writes
1348 ObjectState* maxWrites = rfState->childByName(RF_MAX_WRITES);
1349 regFile->setAttribute(
1351
1352 // set guard latency
1353 if (rfState->hasChild(RF_GUARD_LATENCY)) {
1354 ObjectState* latencyChild = rfState->childByName(RF_GUARD_LATENCY);
1355 regFile->setAttribute(
1357 } else {
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(
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 */
1392
1394
1395 // set name
1396 as->setAttribute(
1398
1399 // set width
1400 ObjectState* width = asState->childByName(AS_WIDTH);
1402
1403 // set min address
1404 ObjectState* minAddress = asState->childByName(AS_MIN_ADDRESS);
1405 as->setAttribute(
1407
1408 // set max address
1409 ObjectState* maxAddress = asState->childByName(AS_MAX_ADDRESS);
1410 as->setAttribute(
1412
1413 if (asState->hasChild(AS_SHARED_MEMORY)) {
1414 ObjectState* shared = asState->childByName(AS_SHARED_MEMORY);
1415 as->setAttribute(
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 =
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 */
1447
1449
1450 // set name
1451 cu->setAttribute(
1453
1454 // set address space
1456 string asName = as->stringValue();
1457 if (asName != "") {
1459 }
1460
1461 // set delay slots
1462 ObjectState* delaySlots = cuState->childByName(CU_DELAY_SLOTS);
1463 cu->setAttribute(
1465
1466 // set the guard latency
1467 ObjectState* gLatency = cuState->childByName(CU_GUARD_LATENCY);
1468 cu->setAttribute(
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 != "") {
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 */
1518 const ObjectState* iuState, ObjectState* machineState) {
1520
1521 // set name
1522 iu->setAttribute(
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);
1548
1549 // set width
1550 ObjectState* width = iuState->childByName(IU_WIDTH);
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 {
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 */
1637 ObjectState* immediateSlot = new ObjectState(
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 */
1660
1661 assert(mdfSRPortState->name() == CU_SPECIAL_PORT);
1662 ObjectState* machPort =
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(
1680 } else if (connIndex == 2) {
1681 machPort->setAttribute(
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 */
1712ADFSerializer::mdfSRPort(const ObjectState* machineSRPortState) {
1713
1714 assert(machineSRPortState->name() ==
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
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 */
1755void
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(
1765 } else if (extensionValue == ZERO_EXTENSION) {
1766 momIUState->setAttribute(
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 */
1793
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(
1803 } else {
1804 port->setAttribute(
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 */
1826ADFSerializer::mdfPort(const ObjectState* machinePortState) {
1827
1829 mdfPort->setAttribute(PORT_NAME, machinePortState->stringAttribute(
1831 if (machinePortState->hasAttribute(Port::OSKEY_FIRST_SOCKET)) {
1833 mdfPort->addChild(conn);
1834 conn->setValue(machinePortState->stringAttribute(
1836 }
1837 if (machinePortState->hasAttribute(Port::OSKEY_SECOND_SOCKET)) {
1839 mdfPort->addChild(conn);
1840 conn->setValue(machinePortState->stringAttribute(
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 */
1864
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(
1876 } else {
1877 fuPort->setAttribute(
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(
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 */
1914ADFSerializer::mdfFUPort(const ObjectState* machineFUPortState) {
1915
1916 ObjectState* mdfFUPort = mdfPort(machineFUPortState);
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 */
1950
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(
1963 machineOperation->addChild(binding);
1964 binding->setAttribute(
1967 binding->setAttribute(
1969 }
1970 }
1971
1972 // set pipeline
1973 ObjectState* mdfPipeline = mdfOperationState->childByName(
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 */
1994ADFSerializer::mdfOperation(const ObjectState* machineOperationState) {
1995
1997 ObjectState* name = new ObjectState(FU_OP_NAME);
1998 mdfOperation->addChild(name);
1999 name->setValue(machineOperationState->stringAttribute(
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(
2012 }
2013 }
2014
2015 ObjectState* machPipeline = machineOperationState->childByName(
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 */
2036
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(
2046 machineResource->setAttribute(
2048 mdfResource->stringAttribute(FU_OP_PL_RES_NAME));
2049 } else if (mdfResource->name() == FU_OP_PL_READS) {
2050 machineResource = new ObjectState(
2052 machineResource->setAttribute(
2054 mdfResource->stringAttribute(FU_OP_PL_READS_NAME));
2055 } else if (mdfResource->name() == FU_OP_PL_WRITES) {
2056 machineResource = new ObjectState(
2058 machineResource->setAttribute(
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(
2073 stringValue());
2074 machineResource->setAttribute(
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 */
2095ADFSerializer::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;
2103 mdfChild = new ObjectState(FU_OP_PL_RESOURCE);
2104 mdfChild->setAttribute(
2106 resChild->stringAttribute(
2108 } else if (resChild->name() ==
2110 mdfChild = new ObjectState(FU_OP_PL_READS);
2111 mdfChild->setAttribute(
2114 } else if (resChild->name() ==
2116 mdfChild = new ObjectState(FU_OP_PL_WRITES);
2117 mdfChild->setAttribute(
2120 } else {
2121 assert(false);
2122 }
2123
2124 mdfPipeline->addChild(mdfChild);
2126 mdfChild->addChild(startCycle);
2127 startCycle->setValue(
2130 mdfChild->addChild(cycles);
2131 cycles->setValue(
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 */
2148void
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);
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(
2184 slotElem->addChild(widthElem);
2185 widthElem->setValue(
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 */
2214void
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() ==
2230 templateName) {
2231 iTempFound = true;
2232 break;
2233 }
2234 }
2235
2236 if (!iTempFound) {
2237 iTemp = new ObjectState(
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) {
2267 iTempSlot->setAttribute(TemplateSlot::OSKEY_SLOT, slotName);
2268 iTempSlot->setAttribute(TemplateSlot::OSKEY_WIDTH, width);
2270 iTemp->addChild(iTempSlot);
2271 } else {
2272 format errorMsg;
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(
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 */
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 */
2331bool
2333 const ObjectState* momMachineState) {
2334
2335 for (int i = 0; i < momMachineState->childCount(); i++) {
2336 ObjectState* child = momMachineState->child(i);
2337 if (child->name() ==
2339 child->childCount() == 0) {
2340 return true;
2341 }
2342 }
2343
2344 return false;
2345}
const string SOCKET_BUS
const string FU_PORT_WIDTH
const string MDF
const string TEMPLATE_FU_READ
const string FU_ADDRESS_SPACE
const string RF_NAME
const string FUNCTION_UNITS_ORDERED
const string ADDRESS_SPACE
const string FU_OP_PL_RESOURCE
const string ALWAYS_WRITE_BACK_RESULTS
const string CU_ADDRESS_SPACE
const string BITNESS64
const string FU_OP_PL_RES_START_CYCLE
const string GUARD_UNIT_PORT
const string IU_TEMPLATE_NAME
const string AS_MAX_ADDRESS
const string CONTROL_UNIT
const string BRIDGE
const string IU_TEMPLATE_SLOT_NAME
const string FUNCTION_UNIT
const string RF_TYPE_VOLATILE
const string ADF_SCHEMA_FILE
const string SIGN_EXTENSION
const string BUS_WIDTH
const string TEMPLATE_RF_WRITE
const string FU_PORT_NO_REGISTER
const string FU_OPERATION
const string FU_OP_PL_RES_CYCLES
const string IU_EXTENSION
const string BRIDGE_WRITES_TO
const string IU_TEMPLATE
const string IU_SIZE
const string SOCKET_READS_FROM
const string GUARD
const string SOCKET
const string REGISTER_FILE
const string CU_SPECIAL_PORT
const string CU_GUARD_LATENCY
const string IU_TYPE_RESERVED
const string RF_SIZE
const string IMMEDIATE_UNIT
const string GUARD_REGFILE_NAME
const string GUARD_BOOL
const string IU_WIDTH
const string BUS
const string ALWAYS_FALSE_GUARD
const string SHORT_IMM_EXTENSION
const string SOCKET_NAME
const string SOCKET_WRITES_TO
const string SHORT_IMM_WIDTH
const string PORT_NAME
const string SEGMENT
const string MDF_VERSION
const string ALWAYS_TRUE_GUARD
const string RF_GUARD_LATENCY
const string AS_NAME
const string MDF_VERSION_NUMBER
const string RF_TYPE_RESERVED
const string GUARD_REGFILE_INDEX
const string BRIDGE_READS_FROM
const string FU_PORT_SETS_OPCODE
const string INVERTED_EXPR
const string IU_GUARD_LATENCY
const string GUARD_UNIT_NAME
const string FU_OP_PL_WRITES
const string RF_MAX_WRITES
const string BUS_NAME
const string PORT_CONNECTS_TO
const string IU_TEMPLATE_BUS
const string IU_MAX_WRITES
const string FU_OP_PL_READS
const string IU_TYPE
const string FU_OP_NAME
const string AS_WIDTH
const string CU_DELAY_SLOTS
const string SHORT_IMMEDIATE
const string FU_OP_BIND
const string CU_RETURN_ADDRESS
const string SEGMENT_NAME
const string TEMPLATE_FU_WRITE
const string AS_MIN_ADDRESS
const string PORT
const string GUARD_UNIT
const string IU_NAME
const string RF_ZERO_REGISTER
const string BRIDGE_NAME
const string SOCKET_SEGMENT
const string RF_TYPE
const string AS_NUMERICAL_ID
const string TEMPLATE_RF_READ
const string SEGMENT_WRITES_TO
const string FU_PORT_TRIGGERS
const string FU_NAME
const string RF_MAX_READS
const string LITTLE_ENDIAN_MACHINE
const string IU_TEMPLATE_SLOT_WIDTH
const string FU_OP_BIND_NAME
const string SIMPLE_EXPR
const string IU_TYPE_NORMAL
const string IU_MAX_READS
const string FU_OP_PL_READS_NAME
const string FU_OP_PL_WRITES_NAME
const string IU_TYPE_VOLATILE
const string CU_NAME
const string IMMEDIATE_SLOT
const string FU_OP_PL_RES_NAME
const string IU_TEMPLATE_SLOT
const string ZERO_EXTENSION
const string IU_LATENCY
const string AS_SHARED_MEMORY
const string FU_OP_PIPELINE
const string CU_CTRL_OPERATION
const string RF_TYPE_NORMAL
const string IMMEDIATE_SLOT_NAME
const string TRIGGER_INVALIDATES_OLD_RESULTS
const string RF_WIDTH
#define assert(condition)
const string SOCKET
const string SOCKET_NAME
const string IMMEDIATE_SLOT
const string IMMEDIATE_SLOT_NAME
TTAMachine::Machine * machine
the architecture definition of the estimated processor
const string RF_NAME
const string BUS
const string BUS_NAME
const string IU_NAME
#define FU_NAME
Definition OSAL.hh:494
#define PORT(FUNAME, PORTNAME)
static ObjectState * convertToMachineFormat(const ObjectState *mdfState)
void writeMachine(const TTAMachine::Machine &machine)
TTAMachine::Machine * readMachine()
static ObjectState * machineOperation(const ObjectState *mdfOperationState)
static ObjectState * immediateUnitToMachine(const ObjectState *iuState, ObjectState *machineState)
static ObjectState * addressSpaceToMDF(const ObjectState *asState)
static ObjectState * momTemplateSlot(const ObjectState *momITState, const std::string &busName)
static bool hasEmptyInstructionTemplate(const ObjectState *momMachineState)
static ObjectState * mdfSRPort(const ObjectState *machineSRPortState)
static ObjectState * controlUnitToMDF(const ObjectState *cuState)
static ObjectState * controlUnitToMachine(const ObjectState *cuState)
static ObjectState * machineSRPort(const ObjectState *mdfSRPortState)
static ObjectState * mdfOperation(const ObjectState *machineOperationState)
static ObjectState * functionUnitToMDF(const ObjectState *fuState)
static ObjectState * functionUnitToMachine(const ObjectState *fuState, const int orderNumber)
static ObjectState * busToMachine(const ObjectState *busState)
static ObjectState * machineRFPort(const ObjectState *mdfPortState)
static ObjectState * mdfPort(const ObjectState *machinePortState)
static ObjectState * socketToMachine(const ObjectState *socketState)
void writeState(const ObjectState *machineState)
static ObjectState * addressSpaceToMachine(const ObjectState *asState)
static ObjectState * registerFileToMachine(const ObjectState *rfState)
static void instructionTemplateToMachine(const ObjectState *mdfITState, ObjectState *momMachineState, const std::string &iuName=std::string(""))
static ObjectState * bridgeToMachine(const ObjectState *bridgeState)
static ObjectState * immediateSlotToMDF(const ObjectState *isState)
static ObjectState * machinePipeline(const ObjectState *mdfPipelineState)
static ObjectState * convertToMDFFormat(const ObjectState *machineState)
static ObjectState * immediateSlotToMachine(const ObjectState *isState)
static void instructionTemplateToMDF(const ObjectState *momITState, ObjectState *mdfIUState)
static ObjectState * machineFUPort(const ObjectState *mdfFUPortState)
static ObjectState * mdfPipeline(const ObjectState *machinePipelineState)
static ObjectState * socketToMDF(const ObjectState *socketState)
ObjectState * readState()
static ObjectState * mdfFUPort(const ObjectState *machineFUPortState)
static ObjectState * immediateUnitToMDF(const ObjectState *iuState, const ObjectState *machineState)
static void setIUExtensionMode(const ObjectState *mdfIUState, ObjectState *momIUState)
static ObjectState * bridgeToMDF(const ObjectState *bridgeState)
static ObjectState * busToMDF(const ObjectState *busState)
virtual ~ADFSerializer()
static ObjectState * registerFileToMDF(const ObjectState *rfState)
static void abortProgram() __attribute__((noreturn))
static void writeToErrorLog(const std::string fileName, const int lineNumber, const std::string functionName, const std::string message, const int neededVerbosity=0)
static std::string schemaDirPath(const std::string &prog)
bool hasAttribute(const std::string &name) const
ObjectState * childByName(const std::string &name) const
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
void setValue(const std::string &value)
bool boolValue() const
bool hasChild(const std::string &name) const
ObjectState * child(int index) const
void addChild(ObjectState *child)
int intValue() const
std::string stringAttribute(const std::string &name) const
bool boolAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string stringValue() const
std::string name() const
int childCount() const
static const std::string OSKEY_NUMERICAL_ID
static const std::string OSNAME_ADDRESS_SPACE
ObjectState name for AddressSpace.
static const std::string OSKEY_SHARED_MEMORY
static const std::string OSKEY_MAX_ADDRESS
ObjectState attribute key for maximum address.
static const std::string OSKEY_MIN_ADDRESS
ObjectState attribute key for minimum address.
static const std::string OSKEY_WIDTH
ObjectState attribute key for the bit width.
static const std::string OSKEY_SIZE
ObjectState attribute key for the number of registers.
static const std::string OSKEY_WIDTH
ObjectState attribute key for bit width of the registers.
static const std::string OSNAME_BRIDGE
ObjectState name for bridge.
Definition Bridge.hh:70
static const std::string OSKEY_DESTINATION_BUS
ObjectState attribute key for destination bus name.
Definition Bridge.hh:74
static const std::string OSKEY_SOURCE_BUS
ObjectState attribute key for source bus name.
Definition Bridge.hh:72
static const std::string OSKEY_EXTENSION
ObjectState attribute key for extension mode.
Definition Bus.hh:122
static const std::string OSKEY_WIDTH
ObjectState attribute key for bus width.
Definition Bus.hh:118
static const std::string OSNAME_BUS
ObjectState name for Bus ObjectState.
Definition Bus.hh:116
static const std::string OSVALUE_ZERO
ObjectState attribute key for zero extension.
Definition Bus.hh:126
static const std::string OSVALUE_SIGN
ObjectState attribute value for sign extension.
Definition Bus.hh:124
static const std::string OSKEY_IMMWIDTH
ObjectState attribute key for immediate width.
Definition Bus.hh:120
static const std::string OSKEY_NAME
ObjectState attribute key for the name of the component.
static const std::string OSKEY_SEGMENT
ObjectState attribute key for segment name.
Definition Connection.hh:64
static const std::string OSKEY_BUS
ObjectState attribute key for bus name.
Definition Connection.hh:62
static const std::string OSKEY_SOCKET
ObjectState attribute key for socket name.
Definition Connection.hh:60
static const std::string OSNAME_CONNECTION
ObjectState name for Connection.
Definition Connection.hh:58
static const std::string OSNAME_CONTROL_UNIT
ObjectState name for ControlUnit.
static const std::string OSKEY_DELAY_SLOTS
ObjectState attribute key for the number of delay slots.
static const std::string OSKEY_GUARD_LATENCY
ObjectState attribute key for the global guard latency.
static const std::string OSKEY_RA_PORT
ObjectState attribute key for the name of the return address port.
static const std::string OSKEY_RESOURCE_NAME
ObjectState attribute key for name of resource.
static const std::string OSNAME_OPERAND_WRITE
ObjectState name for operand write.
static const std::string OSKEY_START_CYCLE
ObjectState attribute key for start cycle of a resource usage.
static const std::string OSKEY_OPERAND
ObjectState attribute key for operand number.
static const std::string OSNAME_OPERAND_READ
ObjectState name for operand read.
static const std::string OSNAME_PIPELINE
ObjectState name for ExecutionPipeline.
static const std::string OSNAME_RESOURCE_USAGE
ObjectState name for pipeline resource usage.
static const std::string OSKEY_CYCLES
ObjectState attribute key for duration of a resource usage.
static const std::string OSNAME_FUPORT
ObjectState name for FUPort.
Definition FUPort.hh:71
static const std::string OSKEY_OPCODE_SETTING
ObjectState attribute key for operand code setting feature.
Definition FUPort.hh:75
static const std::string OSKEY_NO_REGISTER
ObjectState attribute key for noRegister setting feature.
Definition FUPort.hh:77
static const std::string OSKEY_TRIGGERING
ObjectState attribute key for triggering feature.
Definition FUPort.hh:73
static const std::string OSNAME_FU
ObjectState name for function unit.
static const std::string OSKEY_AS
ObjectState attribute key for name of the address space.
static const std::string OSKEY_ORDER_NUMBER
ObjectState attribute key for FU order number name.
static const std::string OSKEY_INVERTED
ObjectState attribute key for inverted feature.
Definition Guard.hh:77
static const std::string OSKEY_NAME
ObjectState attribute key for name of the operation.
static const std::string OSKEY_PORT
ObjectState attribute key for port name.
static const std::string OSKEY_OPERAND
ObjectState attribute key for operand index.
static const std::string OSNAME_OPERAND_BINDING
ObjectState name for an operand binding.
static const std::string OSNAME_OPERATION
ObjectState name for HWOperation.
static const std::string OSNAME_IMMEDIATE_SLOT
ObjectState name for ImmediateSlot.
static const std::string OSVALUE_SIGN
ObjectState attribute value for sign extension.
static const std::string OSKEY_LATENCY
ObjectState attribute key for latency.
static const std::string OSNAME_IMMEDIATE_UNIT
ObjectState name for ImmediateUnit.
static const std::string OSVALUE_ZERO
ObjectState attribute value for zero extension.
static const std::string OSKEY_EXTENSION
ObjectState attribute key for the extension mode.
static const std::string OSNAME_INSTRUCTION_TEMPLATE
ObjectState name for instruction template.
static const std::string OSKEY_ALWAYS_WRITE_BACK_RESULTS
ObjectState attribute key for always-write-back-results.
Definition Machine.hh:251
static const std::string OSKEY_TRIGGER_INVALIDATES_OLD_RESULTS
ObjectState attribute key for trigger-invalidates-old-results.
Definition Machine.hh:253
virtual void loadState(const ObjectState *state)
Definition Machine.cc:728
virtual ObjectState * saveState() const
Definition Machine.cc:686
static const std::string OSKEY_FUNCTION_UNITS_ORDERED
ObjectState attribute key for function units ordered in order of their sequential presence in ADF.
Definition Machine.hh:256
static const std::string OSNAME_MACHINE
ObjectState name for Machine.
Definition Machine.hh:249
static const std::string OSKEY_PORT
ObjectState attribute key for port name.
Definition Guard.hh:121
static const std::string OSKEY_FU
ObjectState attribute key for function unit name.
Definition Guard.hh:119
static const std::string OSNAME_PORT_GUARD
ObjectState name for PortGuard ObjectState.
Definition Guard.hh:117
static const std::string OSKEY_FIRST_SOCKET
ObjectState attribute key for the name of the connected socket.
Definition Port.hh:84
static const std::string OSKEY_SECOND_SOCKET
ObjectState attribute key for the name of the other connected socket.
Definition Port.hh:86
static const std::string OSKEY_NAME
ObjectState attribute key for the name of the port.
Definition Port.hh:82
static const std::string OSNAME_RFPORT
ObjectState name for register file port.
Definition RFPort.hh:58
static const std::string OSKEY_MAX_WRITES
ObjectState attribute key for maximum simultaneous writers.
static const std::string OSKEY_MAX_READS
ObjectState attribute key for maximum simultaneous readers.
static const std::string OSKEY_ZERO_REGISTER
ObjectState attribute key for zero register flag.
static const std::string OSKEY_GUARD_LATENCY
ObjectState attribute key for the guard latency.
static const std::string OSVALUE_RESERVED
ObjectState attribute value for reserved register file type.
static const std::string OSVALUE_VOLATILE
ObjectState attribute value for volatile register file type.
static const std::string OSKEY_TYPE
ObjectState attribute key for register file type.
static const std::string OSNAME_REGISTER_FILE
ObjectState name for RegisterFile.
static const std::string OSVALUE_NORMAL
ObjectState attribute value for normal register file type.
static const std::string OSNAME_REGISTER_GUARD
ObjectState name for RegisterGuard.
Definition Guard.hh:159
static const std::string OSKEY_INDEX
ObjectState attribute key for register index.
Definition Guard.hh:163
static const std::string OSKEY_REGFILE
ObjectState attribute key for register file name.
Definition Guard.hh:161
static const std::string OSKEY_DESTINATION
ObjectState attribute key for destination segment name.
Definition Segment.hh:91
static const std::string OSNAME_SEGMENT
ObjectState name for Segment.
Definition Segment.hh:87
static const std::string OSKEY_NAME
ObjectState attribute key for segment name.
Definition Segment.hh:89
static const std::string OSVALUE_INPUT
ObjectState attribute value for input direction.
Definition Socket.hh:104
static const std::string OSNAME_SOCKET
ObjectState name for socket.
Definition Socket.hh:100
static const std::string OSKEY_DIRECTION
ObjectState attribute key for socket direction.
Definition Socket.hh:102
static const std::string OSVALUE_OUTPUT
ObjectState attribute value for output direction.
Definition Socket.hh:106
static const std::string OSVALUE_UNKNOWN
ObjectState attribute value for unknown direction.
Definition Socket.hh:108
static const std::string OSNAME_SPECIAL_REG_PORT
ObjectState name for special register port.
static const std::string OSNAME_TEMPLATE_SLOT
ObjectState name for template slot.
static const std::string OSKEY_SLOT
ObjectState attribute key for slot name.
static const std::string OSKEY_DESTINATION
ObjectState attribute key for destination.
static const std::string OSKEY_WIDTH
ObjectState attribute key for bit width.
static const std::string OSNAME_UNCONDITIONAL_GUARD
ObjectState name for UnconditionalGuard.
Definition Guard.hh:195
virtual boost::format text(int textId)
void setUseSchema(bool useSchema)
void setSchemaFile(const std::string &fileName)
virtual void writeState(const ObjectState *rootState)
virtual ObjectState * readState()