Remove most Hungarian notation in section module

Seriously, it sucks.
This commit is contained in:
ISSOtm
2020-09-06 20:43:13 +02:00
parent 14be01880d
commit 304bb9f902
10 changed files with 204 additions and 204 deletions

View File

@@ -26,7 +26,7 @@ struct MacroArgs;
struct sContext { struct sContext {
YY_BUFFER_STATE FlexHandle; YY_BUFFER_STATE FlexHandle;
struct Symbol const *pMacro; struct Symbol const *pMacro;
struct sContext *pNext; struct sContext *next;
char tzFileName[_MAX_PATH + 1]; char tzFileName[_MAX_PATH + 1];
struct MacroArgs *macroArgs; struct MacroArgs *macroArgs;
uint32_t uniqueID; uint32_t uniqueID;

View File

@@ -17,17 +17,17 @@
struct Expression; struct Expression;
struct Section { struct Section {
char *pzName; char *name;
enum SectionType nType; enum SectionType type;
enum SectionModifier modifier; enum SectionModifier modifier;
uint32_t size; uint32_t size;
uint32_t nOrg; uint32_t org;
uint32_t nBank; uint32_t bank;
uint8_t nAlign; uint8_t align;
uint16_t alignOfs; uint16_t alignOfs;
struct Section *pNext; struct Section *next;
struct Patch *pPatches; struct Patch *patches;
uint8_t *tData; uint8_t *data;
}; };
struct SectionSpec { struct SectionSpec {
@@ -36,8 +36,8 @@ struct SectionSpec {
uint16_t alignOfs; uint16_t alignOfs;
}; };
struct Section *out_FindSectionByName(const char *pzName); struct Section *out_FindSectionByName(const char *name);
void out_NewSection(char const *pzName, uint32_t secttype, uint32_t org, void out_NewSection(char const *name, uint32_t secttype, uint32_t org,
struct SectionSpec const *attributes, struct SectionSpec const *attributes,
enum SectionModifier mod); enum SectionModifier mod);
void out_SetLoadSection(char const *name, uint32_t secttype, uint32_t org, void out_SetLoadSection(char const *name, uint32_t secttype, uint32_t org,

View File

@@ -71,7 +71,7 @@ static inline bool sym_IsConstant(struct Symbol const *sym)
if (sym->type == SYM_LABEL) { if (sym->type == SYM_LABEL) {
struct Section const *sect = sym_GetSection(sym); struct Section const *sect = sym_GetSection(sym);
return sect && sect->nOrg != -1; return sect && sect->org != -1;
} }
return sym->type == SYM_EQU || sym->type == SYM_SET; return sym->type == SYM_EQU || sym->type == SYM_SET;
} }

View File

@@ -74,7 +74,7 @@ static void pushcontext(void)
ppFileStack = &pFileStack; ppFileStack = &pFileStack;
while (*ppFileStack) while (*ppFileStack)
ppFileStack = &((*ppFileStack)->pNext); ppFileStack = &((*ppFileStack)->next);
*ppFileStack = malloc(sizeof(struct sContext)); *ppFileStack = malloc(sizeof(struct sContext));
@@ -82,7 +82,7 @@ static void pushcontext(void)
fatalerror("No memory for context"); fatalerror("No memory for context");
(*ppFileStack)->FlexHandle = CurrentFlexHandle; (*ppFileStack)->FlexHandle = CurrentFlexHandle;
(*ppFileStack)->pNext = NULL; (*ppFileStack)->next = NULL;
strcpy((char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName); strcpy((char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName);
(*ppFileStack)->nLine = nLineNo; (*ppFileStack)->nLine = nLineNo;
@@ -160,8 +160,8 @@ static int32_t popcontext(void)
return 1; return 1;
ppLastFile = &pFileStack; ppLastFile = &pFileStack;
while (pLastFile->pNext) { while (pLastFile->next) {
ppLastFile = &(pLastFile->pNext); ppLastFile = &(pLastFile->next);
pLastFile = *ppLastFile; pLastFile = *ppLastFile;
} }
@@ -243,8 +243,8 @@ int32_t fstk_GetLine(void)
pLastFile = pFileStack; pLastFile = pFileStack;
if (pLastFile != NULL) { if (pLastFile != NULL) {
while (pLastFile->pNext) { while (pLastFile->next) {
ppLastFile = &(pLastFile->pNext); ppLastFile = &(pLastFile->next);
pLastFile = *ppLastFile; pLastFile = *ppLastFile;
} }
return pLastFile->nLine; return pLastFile->nLine;
@@ -274,7 +274,7 @@ void fstk_Dump(void)
while (pLastFile) { while (pLastFile) {
fprintf(stderr, "%s(%" PRId32 ") -> ", pLastFile->tzFileName, fprintf(stderr, "%s(%" PRId32 ") -> ", pLastFile->tzFileName,
pLastFile->nLine); pLastFile->nLine);
pLastFile = pLastFile->pNext; pLastFile = pLastFile->next;
} }
fprintf(stderr, "%s(%" PRId32 ")", tzCurrentFileName, nLineNo); fprintf(stderr, "%s(%" PRId32 ")", tzCurrentFileName, nLineNo);
@@ -296,7 +296,7 @@ void fstk_DumpToStr(char *buf, size_t buflen)
len = 0; len = 0;
else else
len -= retcode; len -= retcode;
pLastFile = pLastFile->pNext; pLastFile = pLastFile->next;
} }
retcode = snprintf(&buf[buflen - len], len, "%s(%" PRId32 ")", retcode = snprintf(&buf[buflen - len], len, "%s(%" PRId32 ")",

View File

@@ -32,7 +32,7 @@ struct sLexString {
char *tzName; char *tzName;
uint32_t nToken; uint32_t nToken;
uint32_t nNameLength; uint32_t nNameLength;
struct sLexString *pNext; struct sLexString *next;
}; };
#define pLexBufferRealStart (pCurrentBuffer->pBufferRealStart) #define pLexBufferRealStart (pCurrentBuffer->pBufferRealStart)
@@ -492,7 +492,7 @@ void lex_AddStrings(const struct sLexInitString *lex)
ppHash = &tLexHash[hash]; ppHash = &tLexHash[hash];
while (*ppHash) while (*ppHash)
ppHash = &((*ppHash)->pNext); ppHash = &((*ppHash)->next);
*ppHash = malloc(sizeof(struct sLexString)); *ppHash = malloc(sizeof(struct sLexString));
if (*ppHash == NULL) if (*ppHash == NULL)
@@ -504,7 +504,7 @@ void lex_AddStrings(const struct sLexInitString *lex)
(*ppHash)->nNameLength = strlen(lex->tzName); (*ppHash)->nNameLength = strlen(lex->tzName);
(*ppHash)->nToken = lex->nToken; (*ppHash)->nToken = lex->nToken;
(*ppHash)->pNext = NULL; (*ppHash)->next = NULL;
upperstring((*ppHash)->tzName); upperstring((*ppHash)->tzName);
@@ -575,7 +575,7 @@ struct sLexString *yylex_GetLongestFixed(void)
pLongestFixed = lex; pLongestFixed = lex;
break; break;
} }
lex = lex->pNext; lex = lex->next;
} }
} }

