OpenASIP  2.0
LabelManager.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 LabelManager.hh
26  *
27  * Declarations of LabelManager class.
28  *
29  * @author Mikael Lepistö 2005 (tmlepist-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2006 (pekka.jaaskelainen-no.spam-tut.fi)
31  *
32  * @note rating: yellow
33  */
34 
35 #ifndef TCEASM_LABEL_MANAGER_HH
36 #define TCEASM_LABEL_MANAGER_HH
37 
38 #include <set>
39 
40 #include "ParserStructs.hh"
41 #include "Exception.hh"
42 
43 namespace TPEF {
44  class Binary;
45  class RelocSection;
46  class SymbolSection;
47  class CodeSection;
48  class StringSection;
49  class SymbolElement;
50  class SectionElement;
51  class ASpaceElement;
52  class Section;
53 }
54 
57 
58 /**
59  * Keeps track of labels, symbols and relocations.
60  *
61  * After all label and relocation information if added, class
62  * knows how to write SymbolSection and RelocationSectios to TPEF.
63  */
64 class LabelManager {
65 public:
67  TPEF::Binary& bin, MachineResourceManager& resources,
68  AssemblyParserDiagnostic* parent);
69 
70  ~LabelManager();
71 
72  UValue value(std::string& name);
73 
74  TPEF::ASpaceElement& aSpaceElement(std::string& labelName);
75 
76  std::string aSpaceName(std::string& labelName);
77 
78  void addLabel(TPEF::ASpaceElement& aSpace, std::string& name, UValue value);
79 
80  void removeLabel(std::string& name);
81 
82  void addProcedure(std::string& name, UValue value);
83 
84  void setGlobal(std::string& labelName);
85 
86  void addRelocation(
87  TPEF::Section& locationSect,
88  TPEF::SectionElement& location,
89  TPEF::ASpaceElement& dstASpace,
90  UValue destination,
91  UValue bitWidth);
92 
93  void clearLastRelocations();
94 
95  void commitLastRelocations();
96 
97  void finalize();
98 
99  void cleanup();
100 
102  UValue asmLineNumber, LiteralOrExpression& litOrExpr);
103 
104 private:
105  /**
106  * Internal representation of label.
107  */
108  struct InternalLabel {
109  /// Address space of the label.
111  /// Address where label is located.
113  /// Name of the label.
114  std::string name;
115  };
116 
117  /**
118  * Internal representation of relocation.
119  */
121  /// Section where relocated immediate or chunk is stored.
123  /// Element that is reloacted.
125  /// Number of bits that are used to store the value.
127  /// Address space of destination address.
129  /// Destination address.
131  };
132 
134 
136  InternalLabel *currLabel, TPEF::Section* ownerSection);
137 
139  TPEF::CodeSection* codeSect, TPEF::SymbolSection* symbolSect,
140  TPEF::StringSection* strings);
141 
143  InternalRelocation* currReloc, TPEF::SymbolSection* symbolSect);
144 
146 
147 
148  typedef std::map<std::string, InternalLabel*> SymbolMap;
149 
150  /// Contains stored symbols by their name.
152 
153  /// Added relocations.
154  std::set<InternalRelocation*> relocs_;
155 
156  /// Uncommitted relocations.
157  std::set<InternalRelocation*> uncommittedRelocs_;
158 
159  /// Names of global symbols.
160  std::set<std::string> globals_;
161 
162  /// Names and addresses of procedure starts.
163  std::map<std::string, UValue> procedures_;
164 
165  /// For finding sections containing relocated elements.
167 
168  /// Common resources of TPEF.
170 };
171 
172 #endif
LabelManager::createSymbolWithReference
TPEF::SymbolElement * createSymbolWithReference(InternalLabel *currLabel, TPEF::Section *ownerSection)
Definition: LabelManager.cc:507
LabelManager::~LabelManager
~LabelManager()
Definition: LabelManager.cc:93
LabelManager::bin_
TPEF::Binary & bin_
For finding sections containing relocated elements.
Definition: LabelManager.hh:166
Exception.hh
TPEF::Binary
Definition: Binary.hh:49
LabelManager::commitLastRelocations
void commitLastRelocations()
Definition: LabelManager.cc:276
LabelManager::value
UValue value(std::string &name)
Definition: LabelManager.cc:110
ParserStructs.hh
LabelManager::resources_
MachineResourceManager & resources_
Common resources of TPEF.
Definition: LabelManager.hh:169
LabelManager::addProcedure
void addProcedure(std::string &name, UValue value)
Definition: LabelManager.cc:201
LabelManager::finalize
void finalize()
Definition: LabelManager.cc:301
LabelManager::findSectionByAddress
TPEF::Section * findSectionByAddress(InternalLabel *currLabel)
Definition: LabelManager.cc:452
LabelManager::LabelManager
LabelManager(TPEF::Binary &bin, MachineResourceManager &resources, AssemblyParserDiagnostic *parent)
Definition: LabelManager.cc:83
LabelManager::writeProcedureSymbols
void writeProcedureSymbols(TPEF::CodeSection *codeSect, TPEF::SymbolSection *symbolSect, TPEF::StringSection *strings)
Definition: LabelManager.cc:548
LabelManager::InternalRelocation::location
TPEF::SectionElement * location
Element that is reloacted.
Definition: LabelManager.hh:124
AssemblyParserDiagnostic
Definition: AssemblyParserDiagnostic.hh:68
LabelManager::SymbolMap
std::map< std::string, InternalLabel * > SymbolMap
Definition: LabelManager.hh:148
LabelManager
Definition: LabelManager.hh:64
TPEF::RelocSection
Definition: RelocSection.hh:47
LabelManager::resolveExpressionValue
UValue resolveExpressionValue(UValue asmLineNumber, LiteralOrExpression &litOrExpr)
Definition: LabelManager.cc:678
TPEF::Section
Definition: Section.hh:64
TPEF::StringSection
Definition: StringSection.hh:48
LabelManager::InternalRelocation::locationSect
TPEF::Section * locationSect
Section where relocated immediate or chunk is stored.
Definition: LabelManager.hh:122
LabelManager::addRelocation
void addRelocation(TPEF::Section &locationSect, TPEF::SectionElement &location, TPEF::ASpaceElement &dstASpace, UValue destination, UValue bitWidth)
Definition: LabelManager.cc:231
LabelManager::InternalRelocation::dstASpace
TPEF::ASpaceElement * dstASpace
Address space of destination address.
Definition: LabelManager.hh:128
LabelManager::cleanup
void cleanup()
Definition: LabelManager.cc:263
UValue
unsigned long UValue
Definition: ParserStructs.hh:44
TPEF::SymbolSection
Definition: SymbolSection.hh:44
TPEF::ASpaceElement
Definition: ASpaceElement.hh:48
MachineResourceManager
Definition: MachineResourceManager.hh:76
LabelManager::findOrCreateRelocationSection
TPEF::RelocSection * findOrCreateRelocationSection(InternalRelocation *currReloc, TPEF::SymbolSection *symbolSect)
Definition: LabelManager.cc:590
LabelManager::InternalLabel::value
UValue value
Address where label is located.
Definition: LabelManager.hh:112
LiteralOrExpression
Definition: ParserStructs.hh:245
LabelManager::uncommittedRelocs_
std::set< InternalRelocation * > uncommittedRelocs_
Uncommitted relocations.
Definition: LabelManager.hh:157
TPEF::SectionElement
Definition: SectionElement.hh:44
LabelManager::aSpaceName
std::string aSpaceName(std::string &labelName)
Definition: LabelManager.cc:147
LabelManager::addLabel
void addLabel(TPEF::ASpaceElement &aSpace, std::string &name, UValue value)
Definition: LabelManager.cc:160
LabelManager::InternalLabel
Definition: LabelManager.hh:108
TPEF::SymbolElement
Definition: SymbolElement.hh:52
LabelManager::setGlobal
void setGlobal(std::string &labelName)
Definition: LabelManager.cc:217
LabelManager::InternalLabel::name
std::string name
Name of the label.
Definition: LabelManager.hh:114
TPEF::CodeSection
Definition: CodeSection.hh:44
LabelManager::findRelocationDstSection
TPEF::Section * findRelocationDstSection(InternalRelocation *currReloc)
Definition: LabelManager.cc:628
LabelManager::removeLabel
void removeLabel(std::string &name)
Definition: LabelManager.cc:183
LabelManager::globals_
std::set< std::string > globals_
Names of global symbols.
Definition: LabelManager.hh:160
LabelManager::aSpaceElement
TPEF::ASpaceElement & aSpaceElement(std::string &labelName)
Definition: LabelManager.cc:129
LabelManager::InternalLabel::aSpace
TPEF::ASpaceElement * aSpace
Address space of the label.
Definition: LabelManager.hh:110
LabelManager::InternalRelocation::destination
UValue destination
Destination address.
Definition: LabelManager.hh:130
LabelManager::InternalRelocation::bitWidth
UValue bitWidth
Number of bits that are used to store the value.
Definition: LabelManager.hh:126
LabelManager::labels_
SymbolMap labels_
Contains stored symbols by their name.
Definition: LabelManager.hh:151
LabelManager::procedures_
std::map< std::string, UValue > procedures_
Names and addresses of procedure starts.
Definition: LabelManager.hh:163
LabelManager::InternalRelocation
Definition: LabelManager.hh:120
LabelManager::clearLastRelocations
void clearLastRelocations()
Definition: LabelManager.cc:255
TPEF
Definition: Assembler.hh:43
LabelManager::relocs_
std::set< InternalRelocation * > relocs_
Added relocations.
Definition: LabelManager.hh:154