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.
This commit is contained in:
ISSOtm
2019-09-19 15:06:48 +02:00
parent 74f43d4e09
commit 02fe73d1f3

View File

@@ -182,17 +182,25 @@ void rpn_BankSymbol(struct Expression *expr, char *tzSym)
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,8 +208,13 @@ void rpn_BankSection(struct Expression *expr, char *tzSectionName)
{
rpn_Init(expr);
struct Section *pSection = out_FindSectionByName(tzSectionName);
if (pSection && pSection->nBank != -1)
expr->nVal = pSection->nBank;
else
/*
* This symbol is not really relocatable, but this makes the assembler
* This is not really relocatable, but this makes the assembler
* write this expression as a RPN patch to the object file.
*/
expr->isReloc = 1;