Build everything as C++ (#1176)

This commit is contained in:
Rangi
2023-11-07 15:45:56 -05:00
committed by GitHub
parent 78d83be2b2
commit 1e70e703a7
84 changed files with 667 additions and 663 deletions

62
src/link/symbol.cpp Normal file
View File

@@ -0,0 +1,62 @@
/* SPDX-License-Identifier: MIT */
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include "link/object.hpp"
#include "link/symbol.hpp"
#include "link/main.hpp"
#include "error.hpp"
#include "hashmap.hpp"
HashMap symbols;
struct ForEachSymbolArg {
void (*callback)(struct Symbol *symbol, void *arg);
void *arg;
};
static void forEach(void *symbol, void *arg)
{
struct ForEachSymbolArg *callbackArg = (struct ForEachSymbolArg *)arg;
callbackArg->callback((struct Symbol *)symbol, callbackArg->arg);
}
void sym_ForEach(void (*callback)(struct Symbol *, void *), void *arg)
{
struct ForEachSymbolArg callbackArg = { .callback = callback, .arg = arg };
hash_ForEach(symbols, forEach, &callbackArg);
}
void sym_AddSymbol(struct Symbol *symbol)
{
// Check if the symbol already exists
struct Symbol *other = (struct Symbol *)hash_GetElement(symbols, symbol->name);
if (other) {
fprintf(stderr, "error: \"%s\" both in %s from ", symbol->name, symbol->objFileName);
dumpFileStack(symbol->src);
fprintf(stderr, "(%" PRIu32 ") and in %s from ",
symbol->lineNo, other->objFileName);
dumpFileStack(other->src);
fprintf(stderr, "(%" PRIu32 ")\n", other->lineNo);
exit(1);
}
// If not, add it
hash_AddElement(symbols, symbol->name, symbol);
}
struct Symbol *sym_GetSymbol(char const *name)
{
return (struct Symbol *)hash_GetElement(symbols, name);
}
void sym_CleanupSymbols(void)
{
hash_EmptyMap(symbols);
}