mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Use std::map for rgbasm symbols
This commit is contained in:
@@ -102,7 +102,7 @@ static inline char const *sym_GetStringValue(struct Symbol const *sym)
|
|||||||
return sym->equs.value;
|
return sym->equs.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg);
|
void sym_ForEach(void (*func)(struct Symbol *));
|
||||||
|
|
||||||
int32_t sym_GetValue(struct Symbol const *sym);
|
int32_t sym_GetValue(struct Symbol const *sym);
|
||||||
void sym_SetExportAll(bool set);
|
void sym_SetExportAll(bool set);
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ static void writeFileStackNode(struct FileStackNode const *node, FILE *f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void registerUnregisteredSymbol(struct Symbol *symbol, void *)
|
static void registerUnregisteredSymbol(struct Symbol *symbol)
|
||||||
{
|
{
|
||||||
// Check for symbol->src, to skip any built-in symbol from rgbasm
|
// Check for symbol->src, to skip any built-in symbol from rgbasm
|
||||||
if (symbol->src && symbol->ID == (uint32_t)-1) {
|
if (symbol->src && symbol->ID == (uint32_t)-1) {
|
||||||
@@ -438,7 +438,7 @@ void out_WriteObject(void)
|
|||||||
err("Failed to open object file '%s'", objectName);
|
err("Failed to open object file '%s'", objectName);
|
||||||
|
|
||||||
// Also write symbols that weren't written above
|
// Also write symbols that weren't written above
|
||||||
sym_ForEach(registerUnregisteredSymbol, NULL);
|
sym_ForEach(registerUnregisteredSymbol);
|
||||||
|
|
||||||
fprintf(f, RGBDS_OBJECT_VERSION_STRING);
|
fprintf(f, RGBDS_OBJECT_VERSION_STRING);
|
||||||
putlong(RGBDS_OBJECT_REV, f);
|
putlong(RGBDS_OBJECT_REV, f);
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <map>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -22,11 +24,10 @@
|
|||||||
#include "asm/warning.hpp"
|
#include "asm/warning.hpp"
|
||||||
|
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
#include "hashmap.hpp"
|
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
|
|
||||||
HashMap symbols;
|
std::map<std::string, struct Symbol *> symbols;
|
||||||
|
|
||||||
static const char *labelScope; // Current section's label scope
|
static const char *labelScope; // Current section's label scope
|
||||||
static struct Symbol *PCSymbol;
|
static struct Symbol *PCSymbol;
|
||||||
@@ -42,24 +43,10 @@ bool sym_IsPC(struct Symbol const *sym)
|
|||||||
return sym == PCSymbol;
|
return sym == PCSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ForEachArgs {
|
void sym_ForEach(void (*callback)(struct Symbol *))
|
||||||
void (*func)(struct Symbol *sym, void *arg);
|
|
||||||
void *arg;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void forEachWrapper(void *_sym, void *_argWrapper)
|
|
||||||
{
|
{
|
||||||
struct ForEachArgs *argWrapper = (struct ForEachArgs *)_argWrapper;
|
for (auto &it : symbols)
|
||||||
struct Symbol *sym = (struct Symbol *)_sym;
|
callback(it.second);
|
||||||
|
|
||||||
argWrapper->func(sym, argWrapper->arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg)
|
|
||||||
{
|
|
||||||
struct ForEachArgs argWrapper = { .func = func, .arg = arg };
|
|
||||||
|
|
||||||
hash_ForEach(symbols, forEachWrapper, &argWrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Callback_NARG(void)
|
static int32_t Callback_NARG(void)
|
||||||
@@ -138,7 +125,7 @@ static struct Symbol *createsymbol(char const *symName)
|
|||||||
setSymbolFilename(sym);
|
setSymbolFilename(sym);
|
||||||
sym->ID = -1;
|
sym->ID = -1;
|
||||||
|
|
||||||
hash_AddElement(symbols, sym->name, sym);
|
symbols[sym->name] = sym;
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +156,8 @@ static void assignStringSymbol(struct Symbol *sym, char const *value)
|
|||||||
|
|
||||||
struct Symbol *sym_FindExactSymbol(char const *symName)
|
struct Symbol *sym_FindExactSymbol(char const *symName)
|
||||||
{
|
{
|
||||||
return (struct Symbol *)hash_GetElement(symbols, symName);
|
auto search = symbols.find(symName);
|
||||||
|
return search != symbols.end() ? search->second : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Symbol *sym_FindScopedSymbol(char const *symName)
|
struct Symbol *sym_FindScopedSymbol(char const *symName)
|
||||||
@@ -234,7 +222,7 @@ void sym_Purge(char const *symName)
|
|||||||
|
|
||||||
// FIXME: this leaks sym->equs.value for SYM_EQUS and sym->macro.value for SYM_MACRO,
|
// FIXME: this leaks sym->equs.value for SYM_EQUS and sym->macro.value for SYM_MACRO,
|
||||||
// but this can't free either of them because the expansion may be purging itself.
|
// but this can't free either of them because the expansion may be purging itself.
|
||||||
hash_RemoveElement(symbols, sym->name);
|
symbols.erase(sym->name);
|
||||||
// TODO: ideally, also unref the file stack nodes
|
// TODO: ideally, also unref the file stack nodes
|
||||||
free(sym);
|
free(sym);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user