diff --git a/include/asm/symbol.h b/include/asm/symbol.h index 606cb97a..e02220a0 100644 --- a/include/asm/symbol.h +++ b/include/asm/symbol.h @@ -80,4 +80,8 @@ void sym_Purge(char *tzName); uint32_t sym_isConstDefined(char *tzName); int32_t sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2); +/* Functions to save and restore the current symbol scope. */ +struct sSymbol *sym_GetCurrentSymbolScope(void); +void sym_SetCurrentSymbolScope(struct sSymbol *pNewScope); + #endif /* RGBDS_SYMBOL_H */ diff --git a/src/asm/output.c b/src/asm/output.c index 917a3496..678b4a30 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -42,6 +42,7 @@ struct PatchSymbol { struct SectionStackEntry { struct Section *pSection; + struct sSymbol *pScope; /* Section's symbol scope */ struct SectionStackEntry *pNext; }; @@ -64,6 +65,7 @@ void out_PushSection(void) fatalerror("No memory for section stack"); pSect->pSection = pCurrentSection; + pSect->pScope = sym_GetCurrentSymbolScope(); pSect->pNext = pSectionStack; pSectionStack = pSect; } @@ -77,6 +79,7 @@ void out_PopSection(void) pSect = pSectionStack; out_SetCurrentSection(pSect->pSection); + sym_SetCurrentSymbolScope(pSect->pScope); pSectionStack = pSect->pNext; free(pSect); } diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 948d691a..375269d3 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -19,7 +19,7 @@ #include "extern/version.h" struct sSymbol *tHashedSymbols[HASHSIZE]; -static struct sSymbol *pScope; +static struct sSymbol *pScope; /* Current section symbol scope */ struct sSymbol *pPCSymbol; static struct sSymbol *p_NARGSymbol; static struct sSymbol *p__LINE__Symbol; @@ -406,6 +406,16 @@ uint32_t sym_GetDefinedValue(char *s) return 0; } +struct sSymbol *sym_GetCurrentSymbolScope(void) +{ + return pScope; +} + +void sym_SetCurrentSymbolScope(struct sSymbol *pNewScope) +{ + pScope = pNewScope; +} + /* * Macro argument stuff */