OpenASIP  2.0
CodeSectionCreator.hh
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 CodeSectionCreator.hh
26  *
27  * Declaration of CodeSectionCreator class.
28  *
29  * @author Mikael Lepistö 2005 (tmlepist-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2006 (pekka.jaaskelainen-no.spam-tut.fi)
31  *
32  * @note rating: yellow
33  */
34 
35 #ifndef TCEASM_CODE_SECTION_CREATOR_HH
36 #define TCEASM_CODE_SECTION_CREATOR_HH
37 
38 #include "ParserStructs.hh"
39 #include "MoveElement.hh"
40 #include "Exception.hh"
41 
42 namespace TPEF {
43  class CodeSection;
44  class Binary;
45  class InstructionElement;
46 }
47 
49 class LabelManager;
51 namespace TTAMachine {
52  class Machine;
53 }
54 
55 /**
56  * Read moves and creates TPEF code section out of them.
57  */
59 public:
60 
62  MachineResourceManager &resourceManager,
63  const TTAMachine::Machine& targetMachine,
64  AssemblyParserDiagnostic* parent);
65 
66  void newSection(UValue startAddress);
67 
68  void addMove(const ParserMove& move);
69 
70  void finalize(TPEF::Binary& tpef, LabelManager& labels);
71 
72  void cleanup();
73 
74 
75 private:
76 
77  /**
78  * Type of move element.
79  */
80  enum ElementType {
81  EMPTY, ///< Empty move.
82  MOVE, ///< Data transport.
83  IMMEDIATE ///< Long immediate assignment.
84  };
85 
86  /**
87  * Internal representation of one move.
88  *
89  * Element can define normal move, empty move or long immediate
90  * assignment. This format is written as TPEF in finalize pahse.
91  */
92  struct InternalElement {
93  /// Type of move.
95  /// Bus slot number.
97 
98  /// Is first move of an instruction.
99  bool isBegin;
100 
101  /// Is guarded move.
102  bool isGuarded;
103  /// Is guard inverted.
105  /// Guard type.
107  /// TPEF Resource section unit id of guard register or port.
109  /// TPEF Resource section operand id or register number.
111 
112  /// Source type.
114  /// TPEF Resource section unit id of register or port.
116  /// TPEF Resource section operand id or register number.
118 
119  /// Destination type.
121  /// TPEF Resource section unit id of register or port.
123  /// TPEF Resource section operand id or register number.
125 
126  /// If source is immediate, the value.
128 
129  /// Line number where in source code this move is located.
131 
132  /// Annotations for the element.
133  std::vector<Annotation> annotationes;
134  };
135 
136  /**
137  * Internal representation of code section.
138  */
140  /// Start address of the section.
142  /// Elements of the section.
143  std::vector<InternalElement> elements;
144  };
145 
146  void startNewInstruction();
147 
148  UValue slotNumber();
149 
151 
152  bool isDestinationAlreadyWritten(const InternalElement& elem) const;
153 
154  void addAnnotationes(TPEF::InstructionElement& instrElem,
155  InternalElement& elem, LabelManager& lables) const;
156 
158 
159  /// Internal representation of code section.
161 
162  /// TPEF Resources and strings.
164 
165  /// Place to add warnings during compilation.
167 
168  /// Next element is starting element of instruction.
170 
171  /// Slot number of current move.
173 
174  /// Immediate index.
176 
177  /// Bitwidth of immediate value containing address to relocate.
178  static const UValue CODE_RELOC_SIZE;
179 };
180 
181 #endif
CodeSectionCreator::slotNumber
UValue slotNumber()
Definition: CodeSectionCreator.cc:539
CodeSectionCreator::newSection
void newSection(UValue startAddress)
Definition: CodeSectionCreator.cc:81
CodeSectionCreator::internalSection_
InternalSection internalSection_
Internal representation of code section.
Definition: CodeSectionCreator.hh:160
CodeSectionCreator::CODE_RELOC_SIZE
static const UValue CODE_RELOC_SIZE
Bitwidth of immediate value containing address to relocate.
Definition: CodeSectionCreator.hh:178
CodeSectionCreator::CodeSectionCreator
CodeSectionCreator(MachineResourceManager &resourceManager, const TTAMachine::Machine &targetMachine, AssemblyParserDiagnostic *parent)
Definition: CodeSectionCreator.cc:65
CodeSectionCreator::InternalElement::isBegin
bool isBegin
Is first move of an instruction.
Definition: CodeSectionCreator.hh:99
Exception.hh
TPEF::InstructionElement
Definition: InstructionElement.hh:77
CodeSectionCreator::InternalSection::startAddress
UValue startAddress
Start address of the section.
Definition: CodeSectionCreator.hh:141
TPEF::Binary
Definition: Binary.hh:49
CodeSectionCreator::InternalElement::srcType
TPEF::MoveElement::FieldType srcType
Source type.
Definition: CodeSectionCreator.hh:113
TPEF::MoveElement::FieldType
FieldType
Definition: MoveElement.hh:52
CodeSectionCreator
Definition: CodeSectionCreator.hh:58
ParserStructs.hh
CodeSectionCreator::InternalElement::isGuarded
bool isGuarded
Is guarded move.
Definition: CodeSectionCreator.hh:102
CodeSectionCreator::InternalElement::type
ElementType type
Type of move.
Definition: CodeSectionCreator.hh:94
CodeSectionCreator::IMMEDIATE
@ IMMEDIATE
Long immediate assignment.
Definition: CodeSectionCreator.hh:83
CodeSectionCreator::MOVE
@ MOVE
Data transport.
Definition: CodeSectionCreator.hh:82
AssemblyParserDiagnostic
Definition: AssemblyParserDiagnostic.hh:68
CodeSectionCreator::addMove
void addMove(const ParserMove &move)
Definition: CodeSectionCreator.cc:102
LabelManager
Definition: LabelManager.hh:64
CodeSectionCreator::ElementType
ElementType
Definition: CodeSectionCreator.hh:80
CodeSectionCreator::InternalElement::srcUnit
UValue srcUnit
TPEF Resource section unit id of register or port.
Definition: CodeSectionCreator.hh:115
CodeSectionCreator::InternalElement::dstIndex
UValue dstIndex
TPEF Resource section operand id or register number.
Definition: CodeSectionCreator.hh:124
CodeSectionCreator::InternalElement::guardUnit
UValue guardUnit
TPEF Resource section unit id of guard register or port.
Definition: CodeSectionCreator.hh:108
CodeSectionCreator::InternalElement::immValue
LiteralOrExpression immValue
If source is immediate, the value.
Definition: CodeSectionCreator.hh:127
UValue
unsigned long UValue
Definition: ParserStructs.hh:44
CodeSectionCreator::InternalElement::annotationes
std::vector< Annotation > annotationes
Annotations for the element.
Definition: CodeSectionCreator.hh:133
CodeSectionCreator::InternalElement
Definition: CodeSectionCreator.hh:92
MachineResourceManager
Definition: MachineResourceManager.hh:76
CodeSectionCreator::InternalSection
Definition: CodeSectionCreator.hh:139
CodeSectionCreator::InternalElement::dstType
TPEF::MoveElement::FieldType dstType
Destination type.
Definition: CodeSectionCreator.hh:120
LiteralOrExpression
Definition: ParserStructs.hh:245
CodeSectionCreator::startNewInstruction
void startNewInstruction()
Definition: CodeSectionCreator.cc:528
CodeSectionCreator::InternalElement::guardType
TPEF::MoveElement::FieldType guardType
Guard type.
Definition: CodeSectionCreator.hh:106
CodeSectionCreator::slotNumber_
UValue slotNumber_
Slot number of current move.
Definition: CodeSectionCreator.hh:172
CodeSectionCreator::InternalElement::dstUnit
UValue dstUnit
TPEF Resource section unit id of register or port.
Definition: CodeSectionCreator.hh:122
CodeSectionCreator::immediateIndex_
UValue immediateIndex_
Immediate index.
Definition: CodeSectionCreator.hh:175
ParserMove
Definition: ParserStructs.hh:391
CodeSectionCreator::addAnnotationes
void addAnnotationes(TPEF::InstructionElement &instrElem, InternalElement &elem, LabelManager &lables) const
Definition: CodeSectionCreator.cc:636
CodeSectionCreator::resources_
MachineResourceManager & resources_
TPEF Resources and strings.
Definition: CodeSectionCreator.hh:163
CodeSectionCreator::finalize
void finalize(TPEF::Binary &tpef, LabelManager &labels)
Definition: CodeSectionCreator.cc:347
CodeSectionCreator::cleanup
void cleanup()
Definition: CodeSectionCreator.cc:518
CodeSectionCreator::mach_
const TTAMachine::Machine & mach_
Definition: CodeSectionCreator.hh:157
CodeSectionCreator::EMPTY
@ EMPTY
Empty move.
Definition: CodeSectionCreator.hh:81
CodeSectionCreator::InternalElement::asmLineNumber
UValue asmLineNumber
Line number where in source code this move is located.
Definition: CodeSectionCreator.hh:130
CodeSectionCreator::InternalElement::isInverted
bool isInverted
Is guard inverted.
Definition: CodeSectionCreator.hh:104
CodeSectionCreator::InternalElement::srcIndex
UValue srcIndex
TPEF Resource section operand id or register number.
Definition: CodeSectionCreator.hh:117
CodeSectionCreator::InternalElement::slot
UValue slot
Bus slot number.
Definition: CodeSectionCreator.hh:96
TTAMachine
Definition: Assembler.hh:48
CodeSectionCreator::isNextBegin_
bool isNextBegin_
Next element is starting element of instruction.
Definition: CodeSectionCreator.hh:169
MoveElement.hh
CodeSectionCreator::parent_
AssemblyParserDiagnostic * parent_
Place to add warnings during compilation.
Definition: CodeSectionCreator.hh:166
CodeSectionCreator::immediateIndex
UValue immediateIndex()
Definition: CodeSectionCreator.cc:550
TPEF
Definition: Assembler.hh:43
TTAMachine::Machine
Definition: Machine.hh:73
CodeSectionCreator::InternalSection::elements
std::vector< InternalElement > elements
Elements of the section.
Definition: CodeSectionCreator.hh:143
CodeSectionCreator::isDestinationAlreadyWritten
bool isDestinationAlreadyWritten(const InternalElement &elem) const
Definition: CodeSectionCreator.cc:562
CodeSectionCreator::InternalElement::guardIndex
UValue guardIndex
TPEF Resource section operand id or register number.
Definition: CodeSectionCreator.hh:110