View File

@@ -69,7 +69,7 @@ bool warnings; /* True to enable warnings, false to disable them. */
struct sOptionStackEntry { struct sOptionStackEntry {
struct sOptions Options; struct sOptions Options;
struct sOptionStackEntry *pNext; struct sOptionStackEntry *next;
}; };
struct sOptionStackEntry *pOptionStack; struct sOptionStackEntry *pOptionStack;
@@ -196,7 +196,7 @@ void opt_Push(void)
fatalerror("No memory for option stack"); fatalerror("No memory for option stack");
pOpt->Options = CurrentOptions; pOpt->Options = CurrentOptions;
pOpt->pNext = pOptionStack; pOpt->next = pOptionStack;
pOptionStack = pOpt; pOptionStack = pOpt;
} }
@@ -209,7 +209,7 @@ void opt_Pop(void)
pOpt = pOptionStack; pOpt = pOptionStack;
opt_SetCurrentOptions(&(pOpt->Options)); opt_SetCurrentOptions(&(pOpt->Options));
pOptionStack = pOpt->pNext; pOptionStack = pOpt->next;
free(pOpt); free(pOpt);
} }

View File

@@ -37,10 +37,10 @@ struct Patch {
uint32_t nOffset; uint32_t nOffset;
struct Section *pcSection; struct Section *pcSection;
uint32_t pcOffset; uint32_t pcOffset;
uint8_t nType; uint8_t type;
uint32_t nRPNSize; uint32_t nRPNSize;
uint8_t *pRPN; uint8_t *pRPN;
struct Patch *pNext; struct Patch *next;
}; };
struct Assertion { struct Assertion {
@@ -67,13 +67,13 @@ static struct Assertion *assertions = NULL;
*/ */
static uint32_t countsections(void) static uint32_t countsections(void)
{ {
struct Section *pSect; struct Section *sect;
uint32_t count = 0; uint32_t count = 0;
pSect = pSectionList; sect = pSectionList;
while (pSect) { while (sect) {
count++; count++;
pSect = pSect->pNext; sect = sect->next;
} }
return count; return count;
@@ -82,12 +82,12 @@ static uint32_t countsections(void)
/* /*
* Count the number of patches used in this object * Count the number of patches used in this object
*/ */
static uint32_t countpatches(struct Section const *pSect) static uint32_t countpatches(struct Section const *sect)
{ {
uint32_t r = 0; uint32_t r = 0;
for (struct Patch const *patch = pSect->pPatches; patch != NULL; for (struct Patch const *patch = sect->patches; patch != NULL;
patch = patch->pNext) patch = patch->next)
r++; r++;
return r; return r;
@@ -132,7 +132,7 @@ static void fputstring(char const *s, FILE *f)
/* /*
* Return a section's ID * Return a section's ID
*/ */
static uint32_t getsectid(struct Section const *pSect) static uint32_t getsectid(struct Section const *sect)
{ {
struct Section const *sec; struct Section const *sec;
uint32_t ID = 0; uint32_t ID = 0;
@@ -140,13 +140,13 @@ static uint32_t getsectid(struct Section const *pSect)
sec = pSectionList; sec = pSectionList;
while (sec) { while (sec) {
if (sec == pSect) if (sec == sect)
return ID; return ID;
ID++; ID++;
sec = sec->pNext; sec = sec->next;
} }
fatalerror("Unknown section '%s'", pSect->pzName); fatalerror("Unknown section '%s'", sect->name);
} }
static uint32_t getSectIDIfAny(struct Section const *sect) static uint32_t getSectIDIfAny(struct Section const *sect)
@@ -157,42 +157,42 @@ static uint32_t getSectIDIfAny(struct Section const *sect)
/* /*
* Write a patch to a file * Write a patch to a file
*/ */
static void writepatch(struct Patch const *pPatch, FILE *f) static void writepatch(struct Patch const *patch, FILE *f)
{ {
fputstring(pPatch->tzFilename, f); fputstring(patch->tzFilename, f);
fputlong(pPatch->nOffset, f); fputlong(patch->nOffset, f);
fputlong(getSectIDIfAny(pPatch->pcSection), f); fputlong(getSectIDIfAny(patch->pcSection), f);
fputlong(pPatch->pcOffset, f); fputlong(patch->pcOffset, f);
fputc(pPatch->nType, f); fputc(patch->type, f);
fputlong(pPatch->nRPNSize, f); fputlong(patch->nRPNSize, f);
fwrite(pPatch->pRPN, 1, pPatch->nRPNSize, f); fwrite(patch->pRPN, 1, patch->nRPNSize, f);
} }
/* /*
* Write a section to a file * Write a section to a file
*/ */
static void writesection(struct Section const *pSect, FILE *f) static void writesection(struct Section const *sect, FILE *f)
{ {
fputstring(pSect->pzName, f); fputstring(sect->name, f);
fputlong(pSect->size, f); fputlong(sect->size, f);
bool isUnion = pSect->modifier == SECTION_UNION; bool isUnion = sect->modifier == SECTION_UNION;
bool isFragment = pSect->modifier == SECTION_FRAGMENT; bool isFragment = sect->modifier == SECTION_FRAGMENT;
fputc(pSect->nType | isUnion << 7 | isFragment << 6, f); fputc(sect->type | isUnion << 7 | isFragment << 6, f);
fputlong(pSect->nOrg, f); fputlong(sect->org, f);
fputlong(pSect->nBank, f); fputlong(sect->bank, f);
fputc(pSect->nAlign, f); fputc(sect->align, f);
fputlong(pSect->alignOfs, f); fputlong(sect->alignOfs, f);
if (sect_HasData(pSect->nType)) { if (sect_HasData(sect->type)) {
fwrite(pSect->tData, 1, pSect->size, f); fwrite(sect->data, 1, sect->size, f);
fputlong(countpatches(pSect), f); fputlong(countpatches(sect), f);
for (struct Patch const *patch = pSect->pPatches; patch != NULL; for (struct Patch const *patch = sect->patches; patch != NULL;
patch = patch->pNext) patch = patch->next)
writepatch(patch, f); writepatch(patch, f);
} }
} }
@@ -307,39 +307,39 @@ static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
static struct Patch *allocpatch(uint32_t type, struct Expression const *expr, static struct Patch *allocpatch(uint32_t type, struct Expression const *expr,
uint32_t ofs) uint32_t ofs)
{ {
struct Patch *pPatch = malloc(sizeof(struct Patch)); struct Patch *patch = malloc(sizeof(struct Patch));
uint32_t rpnSize = expr->isKnown ? 5 : expr->nRPNPatchSize; uint32_t rpnSize = expr->isKnown ? 5 : expr->nRPNPatchSize;
if (!pPatch) if (!patch)
fatalerror("No memory for patch: %s", strerror(errno)); fatalerror("No memory for patch: %s", strerror(errno));
pPatch->pRPN = malloc(sizeof(*pPatch->pRPN) * rpnSize); patch->pRPN = malloc(sizeof(*patch->pRPN) * rpnSize);
if (!pPatch->pRPN) if (!patch->pRPN)
fatalerror("No memory for patch's RPN expression: %s", fatalerror("No memory for patch's RPN expression: %s",
strerror(errno)); strerror(errno));
pPatch->nType = type; patch->type = type;
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename)); fstk_DumpToStr(patch->tzFilename, sizeof(patch->tzFilename));
pPatch->nOffset = ofs; patch->nOffset = ofs;
pPatch->pcSection = sect_GetSymbolSection(); patch->pcSection = sect_GetSymbolSection();
pPatch->pcOffset = sect_GetSymbolOffset(); patch->pcOffset = sect_GetSymbolOffset();
/* If the expression's value is known, output a constant RPN expression directly */ /* If the expression's value is known, output a constant RPN expression directly */
if (expr->isKnown) { if (expr->isKnown) {
pPatch->nRPNSize = rpnSize; patch->nRPNSize = rpnSize;
/* Make sure to update `rpnSize` above if modifying this! */ /* Make sure to update `rpnSize` above if modifying this! */
pPatch->pRPN[0] = RPN_CONST; patch->pRPN[0] = RPN_CONST;
pPatch->pRPN[1] = (uint32_t)(expr->nVal) & 0xFF; patch->pRPN[1] = (uint32_t)(expr->nVal) & 0xFF;
pPatch->pRPN[2] = (uint32_t)(expr->nVal) >> 8; patch->pRPN[2] = (uint32_t)(expr->nVal) >> 8;
pPatch->pRPN[3] = (uint32_t)(expr->nVal) >> 16; patch->pRPN[3] = (uint32_t)(expr->nVal) >> 16;
pPatch->pRPN[4] = (uint32_t)(expr->nVal) >> 24; patch->pRPN[4] = (uint32_t)(expr->nVal) >> 24;
} else { } else {
pPatch->nRPNSize = 0; patch->nRPNSize = 0;
writerpn(pPatch->pRPN, &pPatch->nRPNSize, expr->tRPN, expr->nRPNLength); writerpn(patch->pRPN, &patch->nRPNSize, expr->tRPN, expr->nRPNLength);
} }
assert(pPatch->nRPNSize == rpnSize); assert(patch->nRPNSize == rpnSize);
return pPatch; return patch;
} }
/* /*
@@ -347,10 +347,10 @@ static struct Patch *allocpatch(uint32_t type, struct Expression const *expr,
*/ */
void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs) void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs)
{ {
struct Patch *pPatch = allocpatch(type, expr, ofs); struct Patch *patch = allocpatch(type, expr, ofs);
pPatch->pNext = pCurrentSection->pPatches; patch->next = pCurrentSection->patches;
pCurrentSection->pPatches = pPatch; pCurrentSection->patches = patch;
} }
/** /**
@@ -415,7 +415,7 @@ void out_WriteObject(void)
for (struct Symbol const *sym = objectSymbols; sym; sym = sym->next) for (struct Symbol const *sym = objectSymbols; sym; sym = sym->next)
writesymbol(sym, f); writesymbol(sym, f);
for (struct Section *sect = pSectionList; sect; sect = sect->pNext) for (struct Section *sect = pSectionList; sect; sect = sect->next)
writesection(sect, f); writesection(sect, f);
fputlong(countasserts(), f); fputlong(countasserts(), f);

View File

@@ -147,12 +147,12 @@ void rpn_BankSelf(struct Expression *expr)
if (!pCurrentSection) { if (!pCurrentSection) {
yyerror("PC has no bank outside a section"); yyerror("PC has no bank outside a section");
expr->nVal = 1; expr->nVal = 1;
} else if (pCurrentSection->nBank == -1) { } else if (pCurrentSection->bank == -1) {
makeUnknown(expr, "Current section's bank is not known"); makeUnknown(expr, "Current section's bank is not known");
expr->nRPNPatchSize++; expr->nRPNPatchSize++;
*reserveSpace(expr, 1) = RPN_BANK_SELF; *reserveSpace(expr, 1) = RPN_BANK_SELF;
} else { } else {
expr->nVal = pCurrentSection->nBank; expr->nVal = pCurrentSection->bank;
} }
} }
@@ -175,9 +175,9 @@ void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
/* If the symbol didn't exist, `sym_Ref` created it */ /* If the symbol didn't exist, `sym_Ref` created it */
sym = sym_FindSymbol(tzSym); sym = sym_FindSymbol(tzSym);
if (sym_GetSection(sym) && sym_GetSection(sym)->nBank != -1) { if (sym_GetSection(sym) && sym_GetSection(sym)->bank != -1) {
/* Symbol's section is known and bank is fixed */ /* Symbol's section is known and bank is fixed */
expr->nVal = sym_GetSection(sym)->nBank; expr->nVal = sym_GetSection(sym)->bank;
} else { } else {
makeUnknown(expr, "\"%s\"'s bank is not known", tzSym); makeUnknown(expr, "\"%s\"'s bank is not known", tzSym);
expr->nRPNPatchSize += 5; /* opcode + 4-byte sect ID */ expr->nRPNPatchSize += 5; /* opcode + 4-byte sect ID */
@@ -196,8 +196,8 @@ void rpn_BankSection(struct Expression *expr, char const *tzSectionName)
struct Section *pSection = out_FindSectionByName(tzSectionName); struct Section *pSection = out_FindSectionByName(tzSectionName);
if (pSection && pSection->nBank != -1) { if (pSection && pSection->bank != -1) {
expr->nVal = pSection->nBank; expr->nVal = pSection->bank;
} else { } else {
makeUnknown(expr, "Section \"%s\"'s bank is not known", makeUnknown(expr, "Section \"%s\"'s bank is not known",
tzSectionName); tzSectionName);

View File

@@ -20,7 +20,7 @@ struct SectionStackEntry {
struct Section *pSection; struct Section *pSection;
struct Symbol *pScope; /* Section's symbol scope */ struct Symbol *pScope; /* Section's symbol scope */
uint32_t offset; uint32_t offset;
struct SectionStackEntry *pNext; struct SectionStackEntry *next;
}; };
struct SectionStackEntry *pSectionStack; struct SectionStackEntry *pSectionStack;
@@ -51,18 +51,18 @@ static inline void checkcodesection(void)
{ {
checksection(); checksection();
if (!sect_HasData(pCurrentSection->nType)) if (!sect_HasData(pCurrentSection->type))
fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)", fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)",
pCurrentSection->pzName); pCurrentSection->name);
} }
static inline void checkSectionSize(struct Section const *sect, uint32_t size) static inline void checkSectionSize(struct Section const *sect, uint32_t size)
{ {
uint32_t maxSize = maxsize[sect->nType]; uint32_t maxSize = maxsize[sect->type];
if (size > maxSize) if (size > maxSize)
fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32 " bytes, reached 0x%" PRIX32 ").", fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32 " bytes, reached 0x%" PRIX32 ").",
sect->pzName, maxSize, size); sect->name, maxSize, size);
} }
/* /*
@@ -81,15 +81,15 @@ static inline void reserveSpace(uint32_t delta_size)
checkSectionSize(currentLoadSection, curOffset + delta_size); checkSectionSize(currentLoadSection, curOffset + delta_size);
} }
struct Section *out_FindSectionByName(const char *pzName) struct Section *out_FindSectionByName(const char *name)
{ {
struct Section *pSect = pSectionList; struct Section *sect = pSectionList;
while (pSect) { while (sect) {
if (strcmp(pzName, pSect->pzName) == 0) if (strcmp(name, sect->name) == 0)
return pSect; return sect;
pSect = pSect->pNext; sect = sect->next;
} }
return NULL; return NULL;
@@ -98,7 +98,7 @@ struct Section *out_FindSectionByName(const char *pzName)
/* /*
* Find a section by name and type. If it doesn't exist, create it * Find a section by name and type. If it doesn't exist, create it
*/ */
static struct Section *getSection(char const *pzName, enum SectionType type, static struct Section *getSection(char const *name, enum SectionType type,
uint32_t org, struct SectionSpec const *attrs, uint32_t org, struct SectionSpec const *attrs,
enum SectionModifier mod) enum SectionModifier mod)
{ {
@@ -131,26 +131,26 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
if (org != -1) { if (org != -1) {
if ((org - alignOffset) & mask) if ((org - alignOffset) & mask)
yyerror("Section \"%s\"'s fixed address doesn't match its alignment", yyerror("Section \"%s\"'s fixed address doesn't match its alignment",
pzName); name);
alignment = 0; /* Ignore it if it's satisfied */ alignment = 0; /* Ignore it if it's satisfied */
} else if (startaddr[type] & mask) { } else if (startaddr[type] & mask) {
yyerror("Section \"%s\"'s alignment cannot be attained in %s", yyerror("Section \"%s\"'s alignment cannot be attained in %s",
pzName, typeNames[type]); name, typeNames[type]);
} }
} }
if (org != -1) { if (org != -1) {
if (org < startaddr[type] || org > endaddr(type)) if (org < startaddr[type] || org > endaddr(type))
yyerror("Section \"%s\"'s fixed address %#" PRIx32 " is outside of range [%#" PRIx16 "; %#" PRIx16 "]", yyerror("Section \"%s\"'s fixed address %#" PRIx32 " is outside of range [%#" PRIx16 "; %#" PRIx16 "]",
pzName, org, startaddr[type], endaddr(type)); name, org, startaddr[type], endaddr(type));
} }
if (nbbanks(type) == 1) if (nbbanks(type) == 1)
bank = bankranges[type][0]; bank = bankranges[type][0];
struct Section *pSect = out_FindSectionByName(pzName); struct Section *sect = out_FindSectionByName(name);
if (pSect) { if (sect) {
unsigned int nbSectErrors = 0; unsigned int nbSectErrors = 0;
#define fail(...) \ #define fail(...) \
do { \ do { \
@@ -158,13 +158,13 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
nbSectErrors++; \ nbSectErrors++; \
} while (0) } while (0)
if (type != pSect->nType) if (type != sect->type)
fail("Section \"%s\" already exists but with type %s", fail("Section \"%s\" already exists but with type %s",
pSect->pzName, typeNames[pSect->nType]); sect->name, typeNames[sect->type]);
if (pSect->modifier != mod) if (sect->modifier != mod)
fail("Section \"%s\" already declared as %s section", fail("Section \"%s\" already declared as %s section",
pSect->pzName, sectionModNames[pSect->modifier]); sect->name, sectionModNames[sect->modifier]);
/* /*
* Normal sections need to have exactly identical constraints; * Normal sections need to have exactly identical constraints;
* but unionized sections only need "compatible" constraints, * but unionized sections only need "compatible" constraints,
@@ -179,125 +179,125 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
fail("Cannot declare ROM sections as UNION"); fail("Cannot declare ROM sections as UNION");
if (org != -1) { if (org != -1) {
/* If both are fixed, they must be the same */ /* If both are fixed, they must be the same */
if (pSect->nOrg != -1 && pSect->nOrg != org) if (sect->org != -1 && sect->org != org)
fail("Section \"%s\" already declared as fixed at different address $%" PRIx32, fail("Section \"%s\" already declared as fixed at different address $%" PRIx32,
pSect->pzName, pSect->nOrg); sect->name, sect->org);
else if (pSect->nAlign != 0 else if (sect->align != 0
&& (mask(pSect->nAlign) && (mask(sect->align)
& (org - pSect->alignOfs))) & (org - sect->alignOfs)))
fail("Section \"%s\" already declared as aligned to %u bytes (offset %" PRIu16 ")", fail("Section \"%s\" already declared as aligned to %u bytes (offset %" PRIu16 ")",
pSect->pzName, 1U << pSect->nAlign, sect->name, 1U << sect->align,
pSect->alignOfs); sect->alignOfs);
else else
/* Otherwise, just override */ /* Otherwise, just override */
pSect->nOrg = org; sect->org = org;
} else if (alignment != 0) { } else if (alignment != 0) {
/* Make sure any fixed address is compatible */ /* Make sure any fixed address is compatible */
if (pSect->nOrg != -1) { if (sect->org != -1) {
if ((pSect->nOrg - alignOffset) if ((sect->org - alignOffset)
& mask(alignment)) & mask(alignment))
fail("Section \"%s\" already declared as fixed at incompatible address $%" PRIx32, fail("Section \"%s\" already declared as fixed at incompatible address $%" PRIx32,
pSect->pzName, sect->name,
pSect->nOrg); sect->org);
/* Check if alignment offsets are compatible */ /* Check if alignment offsets are compatible */
} else if ((alignOffset & mask(pSect->nAlign)) } else if ((alignOffset & mask(sect->align))
!= (pSect->alignOfs != (sect->alignOfs
& mask(alignment))) { & mask(alignment))) {
fail("Section \"%s\" already declared with incompatible %" PRIu8 "-byte alignment (offset %" PRIu16 ")", fail("Section \"%s\" already declared with incompatible %" PRIu8 "-byte alignment (offset %" PRIu16 ")",
pSect->pzName, pSect->nAlign, sect->name, sect->align,
pSect->alignOfs); sect->alignOfs);
} else if (alignment > pSect->nAlign) { } else if (alignment > sect->align) {
/* /*
* If the section is not fixed, * If the section is not fixed,
* its alignment is the largest of both * its alignment is the largest of both
*/ */
pSect->nAlign = alignment; sect->align = alignment;
pSect->alignOfs = alignOffset; sect->alignOfs = alignOffset;
} }
} }
/* If the section's bank is unspecified, override it */ /* If the section's bank is unspecified, override it */
if (pSect->nBank == -1) if (sect->bank == -1)
pSect->nBank = bank; sect->bank = bank;
/* If both specify a bank, it must be the same one */ /* If both specify a bank, it must be the same one */
else if (bank != -1 && pSect->nBank != bank) else if (bank != -1 && sect->bank != bank)
fail("Section \"%s\" already declared with different bank %" PRIu32, fail("Section \"%s\" already declared with different bank %" PRIu32,
pSect->pzName, pSect->nBank); sect->name, sect->bank);
} else { /* Section fragments are handled identically in RGBASM */ } else { /* Section fragments are handled identically in RGBASM */
/* However, concaternating non-fragments will be made an error */ /* However, concaternating non-fragments will be made an error */
if (pSect->modifier != SECTION_FRAGMENT || mod != SECTION_FRAGMENT) if (sect->modifier != SECTION_FRAGMENT || mod != SECTION_FRAGMENT)
warning(WARNING_OBSOLETE, "Concatenation of non-fragment sections is deprecated"); warning(WARNING_OBSOLETE, "Concatenation of non-fragment sections is deprecated");
if (org != pSect->nOrg) { if (org != sect->org) {
if (pSect->nOrg == -1) if (sect->org == -1)
fail("Section \"%s\" already declared as floating", fail("Section \"%s\" already declared as floating",
pSect->pzName); sect->name);
else else
fail("Section \"%s\" already declared as fixed at $%" PRIx32, fail("Section \"%s\" already declared as fixed at $%" PRIx32,
pSect->pzName, pSect->nOrg); sect->name, sect->org);
} }
if (bank != pSect->nBank) { if (bank != sect->bank) {
if (pSect->nBank == -1) if (sect->bank == -1)
fail("Section \"%s\" already declared as floating bank", fail("Section \"%s\" already declared as floating bank",
pSect->pzName); sect->name);
else else
fail("Section \"%s\" already declared as fixed at bank %" PRIu32, fail("Section \"%s\" already declared as fixed at bank %" PRIu32,
pSect->pzName, pSect->nBank); sect->name, sect->bank);
} }
if (alignment != pSect->nAlign) { if (alignment != sect->align) {
if (pSect->nAlign == 0) if (sect->align == 0)
fail("Section \"%s\" already declared as unaligned", fail("Section \"%s\" already declared as unaligned",
pSect->pzName); sect->name);
else else
fail("Section \"%s\" already declared as aligned to %u bytes", fail("Section \"%s\" already declared as aligned to %u bytes",
pSect->pzName, sect->name,
1U << pSect->nAlign); 1U << sect->align);
} }
} }
if (nbSectErrors) if (nbSectErrors)
fatalerror("Cannot create section \"%s\" (%u errors)", fatalerror("Cannot create section \"%s\" (%u errors)",
pSect->pzName, nbSectErrors); sect->name, nbSectErrors);
#undef fail #undef fail
return pSect; return sect;
} }
pSect = malloc(sizeof(*pSect)); sect = malloc(sizeof(*sect));
if (pSect == NULL) if (sect == NULL)
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section");
pSect->pzName = strdup(pzName); sect->name = strdup(name);
if (pSect->pzName == NULL) if (sect->name == NULL)
fatalerror("Not enough memory for sectionname"); fatalerror("Not enough memory for sectionname");
pSect->nType = type; sect->type = type;
pSect->modifier = mod; sect->modifier = mod;
pSect->size = 0; sect->size = 0;
pSect->nOrg = org; sect->org = org;
pSect->nBank = bank; sect->bank = bank;
pSect->nAlign = alignment; sect->align = alignment;
pSect->alignOfs = alignOffset; sect->alignOfs = alignOffset;
pSect->pNext = pSectionList; sect->next = pSectionList;
pSect->pPatches = NULL; sect->patches = NULL;
/* It is only needed to allocate memory for ROM sections. */ /* It is only needed to allocate memory for ROM sections. */
if (sect_HasData(type)) { if (sect_HasData(type)) {
uint32_t sectsize; uint32_t sectsize;
sectsize = maxsize[type]; sectsize = maxsize[type];
pSect->tData = malloc(sectsize); sect->data = malloc(sectsize);
if (pSect->tData == NULL) if (sect->data == NULL)
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section");
} else { } else {
pSect->tData = NULL; sect->data = NULL;
} }
/* /*
* Add the new section to the list * Add the new section to the list
* at the beginning because order doesn't matter * at the beginning because order doesn't matter
*/ */
pSectionList = pSect; pSectionList = sect;
return pSect; return sect;
#undef mask #undef mask
} }
@@ -315,17 +315,17 @@ static void changeSection(void)
/* /*
* Set the current section by name and type * Set the current section by name and type
*/ */
void out_NewSection(char const *pzName, uint32_t type, uint32_t org, void out_NewSection(char const *name, uint32_t type, uint32_t org,
struct SectionSpec const *attribs, enum SectionModifier mod) struct SectionSpec const *attribs, enum SectionModifier mod)
{ {
if (currentLoadSection) if (currentLoadSection)
fatalerror("Cannot change the section within a `LOAD` block"); fatalerror("Cannot change the section within a `LOAD` block");
struct Section *pSect = getSection(pzName, type, org, attribs, mod); struct Section *sect = getSection(name, type, org, attribs, mod);
changeSection(); changeSection();
curOffset = mod == SECTION_UNION ? 0 : pSect->size; curOffset = mod == SECTION_UNION ? 0 : sect->size;
pCurrentSection = pSect; pCurrentSection = sect;
} }
/* /*
@@ -339,12 +339,12 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
if (currentLoadSection) if (currentLoadSection)
fatalerror("`LOAD` blocks cannot be nested"); fatalerror("`LOAD` blocks cannot be nested");
struct Section *pSect = getSection(name, type, org, attribs, false); struct Section *sect = getSection(name, type, org, attribs, false);
loadOffset = curOffset; loadOffset = curOffset;
curOffset = 0; /* curOffset -= loadOffset; */ curOffset = 0; /* curOffset -= loadOffset; */
changeSection(); changeSection();
currentLoadSection = pSect; currentLoadSection = sect;
} }
void out_EndLoadSection(void) void out_EndLoadSection(void)
@@ -380,22 +380,22 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
{ {
struct Section *sect = sect_GetSymbolSection(); struct Section *sect = sect_GetSymbolSection();
if (sect->nOrg != -1) { if (sect->org != -1) {
if ((sym_GetPCValue() - offset) % (1 << alignment)) if ((sym_GetPCValue() - offset) % (1 << alignment))
yyerror("Section's fixed address fails required alignment (PC = $%04" PRIx32 ")", yyerror("Section's fixed address fails required alignment (PC = $%04" PRIx32 ")",
sym_GetPCValue()); sym_GetPCValue());
} else if (sect->nAlign != 0) { } else if (sect->align != 0) {
if ((((sect->alignOfs + curOffset) % (1 << sect->nAlign)) if ((((sect->alignOfs + curOffset) % (1 << sect->align))
- offset) % (1 << alignment)) { - offset) % (1 << alignment)) {
yyerror("Section's alignment fails required alignment (offset from section start = $%04" PRIx32 ")", yyerror("Section's alignment fails required alignment (offset from section start = $%04" PRIx32 ")",
curOffset); curOffset);
} else if (alignment > sect->nAlign) { } else if (alignment > sect->align) {
sect->nAlign = alignment; sect->align = alignment;
sect->alignOfs = sect->alignOfs =
(offset - curOffset) % (1 << alignment); (offset - curOffset) % (1 << alignment);
} }
} else { } else {
sect->nAlign = alignment; sect->align = alignment;
sect->alignOfs = offset; sect->alignOfs = offset;
} }
} }
@@ -411,7 +411,7 @@ static inline void growSection(uint32_t growth)
static inline void writebyte(uint8_t byte) static inline void writebyte(uint8_t byte)
{ {
pCurrentSection->tData[sect_GetOutputOffset()] = byte; pCurrentSection->data[sect_GetOutputOffset()] = byte;
growSection(1); growSection(1);
} }
@@ -439,7 +439,7 @@ void sect_StartUnion(void)
{ {
if (!pCurrentSection) if (!pCurrentSection)
fatalerror("UNIONs must be inside a SECTION"); fatalerror("UNIONs must be inside a SECTION");
if (sect_HasData(pCurrentSection->nType)) if (sect_HasData(pCurrentSection->type))
fatalerror("Cannot use UNION inside of ROM0 or ROMX sections"); fatalerror("Cannot use UNION inside of ROM0 or ROMX sections");
struct UnionStackEntry *entry = malloc(sizeof(*entry)); struct UnionStackEntry *entry = malloc(sizeof(*entry));
@@ -513,10 +513,10 @@ void out_Skip(int32_t skip, bool ds)
checksection(); checksection();
reserveSpace(skip); reserveSpace(skip);
if (!ds && sect_HasData(pCurrentSection->nType)) if (!ds && sect_HasData(pCurrentSection->type))
warning(WARNING_EMPTY_DATA_DIRECTIVE, "db/dw/dl directive without data in ROM"); warning(WARNING_EMPTY_DATA_DIRECTIVE, "db/dw/dl directive without data in ROM");
if (!sect_HasData(pCurrentSection->nType)) { if (!sect_HasData(pCurrentSection->type)) {
growSection(skip); growSection(skip);
} else { } else {
checkcodesection(); checkcodesection();
@@ -781,17 +781,17 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
*/ */
void out_PushSection(void) void out_PushSection(void)
{ {
struct SectionStackEntry *pSect; struct SectionStackEntry *sect;
pSect = malloc(sizeof(struct SectionStackEntry)); sect = malloc(sizeof(struct SectionStackEntry));
if (pSect == NULL) if (sect == NULL)
fatalerror("No memory for section stack"); fatalerror("No memory for section stack");
pSect->pSection = pCurrentSection; sect->pSection = pCurrentSection;
pSect->pScope = sym_GetCurrentSymbolScope(); sect->pScope = sym_GetCurrentSymbolScope();
pSect->offset = curOffset; sect->offset = curOffset;
pSect->pNext = pSectionStack; sect->next = pSectionStack;
pSectionStack = pSect; pSectionStack = sect;
/* TODO: maybe set current section to NULL? */ /* TODO: maybe set current section to NULL? */
} }
@@ -803,14 +803,14 @@ void out_PopSection(void)
if (currentLoadSection) if (currentLoadSection)
fatalerror("Cannot change the section within a `LOAD` block!"); fatalerror("Cannot change the section within a `LOAD` block!");
struct SectionStackEntry *pSect; struct SectionStackEntry *sect;
pSect = pSectionStack; sect = pSectionStack;
changeSection(); changeSection();
pCurrentSection = pSect->pSection; pCurrentSection = sect->pSection;
sym_SetCurrentSymbolScope(pSect->pScope); sym_SetCurrentSymbolScope(sect->pScope);
curOffset = pSect->offset; curOffset = sect->offset;
pSectionStack = pSect->pNext; pSectionStack = sect->next;
free(pSect); free(sect);
} }

View File

@@ -89,7 +89,7 @@ static int32_t CallbackPC(void)
{ {
struct Section const *section = sect_GetSymbolSection(); struct Section const *section = sect_GetSymbolSection();
return section ? section->nOrg + sect_GetSymbolOffset() : 0; return section ? section->org + sect_GetSymbolOffset() : 0;
} }
/* /*
@@ -102,7 +102,7 @@ int32_t sym_GetValue(struct Symbol const *sym)
if (sym->type == SYM_LABEL) if (sym->type == SYM_LABEL)
/* TODO: do not use section's org directly */ /* TODO: do not use section's org directly */
return sym->value + sym_GetSection(sym)->nOrg; return sym->value + sym_GetSection(sym)->org;
return sym->value; return sym->value;
} }
@@ -222,7 +222,7 @@ uint32_t sym_GetPCValue(void)
if (!sect) if (!sect)
yyerror("PC has no value outside a section"); yyerror("PC has no value outside a section");
else if (sect->nOrg == -1) else if (sect->org == -1)
yyerror("Expected constant PC but section is not fixed"); yyerror("Expected constant PC but section is not fixed");
else else
return CallbackPC(); return CallbackPC();