Make symbol creation funcs return ptr to symbol

This commit is contained in:
ISSOtm
2020-03-10 16:36:02 +01:00
parent 3948795d49
commit 2ea329c920
2 changed files with 27 additions and 22 deletions

View File

@@ -77,8 +77,8 @@ static inline bool sym_IsExported(struct sSymbol const *sym)
int32_t sym_GetValue(struct sSymbol const *sym); int32_t sym_GetValue(struct sSymbol const *sym);
uint32_t sym_CalcHash(const char *s); uint32_t sym_CalcHash(const char *s);
void sym_SetExportAll(uint8_t set); void sym_SetExportAll(uint8_t set);
void sym_AddLocalReloc(char const *tzSym); struct sSymbol *sym_AddLocalReloc(char const *tzSym);
void sym_AddReloc(char const *tzSym); struct sSymbol *sym_AddReloc(char const *tzSym);
void sym_Export(char const *tzSym); void sym_Export(char const *tzSym);
void sym_PrintSymbolTable(void); void sym_PrintSymbolTable(void);
struct sSymbol *sym_FindMacro(char const *s); struct sSymbol *sym_FindMacro(char const *s);
@@ -87,8 +87,8 @@ void sym_AddNewMacroArg(char const *s);
void sym_SaveCurrentMacroArgs(char *save[]); void sym_SaveCurrentMacroArgs(char *save[]);
void sym_RestoreCurrentMacroArgs(char *save[]); void sym_RestoreCurrentMacroArgs(char *save[]);
void sym_UseNewMacroArgs(void); void sym_UseNewMacroArgs(void);
void sym_AddEqu(char const *tzSym, int32_t value); struct sSymbol *sym_AddEqu(char const *tzSym, int32_t value);
void sym_AddSet(char const *tzSym, int32_t value); struct sSymbol *sym_AddSet(char const *tzSym, int32_t value);
void sym_Init(void); void sym_Init(void);
uint32_t sym_GetConstantValue(char const *s); uint32_t sym_GetConstantValue(char const *s);
struct sSymbol *sym_FindSymbol(char const *tzName); struct sSymbol *sym_FindSymbol(char const *tzName);
@@ -96,10 +96,10 @@ char *sym_FindMacroArg(int32_t i);
char *sym_GetStringValue(struct sSymbol const *sym); char *sym_GetStringValue(struct sSymbol const *sym);
void sym_UseCurrentMacroArgs(void); void sym_UseCurrentMacroArgs(void);
void sym_SetMacroArgID(uint32_t nMacroCount); 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_Ref(char const *tzSym);
void sym_ShiftCurrentMacroArgs(void); 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); uint32_t sym_GetDefinedValue(char const *s);
void sym_Purge(char const *tzName); void sym_Purge(char const *tzName);
bool sym_IsRelocDiffDefined(char const *tzSym1, char const *tzSym2); bool sym_IsRelocDiffDefined(char const *tzSym1, char const *tzSym2);

View File

