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 {
YY_BUFFER_STATE FlexHandle;
struct Symbol const *pMacro;
struct sContext *pNext;
struct sContext *next;
char tzFileName[_MAX_PATH + 1];
struct MacroArgs *macroArgs;
uint32_t uniqueID;

View File

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

View File

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

View File

@@ -32,7 +32,7 @@ struct sLexString {
char *tzName;
uint32_t nToken;
uint32_t nNameLength;
struct sLexString *pNext;
struct sLexString *next;
};
#define pLexBufferRealStart (pCurrentBuffer->pBufferRealStart)
@@ -492,7 +492,7 @@ void lex_AddStrings(const struct sLexInitString *lex)
ppHash = &tLexHash[hash];
while (*ppHash)
ppHash = &((*ppHash)->pNext);
ppHash = &((*ppHash)->next);
*ppHash = malloc(sizeof(struct sLexString));
if (*ppHash == NULL)
@@ -504,7 +504,7 @@ void lex_AddStrings(const struct sLexInitString *lex)
(*ppHash)->nNameLength = strlen(lex->tzName);
(*ppHash)->nToken = lex->nToken;
(*ppHash)->pNext = NULL;
(*ppHash)->next = NULL;
upperstring((*ppHash)->tzName);
@@ -575,7 +575,7 @@ struct sLexString *yylex_GetLongestFixed(void)
pLongestFixed = lex;
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 sOptions Options;
struct sOptionStackEntry *pNext;
struct sOptionStackEntry *next;
};
struct sOptionStackEntry *pOptionStack;
@@ -196,7 +196,7 @@ void opt_Push(void)
fatalerror("No memory for option stack");
pOpt->Options = CurrentOptions;
pOpt->pNext = pOptionStack;
pOpt->next = pOptionStack;
pOptionStack = pOpt;
}
@@ -209,7 +209,7 @@ void opt_Pop(void)
pOpt = pOptionStack;
opt_SetCurrentOptions(&(pOpt->Options));
pOptionStack = pOpt->pNext;
pOptionStack = pOpt->next;
free(pOpt);
}

View File

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

View File

