Files
rgbds/include/link/symbol.hpp
Sylvie 57c3d74b9e Use a custom generic tagged union Either instead of std::variant for efficiency (#1476)
* Implement custom generic tagged union `Either`

This should be more efficient than `std::variant`, while still
keeping runtime safety as it `assert`s when `get`ting values.

* Use `Either` for RPN expressions

* Use `Either` for file stack node data

* Use `Either` for `File` buffer

* Use `Either` for `STRFMT` args

* Use `Either` for RGBLINK symbol values

* Support an equivalent of `std::monostate` for `Either`

* Use `Either` for lexer tokens

* Use `Either` for symbol values

* Use `Either` for lexer mmap/buffer state
2024-08-20 21:19:11 +02:00

53 lines
1.1 KiB
C++

/* SPDX-License-Identifier: MIT */
#ifndef RGBDS_LINK_SYMBOL_HPP
#define RGBDS_LINK_SYMBOL_HPP
// GUIDELINE: external code MUST NOT BE AWARE of the data structure used!
#include <stdint.h>
#include <string>
#include "either.hpp"
#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;
ExportLevel type;
char const *objFileName;
FileStackNode const *src;
int32_t lineNo;
Either<
int32_t, // Constants just have a numeric value
Label // Label values refer to an offset within a specific section
>
data;
Label &label() { return data.get<Label>(); }
Label const &label() const { return data.get<Label>(); }
};
void sym_ForEach(void (*callback)(Symbol &));
void sym_AddSymbol(Symbol &symbol);
/*
* Finds a symbol in all the defined symbols.
* @param name The name of the symbol to look for
* @return A pointer to the symbol, or `nullptr` if not found.
*/
Symbol *sym_GetSymbol(std::string const &name);
#endif // RGBDS_LINK_SYMBOL_HPP