@@ -441,7 +441,7 @@ static struct sSymbol *createNonrelocSymbol(char const *tzSym)
/* /*
* Add an equated symbol * 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); struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -450,6 +450,8 @@ void sym_AddEqu(char const *tzSym, int32_t value)
nsym->isConstant = true; nsym->isConstant = true;
nsym->pScope = NULL; nsym->pScope = NULL;
updateSymbolFilename(nsym); updateSymbolFilename(nsym);
return nsym;
} }
/* /*
@@ -464,7 +466,7 @@ void sym_AddEqu(char const *tzSym, int32_t value)
* of the string are enough: sym_AddString("M_PI", "3.1415"). This is the same * of the string are enough: sym_AddString("M_PI", "3.1415"). This is the same
* as ``` M_PI EQUS "3.1415" ``` * 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); struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -478,12 +480,14 @@ void sym_AddString(char const *tzSym, char const *tzValue)
nsym->type = SYM_EQUS; nsym->type = SYM_EQUS;
nsym->ulMacroSize = strlen(tzValue); nsym->ulMacroSize = strlen(tzValue);
nsym->pScope = NULL; nsym->pScope = NULL;
return nsym;
} }
/* /*
* Alter a SET symbols value * 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); struct sSymbol *nsym = findsymbol(tzSym, NULL);
@@ -514,28 +518,30 @@ void sym_AddSet(char const *tzSym, int32_t value)
nsym->isConstant = true; nsym->isConstant = true;
nsym->pScope = NULL; nsym->pScope = NULL;
updateSymbolFilename(nsym); updateSymbolFilename(nsym);
return nsym;
} }
/* /*
* Add a local (.name) relocatable symbol * Add a local (.name) relocatable symbol
*/ */
void sym_AddLocalReloc(char const *tzSym) struct sSymbol *sym_AddLocalReloc(char const *tzSym)
{ {
if (pScope) { if (pScope) {
char fullname[MAXSYMLEN + 1]; char fullname[MAXSYMLEN + 1];
fullSymbolName(fullname, sizeof(fullname), tzSym, pScope); fullSymbolName(fullname, sizeof(fullname), tzSym, pScope);
sym_AddReloc(fullname); return sym_AddReloc(fullname);
} else { } else {
yyerror("Local label '%s' in main scope", tzSym); yyerror("Local label '%s' in main scope", tzSym);
return NULL;
} }
} }
/* /*
* Add a relocatable symbol * Add a relocatable symbol
*/ */
void sym_AddReloc(char const *tzSym) struct sSymbol *sym_AddReloc(char const *tzSym)
{ {
struct sSymbol *scope = NULL; struct sSymbol *scope = NULL;
struct sSymbol *nsym; struct sSymbol *nsym;
@@ -544,7 +550,7 @@ void sym_AddReloc(char const *tzSym)
if (localPtr != NULL) { if (localPtr != NULL) {
if (!pScope) { if (!pScope) {
yyerror("Local label in main scope"); yyerror("Local label in main scope");
return; return NULL;
} }
struct sSymbol *parent = pScope->pScope ? struct sSymbol *parent = pScope->pScope ?
@@ -587,6 +593,7 @@ void sym_AddReloc(char const *tzSym)
updateSymbolFilename(nsym); updateSymbolFilename(nsym);
pScope = findsymbol(tzSym, scope); pScope = findsymbol(tzSym, scope);
return pScope;
} }
/* /*
@@ -650,7 +657,7 @@ void sym_Export(char const *tzSym)
/* /*
* Add a macro definition * 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); struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -664,6 +671,8 @@ void sym_AddMacro(char const *tzSym, int32_t nDefLineNo)
* override this with the actual definition line * override this with the actual definition line
*/ */
nsym->nFileLine = nDefLineNo; nsym->nFileLine = nDefLineNo;
return nsym;
} }
/* /*
@@ -725,16 +734,12 @@ void sym_Init(void)
for (i = 0; i < HASHSIZE; i++) for (i = 0; i < HASHSIZE; i++)
tHashedSymbols[i] = NULL; tHashedSymbols[i] = NULL;
sym_AddReloc("@"); pPCSymbol = sym_AddReloc("@");
pPCSymbol = findsymbol("@", NULL);
pPCSymbol->Callback = CallbackPC; pPCSymbol->Callback = CallbackPC;
sym_AddEqu("_NARG", 0); p_NARGSymbol = sym_AddEqu("_NARG", 0);
p_NARGSymbol = findsymbol("_NARG", NULL);
p_NARGSymbol->Callback = Callback_NARG; p_NARGSymbol->Callback = Callback_NARG;
sym_AddEqu("__LINE__", 0); p__LINE__Symbol = sym_AddEqu("__LINE__", 0);
p__LINE__Symbol = findsymbol("__LINE__", NULL);
p__LINE__Symbol->Callback = Callback__LINE__; p__LINE__Symbol->Callback = Callback__LINE__;
sym_AddSet("_RS", 0); sym_AddSet("_RS", 0);
time_t now = time(NULL); time_t now = time(NULL);