OpenASIP 2.2
Loading...
Searching...
No Matches
Section.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 Section.hh
26 *
27 * Declaration of Section and RawSection classes.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
34#ifndef TTA_SECTION_HH
35#define TTA_SECTION_HH
36
37#include <map>
38#include <list>
39#include <vector>
40
41#include "TPEFBaseType.hh"
42#include "ASpaceElement.hh"
43#include "SafePointable.hh"
44#include "Exception.hh"
45#include "Chunk.hh"
46
47namespace TPEF {
48 namespace ReferenceManager {
49 class SafePointer;
50 }
51
52 class SectionElement;
53
54/////////////////////////////////////////////////////////////////////////////
55// Section
56/////////////////////////////////////////////////////////////////////////////
57
58/**
59 * Abstract base class for concrete sections.
60 *
61 * Stores section header data and handles registration requests and
62 * book keeping for concrete sections. See prototype design pattern.
63 */
64class Section : public SafePointable {
65public:
66 /**
67 * TPEF section type ids.
68 */
70 ST_NULL = 0x00, ///< NULL Section
71 ST_STRTAB = 0x01, ///< String table.
72 ST_SYMTAB = 0x02, ///< Symbol table.
73 ST_DEBUG = 0x03, ///< Debug section.
74 ST_RELOC = 0x04, ///< Relocation section.
75 ST_LINENO = 0x05, ///< Line number section.
76 ST_NOTE = 0x06, ///< Note section.
77 ST_ADDRSP = 0x07, ///< Address space section.
78 ST_MR = 0x0A, ///< Machine resources section.
79 ST_CODE = 0x81, ///< Text section.
80 ST_DATA = 0x82, ///< Initialized data section.
81 ST_UDATA = 0x83, ///< Uninitialized data section.
82 ST_LEDATA = 0x84, ///< Initialized little endian data section.
83 ST_DUMMY = 0xff ///< Dummy section type for testing purposes.
84 };
85
86 /**
87 * TPEF section flags.
88 */
90 SF_VLEN = 0x40, ///< Contains elements with variable length.
91 SF_NOBITS = 0x80 ///< Not initialized or not stored in this file.
92 };
93
94 /// Returns SectioType of actual section instance.
95 virtual SectionType type() const = 0;
96
97 virtual ~Section();
98
100
101 virtual bool isChunkable() const;
102
103 virtual Chunk* chunk(SectionOffset offset) const;
104
105 bool isProgramSection() const;
107
108 bool isAuxSection() const;
109
110 virtual void addElement(SectionElement* element);
111
112 virtual void setElement(Word index, SectionElement* element);
113
114 SectionElement* element(Word index) const;
115 Word elementCount() const;
116
119
120 bool noBits() const;
121
122 bool vLen() const;
123
124 Byte flags() const;
125 void setFlags(Byte flagByte);
126
129
131 void setLink(Section* aLink);
132 Section* link() const;
133
135 void setASpace(ASpaceElement* addrSpace);
137
138 void setName(const ReferenceManager::SafePointer* sectionName);
139 void setName(Chunk* sectionName);
140 Chunk* name() const;
141
142 virtual bool isDataSection() const { return false; }
143 virtual bool isCodeSection() const { return false; }
144
145protected:
146 /// Creates clone of instance.
147 virtual Section* clone() const = 0;
148
149 Section();
150
151 static void registerSection(const Section* section);
152
153 // this section type specific flag can't be changed by user
156
157private:
159
160 bool flag(SectionFlag aFlag) const;
161 void setFlag(SectionFlag aFlag);
163
164 /// Type of map that contains section prototypes.
165 typedef std::map<SectionType, const Section*> SectionPrototypeMap;
166
167 /// Container for registere section prototypes.
169 /// Contain elements.
170 std::vector<SectionElement*> elements_;
171
172 /// TPEF link field.
174 /// TPEF address space field.
176 /// TPEF name field.
178 /// TPEF flag byte.
180 /// TPEF startin memory address field.
182 /// Mask for checking if section is auxiliary or program section.
184};
185
186/////////////////////////////////////////////////////////////////////////////
187// RawSection
188/////////////////////////////////////////////////////////////////////////////
189
190/**
191 * Abstract base class for sections that stores raw data.
192 *
193 * These sections are chunkable, that is they can create elements (chunks)
194 * on demand. These chunks point (using offsets) to section's raw data.
195 */
196class RawSection : public Section {
197public:
198 virtual bool isChunkable() const;
199
200 virtual Chunk* chunk(SectionOffset offset) const;
201
202 virtual void assureInSection(
203 SectionOffset offset) const;
204
205 virtual ~RawSection();
206
207 bool empty() const;
208
209 virtual void setLengthInMAUs(Word length);
210 virtual Word lengthInMAUs() const;
211
212 virtual void setDataLength(Word length);
213 virtual Word length() const;
214
215 virtual Word bytesToMAUs(Word byteCount) const;
216 virtual Word MAUsToBytes(Word mauCount) const;
217
218 virtual Word chunkToMAUIndex(const Chunk* chunk) const;
219
220 Word referredChunkCount() const;
221 Chunk* referredChunk(Word index) const;
222 bool belongsToSection(const Chunk* chunk) const;
223
224protected:
225 RawSection();
226
227private:
229
230 /// The length of raw data section.
232
233 /// Type of map that contains chunks.
234 typedef std::map<SectionOffset, Chunk*> ChunkMap;
235
236 /// Container for already created chunks.
238
239 /// Table containing all the chunks that are requested from section.
240 mutable std::vector<Chunk*> referredChunksCache_;
241};
242}
243
244#include "Section.icc"
245
246#endif
UInt32 AddressImage
Type for storing addresses to memory image.
Definition BaseType.hh:179
unsigned char Byte
Definition BaseType.hh:116
virtual Word bytesToMAUs(Word byteCount) const
Definition Section.cc:296
virtual bool isChunkable() const
Definition Section.cc:196
ChunkMap dataChunks_
Container for already created chunks.
Definition Section.hh:237
virtual void assureInSection(SectionOffset offset) const
Definition Section.cc:354
virtual void setLengthInMAUs(Word length)
Definition Section.cc:265
std::map< SectionOffset, Chunk * > ChunkMap
Type of map that contains chunks.
Definition Section.hh:234
Chunk * referredChunk(Word index) const
Definition Section.cc:378
RawSection(const RawSection &)
virtual Chunk * chunk(SectionOffset offset) const
Definition Section.cc:212
virtual Word chunkToMAUIndex(const Chunk *chunk) const
Definition Section.cc:341
virtual Word length() const
Definition Section.cc:275
std::vector< Chunk * > referredChunksCache_
Table containing all the chunks that are requested from section.
Definition Section.hh:240
Word length_
The length of raw data section.
Definition Section.hh:231
virtual void setDataLength(Word length)
Definition Section.cc:253
Word referredChunkCount() const
Definition Section.cc:366
virtual Word MAUsToBytes(Word mauCount) const
Definition Section.cc:320
virtual ~RawSection()
Definition Section.cc:186
virtual Word lengthInMAUs() const
Definition Section.cc:285
bool empty() const
bool belongsToSection(const Chunk *chunk) const
Definition Section.cc:238
static Section * createSection(SectionType type)
Definition Section.cc:91
Chunk * name() const
AddressImage startingAddress() const
virtual void setElement(Word index, SectionElement *element)
Definition Section.cc:145
bool vLen() const
bool isProgramSection() const
static void registerSection(const Section *section)
Definition Section.cc:114
Byte flags() const
virtual void addElement(SectionElement *element)
Definition Section.cc:133
const ReferenceManager::SafePointer * name_
TPEF name field.
Definition Section.hh:177
void setFlag(SectionFlag aFlag)
Section * link() const
virtual Chunk * chunk(SectionOffset offset) const
Definition Section.cc:169
static bool isProgramSection(SectionType type)
std::map< SectionType, const Section * > SectionPrototypeMap
Type of map that contains section prototypes.
Definition Section.hh:165
const ReferenceManager::SafePointer * aSpace_
TPEF address space field.
Definition Section.hh:175
@ ST_SYMTAB
Symbol table.
Definition Section.hh:72
@ ST_DATA
Initialized data section.
Definition Section.hh:80
@ ST_STRTAB
String table.
Definition Section.hh:71
@ ST_ADDRSP
Address space section.
Definition Section.hh:77
@ ST_DUMMY
Dummy section type for testing purposes.
Definition Section.hh:83
@ ST_UDATA
Uninitialized data section.
Definition Section.hh:81
@ ST_LEDATA
Initialized little endian data section.
Definition Section.hh:82
@ ST_LINENO
Line number section.
Definition Section.hh:75
@ ST_NULL
NULL Section.
Definition Section.hh:70
@ ST_CODE
Text section.
Definition Section.hh:79
@ ST_RELOC
Relocation section.
Definition Section.hh:74
@ ST_MR
Machine resources section.
Definition Section.hh:78
@ ST_NOTE
Note section.
Definition Section.hh:76
@ ST_DEBUG
Debug section.
Definition Section.hh:73
static SectionPrototypeMap * prototypes_
Container for registere section prototypes.
Definition Section.hh:168
bool isAuxSection() const
void setStartingAddress(AddressImage address)
Byte flags_
TPEF flag byte.
Definition Section.hh:179
bool flag(SectionFlag aFlag) const
void unsetFlagNoBits()
bool noBits() const
void setLink(Section *aLink)
SectionElement * element(Word index) const
virtual bool isCodeSection() const
Definition Section.hh:143
virtual Section * clone() const =0
Creates clone of instance.
Section(const Section &)
const ReferenceManager::SafePointer * link_
TPEF link field.
Definition Section.hh:173
Word elementCount() const
void setFlags(Byte flagByte)
void setLink(const ReferenceManager::SafePointer *aLink)
void setASpace(const ReferenceManager::SafePointer *addrSpace)
static const Byte PROGRAM_SECTION_MASK
Mask for checking if section is auxiliary or program section.
Definition Section.hh:183
void setName(const ReferenceManager::SafePointer *sectionName)
void unsetFlagVLen()
virtual bool isChunkable() const
Definition Section.cc:157
virtual ~Section()
Definition Section.cc:76
void setFlagVLen()
@ SF_VLEN
Contains elements with variable length.
Definition Section.hh:90
@ SF_NOBITS
Not initialized or not stored in this file.
Definition Section.hh:91
void setFlagNoBits()
virtual SectionType type() const =0
Returns SectioType of actual section instance.
void setName(Chunk *sectionName)
std::vector< SectionElement * > elements_
Contain elements.
Definition Section.hh:170
void unsetFlag(SectionFlag aFlag)
Word startingAddress_
TPEF startin memory address field.
Definition Section.hh:181
ASpaceElement * aSpace() const
virtual bool isDataSection() const
Definition Section.hh:142
void setASpace(ASpaceElement *addrSpace)
Word SectionOffset
Type for storing offsets relative to a given base offset value.