OpenASIP 2.2
Loading...
Searching...
No Matches
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
43namespace 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 */
65public:
67 TPEF::Binary& bin, MachineResourceManager& resources,
69
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
94
96
97 void finalize();
98
99 void cleanup();
100
102 UValue asmLineNumber, LiteralOrExpression& litOrExpr);
103
104private:
105 /**
106 * Internal representation of label.
107 */
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
unsigned long UValue
std::map< std::string, InternalLabel * > SymbolMap
TPEF::SymbolElement * createSymbolWithReference(InternalLabel *currLabel, TPEF::Section *ownerSection)
void removeLabel(std::string &name)
TPEF::RelocSection * findOrCreateRelocationSection(InternalRelocation *currReloc, TPEF::SymbolSection *symbolSect)
void clearLastRelocations()
UValue value(std::string &name)
void addProcedure(std::string &name, UValue value)
SymbolMap labels_
Contains stored symbols by their name.
TPEF::Section * findSectionByAddress(InternalLabel *currLabel)
UValue resolveExpressionValue(UValue asmLineNumber, LiteralOrExpression &litOrExpr)
void setGlobal(std::string &labelName)
std::string aSpaceName(std::string &labelName)
void writeProcedureSymbols(TPEF::CodeSection *codeSect, TPEF::SymbolSection *symbolSect, TPEF::StringSection *strings)
void commitLastRelocations()
TPEF::ASpaceElement & aSpaceElement(std::string &labelName)
std::set< InternalRelocation * > relocs_
Added relocations.
std::set< std::string > globals_
Names of global symbols.
TPEF::Binary & bin_
For finding sections containing relocated elements.
std::set< InternalRelocation * > uncommittedRelocs_
Uncommitted relocations.
void addRelocation(TPEF::Section &locationSect, TPEF::SectionElement &location, TPEF::ASpaceElement &dstASpace, UValue destination, UValue bitWidth)
void addLabel(TPEF::ASpaceElement &aSpace, std::string &name, UValue value)
MachineResourceManager & resources_
Common resources of TPEF.
std::map< std::string, UValue > procedures_
Names and addresses of procedure starts.
TPEF::Section * findRelocationDstSection(InternalRelocation *currReloc)
TPEF::ASpaceElement * aSpace
Address space of the label.
std::string name
Name of the label.
UValue value
Address where label is located.
TPEF::SectionElement * location
Element that is reloacted.
TPEF::Section * locationSect
Section where relocated immediate or chunk is stored.
UValue bitWidth
Number of bits that are used to store the value.
UValue destination
Destination address.
TPEF::ASpaceElement * dstASpace
Address space of destination address.