mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Save location information of symbol definitions
Now, object files save the file name and line number where each global symbol is defined. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -41,6 +41,8 @@ extern void fstk_RunRept(ULONG count);
|
||||
FILE *
|
||||
fstk_FindFile(char *);
|
||||
|
||||
int fstk_GetLine(void);
|
||||
|
||||
extern int yywrap(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,9 @@ struct sSymbol {
|
||||
struct Section *pSection;
|
||||
ULONG ulMacroSize;
|
||||
char *pMacro;
|
||||
SLONG(*Callback) (struct sSymbol *);
|
||||
SLONG(*Callback) (struct sSymbol *);
|
||||
char tzFileName[_MAX_PATH + 1]; /* File where the symbol was defined. */
|
||||
ULONG nFileLine; /* Line where the symbol was defined. */
|
||||
};
|
||||
#define SYMF_RELOC 0x001 /* symbol will be reloc'ed during
|
||||
* linking, it's absolute value is
|
||||
|
||||
@@ -89,6 +89,8 @@ struct sSymbol {
|
||||
SLONG nSectionID; /* internal to object.c */
|
||||
struct sSection *pSection;
|
||||
SLONG nOffset;
|
||||
char *pzFileName; /* Source file where the symbol was defined. */
|
||||
ULONG nFileLine; /* Line where the symbol was defined. */
|
||||
};
|
||||
|
||||
enum ePatchType {
|
||||
|
||||
@@ -42,8 +42,8 @@ extern FILE *dependfile;
|
||||
/*
|
||||
* defines for nCurrentStatus
|
||||
*/
|
||||
#define STAT_isInclude 0
|
||||
#define STAT_isMacro 1
|
||||
#define STAT_isInclude 0 /* 'Normal' state as well */
|
||||
#define STAT_isMacro 1
|
||||
#define STAT_isMacroArg 2
|
||||
#define STAT_isREPTBlock 3
|
||||
|
||||
@@ -151,6 +151,37 @@ popcontext(void)
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
fstk_GetLine(void)
|
||||
{
|
||||
struct sContext *pLastFile, **ppLastFile;
|
||||
|
||||
switch (nCurrentStatus) {
|
||||
case STAT_isInclude:
|
||||
/* This is the normal mode, also used when including a file. */
|
||||
return nLineNo;
|
||||
case STAT_isMacro:
|
||||
break; /* Peek top file of the stack */
|
||||
case STAT_isMacroArg:
|
||||
return nLineNo; /* ??? */
|
||||
case STAT_isREPTBlock:
|
||||
break; /* Peek top file of the stack */
|
||||
}
|
||||
|
||||
if ((pLastFile = pFileStack) != NULL) {
|
||||
ppLastFile = &pFileStack;
|
||||
while (pLastFile->pNext) {
|
||||
ppLastFile = &(pLastFile->pNext);
|
||||
pLastFile = *ppLastFile;
|
||||
}
|
||||
return pLastFile->nLine;
|
||||
}
|
||||
|
||||
/* This is only reached if the lexer is in REPT or MACRO mode but there
|
||||
* are no saved contexts with the origin of said REPT or MACRO. */
|
||||
fatalerror("fstk_GetLine: Internal error.");
|
||||
}
|
||||
|
||||
int
|
||||
yywrap(void)
|
||||
{
|
||||
|
||||
@@ -282,6 +282,9 @@ writesymbol(struct sSymbol * pSym, FILE * f)
|
||||
fputc(type, f);
|
||||
|
||||
if (type != SYM_IMPORT) {
|
||||
fputstring(pSym->tzFileName, f);
|
||||
fputlong(pSym->nFileLine, f);
|
||||
|
||||
fputlong(sectid, f);
|
||||
fputlong(offset, f);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "asm/asm.h"
|
||||
#include "asm/fstack.h"
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/main.h"
|
||||
#include "asm/mymath.h"
|
||||
@@ -109,6 +110,8 @@ createsymbol(char *s)
|
||||
(*ppsym)->pMacro = NULL;
|
||||
(*ppsym)->pSection = NULL;
|
||||
(*ppsym)->Callback = NULL;
|
||||
strcpy((*ppsym)->tzFileName, tzCurrentFileName);
|
||||
(*ppsym)->nFileLine = fstk_GetLine();
|
||||
return (*ppsym);
|
||||
} else {
|
||||
fatalerror("No memory for symbol");
|
||||
|
||||
@@ -126,7 +126,12 @@ obj_ReadSymbol(FILE * f)
|
||||
}
|
||||
|
||||
readasciiz(&pSym->pzName, f);
|
||||
if ((pSym->Type = (enum eSymbolType) fgetc(f)) != SYM_IMPORT) {
|
||||
pSym->Type = (enum eSymbolType)fgetc(f);
|
||||
|
||||
if (pSym->Type != SYM_IMPORT) {
|
||||
readasciiz(&pSym->pzFileName, f);
|
||||
pSym->nFileLine = readlong(f);
|
||||
|
||||
pSym->nSectionID = readlong(f);
|
||||
pSym->nOffset = readlong(f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user