OpenASIP  2.0
Section.icc
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.icc
26  *
27  * Inline definitions 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 /////////////////////////////////////////////////////////////////////////////
35 // Section
36 /////////////////////////////////////////////////////////////////////////////
37 
38 namespace TPEF {
39 
40 /**
41  * Returns an element from index given in parameter.
42  *
43  * @param index Index of requested element.
44  * @return An element of requested index.
45  */
46 inline SectionElement*
47 Section::element(Word index) const {
48  return elements_[index];
49 }
50 
51 /**
52  * Returns number of elements in section.
53  *
54  * @return Number of elements in section.
55  */
56 inline Word
57 Section::elementCount() const {
58  return elements_.size();
59 }
60 
61 /**
62  * Sets NOBITS flag.
63  *
64  * If this is set, section data is not written to file.
65  * There should be undefined element in those sections
66  * that provides it, if this flag is set.
67  */
68 inline void
69 Section::setFlagNoBits() {
70  setFlag(SF_NOBITS);
71 }
72 
73 /**
74  * Unsets NOBITS flag.
75  *
76  * If this is set, section data is not written to file.
77  * There should be undefined element in those sections
78  * that provides it, if this flag is set.
79  */
80 inline void
81 Section::unsetFlagNoBits() {
82  unsetFlag(SF_NOBITS);
83 }
84 
85 /**
86  * Sets VLEN flag.
87  *
88  * If this is set, the section contains elements
89  * with variable length.
90  */
91 inline void
92 Section::setFlagVLen() {
93  setFlag(SF_VLEN);
94 }
95 
96 /**
97  * Unsets VLEN flag.
98  */
99 inline void
100 Section::unsetFlagVLen() {
101  unsetFlag(SF_VLEN);
102 }
103 
104 /**
105  * Tests if NOBITS flag is set.
106  *
107  * If this is set, section data is not written to file.
108  * There should be undefined element in those sections
109  * that provides it, if this flag is set.
110  *
111  * @return True if NOBITS is on, otherwise false.
112  */
113 inline bool
114 Section::noBits() const {
115  return flag(SF_NOBITS);
116 }
117 
118 /**
119  * Tests if VLEN flag is set.
120  *
121  * @return True if VLEN is on, otherwise false.
122  */
123 inline bool
124 Section::vLen() const {
125  return flag(SF_VLEN);
126 }
127 
128 /**
129  * Returns whole flag byte.
130  *
131  * @return Flag byte.
132  */
133 inline Byte
134 Section::flags() const {
135  return flags_;
136 }
137 
138 /**
139  * Sets whole flag byte.
140  *
141  * @param flagByte Value that is set to section flags.
142  */
143 inline void
144 Section::setFlags(Byte flagByte) {
145  flags_ = flagByte;
146 }
147 
148 
149 /**
150  * Returns true if flag is set.
151  *
152  * @param aFlag Flag that is tested.
153  * @return True if flag is set.
154  */
155 inline bool
156 Section::flag(SectionFlag aFlag) const {
157  return flags_ & aFlag;
158 }
159 
160 /**
161  * Sets a flag.
162  *
163  * @param aFlag Flag that is set.
164  */
165 inline void
166 Section::setFlag(SectionFlag aFlag) {
167  flags_ = flags_ | aFlag;
168 }
169 
170 /**
171  * Unsets a flag.
172  *
173  * @param aFlag Flag that is unset.
174  */
175 inline void
176 Section::unsetFlag(SectionFlag aFlag) {
177  flags_ = flags_ & (~aFlag);
178 }
179 
180 /**
181  * Sets starting memory address.
182  *
183  * @param address Memory address to set.
184  */
185 inline void
186 Section::setStartingAddress(AddressImage address) {
187  startingAddress_ = address;
188 }
189 
190 /**
191  * Returns an address where from the section begins.
192  *
193  * @return An address where from the section begins.
194  */
195 inline AddressImage
196 Section::startingAddress() const {
197  return startingAddress_;
198 }
199 
200 /**
201  * Sets pointer to some other section that is connected to this one somehow.
202  *
203  * See Section header from TPEF format specification for more information.
204  *
205  * @param aLink Section which we want to set to link field.
206  */
207 inline void
208 Section::setLink(const ReferenceManager::SafePointer* aLink) {
209  link_ = aLink;
210 }
211 
212 /**
213  * Sets pointer to some other section that is connected to this one somehow.
214  *
215  * See Section header from TPEF format specification for more information.
216  *
217  * @param aLink Section which we want to set to link field.
218  */
219 inline void
220 Section::setLink(Section* aLink) {
221  link_ = ReferenceManager::SafePointer::replaceReference(link_,aLink);
222 }
223 
224 /**
225  * Returns link section.
226  *
227  * Each section may contain link to another section. Link section for
228  * every section type is listed in TPEF format specification.
229  *
230  * @return Link section.
231  */
232 inline Section*
233 Section::link() const {
234  return dynamic_cast<Section*>(link_->pointer());
235 }
236 
237 /**
238  * Sets pointer to the address space entry or program section.
239  *
240  * See Section header from TPEF format specification for more information.
241  *
242  * @param addrSpace Address space entry or program section.
243  */
244 inline void
245 Section::setASpace(const ReferenceManager::SafePointer* addrSpace) {
246  aSpace_ = addrSpace;
247 }
248 
249 /**
250  * Sets pointer to the address space of a section.
251  *
252  * See Section header from TPEF format specification for more information.
253  *
254  * @param addrSpace Address space to set.
255  */
256 inline void
257 Section::setASpace(ASpaceElement* addrSpace) {
258  aSpace_ = ReferenceManager::SafePointer::replaceReference(aSpace_, addrSpace);
259 }
260 
261 /**
262  * Returns the address space of a section.
263  *
264  * @return the address space of a section.
265  */
266 inline ASpaceElement*
267 Section::aSpace() const {
268  return dynamic_cast<ASpaceElement*>(aSpace_->pointer());
269 }
270 
271 /**
272  * Sets name of the section.
273  *
274  * @param sectionName String table element of section name.
275  */
276 inline void
277 Section::setName(const ReferenceManager::SafePointer* sectionName) {
278  name_ = sectionName;
279 }
280 
281 /**
282  * Sets name of the section.
283  *
284  * @param sectionName String table element of section name.
285  */
286 inline void
287 Section::setName(Chunk* sectionName) {
288  name_ =
289  ReferenceManager::SafePointer::replaceReference(name_, sectionName);
290 }
291 
292 /**
293  * Returns section's name.
294  *
295  * @return String table element of section name.
296  */
297 inline Chunk*
298 Section::name() const {
299  return dynamic_cast<Chunk*>(name_->pointer());
300 }
301 
302 /**
303  * Checks if section type is auxiliary section.
304  *
305  * Auxiliary section means, that the section does not contain
306  * instructions or data.
307  *
308  * @return True if section is auxiliary section otherwise false.
309  */
310 inline bool
311 Section::isAuxSection() const {
312  return ((type() & PROGRAM_SECTION_MASK) == 0x00);
313 }
314 
315 /**
316  * Checks if section is program section.
317  *
318  * Program sections are those sections, which contain program or data.
319  *
320  * @return True if section is program section otherwise false.
321  */
322 inline bool
323 Section::isProgramSection() const {
324  return isProgramSection(type());
325 }
326 
327 /**
328  * Checks if section type is program section type.
329  *
330  * Program sections are those sections, which contain program or data.
331  *
332  * @param type Section type to check.
333  * @return True if section is program section otherwise false.
334  */
335 inline bool
336 Section::isProgramSection(SectionType type) {
337  return ((type & PROGRAM_SECTION_MASK) == PROGRAM_SECTION_MASK);
338 }
339 
340 /////////////////////////////////////////////////////////////////////////////
341 // RawSection
342 /////////////////////////////////////////////////////////////////////////////
343 
344 /**
345  * Tells if section has data.
346  *
347  * @return True if raw section has no data.
348  */
349 inline bool
350 RawSection::empty() const {
351  return length() == 0;
352 }
353 
354 }