OpenASIP 2.2
Loading...
Searching...
No Matches
CodeCompressorPlugin.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2011 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 CodeCompressorPlugin.hh
26 *
27 * Declaration of CodeCompressorPlugin class.
28 *
29 * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30 * @author Otto Esko 2008 (lasse.laasonen-no.spam-tut.fi)
31 * @author Pekka Jääskeläinen 2011
32 * @note rating: red
33 */
34
35#ifndef TTA_CODE_COMPRESSOR_PLUGIN_HH
36#define TTA_CODE_COMPRESSOR_PLUGIN_HH
37
38#include <set>
39#include <map>
40#include <vector>
41
42#include "TCEString.hh"
43#include "Exception.hh"
44#include "IndexBound.hh"
45
47class BitVector;
48class BinaryEncoding;
49class MoveSlot;
52class SourceField;
54class GuardField;
55class SlotField;
56class SocketCodeTable;
57class PortCode;
59
60namespace TPEF {
61 class Binary;
62 class ImmediateElement;
63 class CodeSection;
64}
65
66namespace TTAProgram {
67 class Program;
68 class Instruction;
69 class Move;
70 class Immediate;
71 class Terminal;
72}
73
74namespace TTAMachine {
75 class Machine;
76 class InstructionTemplate;
77 class ImmediateUnit;
78 class Bus;
79}
80
81/**
82 * The base class for different code compressors.
83 */
85public:
86
87 /// Parameter struct.
88 struct Parameter {
89 std::string name; ///< Name of the parameter.
90 std::string value; ///< Value of the parameter.
91 };
92
93 /// Table for passing plugin parameters.
94 typedef std::vector<Parameter> ParameterTable;
95
96 virtual ~CodeCompressorPlugin();
97
98 void setParameters(ParameterTable parameters);
99 void setPrograms(std::map<std::string, TPEF::Binary*>& programs);
101 void setBEM(const BinaryEncoding& bem);
102
103 const BinaryEncoding& binaryEncoding() const;
104 const TTAMachine::Machine& machine() const;
105
106 /**
107 * Generates bit image of the program.
108 *
109 * @return The bit image.
110 * @exception InvalidData If the BEM is erroneous.
111 */
112 virtual InstructionBitVector* compress(const std::string& program) = 0;
113
114 /**
115 * Generates the HDL code of the decompressor block.
116 *
117 * @param stream The stream to write.
118 */
120 std::ostream& stream, TCEString entityStr) = 0;
121
122 /**
123 * Prints description of the plugin to the given stream.
124 */
125 virtual void printDescription(std::ostream& stream) = 0;
126
127 unsigned int memoryAddress(
128 const TTAProgram::Instruction& instruction) const;
129
131
132 int imemMauWidth() const;
133
135
136protected:
137 /// Map type for handling programs
138 typedef std::map<std::string, TPEF::Binary*> TPEFMap;
139
141
143
144 int moveSlotCount() const;
145
146 int moveSlotWidth(int index) const;
147
148 int firstMoveSlotIndex() const;
149
150 void startNewProgram(const std::string& programName);
151 void addInstruction(
152 const TTAProgram::Instruction& instruction, InstructionBitVector* bits);
154 const TTAProgram::Instruction& instruction);
157
158 bool hasParameter(const std::string& paramName) const;
159 std::string parameterValue(const std::string& paramName) const;
160
161 void setImemWidth(int mau, int widthInMaus = 1);
162
163 int numberOfPrograms() const;
164
165 TPEFMap::const_iterator programElement(int index) const;
166
167 std::string indentation(int level);
168
169private:
170
171 /// Set type for Instructions.
172 typedef std::set<const TTAProgram::Instruction*> InstructionSet;
173 /// Set type for Immediates.
174 typedef std::set<const TTAProgram::Immediate*> ImmediateSet;
175 /// Set type for Terminals.
176 typedef std::set<const TTAProgram::Terminal*> TerminalSet;
177 /// Map type that maps Immediates to the Instructions they are
178 /// referring to.
179 typedef std::map<const TTAProgram::Immediate*,
181 /// Map type that maps Immediates to a vector of indexes.
182 typedef std::map<const TTAProgram::Immediate*,
183 std::vector<IndexBound> > IndexTable;
184 /// Map type for addresses of instructions.
185 typedef std::map<const TTAProgram::Instruction*, unsigned int>
187
189 const ImmediateControlField& icField,
190 const TTAProgram::Instruction& instruction, BitVector& bitVector) const;
192 const MoveSlot& slot, const TTAProgram::Instruction& instruction,
193 InstructionBitVector& bitVector);
195 const SourceField& srcField, const TTAProgram::Move& move,
196 InstructionBitVector& bitVector) const;
197 static void addBitsForDestinationField(
198 const DestinationField& dstField, const TTAProgram::Move& move,
199 BitVector& bitVector);
200 static void addBitsForGuardField(
201 const GuardField& guardField, const TTAProgram::Move& move,
202 BitVector& bitVector);
204 const ImmediateSlotField& immSlot,
205 const TTAProgram::Instruction& instruction, BitVector& bitVector);
207 const LImmDstRegisterField& field,
208 const TTAProgram::Instruction& instruction, BitVector& bitVector);
209 std::string instructionTemplate(
210 const TTAProgram::Instruction& instruction) const;
212 const TTAProgram::Instruction& instruction) const;
213 unsigned int nextAddressablePositionFrom(unsigned int position) const;
215 const std::string& slotName,
216 int slotWidth,
217 const TTAProgram::Instruction& instruction,
218 BitVector& bitVector);
219 void encodeMove(
220 const MoveSlot& slot, const TTAProgram::Instruction& instruction,
221 InstructionBitVector& bitVector) const;
222 static void encodeNOP(const MoveSlot& slot, BitVector& bitVector);
223 static void encodeIUTerminal(
224 const SlotField& field, const TTAProgram::Terminal& terminal,
225 BitVector& bitVector);
226 static void encodeRFTerminal(
227 const SlotField& field, const TTAProgram::Terminal& terminal,
228 BitVector& bitVector);
229 static void encodeFUTerminal(
230 const SlotField& field, const TTAProgram::Terminal& terminal,
231 BitVector& bitVector);
233 const SourceField& field, const TTAProgram::Terminal& terminal,
234 InstructionBitVector& bitVector) const;
235 static void encodeSlotField(
236 const SlotField& field,
237 const BitVector& componentIDBits,
241 const SocketCodeTable& socketCodes,
242 const PortCode& portCode,
243 unsigned int registerIndex);
245 static void addBits(
246 unsigned int number,
247 int leftmostBit,
248 int rightmostBit,
249 BitVector& bitVector);
251 const TPEF::CodeSection& codeSection,
252 unsigned int elementIndex,
253 const TPEF::ImmediateElement& immElem,
254 const TTAProgram::Instruction& instruction) const;
256 const TPEF::ImmediateElement& immElem,
257 const TTAProgram::Instruction& instruction) const;
258
259 /// Programs run in the machine.
261 /// The current TPEF.
263 /// The current program in POM.
265 /// The current program
266 std::string currentProgram_;
267
268 /// The binary encoding map.
270 /// The machine.
272 /// Parameters for the plugin.
274
275 /// The bits of the program.
277 /// Tells whether all the instructions starts at the beginning of MAU.
279 /// The size of the minimum addressable unit.
280 int mau_;
281 /// The offset of the instruction memory (the address of the first
282 /// instruction).
284
285 /// Set of instructions that start at the beginning of MAU.
287 /// Set of (long) immediates that refer to an instruction.
289 /// Set of (short) immediate terminals that refer to an instruction.
291
292 /// Contains information to which instructions the immediates are
293 /// referring to.
295 /// A table of indexes used when encoding long immediates.
297
298 /// Contains the addresses of instructions.
300};
301
302#endif
find Finds info of the inner loops in the program
void encodeMove(const MoveSlot &slot, const TTAProgram::Instruction &instruction, InstructionBitVector &bitVector) const
void setBEM(const BinaryEncoding &bem)
static void encodeFUTerminal(const SlotField &field, const TTAProgram::Terminal &terminal, BitVector &bitVector)
IndexTable indexTable_
A table of indexes used when encoding long immediates.
void setParameters(ParameterTable parameters)
InstructionBitVector * bemBits(const TTAProgram::Program &program)
void setPrograms(std::map< std::string, TPEF::Binary * > &programs)
int addressSpaceOffset_
The offset of the instruction memory (the address of the first instruction).
void addBitsForDstRegisterField(const LImmDstRegisterField &field, const TTAProgram::Instruction &instruction, BitVector &bitVector)
const TTAMachine::Machine * machine_
The machine.
void setImemWidth(int mau, int widthInMaus=1)
InstructionSet instructionsAtBeginningOfMAU_
Set of instructions that start at the beginning of MAU.
void addBitsForSourceField(const SourceField &srcField, const TTAProgram::Move &move, InstructionBitVector &bitVector) const
void setInstructionToStartAtBeginningOfMAU(const TTAProgram::Instruction &instruction)
std::map< const TTAProgram::Instruction *, unsigned int > InstructionAddressMap
Map type for addresses of instructions.
TPEFMap::const_iterator programElement(int index) const
void startNewProgram(const std::string &programName)
std::string instructionTemplate(const TTAProgram::Instruction &instruction) const
ImmediateSet immediatesToRelocate_
Set of (long) immediates that refer to an instruction.
int moveSlotWidth(int index) const
static void addBits(unsigned int number, int leftmostBit, int rightmostBit, BitVector &bitVector)
void addBitsForMoveSlot(const MoveSlot &slot, const TTAProgram::Instruction &instruction, InstructionBitVector &bitVector)
const TTAMachine::Machine & machine() const
static void addBitsForDestinationField(const DestinationField &dstField, const TTAProgram::Move &move, BitVector &bitVector)
void encodeLongImmediate(const std::string &slotName, int slotWidth, const TTAProgram::Instruction &instruction, BitVector &bitVector)
std::string indentation(int level)
void addInstruction(const TTAProgram::Instruction &instruction, InstructionBitVector *bits)
std::set< const TTAProgram::Instruction * > InstructionSet
Set type for Instructions.
static BitVector socketCodeBits(const SocketCodeTable &socketCodes, const PortCode &portCode, unsigned int registerIndex)
TTAProgram::Program & currentProgram() const
TPEF::Binary * currentTPEF_
The current TPEF.
virtual InstructionBitVector * compress(const std::string &program)=0
InstructionBitVector * programBits_
The bits of the program.
unsigned int memoryAddress(const TTAProgram::Instruction &instruction) const
std::string parameterValue(const std::string &paramName) const
const BinaryEncoding & binaryEncoding() const
void setMachine(const TTAMachine::Machine &machine)
static void encodeRFTerminal(const SlotField &field, const TTAProgram::Terminal &terminal, BitVector &bitVector)
bool hasParameter(const std::string &paramName) const
bool startsAtBeginningOfMAU(const TTAProgram::Instruction &instruction) const
bool allStartsAtBeginningOfMAU_
Tells whether all the instructions starts at the beginning of MAU.
std::set< const TTAProgram::Immediate * > ImmediateSet
Set type for Immediates.
static void encodeNOP(const MoveSlot &slot, BitVector &bitVector)
RelocMap relocMap_
Contains information to which instructions the immediates are referring to.
const BinaryEncoding * bem_
The binary encoding map.
int mau_
The size of the minimum addressable unit.
virtual void printDescription(std::ostream &stream)=0
TTAProgram::Immediate * programImmediate(const TPEF::ImmediateElement &immElem, const TTAProgram::Instruction &instruction) const
static void encodeIUTerminal(const SlotField &field, const TTAProgram::Terminal &terminal, BitVector &bitVector)
std::map< std::string, TPEF::Binary * > TPEFMap
Map type for handling programs.
ParameterTable parameters_
Parameters for the plugin.
void addBitsForImmediateSlot(const ImmediateSlotField &immSlot, const TTAProgram::Instruction &instruction, BitVector &bitVector)
TTAProgram::Program * currentPOM_
The current program in POM.
virtual void generateDecompressor(std::ostream &stream, TCEString entityStr)=0
InstructionAddressMap instructionAddresses_
Contains the addresses of instructions.
std::string currentProgram_
The current program.
void encodeImmediateTerminal(const SourceField &field, const TTAProgram::Terminal &terminal, InstructionBitVector &bitVector) const
std::vector< Parameter > ParameterTable
Table for passing plugin parameters.
static void addBitsForGuardField(const GuardField &guardField, const TTAProgram::Move &move, BitVector &bitVector)
std::set< const TTAProgram::Terminal * > TerminalSet
Set type for Terminals.
static void encodeSlotField(const SlotField &field, const BitVector &componentIDBits, const BitVector &socketCodeBits, BitVector &BitVector)
InstructionBitVector * bemInstructionBits(const TTAProgram::Instruction &)
TPEFMap tpefPrograms_
Programs run in the machine.
void addBitsForICField(const ImmediateControlField &icField, const TTAProgram::Instruction &instruction, BitVector &bitVector) const
unsigned int nextAddressablePositionFrom(unsigned int position) const
TerminalSet terminalsToRelocate_
Set of (short) immediate terminals that refer to an instruction.
std::map< const TTAProgram::Immediate *, std::vector< IndexBound > > IndexTable
Map type that maps Immediates to a vector of indexes.
std::map< const TTAProgram::Immediate *, const TTAProgram::Instruction * > RelocMap
Map type that maps Immediates to the Instructions they are referring to.
InstructionBitVector * programBits() const
TTAProgram::Terminal * immediateTerminal(const TPEF::CodeSection &codeSection, unsigned int elementIndex, const TPEF::ImmediateElement &immElem, const TTAProgram::Instruction &instruction) const
std::string name
Name of the parameter.
std::string value
Value of the parameter.