Use callback for PC's value

This causes it to auto-update whenever the current section's attributes are
updated, simplifying the code and eliminating redundancy.
This should also overall reduce overhead (one extra function call on each
PC evaluation, but less bookkeeping for each byte output)
This commit is contained in:
ISSOtm
2020-02-09 15:10:47 +01:00
parent 8c4b473d6f
commit 598c923506
3 changed files with 6 additions and 13 deletions

View File

@@ -405,7 +405,6 @@ static void updateUnion(void)
nPC = unionStart[unionIndex]; nPC = unionStart[unionIndex];
pCurrentSection->nPC = unionStart[unionIndex]; pCurrentSection->nPC = unionStart[unionIndex];
pPCSymbol->nValue = unionStart[unionIndex];
} }
static size_t strlenUTF8(const char *s) static size_t strlenUTF8(const char *s)
@@ -858,7 +857,6 @@ endu : T_POP_ENDU
nUnionDepth--; nUnionDepth--;
nPC = unionStart[nUnionDepth] + unionSize[nUnionDepth]; nPC = unionStart[nUnionDepth] + unionSize[nUnionDepth];
pCurrentSection->nPC = nPC; pCurrentSection->nPC = nPC;
pPCSymbol->nValue = nPC;
} }
; ;

View File

@@ -148,7 +148,6 @@ static void setCurrentSection(struct Section *pSect)
pCurrentSection = pSect; pCurrentSection = pSect;
nPC = (pSect != NULL) ? pSect->nPC : 0; nPC = (pSect != NULL) ? pSect->nPC : 0;
pPCSymbol->nValue = nPC;
pPCSymbol->pSection = pCurrentSection; pPCSymbol->pSection = pCurrentSection;
pPCSymbol->isConstant = pSect && pSect->nOrg != -1; pPCSymbol->isConstant = pSect && pSect->nOrg != -1;
} }
@@ -207,7 +206,6 @@ static void absByteBypassCheck(int32_t b)
pCurrentSection->tData[nPC] = b; pCurrentSection->tData[nPC] = b;
pCurrentSection->nPC++; pCurrentSection->nPC++;
nPC++; nPC++;
pPCSymbol->nValue++;
} }
/* /*
@@ -237,7 +235,6 @@ void out_Skip(int32_t skip)
if (!sect_HasData(pCurrentSection->nType)) { if (!sect_HasData(pCurrentSection->nType)) {
pCurrentSection->nPC += skip; pCurrentSection->nPC += skip;
nPC += skip; nPC += skip;
pPCSymbol->nValue += skip;
} else if (nUnionDepth > 0) { } else if (nUnionDepth > 0) {
while (skip--) while (skip--)
absByteBypassCheck(CurrentOptions.fillchar); absByteBypassCheck(CurrentOptions.fillchar);
@@ -272,7 +269,6 @@ void out_RelByte(struct Expression *expr)
out_CreatePatch(PATCHTYPE_BYTE, expr); out_CreatePatch(PATCHTYPE_BYTE, expr);
pCurrentSection->nPC++; pCurrentSection->nPC++;
nPC++; nPC++;
pPCSymbol->nValue++;
} else { } else {
out_AbsByte(expr->nVal); out_AbsByte(expr->nVal);
} }
@@ -291,7 +287,6 @@ static void absWord(int32_t b)
pCurrentSection->tData[nPC + 1] = b >> 8; pCurrentSection->tData[nPC + 1] = b >> 8;
pCurrentSection->nPC += 2; pCurrentSection->nPC += 2;
nPC += 2; nPC += 2;
pPCSymbol->nValue += 2;
} }
/* /*
@@ -308,7 +303,6 @@ void out_RelWord(struct Expression *expr)
out_CreatePatch(PATCHTYPE_WORD, expr); out_CreatePatch(PATCHTYPE_WORD, expr);
pCurrentSection->nPC += 2; pCurrentSection->nPC += 2;
nPC += 2; nPC += 2;
pPCSymbol->nValue += 2;
} else { } else {
absWord(expr->nVal); absWord(expr->nVal);
} }
@@ -328,7 +322,6 @@ static void absLong(int32_t b)
pCurrentSection->tData[nPC + 3] = b >> 24; pCurrentSection->tData[nPC + 3] = b >> 24;
pCurrentSection->nPC += 4; pCurrentSection->nPC += 4;
nPC += 4; nPC += 4;
pPCSymbol->nValue += 4;
} }
/* /*
@@ -347,7 +340,6 @@ void out_RelLong(struct Expression *expr)
out_CreatePatch(PATCHTYPE_LONG, expr); out_CreatePatch(PATCHTYPE_LONG, expr);
pCurrentSection->nPC += 4; pCurrentSection->nPC += 4;
nPC += 4; nPC += 4;
pPCSymbol->nValue += 4;
} else { } else {
absLong(expr->nVal); absLong(expr->nVal);
} }
@@ -367,7 +359,6 @@ void out_PCRelByte(struct Expression *expr)
out_CreatePatch(PATCHTYPE_JR, expr); out_CreatePatch(PATCHTYPE_JR, expr);
pCurrentSection->nPC++; pCurrentSection->nPC++;
nPC++; nPC++;
pPCSymbol->nValue++;
} else { } else {
/* Target is relative to the byte *after* the operand */ /* Target is relative to the byte *after* the operand */
uint16_t address = pCurrentSection->nOrg + nPC + 1; uint16_t address = pCurrentSection->nOrg + nPC + 1;
@@ -417,7 +408,6 @@ void out_BinaryFile(char const *s)
pCurrentSection->nPC += fsize; pCurrentSection->nPC += fsize;
nPC += fsize; nPC += fsize;
pPCSymbol->nValue += fsize;
fclose(f); fclose(f);
} }
@@ -464,7 +454,6 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
pCurrentSection->nPC += length; pCurrentSection->nPC += length;
nPC += length; nPC += length;
pPCSymbol->nValue += length;
fclose(f); fclose(f);
} }

View File

@@ -64,6 +64,11 @@ static int32_t Callback__LINE__(unused_ struct sSymbol const *sym)
return nLineNo; return nLineNo;
} }
static int32_t CallbackPC(struct sSymbol const *self)
{
return self->pSection ? self->pSection->nOrg + self->pSection->nPC : 0;
}
/* /*
* Get the nValue field of a symbol * Get the nValue field of a symbol
*/ */
@@ -722,6 +727,7 @@ void sym_Init(void)
sym_AddReloc("@"); sym_AddReloc("@");
pPCSymbol = findsymbol("@", NULL); pPCSymbol = findsymbol("@", NULL);
pPCSymbol->Callback = CallbackPC;
sym_AddEqu("_NARG", 0); sym_AddEqu("_NARG", 0);
p_NARGSymbol = findsymbol("_NARG", NULL); p_NARGSymbol = findsymbol("_NARG", NULL);
p_NARGSymbol->Callback = Callback_NARG; p_NARGSymbol->Callback = Callback_NARG;