OpenASIP  2.0
DisassemblyInstruction.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 DisassemblyInstruction.cc
26  *
27  * Implementation of DisassemblyInstruction class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
34 #include "SequenceTools.hh"
35 
36 /**
37  * Constructor.
38  */
40 }
41 
42 
43 /**
44  * Destructor.
45  */
47  // Delete all moves of the instruction.
49 }
50 
51 
52 /**
53  * Adds a move to the instruction.
54  *
55  * @param move Move to be added.
56  */
57 void
59  moves_.push_back(move);
60 }
61 
62 
63 /**
64  * Returns number of moves in the instruction.
65  *
66  * @return Instruction move count.
67  */
68 Word
70  return moves_.size();
71 }
72 
73 
74 /**
75  * Returns the isntruction move at a given index.
76  *
77  * @param index Index of the move.
78  * @return The move at the index.
79  * @exception OutOfRange If the give index is out of range.
80  */
82 DisassemblyInstruction::move(Word index) const {
83  if (index >= moveCount()) {
84  std::string procName = "DisassemblyInstruction::move";
85  throw OutOfRange(__FILE__, __LINE__, procName);
86  }
87  return *moves_[index];
88 }
89 
90 /**
91  * Adds a long immediate to the instruction.
92  *
93  * @param longImm Immediate to be added.
94  */
95 void
98 
99  longImmediates_.push_back(longImm);
100 }
101 
102 
103 /**
104  * Returns number of long immediates in the instruction.
105  *
106  * @return Instruction's long immediate count.
107  */
108 Word
110  return longImmediates_.size();
111 }
112 
113 
114 /**
115  * Returns the long immediate at a given index.
116  *
117  * @param index Index of the long immediate.
118  * @return The long immediate at the index.
119  * @exception OutOfRange If the give index is out of range.
120  */
123  if (index >= longImmediateCount()) {
124  throw OutOfRange(__FILE__, __LINE__, __func__);
125  }
126  return *longImmediates_[index];
127 }
128 
129 /**
130  * Returns disassembly of the instruction.
131  *
132  * @return Disassembly of the instruction as a string.
133  */
134 std::string
136  std::string disassembly;
137  for (Word i = 0; i < moveCount(); i++) {
138  if (i > 0) {
139  disassembly = disassembly + ", ";
140  }
141  disassembly = disassembly + move(i).toString();
142  }
143 
144  for (Word i = 0; i < longImmediateCount(); i++) {
145 
146  disassembly = disassembly + " " + longImmediate(i).toString();
147  }
148 
149  for (int i = 0; i < annotationCount(); i++) {
150  disassembly += annotation(i).toString();
151  }
152 
153  disassembly = disassembly + " ;";
154  return disassembly;
155 }
156 
157 
158 /**
159  * Returns annotation of requested index.
160  *
161  * @param index Index of annotation to return.
162  * @return Annotation of requested index.
163  */
166  return *(annotations_.at(index));
167 }
168 
169 /**
170  * Adds an annotation to instruction.
171  *
172  * @param annotation Annotation to add.
173  */
174 void
176  annotations_.push_back(annotation);
177 }
178 
179 /**
180  * Returns the number of annotationes stored for the instruction.
181  *
182  * @return The number of annotationes stored for the instruction.
183  */
184 int
186  return static_cast<int>(annotations_.size());
187 }
DisassemblyInstruction::longImmediateCount
Word longImmediateCount() const
Definition: DisassemblyInstruction.cc:109
DisassemblyInstruction::addAnnotation
void addAnnotation(DisassemblyAnnotation *annotation)
Definition: DisassemblyInstruction.cc:175
DisassemblyInstruction::annotation
DisassemblyAnnotation & annotation(int index) const
Definition: DisassemblyInstruction.cc:165
DisassemblyInstruction::toString
std::string toString() const
Definition: DisassemblyInstruction.cc:135
DisassemblyInstructionSlot
Definition: DisassemblyInstructionSlot.hh:43
OutOfRange
Definition: Exception.hh:320
SequenceTools.hh
DisassemblyInstruction::annotations_
std::vector< DisassemblyAnnotation * > annotations_
Annotationes of instruction itself.
Definition: DisassemblyInstruction.hh:84
DisassemblyInstruction::moves_
MoveTable moves_
List of instruction moves.
Definition: DisassemblyInstruction.hh:78
DisassemblyImmediateAssignment
Definition: DisassemblyImmediateAssignment.hh:46
DisassemblyAnnotation::toString
virtual std::string toString() const
Definition: DisassemblyAnnotation.cc:61
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
DisassemblyInstruction.hh
DisassemblyInstruction::annotationCount
int annotationCount() const
Definition: DisassemblyInstruction.cc:185
DisassemblyAnnotation
Definition: DisassemblyAnnotation.hh:44
__func__
#define __func__
Definition: Application.hh:67
DisassemblyImmediateAssignment::toString
virtual std::string toString() const
Definition: DisassemblyImmediateAssignment.cc:67
DisassemblyInstruction::addMove
void addMove(DisassemblyInstructionSlot *move)
Definition: DisassemblyInstruction.cc:58
DisassemblyInstruction::DisassemblyInstruction
DisassemblyInstruction()
Definition: DisassemblyInstruction.cc:39
DisassemblyInstruction::move
DisassemblyInstructionSlot & move(Word index) const
Definition: DisassemblyInstruction.cc:82
DisassemblyInstruction::addLongImmediate
void addLongImmediate(DisassemblyImmediateAssignment *longImm)
Definition: DisassemblyInstruction.cc:96
DisassemblyInstructionSlot::toString
virtual std::string toString() const =0
DisassemblyInstruction::moveCount
Word moveCount() const
Definition: DisassemblyInstruction.cc:69
DisassemblyInstruction::longImmediate
DisassemblyImmediateAssignment & longImmediate(Word index) const
Definition: DisassemblyInstruction.cc:122
DisassemblyInstruction::longImmediates_
LongImmediateTable longImmediates_
List of instruction long immediates.
Definition: DisassemblyInstruction.hh:81
DisassemblyInstruction::~DisassemblyInstruction
~DisassemblyInstruction()
Definition: DisassemblyInstruction.cc:46