Skip to content

Commit

Permalink
Remove superfluous rts from inline assembler blocks that end with a jmp
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Nov 16, 2021
1 parent 5c66e11 commit cd77372
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion oscar64/NativeCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,13 @@ void NativeCodeInstruction::Assemble(NativeCodeBasicBlock* block)
else if (mType == ASMIT_JSR && mLinkerObject && (mLinkerObject->mFlags & LOBJF_INLINE))
{
int pos = block->mCode.Size();
for (int i = 0; i < mLinkerObject->mSize - 1; i++)
int size = mLinkerObject->mSize;

// skip RTS on embedding
if (mLinkerObject->mData[size - 1] == 0x60)
size--;

for (int i = 0; i < size; i++)
block->PutByte(mLinkerObject->mData[i]);
for (int i = 0; i < mLinkerObject->mReferences.Size(); i++)
{
Expand Down
23 changes: 20 additions & 3 deletions oscar64/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,9 @@ Expression* Parser::ParseAssembler(void)
vdasm->mBase = dassm;

Expression* ifirst = new Expression(mScanner->mLocation, EX_ASSEMBLER);
Expression* ilast = ifirst;
Expression* ilast = ifirst, * ifinal = ifirst;

bool exitLabel = false;

ifirst->mDecType = dassm;
ifirst->mDecValue = vdasm;
Expand All @@ -2381,6 +2383,8 @@ Expression* Parser::ParseAssembler(void)
else
mScanner->NextToken();

exitLabel = true;

Declaration* dec = mScope->Lookup(label);
if (dec)
{
Expand All @@ -2398,6 +2402,8 @@ Expression* Parser::ParseAssembler(void)
}
else
{
exitLabel = false;

ilast->mAsmInsType = ins;
mScanner->NextToken();
if (mScanner->mToken == TK_EOL || mScanner->mToken == TK_CLOSE_BRACE)
Expand Down Expand Up @@ -2506,6 +2512,8 @@ Expression* Parser::ParseAssembler(void)

offset += AsmInsSize(ilast->mAsmInsType, ilast->mAsmInsMode);

ifinal = ilast;

ilast->mRight = new Expression(mScanner->mLocation, EX_ASSEMBLER);
ilast = ilast->mRight;
}
Expand All @@ -2523,8 +2531,17 @@ Expression* Parser::ParseAssembler(void)
}
}

ilast->mAsmInsType = ASMIT_RTS;
ilast->mAsmInsMode = ASMIM_IMPLIED;
if ((ifinal->mAsmInsType == ASMIT_RTS || ifinal->mAsmInsType == ASMIT_JMP) && !exitLabel)
{
delete ilast;
ilast = ifinal;
ifinal->mRight = nullptr;
}
else
{
ilast->mAsmInsType = ASMIT_RTS;
ilast->mAsmInsMode = ASMIM_IMPLIED;
}

#if 0
offset = 0;
Expand Down

0 comments on commit cd77372

Please sign in to comment.