mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Move curOffset into section code
Improves organization
This commit is contained in:
@@ -26,8 +26,6 @@ extern uint32_t ulNewMacroSize;
|
||||
extern int32_t nGBGfxID;
|
||||
extern int32_t nBinaryID;
|
||||
|
||||
extern uint32_t curOffset; /* Offset into the current section */
|
||||
|
||||
extern struct sOptions DefaultOptions;
|
||||
extern struct sOptions CurrentOptions;
|
||||
extern bool haltnop;
|
||||
|
||||
@@ -45,6 +45,8 @@ void out_SetLoadSection(char const *name, uint32_t secttype, uint32_t org,
|
||||
void out_EndLoadSection(void);
|
||||
|
||||
struct Section *sect_GetSymbolSection(void);
|
||||
uint32_t sect_GetSymbolOffset(void);
|
||||
void sect_SetSymbolOffset(uint32_t ofs);
|
||||
uint32_t sect_GetOutputOffset(void);
|
||||
void sect_AlignPC(uint8_t alignment, uint16_t offset);
|
||||
|
||||
|
||||
@@ -394,19 +394,19 @@ static void startUnion(void)
|
||||
if (nUnionDepth > MAXUNIONS)
|
||||
fatalerror("Too many nested UNIONs");
|
||||
|
||||
unionStart[unionIndex] = curOffset;
|
||||
unionStart[unionIndex] = sect_GetOutputOffset();
|
||||
unionSize[unionIndex] = 0;
|
||||
}
|
||||
|
||||
static void updateUnion(void)
|
||||
{
|
||||
uint32_t unionIndex = nUnionDepth - 1;
|
||||
uint32_t size = curOffset - unionStart[unionIndex];
|
||||
uint32_t size = sect_GetOutputOffset() - unionStart[unionIndex];
|
||||
|
||||
if (size > unionSize[unionIndex])
|
||||
unionSize[unionIndex] = size;
|
||||
|
||||
curOffset = unionStart[unionIndex];
|
||||
sect_SetSymbolOffset(unionStart[unionIndex]);
|
||||
}
|
||||
|
||||
static size_t strlenUTF8(const char *s)
|
||||
@@ -993,7 +993,7 @@ endu : T_POP_ENDU {
|
||||
updateUnion();
|
||||
|
||||
nUnionDepth--;
|
||||
curOffset = unionStart[nUnionDepth] + unionSize[nUnionDepth];
|
||||
sect_SetSymbolOffset(unionStart[nUnionDepth] + unionSize[nUnionDepth]);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ bool skipElif;
|
||||
uint32_t unionStart[128], unionSize[128];
|
||||
|
||||
int32_t nLineNo;
|
||||
uint32_t curOffset;
|
||||
|
||||
#if defined(YYDEBUG) && YYDEBUG
|
||||
extern int yydebug;
|
||||
|
||||
@@ -322,7 +322,7 @@ static struct Patch *allocpatch(uint32_t type, struct Expression const *expr,
|
||||
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
|
||||
pPatch->nOffset = ofs;
|
||||
pPatch->pcSection = sect_GetSymbolSection();
|
||||
pPatch->pcOffset = curOffset;
|
||||
pPatch->pcOffset = sect_GetSymbolOffset();
|
||||
|
||||
/* If the expression's value is known, output a constant RPN expression directly */
|
||||
if (expr->isKnown) {
|
||||
|
||||
@@ -24,8 +24,9 @@ struct SectionStackEntry {
|
||||
};
|
||||
|
||||
struct SectionStackEntry *pSectionStack;
|
||||
uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */
|
||||
static struct Section *currentLoadSection = NULL;
|
||||
uint32_t loadOffset = 0; /* The offset of the LOAD section within its parent */
|
||||
uint32_t loadOffset; /* The offset of the LOAD section within its parent */
|
||||
|
||||
/*
|
||||
* A quick check to see if we have an initialized section
|
||||
@@ -358,6 +359,19 @@ struct Section *sect_GetSymbolSection(void)
|
||||
return currentLoadSection ? currentLoadSection : pCurrentSection;
|
||||
}
|
||||
|
||||
/*
|
||||
* The offset into the section above
|
||||
*/
|
||||
uint32_t sect_GetSymbolOffset(void)
|
||||
{
|
||||
return curOffset;
|
||||
}
|
||||
|
||||
void sect_SetSymbolOffset(uint32_t ofs)
|
||||
{
|
||||
curOffset = ofs;
|
||||
}
|
||||
|
||||
uint32_t sect_GetOutputOffset(void)
|
||||
{
|
||||
return curOffset + loadOffset;
|
||||
|
||||
@@ -89,7 +89,7 @@ static int32_t CallbackPC(void)
|
||||
{
|
||||
struct Section const *section = sect_GetSymbolSection();
|
||||
|
||||
return section ? section->nOrg + curOffset : 0;
|
||||
return section ? section->nOrg + sect_GetSymbolOffset() : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -414,7 +414,7 @@ struct Symbol *sym_AddReloc(char const *symName)
|
||||
|
||||
sym->type = SYM_LABEL;
|
||||
sym->callback = NULL;
|
||||
sym->value = curOffset;
|
||||
sym->value = sect_GetSymbolOffset();
|
||||
|
||||
if (exportall)
|
||||
sym->isExported = true;
|
||||
|
||||
Reference in New Issue
Block a user