diff --git a/include/asm/constexpr.h b/include/asm/constexpr.h index c1dd21b2..79bad465 100644 --- a/include/asm/constexpr.h +++ b/include/asm/constexpr.h @@ -20,6 +20,8 @@ struct ConstExpression { }; void constexpr_Symbol(struct ConstExpression *expr, char *tzSym); +void constexpr_BanksSymbol(struct ConstExpression *expr, char *tzSym); +void constexpr_BankSection(struct ConstExpression *expr, char *tzSym); void constexpr_Number(struct ConstExpression *expr, int32_t i); void constexpr_UnaryOp(struct ConstExpression *expr, int32_t op, diff --git a/src/asm/asmy.y b/src/asm/asmy.y index ba6dbe9c..22d27da6 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -1394,6 +1394,14 @@ const : T_ID { constexpr_Symbol(&$$, $1); } | T_NUMBER { constexpr_Number(&$$, $1); } | T_OP_HIGH '(' const ')' { constexpr_UnaryOp(&$$, $1, &$3); } | T_OP_LOW '(' const ')' { constexpr_UnaryOp(&$$, $1, &$3); } + | T_OP_BANK '(' T_ID ')' + { + constexpr_BankSymbol(&$$, $3); + } + | T_OP_BANK '(' string ')' + { + constexpr_BankSection(&$$, $3); + } | string { char *s = $1; diff --git a/src/asm/constexpr.c b/src/asm/constexpr.c index cec13b9d..ace38524 100644 --- a/src/asm/constexpr.c +++ b/src/asm/constexpr.c @@ -15,6 +15,7 @@ #include "asm/lexer.h" #include "asm/main.h" #include "asm/mymath.h" +#include "asm/output.h" #include "asm/rpn.h" #include "asm/symbol.h" #include "asm/warning.h" @@ -37,6 +38,42 @@ void constexpr_Symbol(struct ConstExpression *expr, char *tzSym) } } +void constexpr_BankSymbol(struct ConstExpression *expr, char *tzSym) +{ + if (sym_FindSymbol(tzSym) == pPCSymbol) { + if (pCurrentSection->nBank == -1) + yyerror("%s's bank is not known yet", tzSym); + else + constexpr_Number(expr, pCurrentSection->nBank); + return; + } + + if (sym_isConstant(tzSym)) { + yyerror("BANK argument must be a relocatable identifier"); + } else { + struct sSymbol *pSymbol = sym_FindSymbol(tzSym); + + if (!pSymbol) + yyerror("BANK argument doesn't exist"); + else if (!pSymbol->pSection || pSymbol->pSection->nBank == -1) + yyerror("BANK argument must be a relocatable identifier"); + else + constexpr_Number(expr, pSymbol->pSection->nBank); + } +} + +void constexpr_BankSection(struct ConstExpression *expr, char *tzSectionName) +{ + struct Section *pSection = out_FindSectionByName(tzSectionName); + + if (!pSection) + yyerror("Section \"%s\" doesn't exist"); + else if (pSection->nBank == -1) + yyerror("Section \"%s\"'s bank is not known yet"); + else + constexpr_Number(expr, pSection->nBank); +} + void constexpr_Number(struct ConstExpression *expr, int32_t i) { expr->u.nVal = i;