Use std::variant for symbol values (#1330)

This commit is contained in:
Sylvie
2024-03-03 21:16:36 -05:00
committed by GitHub
parent f8dab23e8f
commit 447c561aaa
6 changed files with 92 additions and 45 deletions

View File

@@ -8,12 +8,20 @@
#include <stdint.h>
#include <string>
#include <variant>
#include "linkdefs.hpp"
struct FileStackNode;
struct Section;
struct Label {
int32_t sectionID;
int32_t offset;
// Extra info computed during linking
Section *section;
};
struct Symbol {
// Info contained in the object files
std::string name;
@@ -21,14 +29,10 @@ struct Symbol {
char const *objFileName;
FileStackNode const *src;
int32_t lineNo;
int32_t sectionID;
union {
// Both types must be identical
int32_t offset;
int32_t value;
};
// Extra info computed during linking
Section *section;
std::variant<
int32_t, // Constants just have a numeric value
Label // Label values refer to an offset within a specific section
> data;
};
void sym_AddSymbol(Symbol &symbol);