OpenASIP  2.0
Binary.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 Binary.icc
26  *
27  * Inline definitions of Binary class.
28  *
29  * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30  *
31  * @note rating: yellow
32  */
33 
34 namespace TPEF {
35 
36 /**
37  * Adds any section to the binary.
38  *
39  * @param section Section to add.
40  */
41 inline void
42 Binary::addSection(Section* section) {
43  assert(section != NULL);
44  sections_.push_back(section);
45 }
46 
47 /**
48  * Returns section from given index.
49  *
50  * @param index Number of section to be returned.
51  * @return Section in requested index or NULL if out of range.
52  */
53 inline Section*
54 Binary::section(Word index) const {
55  if (index < sections_.size()) {
56  return sections_[index];
57  } else {
58  assert(false);
59  return NULL;
60  }
61 }
62 
63 /**
64  * Returns section of requested type by it's ordinal number.
65  *
66  * @param type Type of sections which are looked for.
67  * @param number Ordinal number of section to be returned.
68  * @return Section of requested number or NULL if out of range.
69  */
70 inline Section*
71 Binary::section(Section::SectionType type, Word number) const {
72  Word foundSections = 0;
73  for (Word i = 0; i < sectionCount(); i++) {
74  if (section(i)->type() == type) {
75  if (foundSections == number) {
76  return section(i);
77  }
78  foundSections++;
79  }
80  }
81  return NULL;
82 }
83 
84 /**
85  * Returns how many sections are stored in Binary.
86  *
87  * @return Number of sections stored in Binary.
88  */
89 inline Word
90 Binary::sectionCount() const {
91  return sections_.size();
92 }
93 
94 /**
95  * Returns how many sections of requested type is stored in Binary.
96  *
97  * @return Number of sections of requested type.
98  */
99 inline Word
100 Binary::sectionCount(Section::SectionType type) const {
101  Word sectionCountByType = 0;
102  for (Word i = 0; i < sectionCount(); i++) {
103  if (section(i)->type() == type) {
104  sectionCountByType++;
105  }
106  }
107  return sectionCountByType;
108 }
109 
110 /**
111  * Returns string table section that holds section names.
112  *
113  * @return Section that contain section names.
114  */
115 inline StringSection*
116 Binary::strings() const {
117  return dynamic_cast<StringSection*>(strings_->pointer());
118 }
119 
120 /**
121  * Sets string table which holds sections' names.
122  *
123  * @param strTable String table of section names.
124  */
125 inline void
126 Binary::setStrings(StringSection* strTable) {
127  strings_ =
128  ReferenceManager::SafePointer::replaceReference(strings_, strTable);
129 }
130 
131 /**
132  * Sets string table which holds sections' names.
133  *
134  * @param strTable String table of section names.
135  */
136 inline void
137 Binary::setStrings(const ReferenceManager::SafePointer* strTable) {
138  strings_ = strTable;
139 }
140 
141 /**
142  * Sets encoding of program sections.
143  *
144  * @param arch Architecture of encoding of program sections.
145  */
146 inline void
147 Binary::setArch(FileArchitecture arch) {
148  fileArch_ = arch;
149 }
150 
151 /**
152  * Sets file type of TTA code.
153  *
154  * @param type File type of TTA code.
155  */
156 inline void
157 Binary::setType(FileType type) {
158  fileType_ = type;
159 }
160 
161 /**
162  * Returns encoding of program sections.
163  *
164  * @return Encoding of program sections.
165  */
166 inline Binary::FileArchitecture
167 Binary::arch() const {
168  return fileArch_;
169 }
170 
171 /**
172  * Returns file type of binary.
173  *
174  * @return File type of binary.
175  */
176 inline Binary::FileType
177 Binary::type() const {
178  return fileType_;
179 }
180 
181 /**
182  * Sets TPEF version to be used.
183  *
184  * @param version TPEF format version.
185  */
186 inline void
187 Binary::setTPEFVersion(TPEFHeaders::TPEFVersion version) {
188  tpefVersion_ = version;
189 }
190 
191 /**
192  * Returns TPEF version being used.
193  *
194  */
195 inline TPEFHeaders::TPEFVersion
196 Binary::TPEFVersion() const {
197  return tpefVersion_;
198 }
199 
200 }