OpenASIP  2.0
BinaryEncoding.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2014 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 BinaryEncoding.cc
26  *
27  * Implementation of BinaryEncoding class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2014
31  * @note rating: red
32  */
33 
34 #include <string>
35 #include <algorithm>
36 
37 #include "BinaryEncoding.hh"
38 #include "MoveSlot.hh"
39 #include "ImmediateSlotField.hh"
40 #include "LImmDstRegisterField.hh"
42 #include "NullInstructionField.hh"
43 #include "SocketCodeTable.hh"
44 #include "NullSocketCodeTable.hh"
45 #include "ContainerTools.hh"
46 #include "SequenceTools.hh"
47 #include "Application.hh"
48 #include "ObjectState.hh"
49 #include "InstructionFormat.hh"
50 
51 using std::string;
52 
53 const std::string BinaryEncoding::OSNAME_BEM = "bem";
55  "template-extra-bits";
57  "bit-count";
58 const std::string BinaryEncoding::OSNAME_TEMPLATE_NAME = "template";
59 
60 /**
61  * The constructor.
62  *
63  * Creates an empty BEM.
64  */
66  InstructionField(NULL), immediateField_(NULL) {
67 }
68 
69 
70 /**
71  * The constructor.
72  *
73  * Loads the state of the object from the given ObjectState tree.
74  *
75  * @exception ObjectStateLoadingException If an error occurs while loading
76  * the state.
77  */
79  : InstructionField(NULL), immediateField_(NULL) {
80  loadState(state);
81 }
82 
83 /**
84  * The destructor.
85  */
88  delete immediateField_;
89  }
95 }
96 
97 
98 /**
99  * Returns the number of move slots in the instruction.
100  *
101  * @return The number of move slots.
102  */
103 int
105  return moveSlots_.size();
106 }
107 
108 
109 /**
110  * Returns the move slot at given index.
111  *
112  * The index does not have to reflect the actual order within the TTA
113  * instruction word.
114  *
115  * @param index The index.
116  * @return The move slot at given index.
117  * @exception OutOfRange If the index is negative or is not smaller than the
118  * number of move slots of the TTA instruction word.
119  */
120 MoveSlot&
121 BinaryEncoding::moveSlot(int index) const {
122  if (index < 0 || index >= moveSlotCount()) {
123  const string procName = "BinaryEncoding::moveSlot";
124  throw OutOfRange(__FILE__, __LINE__, procName);
125  }
126 
127  return *moveSlots_[index];
128 }
129 
130 /**
131  * Tells whether the encoding map contains a move slot with the given (bus)
132  * name.
133  *
134  * @param name The bus name.
135  * @return True if there is a move slot with the given name, otherwise false.
136  */
137 bool
138 BinaryEncoding::hasMoveSlot(const std::string& name) const {
139  for (MoveSlotContainer::const_iterator iter = moveSlots_.begin();
140  iter != moveSlots_.end(); iter++) {
141  MoveSlot* slot = *iter;
142  if (slot->name() == name) {
143  return true;
144  }
145  }
146 
147  return false;
148 }
149 
150 
151 /**
152  * Returns the move slot that programs the bus identified by the given name.
153  *
154  * @param The bus name.
155  * @return The move slot.
156  * @exception InstanceNotFound If the encoding map does not contain a move
157  * slot with the given name.
158  */
159 MoveSlot&
160 BinaryEncoding::moveSlot(const std::string& name) const {
161  for (MoveSlotContainer::const_iterator iter = moveSlots_.begin();
162  iter != moveSlots_.end(); iter++) {
163  MoveSlot* slot = *iter;
164  if (slot->name() == name) {
165  return *slot;
166  }
167  }
168 
169  const string procName = "BinaryEncoding::moveSlot";
170  throw InstanceNotFound(__FILE__, __LINE__, procName);
171 }
172 
173 /**
174  * Adds the given move slot to the encoding map.
175  *
176  * This method is to be called from the constructor of MoveSlot.
177  *
178  * @param slot The move slot to be added.
179  * @exception ObjectAlreadyExists If the encoding map contains a slot with
180  * the same name already.
181  */
182 void
184  // verify that this is called from MoveSlot constructor
185  assert(slot.parent() == NULL);
186 
187  if (hasMoveSlot(slot.name())) {
188  const string procName = "BinaryEncoding::addMoveSlot";
189  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
190  }
191 
192  moveSlots_.push_back(&slot);
193 }
194 
195 /**
196  * Removes the given move slot from the encoding map.
197  *
198  * This method is to be called from the destructor of MoveSlot.
199  *
200  * @param slot The move slot to be removed.
201  */
202 void
204  // verify that this is called from MoveSlot destructor.
205  assert(slot.parent() == NULL);
207 }
208 
209 
210 /**
211  * Returns the number of immediate slots in the instruction.
212  *
213  * @return The number of immediate slots.
214  */
215 int
217  return immediateSlots_.size();
218 }
219 
220 
221 /**
222  * Returns the immediate slot at given index.
223  *
224  * The index does not have to reflect the actual order within the TTA
225  * instruction word.
226  *
227  * @param index The index.
228  * @return The immediate slot at given index.
229  * @exception OutOfRange If the index is negative or is not smaller than the
230  * number of immediate slots in the TTA instruction
231  * word.
232  */
235  if (index < 0 || index >= immediateSlotCount()) {
236  const string procName = "BinaryEncoding::immediateSlot";
237  throw OutOfRange(__FILE__, __LINE__, procName);
238  }
239 
240  return *immediateSlots_[index];
241 }
242 
243 /**
244  * Tells whether the encoding map contains an immediate slot with the given
245  * name.
246  *
247  * @param name The name of the immediate slot.
248  * @return True if there is an immediate slot with the given name, otherwise
249  * false.
250  */
251 bool
252 BinaryEncoding::hasImmediateSlot(const std::string& name) const {
253 
254  for (ImmediateSlotContainer::const_iterator iter =
255  immediateSlots_.begin(); iter != immediateSlots_.end();
256  iter++) {
257  ImmediateSlotField* slot = *iter;
258  if (slot->name() == name) {
259  return true;
260  }
261  }
262 
263  return false;
264 }
265 
266 
267 /**
268  * Returns the immediate slot of the given name.
269  *
270  * @param name The name of the immediate slot.
271  * @return The immediate slot.
272  * @exception InstanceNotFound If the encoding map does not contain an
273  * immediate slot with the given name.
274  */
276 BinaryEncoding::immediateSlot(const std::string& name) const {
277  for (ImmediateSlotContainer::const_iterator iter =
278  immediateSlots_.begin(); iter != immediateSlots_.end();
279  iter++) {
280  ImmediateSlotField* slot = *iter;
281  if (slot->name() == name) {
282  return *slot;
283  }
284  }
285 
286  const string procName = "BinaryEncoding::immediateSlot";
287  throw InstanceNotFound(__FILE__, __LINE__, procName);
288 }
289 
290 /**
291  * Adds the given immediate slot to the encoding map.
292  *
293  * This method is to be called from the constructor of ImmediateSlotField.
294  *
295  * @param slot The immediate slot to be added.
296  * @exception ObjectAlreadyExists If the encoding map contains an immediate
297  * slot with the same name already.
298  */
299 void
301  // verify that this is called from MoveSlot constructor
302  assert(slot.parent() == NULL);
303 
304  if (hasImmediateSlot(slot.name())) {
305  const string procName = "BinaryEncoding::addImmediateSlot";
306  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
307  }
308 
309  immediateSlots_.push_back(&slot);
310 }
311 
312 /**
313  * Removes the given immediate slot from the encoding map.
314  *
315  * This method is to be called from the destructor of ImmediateSlotField.
316  *
317  * @param slot The immediate slot to be removed.
318  */
319 void
321  // verify that this is called from ImmediateSlotField destructor.
322  assert(slot.parent() == NULL);
324 }
325 
326 
327 /**
328  * Tells whether the instruction word has an immediate control field.
329  *
330  * @return True if the instruction word has an immediate control field,
331  * otherwise false.
332  */
333 bool
335  return immediateField_ != NULL;
336 }
337 
338 
339 /**
340  * Returns the immediate control field of the instruction word, if one exists.
341  *
342  * Returns a NullImmediateControlField instance otherwise (a single-template
343  * instruction).
344  *
345  * @return The immediate control field.
346  */
349  if (hasImmediateControlField()) {
350  return *immediateField_;
351  } else {
353  }
354 }
355 
356 
357 /**
358  * Adds the given immediate control field to the instruction word.
359  *
360  * This method is to be called from the constructor of ImmediateControlField.
361  *
362  * @param field The immediate control field to be added.
363  * @exception ObjectAlreadyExists If the instruction word already has an
364  * immediate control field.
365  */
366 void
368  // verify that this is called from ImmediateControlField constructor
369  assert(field.parent() == NULL);
370 
371  if (hasImmediateControlField()) {
372  const string procName = "BinaryEncoding::setImmediateControlField";
373  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
374  }
375 
376  immediateField_ = &field;
377 }
378 
379 /**
380  * Removes the immediate control field.
381  *
382  * This method is to be called from the destructor of ImmediateControlField.
383  */
384 void
386  // verify that this is called from ImmediateControlField destructor
388  assert(immediateControlField().parent() == NULL);
389  immediateField_ = NULL;
390 }
391 
392 
393 /**
394  * Returns the number of long immediate destination register fields in the
395  * instruction.
396  *
397  * @return The number of fields.
398  */
399 int
401  return longImmDstRegFields_.size();
402 }
403 
404 
405 /**
406  * Returns a long immediate destination register field by the given index.
407  *
408  * @param index The index.
409  * @return The field.
410  * @exception OutOfRange If the index is negative or not smaller than the
411  * number of long immediate destination register
412  * fields.
413  */
416  if (index < 0 || index >= longImmDstRegisterFieldCount()) {
417  throw OutOfRange(__FILE__, __LINE__, __func__);
418  }
419 
420  return *longImmDstRegFields_[index];
421 }
422 
423 /**
424  * Returns the long immediate destination register field that gives the
425  * destination register of the given immediate unit in the given instruction
426  * template.
427  *
428  * @param iTemp Name of the instruction template.
429  * @param dstUnit Name of the immediate unit.
430  * @return The long immediate destination register field.
431  * @exception InstanceNotFound If there is no such field.
432  */
435  const std::string& iTemp, const std::string& dstUnit) const {
436  int fields = longImmDstRegisterFieldCount();
437  for (int i = 0; i < fields; i++) {
439  if (field.usedByInstructionTemplate(iTemp)) {
440  if (field.immediateUnit(iTemp) == dstUnit) {
441  return field;
442  }
443  }
444  }
445 
446  throw InstanceNotFound(__FILE__, __LINE__, __func__);
447 }
448 
449 /**
450  * Adds the given long immediate destination register field to the
451  * instruction format.
452  *
453  * This method is to be called from the constructor of LImmDstRegisterField
454  * only!
455  *
456  * @param field The field to add.
457  */
458 void
460  assert(field.parent() == NULL);
461  longImmDstRegFields_.push_back(&field);
462 }
463 
464 
465 /**
466  * Removes the given long immediate destination register field from the
467  * instruction format.
468  *
469  * This method is to be called from the destructor of LImmDstRegisterField
470  * only!
471  *
472  * @param field The field to remove.
473  */
474 void
476  assert(field.parent() == NULL);
477  assert(
479 }
480 
481 /**
482  * Returns the number of instruction formats in the in binary encoding.
483  *
484  * @return The number of instruction formats.
485  */
486 
487 int
489  return instructionFormats_.size();
490 }
491 
492 /**
493  * Tells whether the binary encoding has an instruction format with the given
494  * name.
495  *
496  * @param name The name.
497  * @return True if the ecoding map contains an instruction format with the
498  * given name, otherwise false.
499  */
500 
501 bool
502 BinaryEncoding::hasInstructionFormat(const std::string name) const {
503  return std::find_if(
505  [name](const InstructionFormat* it) {
506  return it->name() == name;
507  }) != instructionFormats_.end();
508 }
509 
510 /**
511  * Returns the instruction format with the given index.
512  *
513  * @param index The index.
514  * @return The instruction format
515  * @exception OutOfRange If the given index is negative or not smaller than
516  * the number of instruction formats in the encoding
517  * map.
518  */
519 
522  if (index < 0 || index >= instructionFormatCount()) {
523  throw OutOfRange(__FILE__, __LINE__, __func__);
524  }
525  return *instructionFormats_[index];
526 }
527 
528 /**
529  * Adds the given instruction format to the encoding map.
530  *
531  * @param format The instruction format to be added.
532  * @exception ObjectAlreadyExists If the encoding map already contains a
533  * a socket code table with the same name as
534  * the given table.
535  */
536 
537 void
539  // verify that this is called from InstructionFormat constructor
540  assert(format.parent() == NULL);
541 
542  if (hasInstructionFormat(format.name())) {
543  const string procName = "BinaryEncoding::addInstructionFormat";
544  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
545  }
546 
547  instructionFormats_.push_back(&format);
548 }
549 
550 /**
551  * Removes the given instruction format from the encoding map.
552  * This method is to be called from the destructor Instruction Format.
553  *
554  * @param format The instruction format to be removed.
555  */
556 
557 void
559  assert(format.parent() == NULL);
561 }
562 
563 /**
564  * Returns the number of socket code tables contained by the encoding map.
565  *
566  * @return The number of socket code tables.
567  */
568 int
570  return socketCodes_.size();
571 }
572 
573 
574 /**
575  * Returns the socket code table at the given index.
576  *
577  * @param index The index.
578  * @exception OutOfRange If the given index is negative or not smaller than
579  * the number of socket code tables in the encoding
580  * map.
581  */
584  if (index < 0 || index >= socketCodeTableCount()) {
585  const string procName = "BinaryEncoding::socketCodeTable";
586  throw OutOfRange(__FILE__, __LINE__, procName);
587  }
588 
589  return *socketCodes_[index];
590 }
591 
592 /**
593  * Returns the socket code table which has the given name.
594  *
595  * Returns a NullSocketCodeTable instance if there is no such table.
596  *
597  * @param name Name of the table.
598  * @return The socket code table.
599  */
601 BinaryEncoding::socketCodeTable(const std::string& name) const {
602 
603  for (int i = 0; i < socketCodeTableCount(); i++) {
604  SocketCodeTable& table = socketCodeTable(i);
605  if (table.name() == name) {
606  return table;
607  }
608  }
609 
611 }
612 
613 
614 /**
615  * Adds the given socket code table to the encoding map.
616  *
617  * This method is to be called from the constructor of SocketCodeTable.
618  *
619  * @param table The socket code table to be added.
620  * @exception ObjectAlreadyExists If the encoding map already contains a
621  * socket code table with the same name as
622  * the given table.
623  */
624 void
626  // verify that this is called from SocketCodeTable constructor
627  assert(table.parent() == NULL);
628 
629  if (hasSocketCodeTable(table.name())) {
630  const string procName = "BinaryEncoding::addSocketCodeTable";
631  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
632  }
633 
634  socketCodes_.push_back(&table);
635 }
636 
637 /**
638  * Removes the given socket code table from the encoding map.
639  *
640  * This method is to be called from the destructor of SocketCodeTable.
641  *
642  * @param table The socket code table to be removed.
643  */
644 void
646  assert(table.parent() == NULL);
648 }
649 
650 /**
651  * Returns the extra template bit amount in the largest template in the
652  * machine. Needed for instructionField's bitPosition-method.
653  *
654  * @return The extra padding bits in the longest instruction template.
655  */
656 int
658  if (immediateField_ == NULL) return 0;
659 
660  TCEString longestTemplate = "";
661  int maxWidth = 0;
662 
663  for (int i = 0; i < immediateField_->templateCount(); ++i) {
665  int w = width(iTemplate);
666  if (w > maxWidth) {
667  maxWidth = w;
668  longestTemplate = iTemplate;
669  }
670  }
671  return templateExtraBits(longestTemplate);
672 }
673 
674 /**
675  * Returns the number of immediate child fields
676  * (move slots + immediate slots + immediate control field).
677  *
678  * @return The number of child fields.
679  */
680 int
682  int count = moveSlotCount() + immediateSlotCount() +
684  if (hasImmediateControlField()) {
685  count++;
686  }
687  return count;
688 }
689 
690 
691 /**
692  * Returns the child instruction field at the given relative position.
693  *
694  * Returns a NullInstructionField instance if there is no child field at
695  * the given position. This is, however, not possible if the object model is
696  * in consistent state.
697  *
698  * @param position The relative position.
699  * @return The instruction field at the given relative position.
700  * @exception OutOfRange If the given position is negative or not smaller
701  * than the number of child fields.
702  */
704 BinaryEncoding::childField(int position) const {
705  if (position < 0 || position >= childFieldCount()) {
706  const string procName = "BinaryEncoding::childField";
707  throw OutOfRange(__FILE__, __LINE__, procName);
708  }
709 
710  if (hasImmediateControlField() &&
711  immediateControlField().relativePosition() == position) {
712  return immediateControlField();
713  }
714 
715  int moveSlots = moveSlotCount();
716  for (int i = 0; i < moveSlots; i++) {
717  MoveSlot& slot = moveSlot(i);
718  if (slot.relativePosition() == position) {
719  return slot;
720  }
721  }
722 
723  int immediateSlots = immediateSlotCount();
724  for (int i = 0; i < immediateSlots; i++) {
726  if (slot.relativePosition() == position) {
727  return slot;
728  }
729  }
730 
731  int limmDstRegFields = longImmDstRegisterFieldCount();
732  for (int i = 0; i < limmDstRegFields; i++) {
734  if (field.relativePosition() == position) {
735  return field;
736  }
737  }
738 
740 }
741 
742 /**
743  * Returns the bit width of the maximum width instruction word defined by this
744  * encoding map.
745  *
746  * @param If set, returns the instruction width of the given instruction
747  * template, otherwise the maximum.
748  * @return The bit width of the instruction word.
749  */
750 int
752  if (immediateField_ == NULL) return width("");
753 
754  int maxWidth = 0;
755  for (int i = 0; i < immediateField_->templateCount(); ++i) {
757  int w = width(iTemplate);
758  if (w > maxWidth) maxWidth = w;
759  }
760  return maxWidth;
761 }
762 
763 /**
764  * Returns the bit width of the instruction word defined by an instruction
765  * template in this encoding map.
766  */
767 int
768 BinaryEncoding::width(const TCEString& templateName) const {
769  int moveSlots = moveSlotCount();
770  int immediateSlots = immediateSlotCount();
771  int limmDstRegFields = longImmDstRegisterFieldCount();
772  int width = 0;
773 
774  for (int i = 0; i < moveSlots; i++) {
775  MoveSlot& slot = moveSlot(i);
776  width += slot.width();
777  }
778 
779  for (int i = 0; i < immediateSlots; i++) {
781  width += slot.width();
782  }
783 
784  for (int i = 0; i < limmDstRegFields; i++) {
786  width += field.width();
787  }
788 
789  if (hasImmediateControlField()) {
791  }
792 
793  width += templateExtraBits(templateName);
794  width += extraBits();
795  return width;
796 }
797 
798 /**
799  * Loads the state of the binary encoding map from the given ObjectState
800  * tree.
801  *
802  * @param state The ObjectState tree.
803  * @exception ObjectStateLoadingException If an error occurs while loading
804  * the state.
805  */
806 void
808  if (state->name() != OSNAME_BEM) {
809  const string procName = "BinaryEncoding::loadState";
810  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
811  }
812 
813  // create socket code tables at first
814  for (int i = 0; i < state->childCount(); i++) {
815  ObjectState* child = state->child(i);
817  new SocketCodeTable(child, *this);
818  }
819  }
820 
821  // create subfields in the correct order
822  ObjectState* newState = new ObjectState(*state);
823  reorderSubfields(newState);
824 
825  for (int i = 0; i < newState->childCount(); i++) {
826  ObjectState* child = newState->child(i);
827  if (child->name() == MoveSlot::OSNAME_MOVE_SLOT) {
828  new MoveSlot(child, *this);
829  } else if (child->name() ==
831  new ImmediateSlotField(child, *this);
832  } else if (child->name() ==
834  new ImmediateControlField(child, *this);
835  } else if (child->name() ==
837  new LImmDstRegisterField(child, *this);
838  } else if (
842  ->stringValue(),
843  child
844  ->childByName(
846  ->intValue());
847  }
848  }
849  delete newState;
850 }
851 
852 /**
853  * Saves the state of the binary encoding map to an ObjectState tree.
854  *
855  * @return The newly created ObjectState tree.
856  */
859 
860  ObjectState* bem = new ObjectState(OSNAME_BEM);
861 
862  // add move slots
863  int moveSlots = moveSlotCount();
864  for (int i = 0; i < moveSlots; i++) {
865  MoveSlot& slot = moveSlot(i);
866  bem->addChild(slot.saveState());
867  }
868 
869  // add immediate slots
870  int immediateSlots = immediateSlotCount();
871  for (int i = 0; i < immediateSlots; i++) {
873  bem->addChild(slot.saveState());
874  }
875 
876  // add long immediate destination register fields
877  int limmDstRegFields = longImmDstRegisterFieldCount();
878  for (int i = 0; i < limmDstRegFields; i++) {
880  bem->addChild(field.saveState());
881  }
882 
883  // add socket code tables
884  int tableCount = socketCodeTableCount();
885  for (int i = 0; i < tableCount; i++) {
886  SocketCodeTable& table = socketCodeTable(i);
887  bem->addChild(table.saveState());
888  }
889 
890  // add immediate control field
891  if (hasImmediateControlField()) {
893  }
894 
895  for (TemplateExtraBitCountMap::const_iterator
896  i = extraTemplateBits_.begin(),
897  e = extraTemplateBits_.end();
898  i != e; ++i) {
899  TCEString templateName = (*i).first;
900  int bitCount = (*i).second;
901  ObjectState* root =
903 
904  ObjectState* templateNameObj =
906  templateNameObj->setValue(templateName);
907 
908  ObjectState* bitCountObj =
910  bitCountObj->setValue(bitCount);
911 
912  root->addChild(templateNameObj);
913  root->addChild(bitCountObj);
914 
915  bem->addChild(root);
916  }
917 
918  for (int i = 0; i < instructionFormatCount(); i++) {
919  bem->addChild(instructionFormats_.at(i)->saveState());
920  }
921 
922  return bem;
923 }
924 
925 
926 /**
927  * Tells whether the encoding map contains a socket code table with the given
928  * name.
929  *
930  * @param name The name.
931  * @return True if the encoding map contains a socket code table with the
932  * given name, otherwise false.
933  */
934 bool
935 BinaryEncoding::hasSocketCodeTable(const std::string& name) const {
936  for (SocketCodeTableContainer::const_iterator iter = socketCodes_.begin();
937  iter != socketCodes_.end(); iter++) {
938  SocketCodeTable* table = *iter;
939  if (table->name() == name) {
940  return true;
941  }
942  }
943 
944  return false;
945 }
946 
947 
948 /**
949  * Deletes all the move slots contained by the encoding map.
950  */
951 void
954 }
955 
956 
957 /**
958  * Deletes all the immediate slots contained by the encoding map.
959  */
960 void
963 }
964 
965 
966 /**
967  * Deletes all the long immediate destination register fields contained
968  * by the encoding map.
969  */
970 void
973 }
974 
975 
976 /**
977  * Deletes all the socket code tables contained by the encoding map.
978  */
979 void
982 }
983 
984 /**
985  * Deletes all the instruction formats contained by the encoding map.
986  */
987 void
990 }
991 /**
992  * Sets the extra padding bit count for an instruction template
993  */
994 void
996  const TCEString& templateName, int bitCount) {
997  extraTemplateBits_[templateName] = bitCount;
998 }
999 
1000 int
1001 BinaryEncoding::templateExtraBits(const TCEString& templateName) const {
1002  TemplateExtraBitCountMap::const_iterator pos =
1003  extraTemplateBits_.find(templateName);
1004 
1005  if (pos == extraTemplateBits_.end()) return 0;
1006  return (*pos).second;
1007 }
BinaryEncoding::instructionFormat
InstructionFormat & instructionFormat(int index) const
Definition: BinaryEncoding.cc:521
BinaryEncoding::childFieldCount
virtual int childFieldCount() const
Definition: BinaryEncoding.cc:681
MoveSlot::OSNAME_MOVE_SLOT
static const std::string OSNAME_MOVE_SLOT
ObjectState name for move slot.
Definition: MoveSlot.hh:96
NullImmediateControlField.hh
BinaryEncoding::immediateSlot
ImmediateSlotField & immediateSlot(int index) const
Definition: BinaryEncoding.cc:234
InstructionFormat::name
std::string name() const
Definition: InstructionFormat.cc:115
MoveSlot::name
std::string name() const
Definition: MoveSlot.cc:136
BinaryEncoding::hasMoveSlot
bool hasMoveSlot(const std::string &name) const
Definition: BinaryEncoding.cc:138
BinaryEncoding::deleteImmediateSlots
void deleteImmediateSlots()
Definition: BinaryEncoding.cc:961
BinaryEncoding::removeInstructionFormat
void removeInstructionFormat(InstructionFormat &format)
Definition: BinaryEncoding.cc:558
MoveSlot
Definition: MoveSlot.hh:60
BinaryEncoding::removeMoveSlot
void removeMoveSlot(MoveSlot &slot)
Definition: BinaryEncoding.cc:203
BinaryEncoding::instructionFormats_
InstructionFormatContainer instructionFormats_
A container for instruction formats.
Definition: BinaryEncoding.hh:154
ObjectStateLoadingException
Definition: Exception.hh:551
BinaryEncoding::longImmDstRegisterFieldCount
int longImmDstRegisterFieldCount() const
Definition: BinaryEncoding.cc:400
ObjectState::intValue
int intValue() const
BinaryEncoding::moveSlots_
MoveSlotContainer moveSlots_
A container for move slots.
Definition: BinaryEncoding.hh:156
ImmediateSlotField::saveState
virtual ObjectState * saveState() const
Definition: ImmediateSlotField.cc:193
OutOfRange
Definition: Exception.hh:320
ImmediateControlField::OSNAME_IMM_CONTROL_FIELD
static const std::string OSNAME_IMM_CONTROL_FIELD
ObjectState name for immediate control field.
Definition: ImmediateControlField.hh:84
BinaryEncoding::setImmediateControlField
void setImmediateControlField(ImmediateControlField &field)
Definition: BinaryEncoding.cc:367
SequenceTools.hh
ImmediateSlotField::OSNAME_IMMEDIATE_SLOT_FIELD
static const std::string OSNAME_IMMEDIATE_SLOT_FIELD
ObjectState name for immediate slot field.
Definition: ImmediateSlotField.hh:63
BinaryEncoding::unsetImmediateControlField
void unsetImmediateControlField()
Definition: BinaryEncoding.cc:385
BinaryEncoding::OSNAME_TEMPLATE_EXTRA_BITS
static const std::string OSNAME_TEMPLATE_EXTRA_BITS
Definition: BinaryEncoding.hh:128
BinaryEncoding::hasImmediateControlField
bool hasImmediateControlField() const
Definition: BinaryEncoding.cc:334
ImmediateControlField::parent
BinaryEncoding * parent() const
Definition: ImmediateControlField.cc:106
BinaryEncoding::socketCodeTableCount
int socketCodeTableCount() const
Definition: BinaryEncoding.cc:569
SocketCodeTable.hh
ImmediateSlotField.hh
ObjectState
Definition: ObjectState.hh:59
InstructionFormat::parent
InstructionField * parent() const
Definition: InstructionFormat.cc:99
ImmediateControlField::templateCount
int templateCount() const
Definition: ImmediateControlField.cc:124
BinaryEncoding::width
virtual int width() const
Definition: BinaryEncoding.cc:751
LImmDstRegisterField::saveState
virtual ObjectState * saveState() const
Definition: LImmDstRegisterField.cc:235
NullInstructionField.hh
BinaryEncoding::hasInstructionFormat
bool hasInstructionFormat(const std::string name) const
Definition: BinaryEncoding.cc:502
BinaryEncoding::socketCodeTable
SocketCodeTable & socketCodeTable(int index) const
Definition: BinaryEncoding.cc:583
MoveSlot.hh
NullInstructionField::instance
static NullInstructionField & instance()
Definition: NullInstructionField.cc:62
ImmediateSlotField
Definition: ImmediateSlotField.hh:44
InstructionField
Definition: InstructionField.hh:43
BinaryEncoding::OSNAME_TEMPLATE_NAME
static const std::string OSNAME_TEMPLATE_NAME
Definition: BinaryEncoding.hh:130
SocketCodeTable
Definition: SocketCodeTable.hh:68
ObjectState::childByName
ObjectState * childByName(const std::string &name) const
Definition: ObjectState.cc:443
SocketCodeTable::saveState
virtual ObjectState * saveState() const
Definition: SocketCodeTable.cc:716
BinaryEncoding::templateExtraBits
int templateExtraBits(const TCEString &templateName) const
Definition: BinaryEncoding.cc:1001
assert
#define assert(condition)
Definition: Application.hh:86
SocketCodeTable::parent
BinaryEncoding * parent() const
Definition: SocketCodeTable.cc:126
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
ImmediateControlField
Definition: ImmediateControlField.hh:57
ImmediateControlField::width
virtual int width() const
Definition: ImmediateControlField.cc:243
BinaryEncoding::saveState
virtual ObjectState * saveState() const
Definition: BinaryEncoding.cc:858
ImmediateSlotField::parent
BinaryEncoding * parent() const
Definition: ImmediateSlotField.cc:105
BinaryEncoding::addLongImmDstRegisterField
void addLongImmDstRegisterField(LImmDstRegisterField &field)
Definition: BinaryEncoding.cc:459
ContainerTools::removeValueIfExists
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)
BinaryEncoding.hh
Application.hh
BinaryEncoding::immediateField_
ImmediateControlField * immediateField_
The immediate control field.
Definition: BinaryEncoding.hh:162
__func__
#define __func__
Definition: Application.hh:67
InstructionField::parent
InstructionField * parent() const
Definition: InstructionField.cc:100
BinaryEncoding::longestTemplateExtraBits
int longestTemplateExtraBits() const
Definition: BinaryEncoding.cc:657
ObjectState.hh
LImmDstRegisterField::immediateUnit
std::string immediateUnit(const std::string &instructionTemplate) const
Definition: LImmDstRegisterField.cc:197
BinaryEncoding::loadState
virtual void loadState(const ObjectState *state)
Definition: BinaryEncoding.cc:807
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
BinaryEncoding::longImmDstRegFields_
LImmDstRegisterFieldContainer longImmDstRegFields_
A container for long immediate register fields.
Definition: BinaryEncoding.hh:164
NullSocketCodeTable::instance
static NullSocketCodeTable & instance()
Definition: NullSocketCodeTable.cc:59
ObjectState::childCount
int childCount() const
BinaryEncoding::deleteSocketCodes
void deleteSocketCodes()
Definition: BinaryEncoding.cc:980
LImmDstRegisterField::width
virtual int width() const
Definition: LImmDstRegisterField.cc:213
InstructionField::reorderSubfields
static void reorderSubfields(ObjectState *state)
Definition: InstructionField.cc:297
BinaryEncoding::removeSocketCodeTable
void removeSocketCodeTable(SocketCodeTable &table)
Definition: BinaryEncoding.cc:645
MoveSlot::width
virtual int width() const
Definition: MoveSlot.cc:406
ImmediateSlotField::width
virtual int width() const
Definition: ImmediateSlotField.cc:167
ObjectState::name
std::string name() const
InstructionFormat
Definition: InstructionFormat.hh:46
BinaryEncoding::socketCodes_
SocketCodeTableContainer socketCodes_
A container for socket code tables.
Definition: BinaryEncoding.hh:160
BinaryEncoding::instructionFormatCount
int instructionFormatCount() const
Definition: BinaryEncoding.cc:488
LImmDstRegisterField::OSNAME_LIMM_DST_REGISTER_FIELD
static const std::string OSNAME_LIMM_DST_REGISTER_FIELD
ObjectState name for long immediate destination register field.
Definition: LImmDstRegisterField.hh:70
BinaryEncoding::removeImmediateSlot
void removeImmediateSlot(ImmediateSlotField &slot)
Definition: BinaryEncoding.cc:320
ImmediateControlField::instructionTemplate
std::string instructionTemplate(int index) const
Definition: ImmediateControlField.cc:138
MoveSlot::saveState
virtual ObjectState * saveState() const
Definition: MoveSlot.cc:469
BinaryEncoding::extraTemplateBits_
TemplateExtraBitCountMap extraTemplateBits_
Extra (padding) bits per instruction template.
Definition: BinaryEncoding.hh:166
BinaryEncoding::immediateSlotCount
int immediateSlotCount() const
Definition: BinaryEncoding.cc:216
LImmDstRegisterField::usedByInstructionTemplate
bool usedByInstructionTemplate(const std::string &instructionTemplate) const
Definition: LImmDstRegisterField.cc:181
BinaryEncoding::OSNAME_TEMPLATE_EXTRA_BIT_COUNT
static const std::string OSNAME_TEMPLATE_EXTRA_BIT_COUNT
Definition: BinaryEncoding.hh:129
ImmediateSlotField::name
std::string name() const
Definition: ImmediateSlotField.cc:123
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
BinaryEncoding::hasImmediateSlot
bool hasImmediateSlot(const std::string &name) const
Definition: BinaryEncoding.cc:252
BinaryEncoding::setTemplateExtraBits
void setTemplateExtraBits(const TCEString &templateName, int bitCount)
Definition: BinaryEncoding.cc:995
BinaryEncoding::~BinaryEncoding
virtual ~BinaryEncoding()
Definition: BinaryEncoding.cc:86
BinaryEncoding::addMoveSlot
void addMoveSlot(MoveSlot &slot)
Definition: BinaryEncoding.cc:183
MoveSlot::parent
BinaryEncoding * parent() const
Definition: MoveSlot.cc:118
BinaryEncoding::BinaryEncoding
BinaryEncoding()
Definition: BinaryEncoding.cc:65
BinaryEncoding::hasSocketCodeTable
bool hasSocketCodeTable(const std::string &name) const
Definition: BinaryEncoding.cc:935
BinaryEncoding::addInstructionFormat
void addInstructionFormat(InstructionFormat &format)
Definition: BinaryEncoding.cc:538
BinaryEncoding::OSNAME_BEM
static const std::string OSNAME_BEM
ObjectState name for binary encoding.
Definition: BinaryEncoding.hh:126
ObjectAlreadyExists
Definition: Exception.hh:1002
TCEString
Definition: TCEString.hh:53
BinaryEncoding::addSocketCodeTable
void addSocketCodeTable(SocketCodeTable &table)
Definition: BinaryEncoding.cc:625
NullImmediateControlField::instance
static NullImmediateControlField & instance()
Definition: NullImmediateControlField.cc:58
SocketCodeTable::OSNAME_SOCKET_CODE_TABLE
static const std::string OSNAME_SOCKET_CODE_TABLE
ObjectState name for socket code table.
Definition: SocketCodeTable.hh:121
LImmDstRegisterField
Definition: LImmDstRegisterField.hh:47
NullSocketCodeTable.hh
BinaryEncoding::deleteInstructionFormats
void deleteInstructionFormats()
Definition: BinaryEncoding.cc:988
BinaryEncoding::immediateSlots_
ImmediateSlotContainer immediateSlots_
A container for immediate slots.
Definition: BinaryEncoding.hh:158
InstructionField::relativePosition
int relativePosition() const
Definition: InstructionField.cc:160
ObjectState::stringValue
std::string stringValue() const
BinaryEncoding::immediateControlField
ImmediateControlField & immediateControlField() const
Definition: BinaryEncoding.cc:348
BinaryEncoding::removeLongImmDstRegisterField
void removeLongImmDstRegisterField(LImmDstRegisterField &field)
Definition: BinaryEncoding.cc:475
InstructionFormat.hh
BinaryEncoding::moveSlot
MoveSlot & moveSlot(int index) const
Definition: BinaryEncoding.cc:121
BinaryEncoding::childField
virtual InstructionField & childField(int position) const
Definition: BinaryEncoding.cc:704
BinaryEncoding::deleteMoveSlots
void deleteMoveSlots()
Definition: BinaryEncoding.cc:952
BinaryEncoding::deleteLongImmDstRegisterFields
void deleteLongImmDstRegisterFields()
Definition: BinaryEncoding.cc:971
LImmDstRegisterField::parent
BinaryEncoding * parent() const
Definition: LImmDstRegisterField.cc:106
BinaryEncoding::moveSlotCount
int moveSlotCount() const
Definition: BinaryEncoding.cc:104
BinaryEncoding::addImmediateSlot
void addImmediateSlot(ImmediateSlotField &slot)
Definition: BinaryEncoding.cc:300
BinaryEncoding::longImmDstRegisterField
LImmDstRegisterField & longImmDstRegisterField(int index) const
Definition: BinaryEncoding.cc:415
ObjectState::setValue
void setValue(const std::string &value)
LImmDstRegisterField.hh
SocketCodeTable::name
std::string name() const
Definition: SocketCodeTable.cc:137
InstanceNotFound
Definition: Exception.hh:304
ContainerTools.hh