2 Copyright (c) 2002-2009 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
27 * Inline definitions of Binary class.
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
31 * @note rating: yellow
37 * Adds any section to the binary.
39 * @param section Section to add.
42 Binary::addSection(Section* section) {
43 assert(section != NULL);
44 sections_.push_back(section);
48 * Returns section from given index.
50 * @param index Number of section to be returned.
51 * @return Section in requested index or NULL if out of range.
54 Binary::section(Word index) const {
55 if (index < sections_.size()) {
56 return sections_[index];
64 * Returns section of requested type by it's ordinal number.
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.
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) {
85 * Returns how many sections are stored in Binary.
87 * @return Number of sections stored in Binary.
90 Binary::sectionCount() const {
91 return sections_.size();
95 * Returns how many sections of requested type is stored in Binary.
97 * @return Number of sections of requested type.
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++;
107 return sectionCountByType;
111 * Returns string table section that holds section names.
113 * @return Section that contain section names.
115 inline StringSection*
116 Binary::strings() const {
117 return dynamic_cast<StringSection*>(strings_->pointer());
121 * Sets string table which holds sections' names.
123 * @param strTable String table of section names.
126 Binary::setStrings(StringSection* strTable) {
128 ReferenceManager::SafePointer::replaceReference(strings_, strTable);
132 * Sets string table which holds sections' names.
134 * @param strTable String table of section names.
137 Binary::setStrings(const ReferenceManager::SafePointer* strTable) {
142 * Sets encoding of program sections.
144 * @param arch Architecture of encoding of program sections.
147 Binary::setArch(FileArchitecture arch) {
152 * Sets file type of TTA code.
154 * @param type File type of TTA code.
157 Binary::setType(FileType type) {
162 * Returns encoding of program sections.
164 * @return Encoding of program sections.
166 inline Binary::FileArchitecture
167 Binary::arch() const {
172 * Returns file type of binary.
174 * @return File type of binary.
176 inline Binary::FileType
177 Binary::type() const {
182 * Sets TPEF version to be used.
184 * @param version TPEF format version.
187 Binary::setTPEFVersion(TPEFHeaders::TPEFVersion version) {
188 tpefVersion_ = version;
192 * Returns TPEF version being used.
195 inline TPEFHeaders::TPEFVersion
196 Binary::TPEFVersion() const {