shithub: rgbds

Download patch

ref: 7deb8d3e8ae95a5e669cb8b7531aa133486e09c9
parent: cb0a882a311d94628b3197c1b9388203b25c92c5
author: ISSOtm <[email protected]>
date: Tue Mar 24 06:52:02 EDT 2020

Allow purging exported symbols

--- a/include/asm/symbol.h
+++ b/include/asm/symbol.h
@@ -101,7 +101,7 @@
 struct sSymbol *sym_FindSymbol(char const *tzName);
 char *sym_GetStringValue(struct sSymbol const *sym);
 struct sSymbol *sym_AddMacro(char const *tzSym, int32_t nDefLineNo);
-void sym_Ref(char const *tzSym);
+struct sSymbol *sym_Ref(char const *tzSym);
 struct sSymbol *sym_AddString(char const *tzSym, char const *tzValue);
 uint32_t sym_GetDefinedValue(char const *s);
 void sym_Purge(char const *tzName);
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -500,9 +500,13 @@
  */
 void sym_Export(char const *tzSym)
 {
-	sym_Ref(tzSym);
 	struct sSymbol *nsym = sym_FindSymbol(tzSym);
 
+	/* If the symbol doesn't exist, create a ref that can be purged */
+	if (!nsym) {
+		nsym = sym_Ref(tzSym);
+		nsym->isReferenced = false;
+	}
 	nsym->isExported = true;
 }
 
@@ -531,7 +535,7 @@
  * Flag that a symbol is referenced in an RPN expression
  * and create it if it doesn't exist yet
  */
-void sym_Ref(char const *tzSym)
+struct sSymbol *sym_Ref(char const *tzSym)
 {
 	struct sSymbol *nsym = sym_FindSymbol(tzSym);
 
@@ -551,6 +555,8 @@
 		nsym->type = SYM_REF;
 	}
 	nsym->isReferenced = true;
+
+	return nsym;
 }
 
 /*