ref: 02fe73d1f38b702b7a94a8b4934eb9e829eb4278
parent: 74f43d4e094d6ed6048d784a9275f0a7a26a7097
author: ISSOtm <eldredhabert0@gmail.com>
date: Thu Sep 19 11:06:48 EDT 2019
Make `BANK("Section")` known at assembling time when possible If the target section is in the current file and its bank is known, this means this value is known prior to linking.
--- a/src/asm/rpn.c
+++ b/src/asm/rpn.c
@@ -182,17 +182,25 @@
return;
}
- if (!sym_isConstant(tzSym)) {
+ if (sym_isConstant(tzSym)) {
+ yyerror("BANK argument must be a relocatable identifier");
+ } else {
rpn_Init(expr);
sym_Ref(tzSym);
- expr->isReloc = 1;
pushbyte(expr, RPN_BANK_SYM);
- while (*tzSym)
- pushbyte(expr, *tzSym++);
+ for (unsigned int i = 0; tzSym[i]; i++)
+ pushbyte(expr, tzSym[i]);
pushbyte(expr, 0);
expr->nRPNPatchSize += 5;
- } else {
- yyerror("BANK argument must be a relocatable identifier");
+
+ /* If the symbol didn't exist, `sym_Ref` created it */
+ struct sSymbol *pSymbol = sym_FindSymbol(tzSym);
+
+ if (pSymbol->pSection && pSymbol->pSection->nBank != -1)
+ /* Symbol's section is known and bank's fixed */
+ expr->nVal = pSymbol->pSection->nBank;
+ else
+ expr->isReloc = 1;
}
}
@@ -200,11 +208,16 @@
{
rpn_Init(expr);
- /*
- * This symbol is not really relocatable, but this makes the assembler
- * write this expression as a RPN patch to the object file.
- */
- expr->isReloc = 1;
+ struct Section *pSection = out_FindSectionByName(tzSectionName);
+
+ if (pSection && pSection->nBank != -1)
+ expr->nVal = pSection->nBank;
+ else
+ /*
+ * This is not really relocatable, but this makes the assembler
+ * write this expression as a RPN patch to the object file.
+ */
+ expr->isReloc = 1;
pushbyte(expr, RPN_BANK_SECT);
expr->nRPNPatchSize++;