OpenASIP  2.0
AOutSymbolSectionReader.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 AOutSymbolSectionReader.hh
26  *
27  * Declaration of AOutSymbolSectionReader.
28  *
29  * @author Jussi Nykänen 2003 (nykanen-no.spam-cs.tut.fi)
30  * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
31  * @note reviewed 23 October 2003 by pj, am, ll, jn
32  *
33  * @note rating: yellow
34  */
35 
36 #ifndef TTA_AOUT_SYMBOL_SECTION_READER_HH
37 #define TTA_AOUT_SYMBOL_SECTION_READER_HH
38 
39 #include <deque>
40 
41 #include "AOutSectionReader.hh"
42 #include "Section.hh"
43 #include "Exception.hh"
44 #include "TPEFBaseType.hh"
45 
46 namespace TPEF {
47 
48  class SymbolElement;
49  class AOutReader;
50 
51 /**
52  * Reads symbol table section from a.out binary file.
53  */
55 
56 public:
57  virtual ~AOutSymbolSectionReader();
58 
59 protected:
60 
62 
63  virtual Section::SectionType type() const;
64 
65  virtual void finalize(Section* section) const;
66 
67  virtual void readData(BinaryStream& stream, Section* section) const;
68 
69 private:
70  /**
71  * All the information of read a.out stab.
72  */
73  struct StabData {
75  Byte aType, Byte anOther, HalfWord aDescr,
76  Word aValue, Word aName) :
77  stabType(aType), other(anOther), description(aDescr),
78  value(aValue), nameOffset(aName) {
79  }
80 
81  /// Stab type.
83  /// Stab other field.
85  /// Description field.
86  HalfWord description;
87  /// Value of the stab.
88  Word value;
89  /// Offset to string table.
90  Word nameOffset;
91  };
92 
94  BinaryStream& stream, SectionOffset sectionOffset,
95  AOutReader* reader) const;
96 
97  /// Copying not allowed.
99  /// Assignment not allowed.
101 
102  /// Data symbol size in bytes.
103  static const Word DATA_SYMBOL_SIZE;
104 
105  /// One of the symbols that are used to indicate start of new
106  /// compilation module in a.out symbol table
107  static const std::string GCC_MODULE_START_SYMBOL1;
108 
109  /// One of the symbols that are used to indicate start of new
110  /// compilation module in a.out symbol table
111  static const std::string GCC_MODULE_START_SYMBOL2;
112 
113  /// Class-wide (unique) prototype instance of AOutSymbolSectionReader
114  /// registered into SectionReader.
116 
117  /**
118  * Map of recources for each compilation module.
119  *
120  * In linked a.out the same resource symbols are added for
121  * every different compilation unit, with a different value.
122  *
123  * This class stores information how resource ids should be replaced
124  * for instructions starting from startAddress. There is own
125  * replacement map for each compilation unit.
126  */
128  CompilationModule(Word startAddress) :
129  startAddress_(startAddress) {
130  }
131 
132  /// Start address of linked compilation module in a.out
134 
135  /// Resources id replacements for the compilation module.
136  std::map<Word, SectionOffset> resources_;
137  };
138 
139  /// Resource id:s for strings.
140  mutable std::map<std::string, Word> resolvedResources_;
141 
142  /// List of compilation modules of a.out
143  mutable std::vector<CompilationModule> addedResources_;
144 
145  mutable std::vector< std::pair<Word, std::string> > annotationes_;
146 };
147 }
148 
149 #endif
TPEF::AOutSymbolSectionReader::DATA_SYMBOL_SIZE
static const Word DATA_SYMBOL_SIZE
Data symbol size in bytes.
Definition: AOutSymbolSectionReader.hh:103
TPEF::AOutSymbolSectionReader::initializeSymbol
SymbolElement * initializeSymbol(BinaryStream &stream, SectionOffset sectionOffset, AOutReader *reader) const
Definition: AOutSymbolSectionReader.cc:261
Exception.hh
TPEF::AOutSymbolSectionReader
Definition: AOutSymbolSectionReader.hh:54
TPEF::BinaryStream
Definition: BinaryStream.hh:59
TPEF::AOutSymbolSectionReader::GCC_MODULE_START_SYMBOL2
static const std::string GCC_MODULE_START_SYMBOL2
One of the symbols that are used to indicate start of new compilation module in a....
Definition: AOutSymbolSectionReader.hh:111
TPEF::AOutSymbolSectionReader::resolvedResources_
std::map< std::string, Word > resolvedResources_
Resource id:s for strings.
Definition: AOutSymbolSectionReader.hh:140
TPEF::AOutSymbolSectionReader::readData
virtual void readData(BinaryStream &stream, Section *section) const
Definition: AOutSymbolSectionReader.cc:112
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::Section
Definition: Section.hh:64
TPEF::AOutSymbolSectionReader::StabData::stabType
Byte stabType
Stab type.
Definition: AOutSymbolSectionReader.hh:82
TPEF::AOutSymbolSectionReader::AOutSymbolSectionReader
AOutSymbolSectionReader()
Definition: AOutSymbolSectionReader.cc:79
TPEF::AOutSymbolSectionReader::proto_
static AOutSymbolSectionReader proto_
Class-wide (unique) prototype instance of AOutSymbolSectionReader registered into SectionReader.
Definition: AOutSymbolSectionReader.hh:115
TPEF::AOutReader
Definition: AOutReader.hh:54
TPEF::AOutSymbolSectionReader::CompilationModule::resources_
std::map< Word, SectionOffset > resources_
Resources id replacements for the compilation module.
Definition: AOutSymbolSectionReader.hh:136
TPEF::AOutSymbolSectionReader::annotationes_
std::vector< std::pair< Word, std::string > > annotationes_
Definition: AOutSymbolSectionReader.hh:145
TPEF::AOutSymbolSectionReader::finalize
virtual void finalize(Section *section) const
Definition: AOutSymbolSectionReader.cc:433
TPEF::AOutSymbolSectionReader::addedResources_
std::vector< CompilationModule > addedResources_
List of compilation modules of a.out.
Definition: AOutSymbolSectionReader.hh:143
TPEF::AOutSymbolSectionReader::StabData::description
HalfWord description
Description field.
Definition: AOutSymbolSectionReader.hh:86
TPEF::AOutSymbolSectionReader::CompilationModule
Definition: AOutSymbolSectionReader.hh:127
TPEF::SymbolElement
Definition: SymbolElement.hh:52
TPEF::AOutSymbolSectionReader::StabData::nameOffset
Word nameOffset
Offset to string table.
Definition: AOutSymbolSectionReader.hh:90
TPEF::AOutSymbolSectionReader::StabData
Definition: AOutSymbolSectionReader.hh:73
TPEF::AOutSymbolSectionReader::StabData::value
Word value
Value of the stab.
Definition: AOutSymbolSectionReader.hh:88
TPEF::AOutSymbolSectionReader::operator=
AOutSymbolSectionReader & operator=(const AOutSymbolSectionReader &)
Assignment not allowed.
TPEF::AOutSymbolSectionReader::CompilationModule::CompilationModule
CompilationModule(Word startAddress)
Definition: AOutSymbolSectionReader.hh:128
TPEF::SectionOffset
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Definition: TPEFBaseType.hh:49
AOutSectionReader.hh
TPEF::AOutSymbolSectionReader::GCC_MODULE_START_SYMBOL1
static const std::string GCC_MODULE_START_SYMBOL1
One of the symbols that are used to indicate start of new compilation module in a....
Definition: AOutSymbolSectionReader.hh:107
TPEF::AOutSymbolSectionReader::StabData::StabData
StabData(Byte aType, Byte anOther, HalfWord aDescr, Word aValue, Word aName)
Definition: AOutSymbolSectionReader.hh:74
TPEF::AOutSymbolSectionReader::~AOutSymbolSectionReader
virtual ~AOutSymbolSectionReader()
Definition: AOutSymbolSectionReader.cc:86
TPEF::AOutSectionReader
Definition: AOutSectionReader.hh:45
TPEF::AOutSymbolSectionReader::CompilationModule::startAddress_
Word startAddress_
Start address of linked compilation module in a.out.
Definition: AOutSymbolSectionReader.hh:133
TPEF::AOutSymbolSectionReader::StabData::other
Byte other
Stab other field.
Definition: AOutSymbolSectionReader.hh:84
Section.hh
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
TPEFBaseType.hh
TPEF::AOutSymbolSectionReader::type
virtual Section::SectionType type() const
Definition: AOutSymbolSectionReader.cc:95
TPEF
Definition: Assembler.hh:43