Clean up symbol management

Stop using that bitfield for everything, including what can be determined otherwise
It also makes it easier to have a sane state, since some bits were (supposedly)
mutually exclusive
This commit is contained in:
ISSOtm
2020-01-22 15:05:07 +01:00
parent e3ef194b4f
commit ab9307ac61
10 changed files with 162 additions and 169 deletions

View File

@@ -9,20 +9,33 @@
#ifndef RGBDS_SYMBOL_H
#define RGBDS_SYMBOL_H
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "types.h"
#define HASHSIZE (1 << 16)
#define MAXSYMLEN 256
enum SymbolType {
SYM_LABEL,
SYM_EQU,
SYM_SET,
SYM_MACRO,
SYM_EQUS,
SYM_REF // Forward reference to a label
};
struct sSymbol {
char tzName[MAXSYMLEN + 1];
int32_t nValue;
uint32_t nType;
enum SymbolType type;
bool isConstant; /* Whether the symbol's value is currently known */
bool isExported; /* Whether the symbol is to be exported */
struct sSymbol *pScope;
struct sSymbol *pNext;
struct Section *pSection;
int32_t nValue;
uint32_t ulMacroSize;
char *pMacro;
int32_t (*Callback)(struct sSymbol *self);
@@ -30,26 +43,49 @@ struct sSymbol {
uint32_t nFileLine; /* Line where the symbol was defined. */
};
/* Symbol will be relocated during linking, it's absolute value is unknown */
static inline bool sym_IsDefined(struct sSymbol const *sym)
{
return sym->type != SYM_REF;
}
static inline bool sym_IsConstant(struct sSymbol const *sym)
{
return sym->isConstant;
}
static inline bool sym_IsNumeric(struct sSymbol const *sym)
{
return sym->type == SYM_LABEL || sym->type == SYM_EQU
|| sym->type == SYM_SET;
}
static inline bool sym_IsLocal(struct sSymbol const *sym)
{
return (sym->type == SYM_LABEL || sym->type == SYM_REF)
&& strchr(sym->tzName, '.');
}
static inline bool sym_IsExported(struct sSymbol const *sym)
{
return sym->isExported;
}
/* Symbol will be relocated during linking, it's absolute value is unknown
#define SYMF_RELOC 0x001
/* Symbol is defined using EQU, will not be changed during linking */
Symbol is defined using EQU, will not be changed during linking
#define SYMF_EQU 0x002
/* Symbol is (re)defined using SET, will not be changed during linking */
Symbol is (re)defined using SET, will not be changed during linking
#define SYMF_SET 0x004
/* Symbol should be exported */
Symbol should be exported
#define SYMF_EXPORT 0x008
/* Symbol referenced in RPN expression */
Symbol referenced in RPN expression
#define SYMF_REF 0x010
/* Symbol is a local symbol */
Symbol is a local symbol
#define SYMF_LOCAL 0x020
/* Symbol has been defined, not only referenced */
Symbol has been defined, not only referenced
#define SYMF_DEFINED 0x040
/* Symbol is a macro */
Symbol is a macro
#define SYMF_MACRO 0x080
/* Symbol is a stringsymbol */
Symbol is a stringsymbol
#define SYMF_STRING 0x100
/* Symbol has a constant value, will not be changed during linking */
Symbol has a constant value, will not be changed during linking
#define SYMF_CONST 0x200
*/
uint32_t sym_CalcHash(const char *s);
void sym_SetExportAll(uint8_t set);
@@ -67,22 +103,18 @@ void sym_AddEqu(char *tzSym, int32_t value);
void sym_AddSet(char *tzSym, int32_t value);
void sym_Init(void);
uint32_t sym_GetConstantValue(char *s);
uint32_t sym_isConstant(char *s);
struct sSymbol *sym_FindSymbol(char *tzName);
char *sym_FindMacroArg(int32_t i);
char *sym_GetStringValue(char *tzSym);
char *sym_GetStringValue(struct sSymbol const *sym);
void sym_UseCurrentMacroArgs(void);
void sym_SetMacroArgID(uint32_t nMacroCount);
uint32_t sym_isString(char *tzSym);
void sym_AddMacro(char *tzSym, int32_t nDefLineNo);
void sym_Ref(char *tzSym);
void sym_ShiftCurrentMacroArgs(void);
void sym_AddString(char *tzSym, char *tzValue);
uint32_t sym_GetDefinedValue(char *s);
uint32_t sym_isDefined(char *tzName);
void sym_Purge(char *tzName);
uint32_t sym_isConstDefined(char *tzName);
int32_t sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
bool sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
/* Functions to save and restore the current symbol scope. */
struct sSymbol *sym_GetCurrentSymbolScope(void);