Improve bankof implementation

This commit is contained in:
drmortalwombat 2024-09-30 20:13:54 +02:00
parent 581137ade7
commit 73c2206a1a

View File

@ -3286,14 +3286,28 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
case TK_BANKOF: case TK_BANKOF:
{ {
LinkerRegion* rgn; if (exp->mLeft->mDecValue)
if (exp->mLeft->mDecValue->mSection && (rgn = mLinker->FindRegionOfSection(exp->mLeft->mDecValue->mSection)))
{ {
uint64 i = 0; LinkerSection* section = nullptr;
while (i < 64 && rgn->mCartridgeBanks != (1ULL << i))
i++; if (exp->mLeft->mDecValue->mSection)
if (i < 64)
{ {
section = exp->mLeft->mDecValue->mSection;
}
else if (exp->mLeft->mDecValue->mType == DT_CONST_INTEGER)
{
section = proc->mLinkerObject->mSection;
}
if (section)
{
LinkerRegion* rgn = mLinker->FindRegionOfSection(section);
uint64 i = 0;
while (i < 64 && rgn->mCartridgeBanks != (1ULL << i))
i++;
if (i == 64)
i = 255;
ins->mCode = IC_CONSTANT; ins->mCode = IC_CONSTANT;
ins->mNumOperands = 0; ins->mNumOperands = 0;
ins->mConst.mType = IT_INT8; ins->mConst.mType = IT_INT8;