@@ -147,12 +147,12 @@ void rpn_BankSelf(struct Expression *expr)
if (!pCurrentSection) {
yyerror("PC has no bank outside a section");
expr->nVal = 1;
} else if (pCurrentSection->nBank == -1) {
} else if (pCurrentSection->bank == -1) {
makeUnknown(expr, "Current section's bank is not known");
expr->nRPNPatchSize++;
*reserveSpace(expr, 1) = RPN_BANK_SELF;
} 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 */
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 */
expr->nVal = sym_GetSection(sym)->nBank;
expr->nVal = sym_GetSection(sym)->bank;
} else {
makeUnknown(expr, "\"%s\"'s bank is not known", tzSym);
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);
if (pSection && pSection->nBank != -1) {
expr->nVal = pSection->nBank;
if (pSection && pSection->bank != -1) {
expr->nVal = pSection->bank;
} else {
makeUnknown(expr, "Section \"%s\"'s bank is not known",
tzSectionName);

View File

@@ -20,7 +20,7 @@ struct SectionStackEntry {
struct Section *pSection;
struct Symbol *pScope; /* Section's symbol scope */
uint32_t offset;
struct SectionStackEntry *pNext;
struct SectionStackEntry *next;
};
struct SectionStackEntry *pSectionStack;
@@ -51,18 +51,18 @@ static inline void checkcodesection(void)
{
checksection();
if (!sect_HasData(pCurrentSection->nType))
if (!sect_HasData(pCurrentSection->type))
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)
{
uint32_t maxSize = maxsize[sect->nType];
uint32_t maxSize = maxsize[sect->type];
if (size > maxSize)
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);
}
struct Section *out_FindSectionByName(const char *pzName)
struct Section *out_FindSectionByName(const char *name)
{
struct Section *pSect = pSectionList;
struct Section *sect = pSectionList;
while (pSect) {
if (strcmp(pzName, pSect->pzName) == 0)
return pSect;
while (sect) {
if (strcmp(name, sect->name) == 0)
return sect;
pSect = pSect->pNext;
sect = sect->next;
}
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
*/
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,
enum SectionModifier mod)
{
@@ -131,26 +131,26 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
if (org != -1) {
if ((org - alignOffset) & mask)
yyerror("Section \"%s\"'s fixed address doesn't match its alignment",
pzName);
name);
alignment = 0; /* Ignore it if it's satisfied */
} else if (startaddr[type] & mask) {
yyerror("Section \"%s\"'s alignment cannot be attained in %s",
pzName, typeNames[type]);
name, typeNames[type]);
}
}
if (org != -1) {
if (org < startaddr[type] || org > endaddr(type))
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)
bank = bankranges[type][0];
struct Section *pSect = out_FindSectionByName(pzName);
struct Section *sect = out_FindSectionByName(name);
if (pSect) {
if (sect) {
unsigned int nbSectErrors = 0;
#define fail(...) \
do { \
@@ -158,13 +158,13 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
nbSectErrors++; \
} while (0)
if (type != pSect->nType)
if (type != sect->type)
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",
pSect->pzName, sectionModNames[pSect->modifier]);
sect->name, sectionModNames[sect->modifier]);
/*
* Normal sections need to have exactly identical 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");
if (org != -1) {
/* 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,
pSect->pzName, pSect->nOrg);
else if (pSect->nAlign != 0
&& (mask(pSect->nAlign)
& (org - pSect->alignOfs)))
sect->name, sect->org);
else if (sect->align != 0
&& (mask(sect->align)
& (org - sect->alignOfs)))
fail("Section \"%s\" already declared as aligned to %u bytes (offset %" PRIu16 ")",
pSect->pzName, 1U << pSect->nAlign,
pSect->alignOfs);
sect->name, 1U << sect->align,
sect->alignOfs);
else
/* Otherwise, just override */
pSect->nOrg = org;
sect->org = org;
} else if (alignment != 0) {
/* Make sure any fixed address is compatible */
if (pSect->nOrg != -1) {
if ((pSect->nOrg - alignOffset)
if (sect->org != -1) {
if ((sect->org - alignOffset)
& mask(alignment))
fail("Section \"%s\" already declared as fixed at incompatible address $%" PRIx32,
pSect->pzName,
pSect->nOrg);
sect->name,
sect->org);
/* Check if alignment offsets are compatible */
} else if ((alignOffset & mask(pSect->nAlign))
!= (pSect->alignOfs
} else if ((alignOffset & mask(sect->align))
!= (sect->alignOfs
& mask(alignment))) {
fail("Section \"%s\" already declared with incompatible %" PRIu8 "-byte alignment (offset %" PRIu16 ")",
pSect->pzName, pSect->nAlign,
pSect->alignOfs);
} else if (alignment > pSect->nAlign) {
sect->name, sect->align,
sect->alignOfs);
} else if (alignment > sect->align) {
/*
* If the section is not fixed,
* its alignment is the largest of both
*/
pSect->nAlign = alignment;
pSect->alignOfs = alignOffset;
sect->align = alignment;
sect->alignOfs = alignOffset;
}
}
/* If the section's bank is unspecified, override it */
if (pSect->nBank == -1)
pSect->nBank = bank;
if (sect->bank == -1)
sect->bank = bank;
/* 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,
pSect->pzName, pSect->nBank);
sect->name, sect->bank);
} else { /* Section fragments are handled identically in RGBASM */
/* 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");
if (org != pSect->nOrg) {
if (pSect->nOrg == -1)
if (org != sect->org) {
if (sect->org == -1)
fail("Section \"%s\" already declared as floating",
pSect->pzName);
sect->name);
else
fail("Section \"%s\" already declared as fixed at $%" PRIx32,
pSect->pzName, pSect->nOrg);
sect->name, sect->org);
}
if (bank != pSect->nBank) {
if (pSect->nBank == -1)
if (bank != sect->bank) {
if (sect->bank == -1)
fail("Section \"%s\" already declared as floating bank",
pSect->pzName);
sect->name);
else
fail("Section \"%s\" already declared as fixed at bank %" PRIu32,
pSect->pzName, pSect->nBank);
sect->name, sect->bank);
}
if (alignment != pSect->nAlign) {
if (pSect->nAlign == 0)
if (alignment != sect->align) {
if (sect->align == 0)
fail("Section \"%s\" already declared as unaligned",
pSect->pzName);
sect->name);
else
fail("Section \"%s\" already declared as aligned to %u bytes",
pSect->pzName,
1U << pSect->nAlign);
sect->name,
1U << sect->align);
}
}
if (nbSectErrors)
fatalerror("Cannot create section \"%s\" (%u errors)",
pSect->pzName, nbSectErrors);
sect->name, nbSectErrors);
#undef fail
return pSect;
return sect;
}
pSect = malloc(sizeof(*pSect));
if (pSect == NULL)
sect = malloc(sizeof(*sect));
if (sect == NULL)
fatalerror("Not enough memory for section");
pSect->pzName = strdup(pzName);
if (pSect->pzName == NULL)
sect->name = strdup(name);
if (sect->name == NULL)
fatalerror("Not enough memory for sectionname");
pSect->nType = type;
pSect->modifier = mod;
pSect->size = 0;
pSect->nOrg = org;
pSect->nBank = bank;
pSect->nAlign = alignment;
pSect->alignOfs = alignOffset;
pSect->pNext = pSectionList;
pSect->pPatches = NULL;
sect->type = type;
sect->modifier = mod;
sect->size = 0;
sect->org = org;
sect->bank = bank;
sect->align = alignment;
sect->alignOfs = alignOffset;
sect->next = pSectionList;
sect->patches = NULL;
/* It is only needed to allocate memory for ROM sections. */
if (sect_HasData(type)) {
uint32_t sectsize;
sectsize = maxsize[type];
pSect->tData = malloc(sectsize);
if (pSect->tData == NULL)
sect->data = malloc(sectsize);
if (sect->data == NULL)
fatalerror("Not enough memory for section");
} else {
pSect->tData = NULL;
sect->data = NULL;
}
/*
* Add the new section to the list
* at the beginning because order doesn't matter
*/
pSectionList = pSect;
pSectionList = sect;
return pSect;
return sect;
#undef mask
}
@@ -315,17 +315,17 @@ static void changeSection(void)
/*
* 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)
{
if (currentLoadSection)
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();
curOffset = mod == SECTION_UNION ? 0 : pSect->size;
pCurrentSection = pSect;
curOffset = mod == SECTION_UNION ? 0 : sect->size;
pCurrentSection = sect;
}
/*
@@ -339,12 +339,12 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
if (currentLoadSection)
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;
curOffset = 0; /* curOffset -= loadOffset; */
changeSection();
currentLoadSection = pSect;
currentLoadSection = sect;
}
void out_EndLoadSection(void)
@@ -380,22 +380,22 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
{
struct Section *sect = sect_GetSymbolSection();
if (sect->nOrg != -1) {
if (sect->org != -1) {
if ((sym_GetPCValue() - offset) % (1 << alignment))
yyerror("Section's fixed address fails required alignment (PC = $%04" PRIx32 ")",
sym_GetPCValue());
} else if (sect->nAlign != 0) {
if ((((sect->alignOfs + curOffset) % (1 << sect->nAlign))
} else if (sect->align != 0) {
if ((((sect->alignOfs + curOffset) % (1 << sect->align))
- offset) % (1 << alignment)) {
yyerror("Section's alignment fails required alignment (offset from section start = $%04" PRIx32 ")",
curOffset);
} else if (alignment > sect->nAlign) {
sect->nAlign = alignment;
} else if (alignment > sect->align) {
sect->align = alignment;
sect->alignOfs =
(offset - curOffset) % (1 << alignment);
}
} else {
sect->nAlign = alignment;
sect->align = alignment;
sect->alignOfs = offset;
}
}
@@ -411,7 +411,7 @@ static inline void growSection(uint32_t growth)
static inline void writebyte(uint8_t byte)
{
pCurrentSection->tData[sect_GetOutputOffset()] = byte;
pCurrentSection->data[sect_GetOutputOffset()] = byte;
growSection(1);
}
@@ -439,7 +439,7 @@ void sect_StartUnion(void)
{
if (!pCurrentSection)
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");
struct UnionStackEntry *entry = malloc(sizeof(*entry));
@@ -513,10 +513,10 @@ void out_Skip(int32_t skip, bool ds)
checksection();
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");
if (!sect_HasData(pCurrentSection->nType)) {
if (!sect_HasData(pCurrentSection->type)) {
growSection(skip);
} else {
checkcodesection();
@@ -781,17 +781,17 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
*/
void out_PushSection(void)
{
struct SectionStackEntry *pSect;
struct SectionStackEntry *sect;
pSect = malloc(sizeof(struct SectionStackEntry));
if (pSect == NULL)
sect = malloc(sizeof(struct SectionStackEntry));
if (sect == NULL)
fatalerror("No memory for section stack");
pSect->pSection = pCurrentSection;
pSect->pScope = sym_GetCurrentSymbolScope();
pSect->offset = curOffset;
pSect->pNext = pSectionStack;
pSectionStack = pSect;
sect->pSection = pCurrentSection;
sect->pScope = sym_GetCurrentSymbolScope();
sect->offset = curOffset;
sect->next = pSectionStack;
pSectionStack = sect;
/* TODO: maybe set current section to NULL? */
}
@@ -803,14 +803,14 @@ void out_PopSection(void)
if (currentLoadSection)
fatalerror("Cannot change the section within a `LOAD` block!");
struct SectionStackEntry *pSect;
struct SectionStackEntry *sect;
pSect = pSectionStack;
sect = pSectionStack;
changeSection();
pCurrentSection = pSect->pSection;
sym_SetCurrentSymbolScope(pSect->pScope);
curOffset = pSect->offset;
pCurrentSection = sect->pSection;
sym_SetCurrentSymbolScope(sect->pScope);
curOffset = sect->offset;
pSectionStack = pSect->pNext;
free(pSect);
pSectionStack = sect->next;
free(sect);
}

View File

@@ -89,7 +89,7 @@ static int32_t CallbackPC(void)
{
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)
/* 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;
}
@@ -222,7 +222,7 @@ uint32_t sym_GetPCValue(void)
if (!sect)
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");
else
return CallbackPC();