ref: 2ea329c920e20fbbdf9ccb5039c1ce3a929b34ca
parent: 3948795d498827f9b4fb1babcf9cdfe00a6ec4fc
author: ISSOtm <[email protected]>
date: Tue Mar 10 12:36:02 EDT 2020
Make symbol creation funcs return ptr to symbol
--- a/include/asm/symbol.h
+++ b/include/asm/symbol.h
@@ -77,8 +77,8 @@
int32_t sym_GetValue(struct sSymbol const *sym);
uint32_t sym_CalcHash(const char *s);
void sym_SetExportAll(uint8_t set);
-void sym_AddLocalReloc(char const *tzSym);
-void sym_AddReloc(char const *tzSym);
+struct sSymbol *sym_AddLocalReloc(char const *tzSym);
+struct sSymbol *sym_AddReloc(char const *tzSym);
void sym_Export(char const *tzSym);
void sym_PrintSymbolTable(void);
struct sSymbol *sym_FindMacro(char const *s);
@@ -87,8 +87,8 @@
void sym_SaveCurrentMacroArgs(char *save[]);
void sym_RestoreCurrentMacroArgs(char *save[]);
void sym_UseNewMacroArgs(void);
-void sym_AddEqu(char const *tzSym, int32_t value);
-void sym_AddSet(char const *tzSym, int32_t value);
+struct sSymbol *sym_AddEqu(char const *tzSym, int32_t value);
+struct sSymbol *sym_AddSet(char const *tzSym, int32_t value);
void sym_Init(void);
uint32_t sym_GetConstantValue(char const *s);
struct sSymbol *sym_FindSymbol(char const *tzName);
@@ -96,10 +96,10 @@
char *sym_GetStringValue(struct sSymbol const *sym);
void sym_UseCurrentMacroArgs(void);
void sym_SetMacroArgID(uint32_t nMacroCount);
-void sym_AddMacro(char const *tzSym, int32_t nDefLineNo);
+struct sSymbol *sym_AddMacro(char const *tzSym, int32_t nDefLineNo);
void sym_Ref(char const *tzSym);
void sym_ShiftCurrentMacroArgs(void);
-void sym_AddString(char const *tzSym, char const *tzValue);
+struct sSymbol *sym_AddString(char const *tzSym, char const *tzValue);
uint32_t sym_GetDefinedValue(char const *s);
void sym_Purge(char const *tzName);
bool sym_IsRelocDiffDefined(char const *tzSym1, char const *tzSym2);
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -441,7 +441,7 @@
/*
* Add an equated symbol
*/
-void sym_AddEqu(char const *tzSym, int32_t value)
+struct sSymbol *sym_AddEqu(char const *tzSym, int32_t value)
{
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -450,6 +450,8 @@
nsym->isConstant = true;
nsym->pScope = NULL;
updateSymbolFilename(nsym);
+
+ return nsym;
}
/*
@@ -464,7 +466,7 @@
* of the string are enough: sym_AddString("M_PI", "3.1415"). This is the same
* as ``` M_PI EQUS "3.1415" ```
*/
-void sym_AddString(char const *tzSym, char const *tzValue)
+struct sSymbol *sym_AddString(char const *tzSym, char const *tzValue)
{
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -478,12 +480,14 @@
nsym->type = SYM_EQUS;
nsym->ulMacroSize = strlen(tzValue);
nsym->pScope = NULL;
+
+ return nsym;
}
/*
* Alter a SET symbols value
*/
-void sym_AddSet(char const *tzSym, int32_t value)
+struct sSymbol *sym_AddSet(char const *tzSym, int32_t value)
{
struct sSymbol *nsym = findsymbol(tzSym, NULL);
@@ -514,21 +518,23 @@
nsym->isConstant = true;
nsym->pScope = NULL;
updateSymbolFilename(nsym);
+
+ return nsym;
}
/*
* Add a local (.name) relocatable symbol
*/
-void sym_AddLocalReloc(char const *tzSym)
+struct sSymbol *sym_AddLocalReloc(char const *tzSym)
{
if (pScope) {
char fullname[MAXSYMLEN + 1];
fullSymbolName(fullname, sizeof(fullname), tzSym, pScope);
- sym_AddReloc(fullname);
-
+ return sym_AddReloc(fullname);
} else {
yyerror("Local label '%s' in main scope", tzSym);
+ return NULL;
}
}
@@ -535,7 +541,7 @@
/*
* Add a relocatable symbol
*/
-void sym_AddReloc(char const *tzSym)
+struct sSymbol *sym_AddReloc(char const *tzSym)
{
struct sSymbol *scope = NULL;
struct sSymbol *nsym;
@@ -544,7 +550,7 @@
if (localPtr != NULL) {
if (!pScope) {
yyerror("Local label in main scope");
- return;
+ return NULL;
}
struct sSymbol *parent = pScope->pScope ?
@@ -587,6 +593,7 @@
updateSymbolFilename(nsym);
pScope = findsymbol(tzSym, scope);
+ return pScope;
}
/*
@@ -650,7 +657,7 @@
/*
* Add a macro definition
*/
-void sym_AddMacro(char const *tzSym, int32_t nDefLineNo)
+struct sSymbol *sym_AddMacro(char const *tzSym, int32_t nDefLineNo)
{
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -664,6 +671,8 @@
* override this with the actual definition line
*/
nsym->nFileLine = nDefLineNo;
+
+ return nsym;
}
/*
@@ -725,16 +734,12 @@
for (i = 0; i < HASHSIZE; i++)
tHashedSymbols[i] = NULL;
- sym_AddReloc("@");
- pPCSymbol = findsymbol("@", NULL);
+ pPCSymbol = sym_AddReloc("@");
pPCSymbol->Callback = CallbackPC;
- sym_AddEqu("_NARG", 0);
- p_NARGSymbol = findsymbol("_NARG", NULL);
+ p_NARGSymbol = sym_AddEqu("_NARG", 0);
p_NARGSymbol->Callback = Callback_NARG;
- sym_AddEqu("__LINE__", 0);
- p__LINE__Symbol = findsymbol("__LINE__", NULL);
+ p__LINE__Symbol = sym_AddEqu("__LINE__", 0);
p__LINE__Symbol->Callback = Callback__LINE__;
-
sym_AddSet("_RS", 0);
time_t now = time(NULL);