ref: ed72baca2a8a6bc1332813e9c21f9117469b4cc4
parent: edb562d2e576e14661860860dd321e4f6fc3933c
author: ISSOtm <eldredhabert0@gmail.com>
date: Wed Jan 29 21:38:33 EST 2020
Make more symbol functions `const` Can't hurt to specify those as they are now. Perhaps it'll enable slightly more compiler optimizations, too?
--- a/include/asm/symbol.h
+++ b/include/asm/symbol.h
@@ -38,7 +38,7 @@
int32_t nValue;
uint32_t ulMacroSize;
char *pMacro;
- int32_t (*Callback)(struct sSymbol *self);
+ int32_t (*Callback)(struct sSymbol const *self);
char tzFileName[_MAX_PATH + 1]; /* File where the symbol was defined. */
uint32_t nFileLine; /* Line where the symbol was defined. */
};
@@ -72,32 +72,32 @@
uint32_t sym_CalcHash(const char *s);
void sym_SetExportAll(uint8_t set);
-void sym_AddLocalReloc(char *tzSym);
-void sym_AddReloc(char *tzSym);
-void sym_Export(char *tzSym);
+void sym_AddLocalReloc(char const *tzSym);
+void sym_AddReloc(char const *tzSym);
+void sym_Export(char const *tzSym);
void sym_PrintSymbolTable(void);
-struct sSymbol *sym_FindMacro(char *s);
+struct sSymbol *sym_FindMacro(char const *s);
void sym_InitNewMacroArgs(void);
-void sym_AddNewMacroArg(char *s);
+void sym_AddNewMacroArg(char const *s);
void sym_SaveCurrentMacroArgs(char *save[]);
void sym_RestoreCurrentMacroArgs(char *save[]);
void sym_UseNewMacroArgs(void);
-void sym_AddEqu(char *tzSym, int32_t value);
-void sym_AddSet(char *tzSym, int32_t value);
+void sym_AddEqu(char const *tzSym, int32_t value);
+void sym_AddSet(char const *tzSym, int32_t value);
void sym_Init(void);
-uint32_t sym_GetConstantValue(char *s);
-struct sSymbol *sym_FindSymbol(char *tzName);
+uint32_t sym_GetConstantValue(char const *s);
+struct sSymbol *sym_FindSymbol(char const *tzName);
char *sym_FindMacroArg(int32_t i);
char *sym_GetStringValue(struct sSymbol const *sym);
void sym_UseCurrentMacroArgs(void);
void sym_SetMacroArgID(uint32_t nMacroCount);
-void sym_AddMacro(char *tzSym, int32_t nDefLineNo);
-void sym_Ref(char *tzSym);
+void sym_AddMacro(char const *tzSym, int32_t nDefLineNo);
+void sym_Ref(char const *tzSym);
void sym_ShiftCurrentMacroArgs(void);
-void sym_AddString(char *tzSym, char const *tzValue);
-uint32_t sym_GetDefinedValue(char *s);
-void sym_Purge(char *tzName);
-bool sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
+void 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);
/* Functions to save and restore the current symbol scope. */
struct sSymbol *sym_GetCurrentSymbolScope(void);
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -49,7 +49,7 @@
static char SavedSECOND[3];
static bool exportall;
-static int32_t Callback_NARG(unused_ struct sSymbol *sym)
+static int32_t Callback_NARG(unused_ struct sSymbol const *sym)
{
uint32_t i = 0;
@@ -59,7 +59,7 @@
return i;
}
-static int32_t Callback__LINE__(unused_ struct sSymbol *sym)
+static int32_t Callback__LINE__(unused_ struct sSymbol const *sym)
{
return nLineNo;
}
@@ -67,7 +67,7 @@
/*
* Get the nValue field of a symbol
*/
-static int32_t getvaluefield(struct sSymbol *sym)
+static int32_t getvaluefield(struct sSymbol const *sym)
{
if (sym->Callback)
return sym->Callback(sym);
@@ -102,7 +102,7 @@
/*
* Create a new symbol by name
*/
-static struct sSymbol *createsymbol(char *s)
+static struct sSymbol *createsymbol(char const *s)
{
struct sSymbol **ppsym;
uint32_t hash;
@@ -139,8 +139,8 @@
* Creates the full name of a local symbol in a given scope, by prepending
* the name with the parent symbol's name.
*/
-static void fullSymbolName(char *output, size_t outputSize, char *localName,
- const struct sSymbol *scope)
+static void fullSymbolName(char *output, size_t outputSize,
+ char const *localName, const struct sSymbol *scope)
{
const struct sSymbol *parent = scope->pScope ? scope->pScope : scope;
int n = snprintf(output, outputSize, "%s%s", parent->tzName, localName);
@@ -153,7 +153,7 @@
/*
* Find the pointer to a symbol by name and scope
*/
-static struct sSymbol **findpsymbol(char *s, struct sSymbol *scope)
+static struct sSymbol **findpsymbol(char const *s, struct sSymbol const *scope)
{
struct sSymbol **ppsym;
int32_t hash;
@@ -164,7 +164,7 @@
s = fullname;
}
- char *separator = strchr(s, '.');
+ char const *separator = strchr(s, '.');
if (separator) {
if (strchr(separator + 1, '.'))
@@ -187,7 +187,7 @@
/*
* Find a symbol by name and scope
*/
-static struct sSymbol *findsymbol(char *s, struct sSymbol *scope)
+static struct sSymbol *findsymbol(char const *s, struct sSymbol const *scope)
{
struct sSymbol **ppsym = findpsymbol(s, scope);
@@ -197,7 +197,7 @@
/*
* Find a symbol by name, with automatically determined scope
*/
-struct sSymbol *sym_FindSymbol(char *tzName)
+struct sSymbol *sym_FindSymbol(char const *tzName)
{
struct sSymbol *pscope;
@@ -212,7 +212,7 @@
/*
* Purge a symbol
*/
-void sym_Purge(char *tzName)
+void sym_Purge(char const *tzName)
{
struct sSymbol **ppSym;
struct sSymbol *pscope;
@@ -255,9 +255,9 @@
/*
* Return a constant symbols value
*/
-uint32_t sym_GetConstantValue(char *s)
+uint32_t sym_GetConstantValue(char const *s)
{
- struct sSymbol *psym = sym_FindSymbol(s);
+ struct sSymbol const *psym = sym_FindSymbol(s);
if (psym == pPCSymbol) {
if (pCurrentSection->nOrg == -1)
@@ -280,9 +280,9 @@
/*
* Return a defined symbols value... aborts if not defined yet
*/
-uint32_t sym_GetDefinedValue(char *s)
+uint32_t sym_GetDefinedValue(char const *s)
{
- struct sSymbol *psym = sym_FindSymbol(s);
+ struct sSymbol const *psym = sym_FindSymbol(s);
if (psym != NULL) {
if (sym_IsDefined(psym)) {
@@ -366,7 +366,7 @@
}
}
-void sym_AddNewMacroArg(char *s)
+void sym_AddNewMacroArg(char const *s)
{
int32_t i = 0;
@@ -402,7 +402,7 @@
/*
* Find a macro by name
*/
-struct sSymbol *sym_FindMacro(char *s)
+struct sSymbol *sym_FindMacro(char const *s)
{
return findsymbol(s, NULL);
}
@@ -412,7 +412,7 @@
* hasn't already been defined or referenced in a context that would
* require that it be relocatable
*/
-static struct sSymbol *createNonrelocSymbol(char *tzSym)
+static struct sSymbol *createNonrelocSymbol(char const *tzSym)
{
struct sSymbol *nsym = findsymbol(tzSym, NULL);
@@ -434,7 +434,7 @@
/*
* Add an equated symbol
*/
-void sym_AddEqu(char *tzSym, int32_t value)
+void sym_AddEqu(char const *tzSym, int32_t value)
{
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -457,7 +457,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 *tzSym, char const *tzValue)
+void sym_AddString(char const *tzSym, char const *tzValue)
{
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -476,7 +476,7 @@
/*
* Alter a SET symbols value
*/
-void sym_AddSet(char *tzSym, int32_t value)
+void sym_AddSet(char const *tzSym, int32_t value)
{
struct sSymbol *nsym = findsymbol(tzSym, NULL);
@@ -512,7 +512,7 @@
/*
* Add a local (.name) relocatable symbol
*/
-void sym_AddLocalReloc(char *tzSym)
+void sym_AddLocalReloc(char const *tzSym)
{
if (pScope) {
char fullname[MAXSYMLEN + 1];
@@ -528,7 +528,7 @@
/*
* Add a relocatable symbol
*/
-void sym_AddReloc(char *tzSym)
+void sym_AddReloc(char const *tzSym)
{
struct sSymbol *scope = NULL;
struct sSymbol *nsym;
@@ -591,7 +591,7 @@
*
* It returns 1 if the difference is defined, 0 if not.
*/
-bool sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2)
+bool sym_IsRelocDiffDefined(char const *tzSym1, char const *tzSym2)
{
const struct sSymbol *nsym1 = sym_FindSymbol(tzSym1);
const struct sSymbol *nsym2 = sym_FindSymbol(tzSym2);
@@ -634,7 +634,7 @@
/*
* Export a symbol
*/
-void sym_Export(char *tzSym)
+void sym_Export(char const *tzSym)
{
sym_Ref(tzSym);
struct sSymbol *nsym = sym_FindSymbol(tzSym);
@@ -645,7 +645,7 @@
/*
* Add a macro definition
*/
-void sym_AddMacro(char *tzSym, int32_t nDefLineNo)
+void sym_AddMacro(char const *tzSym, int32_t nDefLineNo)
{
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
@@ -665,7 +665,7 @@
* Flag that a symbol is referenced in an RPN expression
* and create it if it doesn't exist yet
*/
-void sym_Ref(char *tzSym)
+void sym_Ref(char const *tzSym)
{
struct sSymbol *nsym = sym_FindSymbol(tzSym);