ref: cfe21876e5d1793fbcf1c8544f1e27c4fc234919
parent: ef2bfe4ea0cd6d91edc9baec999506721d28439c
author: ISSOtm <[email protected]>
date: Sun Feb 23 17:27:33 EST 2020
Make writing patches not affect the expression This also removes one int member from the struct that shouldn't be there
--- a/include/asm/output.h
+++ b/include/asm/output.h
@@ -19,7 +19,7 @@
extern struct Section *pSectionList, *pCurrentSection;
void out_SetFileName(char *s);
-void out_CreatePatch(uint32_t type, struct Expression *expr);
+void out_CreatePatch(uint32_t type, struct Expression const *expr);
void out_WriteObject(void);
#endif /* RGBDS_ASM_OUTPUT_H */
--- a/include/asm/rpn.h
+++ b/include/asm/rpn.h
@@ -25,8 +25,6 @@
uint32_t nRPNCapacity; // Size of the `tRPN` buffer
uint32_t nRPNLength; // Used size of the `tRPN` buffer
uint32_t nRPNPatchSize; // Size the expression will take in the obj file
- // FIXME: does this need to be part of the struct?
- uint32_t nRPNOut; // How many bytes have been written
};
/* FIXME: Should be defined in `asmy.h`, but impossible with POSIX Yacc */
@@ -44,7 +42,6 @@
void rpn_LOW(struct Expression *expr, const struct Expression *src);
void rpn_UNNEG(struct Expression *expr, const struct Expression *src);
void rpn_UNNOT(struct Expression *expr, const struct Expression *src);
-uint16_t rpn_PopByte(struct Expression *expr);
void rpn_BankSymbol(struct Expression *expr, char *tzSym);
void rpn_BankSection(struct Expression *expr, char *tzSectionName);
void rpn_BankSelf(struct Expression *expr);
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -310,10 +310,9 @@
/*
* Create a new patch (includes the rpn expr)
*/
-void out_CreatePatch(uint32_t type, struct Expression *expr)
+void out_CreatePatch(uint32_t type, struct Expression const *expr)
{
struct Patch *pPatch;
- uint16_t rpndata;
uint8_t *rpnexpr;
char tzSym[512];
uint32_t rpnptr = 0, symptr;
@@ -328,19 +327,22 @@
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
pPatch->nOffset = pCurrentSection->nPC;
- while ((rpndata = rpn_PopByte(expr)) != 0xDEAD) {
+ for (size_t offset = 0; offset < expr->nRPNLength; ) {
+#define popbyte(expr) (expr)->tRPN[offset++]
+ uint8_t rpndata = popbyte(expr);
+
switch (rpndata) {
case RPN_CONST:
rpnexpr[rpnptr++] = RPN_CONST;
- rpnexpr[rpnptr++] = rpn_PopByte(expr);
- rpnexpr[rpnptr++] = rpn_PopByte(expr);
- rpnexpr[rpnptr++] = rpn_PopByte(expr);
- rpnexpr[rpnptr++] = rpn_PopByte(expr);
+ rpnexpr[rpnptr++] = popbyte(expr);
+ rpnexpr[rpnptr++] = popbyte(expr);
+ rpnexpr[rpnptr++] = popbyte(expr);
+ rpnexpr[rpnptr++] = popbyte(expr);
break;
case RPN_SYM:
{
symptr = 0;
- while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0)
+ while ((tzSym[symptr++] = popbyte(expr)) != 0)
;
struct sSymbol const *sym = sym_FindSymbol(tzSym);
@@ -371,7 +373,7 @@
struct sSymbol *sym;
symptr = 0;
- while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0)
+ while ((tzSym[symptr++] = popbyte(expr)) != 0)
;
sym = sym_FindSymbol(tzSym);
@@ -393,7 +395,7 @@
rpnexpr[rpnptr++] = RPN_BANK_SECT;
do {
- b = rpn_PopByte(expr);
+ b = popbyte(expr);
rpnexpr[rpnptr++] = b & 0xFF;
} while (b != 0);
break;
@@ -402,6 +404,7 @@
rpnexpr[rpnptr++] = rpndata;
break;
}
+#undef popbyte
}
assert(rpnptr == expr->nRPNPatchSize);
--- a/src/asm/rpn.c
+++ b/src/asm/rpn.c
@@ -81,7 +81,6 @@
expr->nRPNCapacity = 0;
expr->nRPNLength = 0;
expr->nRPNPatchSize = 0;
- expr->nRPNOut = 0;
}
/*
@@ -92,17 +91,6 @@
free(expr->tRPN);
free(expr->reason);
rpn_Init(expr);
-}
-
-/*
- * Returns the next rpn byte in expression
- */
-uint16_t rpn_PopByte(struct Expression *expr)
-{
- if (expr->nRPNOut == expr->nRPNLength)
- return 0xDEAD;
-
- return expr->tRPN[expr->nRPNOut++];
}
/*