Fix float parameter and return values

This commit is contained in:
drmortalwombat 2021-12-09 21:38:36 +01:00
parent cf9f38d4dc
commit a1fda2b957
3 changed files with 16 additions and 7 deletions

View File

@ -3297,7 +3297,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod
dec->mLinkerObject->mNumTemporaries = 1;
dec->mLinkerObject->mTemporaries[0] = BC_REG_FPARAMS;
dec->mLinkerObject->mTempSizes[0] = 8;
dec->mLinkerObject->mTempSizes[0] = BC_REG_FPARAMS_END - BC_REG_FPARAMS;
}
InterCodeBasicBlock* entryBlock = new InterCodeBasicBlock();

View File

@ -2880,22 +2880,25 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
{
if (ins->mSrc[1].mMemory == IM_INDIRECT)
{
union { float f; unsigned int v; } cc;
cc.f = ins->mSrc[0].mFloatConst;
int reg = BC_REG_TMP + proc->mTempOffset[ins->mSrc[1].mTemp];
int index = ins->mSrc[1].mIntConst;
CheckFrameIndex(reg, index, 4);
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins->mSrc[0].mIntConst & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, cc.v & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_INDIRECT_Y, reg));
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index + 1));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, (ins->mSrc[0].mIntConst >> 8) & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, (cc.v >> 8) & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_INDIRECT_Y, reg));
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index + 2));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, (ins->mSrc[0].mIntConst >> 16) & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, (cc.v >> 16) & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_INDIRECT_Y, reg));
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index + 3));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, (ins->mSrc[0].mIntConst >> 24) & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, (cc.v >> 24) & 0xff));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_INDIRECT_Y, reg));
}
}

View File

@ -807,10 +807,15 @@ Declaration* Parser::ParseDeclaration(bool variable)
ndec = ReverseDeclaration(ndec, bdec);
Declaration* npdec = ndec;
if (npdec->mBase->mType == DT_TYPE_POINTER)
npdec = npdec->mBase;
// Make room for return value pointer on struct return
if (ndec->mBase->mType == DT_TYPE_FUNCTION && ndec->mBase->mBase->mType == DT_TYPE_STRUCT)
if (npdec->mBase->mType == DT_TYPE_FUNCTION && npdec->mBase->mBase->mType == DT_TYPE_STRUCT)
{
Declaration* pdec = ndec->mBase->mParams;
Declaration* pdec = npdec->mBase->mParams;
while (pdec)
{
pdec->mVarIndex += 2;
@ -818,6 +823,7 @@ Declaration* Parser::ParseDeclaration(bool variable)
}
}
if (definingType)
{
if (ndec->mIdent)