fxos/include/fxos/symbols.h

48 lines
1.1 KiB
C++

//---
// fxos.symbols: User-defined symbols for OS objects
//---
#ifndef LIBFXOS_SYMBOLS_H
#define LIBFXOS_SYMBOLS_H
#include <optional>
#include <string>
#include <vector>
namespace FxOS
{
/* A named symbol that can be substituted to literal values in the code. */
struct Symbol
{
/* Syscall: The value is a syscall number. The syscall number for an
address is determined by querying the OS object.
Address: The value is a fixed 32-bit virtual address. */
enum Type { Syscall=1, Address=2 };
enum Type type;
uint32_t value;
/* Symbol name, no particular conventions */
std::string name;
};
/* A symbol table, essentially a set of symbols loaded from the same file */
struct SymbolTable
{
std::string table_name;
std::vector<Symbol> symbols;
/* Add a symbol to the table */
void add(Symbol s);
/* Query a value for a certain type of symbol */
std::optional<std::string> query(Symbol::Type type, uint32_t value)
const;
/* Lookup the symbol behind a given name */
std::optional<Symbol> lookup(std::string name) const;
};
} /* namespace FxOS */
#endif /* LIBFXOS_SYMBOLS_H */