shithub: rgbds

Download patch

ref: 598c923506a25e8e3a737e1e6d588a7404d4d221
parent: 8c4b473d6f178a583bba81e1155febc7626b29c3
author: ISSOtm <eldredhabert0@gmail.com>
date: Sun Feb 9 10:10:47 EST 2020

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)

--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -405,7 +405,6 @@
 
 	nPC = unionStart[unionIndex];
 	pCurrentSection->nPC = unionStart[unionIndex];
-	pPCSymbol->nValue = unionStart[unionIndex];
 }
 
 static size_t strlenUTF8(const char *s)
@@ -858,7 +857,6 @@
 			nUnionDepth--;
 			nPC = unionStart[nUnionDepth] + unionSize[nUnionDepth];
 			pCurrentSection->nPC = nPC;
-			pPCSymbol->nValue = nPC;
 		}
 ;
 
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -148,7 +148,6 @@
 	pCurrentSection = pSect;
 	nPC = (pSect != NULL) ? pSect->nPC : 0;
 
-	pPCSymbol->nValue = nPC;
 	pPCSymbol->pSection = pCurrentSection;
 	pPCSymbol->isConstant = pSect && pSect->nOrg != -1;
 }
@@ -207,7 +206,6 @@
 	pCurrentSection->tData[nPC] = b;
 	pCurrentSection->nPC++;
 	nPC++;
-	pPCSymbol->nValue++;
 }
 
 /*
@@ -237,7 +235,6 @@
 	if (!sect_HasData(pCurrentSection->nType)) {
 		pCurrentSection->nPC += skip;
 		nPC += skip;
-		pPCSymbol->nValue += skip;
 	} else if (nUnionDepth > 0) {
 		while (skip--)
 			absByteBypassCheck(CurrentOptions.fillchar);
@@ -272,7 +269,6 @@
 		out_CreatePatch(PATCHTYPE_BYTE, expr);
 		pCurrentSection->nPC++;
 		nPC++;
-		pPCSymbol->nValue++;
 	} else {
 		out_AbsByte(expr->nVal);
 	}
@@ -291,7 +287,6 @@
 	pCurrentSection->tData[nPC + 1] = b >> 8;
 	pCurrentSection->nPC += 2;
 	nPC += 2;
-	pPCSymbol->nValue += 2;
 }
 
 /*
@@ -308,7 +303,6 @@
 		out_CreatePatch(PATCHTYPE_WORD, expr);
 		pCurrentSection->nPC += 2;
 		nPC += 2;
-		pPCSymbol->nValue += 2;
 	} else {
 		absWord(expr->nVal);
 	}
@@ -328,7 +322,6 @@
 	pCurrentSection->tData[nPC + 3] = b >> 24;
 	pCurrentSection->nPC += 4;
 	nPC += 4;
-	pPCSymbol->nValue += 4;
 }
 
 /*
@@ -347,7 +340,6 @@
 		out_CreatePatch(PATCHTYPE_LONG, expr);
 		pCurrentSection->nPC += 4;
 		nPC += 4;
-		pPCSymbol->nValue += 4;
 	} else {
 		absLong(expr->nVal);
 	}
@@ -367,7 +359,6 @@
 		out_CreatePatch(PATCHTYPE_JR, expr);
 		pCurrentSection->nPC++;
 		nPC++;
-		pPCSymbol->nValue++;
 	} else {
 		/* Target is relative to the byte *after* the operand */
 		uint16_t address = pCurrentSection->nOrg + nPC + 1;
@@ -417,7 +408,6 @@
 
 	pCurrentSection->nPC += fsize;
 	nPC += fsize;
-	pPCSymbol->nValue += fsize;
 	fclose(f);
 }
 
@@ -464,7 +454,6 @@
 
 	pCurrentSection->nPC += length;
 	nPC += length;
-	pPCSymbol->nValue += length;
 
 	fclose(f);
 }
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -64,6 +64,11 @@
 	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
  */
@@ -722,6 +727,7 @@
 
 	sym_AddReloc("@");
 	pPCSymbol = findsymbol("@", NULL);
+	pPCSymbol->Callback = CallbackPC;
 	sym_AddEqu("_NARG", 0);
 	p_NARGSymbol = findsymbol("_NARG", NULL);
 	p_NARGSymbol->Callback = Callback_NARG;