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:
Antonio Niño Díaz
2017-07-22 14:17:27 +01:00
parent 3dec5698db
commit 4dc376b0ee
7 changed files with 52 additions and 4 deletions

View File

@@ -41,6 +41,8 @@ extern void fstk_RunRept(ULONG count);
FILE *
fstk_FindFile(char *);
int fstk_GetLine(void);
extern int yywrap(void);
#endif

View File

@@ -16,6 +16,8 @@ struct sSymbol {
ULONG ulMacroSize;
char *pMacro;
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

View File

@@ -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 {

View File

@@ -42,7 +42,7 @@ extern FILE *dependfile;
/*
* defines for nCurrentStatus
*/
#define STAT_isInclude 0
#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)
{

View File

@@ -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);
}

View File

@@ -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");

View File

@@ -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);
}