RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
symbol_name.h
1#ifndef SYMBOL_NAME_H
2#define SYMBOL_NAME_H
3
4#include <iostream>
5#include <optional>
6#include <string>
7#include "../common.h"
8
9namespace Linker
10{
18 {
19 protected:
20 std::optional<std::string> library;
21 /* internal symbols: empty, imported symbols: refers to the library (NE, LE, PE) */
22 std::optional<std::string> name;
23 /* symbols imported by ordinal: empty (NE, LE, PE), other symbols: the name of the symbol */
24 std::optional<uint16_t> hint;
25 /* symbols imported not by ordinal: empty (NE, LE), except PE where it is a hint, other symbols: ordinal */
26
27 public:
31 SymbolName(std::string name)
32 : name(name)
33 {
34 }
35
39 SymbolName(std::string library, std::string name)
40 : library(library), name(name)
41 {
42 }
43
49 SymbolName(std::string library, std::string name, uint16_t hint)
50 : library(library), name(name), hint(hint)
51 {
52 }
53
59 SymbolName(std::string library, uint16_t ordinal)
60 : library(library), hint(ordinal)
61 {
62 }
63
67 bool LoadName(std::string& result) const;
68
72 bool LoadLibraryName(std::string& result) const;
73
77 bool LoadOrdinalOrHint(uint16_t& result) const;
78
82 bool GetLocalName(std::string& result) const;
83
87 bool GetImportedName(std::string& result_library, std::string& result_name) const;
88
92 bool GetImportedName(std::string& result_library, std::string& result_name, uint16_t& result_hint) const;
93
97 bool GetImportedOrdinal(std::string& result_library, uint16_t& result_ordinal) const;
98
102 bool operator ==(const SymbolName& other) const;
103
107 bool operator !=(const SymbolName& other) const;
108 };
109
113 std::ostream& operator<<(std::ostream& out, const SymbolName& symbol);
114
119 {
120 protected:
121 bool by_ordinal;
122 std::string name;
123 std::optional<uint16_t> ordinal;
124
125 public:
129 ExportedSymbolName(std::string name)
130 : by_ordinal(false), name(name), ordinal()
131 {
132 }
133
139 ExportedSymbolName(std::string name, uint16_t hint)
140 : by_ordinal(false), name(name), ordinal(hint)
141 {
142 }
143
147 ExportedSymbolName(uint16_t ordinal, std::string internal_name)
148 : by_ordinal(true), name(internal_name), ordinal(ordinal)
149 {
150 }
151
152 bool IsExportedByOrdinal() const;
153
157 bool LoadName(std::string& result) const;
158
162 bool LoadOrdinalOrHint(uint16_t& result) const;
163
167 bool GetExportedByName(std::string& result) const;
168
172 bool GetExportedByName(std::string& result, uint16_t& hint) const;
173
177 bool GetExportedByOrdinal(uint16_t& result) const;
178
182 bool GetExportedByOrdinal(uint16_t& result, std::string& result_name) const;
183
187 bool operator ==(const ExportedSymbolName& other) const;
188
192 bool operator !=(const ExportedSymbolName& other) const;
193
197 bool operator <(const ExportedSymbolName& other) const;
198
202 bool operator >=(const ExportedSymbolName& other) const;
203
207 bool operator >(const ExportedSymbolName& other) const;
208
212 bool operator <=(const ExportedSymbolName& other) const;
213 };
214
218 std::ostream& operator<<(std::ostream& out, const ExportedSymbolName& symbol);
219}
220
221#endif /* SYMBOL_NAME_H */
Represents a symbol to be exported from the module.
Definition symbol_name.h:119
bool operator<(const ExportedSymbolName &other) const
Compares two symbols for ordering.
Definition symbol_name.cc:236
bool operator!=(const ExportedSymbolName &other) const
Compares two symbols for inequality.
Definition symbol_name.cc:231
ExportedSymbolName(std::string name, uint16_t hint)
Creates a symbol exported by name, with a corresponding hint.
Definition symbol_name.h:139
bool operator<=(const ExportedSymbolName &other) const
Compares two symbols for ordering.
Definition symbol_name.cc:254
bool operator==(const ExportedSymbolName &other) const
Compares two symbols for equality.
Definition symbol_name.cc:226
bool operator>(const ExportedSymbolName &other) const
Compares two symbols for ordering.
Definition symbol_name.cc:249
bool GetExportedByName(std::string &result) const
For symbols exported by name, returns the name.
Definition symbol_name.cc:167
bool LoadName(std::string &result) const
Returns the name of the symbol.
Definition symbol_name.cc:148
ExportedSymbolName(std::string name)
Creates a symbol exported by name.
Definition symbol_name.h:129
ExportedSymbolName(uint16_t ordinal, std::string internal_name)
Creates a symbol exported by ordinal, with an associated internal name.
Definition symbol_name.h:147
bool GetExportedByOrdinal(uint16_t &result) const
For symbols exported by ordinal, returns the ordinal.
Definition symbol_name.cc:197
bool LoadOrdinalOrHint(uint16_t &result) const
Returns the hint or ordinal of the symbol.
Definition symbol_name.cc:154
bool operator>=(const ExportedSymbolName &other) const
Compares two symbols for ordering.
Definition symbol_name.cc:244
Represents an (imported or internal) symbol name, which can be more complex than a string.
Definition symbol_name.h:18
bool GetImportedOrdinal(std::string &result_library, uint16_t &result_ordinal) const
For symbols imported by ordinal, returns the library and ordinal.
Definition symbol_name.cc:92
bool operator!=(const SymbolName &other) const
Compares two symbols for inequality.
Definition symbol_name.cc:112
SymbolName(std::string library, uint16_t ordinal)
Creates a symbol imported via ordinal, from a library.
Definition symbol_name.h:59
SymbolName(std::string name)
Creates an internal symbol with a name.
Definition symbol_name.h:31
bool GetLocalName(std::string &result) const
For local symbols, returns the name.
Definition symbol_name.cc:45
bool LoadName(std::string &result) const
Retrieves the name of the symbol, if it has one.
Definition symbol_name.cc:6
SymbolName(std::string library, std::string name)
Creates a symbol imported via name, from a library.
Definition symbol_name.h:39
SymbolName(std::string library, std::string name, uint16_t hint)
Creates a symbol imported via name and a hint, from a library.
Definition symbol_name.h:49
bool LoadOrdinalOrHint(uint16_t &result) const
Retrieves the ordinal of symbols imported by ordinal, or the hint for imported symbols with a hint.
Definition symbol_name.cc:32
bool LoadLibraryName(std::string &result) const
Retrieves the name of the library, if it is imported.
Definition symbol_name.cc:19
bool GetImportedName(std::string &result_library, std::string &result_name) const
For symbols imported by name, returns the library and name.
Definition symbol_name.cc:60
bool operator==(const SymbolName &other) const
Compares two symbols for equality.
Definition symbol_name.cc:107