OpenASIP  2.0
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 
47 namespace 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  */
64 class Section : public SafePointable {
65 public:
66  /**
67  * TPEF section type ids.
68  */
69  enum SectionType {
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  */
89  enum SectionFlag {
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;
106  static bool isProgramSection(SectionType type);
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 
117  void setFlagNoBits();
118  void unsetFlagNoBits();
119 
120  bool noBits() const;
121 
122  bool vLen() const;
123 
124  Byte flags() const;
125  void setFlags(Byte flagByte);
126 
127  void setStartingAddress(AddressImage address);
129 
130  void setLink(const ReferenceManager::SafePointer* aLink);
131  void setLink(Section* aLink);
132  Section* link() const;
133 
134  void setASpace(const ReferenceManager::SafePointer* addrSpace);
135  void setASpace(ASpaceElement* addrSpace);
136  ASpaceElement* aSpace() const;
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 
145 protected:
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
154  void setFlagVLen();
155  void unsetFlagVLen();
156 
157 private:
158  Section(const Section&);
159 
160  bool flag(SectionFlag aFlag) const;
161  void setFlag(SectionFlag aFlag);
162  void unsetFlag(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  */
196 class RawSection : public Section {
197 public:
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 
224 protected:
225  RawSection();
226 
227 private:
228  RawSection(const RawSection&);
229 
230  /// The length of raw data section.
231  Word length_;
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
TPEF::Section::flags_
Byte flags_
TPEF flag byte.
Definition: Section.hh:179
ASpaceElement.hh
TPEF::Section::isChunkable
virtual bool isChunkable() const
Definition: Section.cc:157
TPEF::Section::prototypes_
static SectionPrototypeMap * prototypes_
Container for registere section prototypes.
Definition: Section.hh:168
TPEF::Section::vLen
bool vLen() const
TPEF::Section::chunk
virtual Chunk * chunk(SectionOffset offset) const
Definition: Section.cc:169
TPEF::RawSection::lengthInMAUs
virtual Word lengthInMAUs() const
Definition: Section.cc:285
TPEF::Section::aSpace_
const ReferenceManager::SafePointer * aSpace_
TPEF address space field.
Definition: Section.hh:175
TPEF::Section::aSpace
ASpaceElement * aSpace() const
TPEF::Section::setFlag
void setFlag(SectionFlag aFlag)
TPEF::Section::ST_SYMTAB
@ ST_SYMTAB
Symbol table.
Definition: Section.hh:72
TPEF::Section::ST_DUMMY
@ ST_DUMMY
Dummy section type for testing purposes.
Definition: Section.hh:83
TPEF::Section::link_
const ReferenceManager::SafePointer * link_
TPEF link field.
Definition: Section.hh:173
TPEF::RawSection::referredChunkCount
Word referredChunkCount() const
Definition: Section.cc:366
TPEF::Section::unsetFlagVLen
void unsetFlagVLen()
TPEF::Section::ST_DEBUG
@ ST_DEBUG
Debug section.
Definition: Section.hh:73
TPEF::Section::isDataSection
virtual bool isDataSection() const
Definition: Section.hh:142
Exception.hh
TPEF::RawSection::setDataLength
virtual void setDataLength(Word length)
Definition: Section.cc:253
TPEF::Section::~Section
virtual ~Section()
Definition: Section.cc:76
TPEF::Section::SectionPrototypeMap
std::map< SectionType, const Section * > SectionPrototypeMap
Type of map that contains section prototypes.
Definition: Section.hh:165
TPEF::Section::setElement
virtual void setElement(Word index, SectionElement *element)
Definition: Section.cc:145
TPEF::Section::type
virtual SectionType type() const =0
Returns SectioType of actual section instance.
TPEF::Section::name_
const ReferenceManager::SafePointer * name_
TPEF name field.
Definition: Section.hh:177
TPEF::Section::isAuxSection
bool isAuxSection() const
TPEF::Section::setFlagNoBits
void setFlagNoBits()
TPEF::RawSection::isChunkable
virtual bool isChunkable() const
Definition: Section.cc:196
TPEF::Section::startingAddress_
Word startingAddress_
TPEF startin memory address field.
Definition: Section.hh:181
TPEF::Section::setFlagVLen
void setFlagVLen()
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::RawSection::MAUsToBytes
virtual Word MAUsToBytes(Word mauCount) const
Definition: Section.cc:320
TPEF::Section::setFlags
void setFlags(Byte flagByte)
TPEF::Section
Definition: Section.hh:64
TPEF::RawSection::referredChunksCache_
std::vector< Chunk * > referredChunksCache_
Table containing all the chunks that are requested from section.
Definition: Section.hh:240
TPEF::RawSection::belongsToSection
bool belongsToSection(const Chunk *chunk) const
Definition: Section.cc:238
TPEF::RawSection::dataChunks_
ChunkMap dataChunks_
Container for already created chunks.
Definition: Section.hh:237
TPEF::Section::link
Section * link() const
TPEF::Section::element
SectionElement * element(Word index) const
Section.icc
TPEF::Section::addElement
virtual void addElement(SectionElement *element)
Definition: Section.cc:133
TPEF::RawSection::assureInSection
virtual void assureInSection(SectionOffset offset) const
Definition: Section.cc:354
TPEF::Section::Section
Section()
Definition: Section.cc:64
TPEF::ReferenceManager::SafePointer
Definition: SafePointer.hh:188
TPEF::RawSection::length_
Word length_
The length of raw data section.
Definition: Section.hh:231
TPEF::Section::ST_DATA
@ ST_DATA
Initialized data section.
Definition: Section.hh:80
TPEF::Section::createSection
static Section * createSection(SectionType type)
Definition: Section.cc:91
TPEF::Section::ST_LEDATA
@ ST_LEDATA
Initialized little endian data section.
Definition: Section.hh:82
TPEF::ASpaceElement
Definition: ASpaceElement.hh:48
TPEF::RawSection::referredChunk
Chunk * referredChunk(Word index) const
Definition: Section.cc:378
TPEF::SectionElement
Definition: SectionElement.hh:44
TPEF::Section::unsetFlag
void unsetFlag(SectionFlag aFlag)
TPEF::RawSection::bytesToMAUs
virtual Word bytesToMAUs(Word byteCount) const
Definition: Section.cc:296
TPEF::SafePointable
Definition: SafePointable.hh:48
TPEF::Section::unsetFlagNoBits
void unsetFlagNoBits()
TPEF::Section::setName
void setName(const ReferenceManager::SafePointer *sectionName)
TPEF::Section::elements_
std::vector< SectionElement * > elements_
Contain elements.
Definition: Section.hh:170
TPEF::Section::PROGRAM_SECTION_MASK
static const Byte PROGRAM_SECTION_MASK
Mask for checking if section is auxiliary or program section.
Definition: Section.hh:183
TPEF::RawSection::ChunkMap
std::map< SectionOffset, Chunk * > ChunkMap
Type of map that contains chunks.
Definition: Section.hh:234
TPEF::Section::noBits
bool noBits() const
TPEF::Section::setStartingAddress
void setStartingAddress(AddressImage address)
AddressImage
UInt32 AddressImage
Type for storing addresses to memory image.
Definition: BaseType.hh:179
TPEF::Section::ST_UDATA
@ ST_UDATA
Uninitialized data section.
Definition: Section.hh:81
TPEF::Section::registerSection
static void registerSection(const Section *section)
Definition: Section.cc:114
TPEF::SectionOffset
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Definition: TPEFBaseType.hh:49
TPEF::Section::ST_LINENO
@ ST_LINENO
Line number section.
Definition: Section.hh:75
TPEF::Section::name
Chunk * name() const
TPEF::Section::SF_VLEN
@ SF_VLEN
Contains elements with variable length.
Definition: Section.hh:90
TPEF::Section::SectionFlag
SectionFlag
Definition: Section.hh:89
TPEF::Section::ST_STRTAB
@ ST_STRTAB
String table.
Definition: Section.hh:71
TPEF::Section::setASpace
void setASpace(const ReferenceManager::SafePointer *addrSpace)
Chunk.hh
TPEF::RawSection::setLengthInMAUs
virtual void setLengthInMAUs(Word length)
Definition: Section.cc:265
TPEF::RawSection
Definition: Section.hh:196
TPEF::Section::flags
Byte flags() const
TPEF::RawSection::empty
bool empty() const
TPEF::Section::ST_RELOC
@ ST_RELOC
Relocation section.
Definition: Section.hh:74
TPEF::Section::setLink
void setLink(const ReferenceManager::SafePointer *aLink)
TPEF::Section::ST_NOTE
@ ST_NOTE
Note section.
Definition: Section.hh:76
TPEF::RawSection::~RawSection
virtual ~RawSection()
Definition: Section.cc:186
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
SafePointable.hh
TPEF::RawSection::length
virtual Word length() const
Definition: Section.cc:275
TPEF::Section::isProgramSection
bool isProgramSection() const
TPEF::Section::ST_NULL
@ ST_NULL
NULL Section.
Definition: Section.hh:70
TPEFBaseType.hh
TPEF::Section::flag
bool flag(SectionFlag aFlag) const
TPEF::Section::ST_CODE
@ ST_CODE
Text section.
Definition: Section.hh:79
TPEF::Section::isCodeSection
virtual bool isCodeSection() const
Definition: Section.hh:143
TPEF::Section::ST_MR
@ ST_MR
Machine resources section.
Definition: Section.hh:78
TPEF::RawSection::chunk
virtual Chunk * chunk(SectionOffset offset) const
Definition: Section.cc:212
TPEF::Section::SF_NOBITS
@ SF_NOBITS
Not initialized or not stored in this file.
Definition: Section.hh:91
TPEF::Section::startingAddress
AddressImage startingAddress() const
TPEF::RawSection::chunkToMAUIndex
virtual Word chunkToMAUIndex(const Chunk *chunk) const
Definition: Section.cc:341
TPEF::Section::clone
virtual Section * clone() const =0
Creates clone of instance.
TPEF::Chunk
Definition: Chunk.hh:45
TPEF::Section::ST_ADDRSP
@ ST_ADDRSP
Address space section.
Definition: Section.hh:77
TPEF::Section::elementCount
Word elementCount() const
TPEF
Definition: Assembler.hh:43
TPEF::RawSection::RawSection
RawSection()
Definition: Section.cc:180