diff --git a/autotest/arrayindexintrangecheck.c b/autotest/arrayindexintrangecheck.c index e71ce42..946ceba 100644 --- a/autotest/arrayindexintrangecheck.c +++ b/autotest/arrayindexintrangecheck.c @@ -16,7 +16,7 @@ int main(void) put(j, j); int s = -45; for(int j=0; j<10; j++) - s += get[j]; + s += get(j); return s; } diff --git a/autotest/autotest.bat b/autotest/autotest.bat index 16355f7..38ae467 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -87,6 +87,9 @@ rem @echo off @call :test arrayinittest.c @if %errorlevel% neq 0 goto :error +@call :test arrayindexintrangecheck.c +@if %errorlevel% neq 0 goto :error + @call :test array2stringinittest.c @if %errorlevel% neq 0 goto :error diff --git a/autotest/floatcmptest.c b/autotest/floatcmptest.c index 9afa51f..8e3b202 100644 --- a/autotest/floatcmptest.c +++ b/autotest/floatcmptest.c @@ -65,7 +65,7 @@ int main(void) cmpflt( 1.0, 0.0, false, false, true); cmpflt(-1.0, 0.0, false, true, false); -#if 1 + cmpflt( 1.0, 1.0, true, false, false); cmpflt( 1.0, 2.0, false, true, false); cmpflt( 2.0, 1.0, false, false, true); @@ -94,7 +94,6 @@ int main(void) cmpflt( -1.0, -1.000001, false, false, true); cmpflt( -1.000001, -1.0, false, true, false); cmpflt( -1.000001, -1.000001, true, false, false); -#endif return 0; } diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 240ffb2..f271383 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -126,7 +126,7 @@ void DeclarationScope::End(const Location& loc) } Expression::Expression(const Location& loc, ExpressionType type) - : mLocation(loc), mEndLocation(loc), mType(type), mLeft(nullptr), mRight(nullptr), mConst(false), mDecType(nullptr), mDecValue(nullptr) + : mLocation(loc), mEndLocation(loc), mType(type), mLeft(nullptr), mRight(nullptr), mConst(false), mDecType(nullptr), mDecValue(nullptr), mToken(TK_NONE) { } diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index e525c1c..56d7a41 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -1797,6 +1797,7 @@ InterInstruction* InterInstruction::Clone(void) const { InterInstruction* ins = new InterInstruction(mLocation, mCode); *ins = *this; + ins->mRemove = false; return ins; } @@ -3866,6 +3867,8 @@ void InterInstruction::BuildCollisionTable(NumberSet& liveTemps, NumberSet* coll { if (mDst.mTemp >= 0) { + // Ensure collision with unused destination register + UpdateCollisionSet(liveTemps, collisionSets, mDst.mTemp); // if (!liveTemps[ttemp]) __asm int 3 liveTemps -= mDst.mTemp; } @@ -4500,6 +4503,10 @@ void InterCodeBasicBlock::Append(InterInstruction * code) { assert(code->mSrc[1].mType != IT_POINTER); } + if (code->mCode == IC_CONSTANT) + { + assert(code->mDst.mType == code->mConst.mType); + } for (int i = 0; i < code->mNumOperands; i++) assert(code->mSrc[i].mType != IT_NONE); @@ -7928,7 +7935,9 @@ bool InterCodeBasicBlock::CalculateSingleAssignmentTemps(FastNumberSet& tassigne valid = false; else if (ins->mCode == IC_LOAD) { - if (ins->mSrc[0].mMemory == paramMemory) + if (ins->mVolatile) + valid = false; + else if (ins->mSrc[0].mMemory == paramMemory) { if (modifiedParams[ins->mSrc[0].mVarIndex]) valid = false; @@ -12450,6 +12459,8 @@ bool InterCodeBasicBlock::CheapInlining(int & numTemps) InterInstruction* pins = nins->Clone(); if (pins->mSrc[0].mTemp >= 0) pins->mSrc[0].mTemp = tmap[pins->mSrc[0].mTemp]; + if (pins->mSrc[1].mTemp >= 0) + pins->mSrc[1].mTemp = tmap[pins->mSrc[1].mTemp]; mInstructions.Insert(i, pins); i++; } break; @@ -12462,20 +12473,43 @@ bool InterCodeBasicBlock::CheapInlining(int & numTemps) mInstructions.Insert(i, pins); i++; } break; + case IC_RETURN: + break; case IC_RETURN_VALUE: { if (ins->mDst.mTemp >= 0) { InterInstruction* pins = nins->Clone(); - pins->mCode = IC_LOAD_TEMPORARY; + if (pins->mSrc[0].mTemp < 0) + { + pins->mCode = IC_CONSTANT; + pins->mConst = pins->mSrc[0]; + pins->mNumOperands = 0; + } + else + { + pins->mCode = IC_LOAD_TEMPORARY; + pins->mNumOperands = 1; + } + pins->mDst = ins->mDst; if (pins->mSrc[0].mTemp >= 0) pins->mSrc[0].mTemp = tmap[pins->mSrc[0].mTemp]; - pins->mNumOperands = 1; mInstructions.Insert(i, pins); i++; } } break; + default: + { + InterInstruction* pins = nins->Clone(); + for (int k = 0; k < pins->mNumOperands; k++) + if (pins->mSrc[k].mTemp >= 0) + pins->mSrc[k].mTemp = tmap[pins->mSrc[k].mTemp]; + if (pins->mDst.mTemp >= 0) + pins->mDst.mTemp = ntemps; + mInstructions.Insert(i, pins); + i++; + } break; } if (nins->mDst.mTemp >= 0) @@ -15853,12 +15887,12 @@ void InterCodeProcedure::SingleAssignmentForwarding(void) ResetVisited(); mEntryBlock->SingleAssignmentTempForwarding(tunified, tvalues); + DisassembleDebug("single assignment forwarding"); + BuildDataFlowSets(); TempForwarding(); RemoveUnusedInstructions(); - DisassembleDebug("single assignment forwarding"); - } void InterCodeProcedure::PeepholeOptimization(void) @@ -16435,7 +16469,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "tile_draw_g"); + CheckFunc = !strcmp(mIdent->mString, "main"); mEntryBlock = mBlocks[0]; @@ -16542,7 +16576,7 @@ void InterCodeProcedure::Close(void) // Check for cheap inlining // - if (mCompilerOptions & COPT_OPTIMIZE_AUTO_INLINE) + if (mCompilerOptions & COPT_OPTIMIZE_INLINE) { ResetVisited(); if (mEntryBlock->CheapInlining(numTemps)) @@ -16551,6 +16585,8 @@ void InterCodeProcedure::Close(void) mTemporaries.SetSize(numTemps, true); DisassembleDebug("Cheap Inlining"); + + BuildDataFlowSets(); } } @@ -17263,7 +17299,7 @@ void InterCodeProcedure::Close(void) if (!mEntryBlock->mTrueJump) { - int nconst = 0, nvariables = 0, nparams = 0, ncalls = 0, nret = 0, nother = 0; + int nconst = 0, nvariables = 0, nparams = 0, ncalls = 0, nret = 0, nother = 0, nops = 0; for (int i = 0; i < mEntryBlock->mInstructions.Size(); i++) { InterInstruction* ins = mEntryBlock->mInstructions[i]; @@ -17284,10 +17320,34 @@ void InterCodeProcedure::Close(void) break; case IC_STORE: if (ins->mSrc[1].mTemp >= 0 || (ins->mSrc[1].mMemory != IM_FFRAME && ins->mSrc[1].mMemory != IM_FRAME)) - nother++; + nops++; if (ins->mSrc[0].mTemp < 0) nconst++; break; + +#if 1 + case IC_CONSTANT: + if (ins->mConst.mType == IT_POINTER && (ins->mConst.mMemory == IM_FPARAM || ins->mConst.mMemory == IM_PARAM || ins->mConst.mMemory == IM_LOCAL)) + nother++; + else + nconst++; + break; +#endif +#if 1 + case IC_LEA: + if (ins->mSrc[1].mTemp >= 0 || (ins->mSrc[1].mMemory != IM_FPARAM && ins->mSrc[1].mMemory != IM_PARAM && ins->mSrc[1].mMemory != IM_LOCAL)) + nops++; + else + nother++; + break; +#endif +#if 1 + case IC_BINARY_OPERATOR: + case IC_UNARY_OPERATOR: + case IC_RELATIONAL_OPERATOR: + nops++; + break; +#endif case IC_CALL: case IC_CALL_NATIVE: if (ins->mSrc[0].mTemp < 0) @@ -17304,7 +17364,7 @@ void InterCodeProcedure::Close(void) } } - if (nother == 0 && ncalls == 1 && nret == 1 && nconst < 2) + if (nother == 0 && ncalls <= 1 && nret == 1 && nconst <= 1 + nparams && nops <= 1 + nparams) mCheapInline = true; } } diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index b5df555..7414ced 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -925,6 +925,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro InterInstruction* ains = new InterInstruction(pex->mLocation, IC_CONSTANT); ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(ains->mDst.mType); + ains->mConst.mType = IT_POINTER; ains->mConst.mMemory = IM_LOCAL; ains->mConst.mVarIndex = nindex; @@ -1090,6 +1091,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro InterInstruction* ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = IT_POINTER; ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ins->mConst.mType = IT_POINTER; ins->mConst.mOperandSize = rdec->mSize; ins->mConst.mIntConst = rdec->mOffset; ins->mConst.mVarIndex = rdec->mVarIndex; @@ -1158,6 +1160,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I InterInstruction* ains = new InterInstruction(exp->mLocation, IC_CONSTANT); ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(ains->mDst.mType); + ains->mConst.mType = IT_POINTER; ains->mConst.mMemory = IM_LOCAL; ains->mConst.mVarIndex = nindex; @@ -1192,6 +1195,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I ains->mNumOperands = 0; ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(ains->mDst.mType); + ains->mConst.mType = IT_POINTER; ains->mConst.mMemory = IM_LOCAL; ains->mConst.mVarIndex = nindex; @@ -1230,6 +1234,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I InterInstruction* psins = new InterInstruction(exp->mLocation, IC_CONSTANT); psins->mDst.mType = IT_POINTER; psins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + psins->mConst.mType = IT_POINTER; psins->mConst.mVarIndex = 0; psins->mConst.mIntConst = 0; psins->mConst.mOperandSize = 2; @@ -1253,6 +1258,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I InterInstruction* plins = new InterInstruction(exp->mLocation, IC_CONSTANT); plins->mDst.mType = IT_POINTER; plins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + plins->mConst.mType = IT_POINTER; plins->mConst.mVarIndex = 2; plins->mConst.mIntConst = 0; plins->mConst.mOperandSize = 2; @@ -1374,6 +1380,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* ains->mCode = IC_CONSTANT; ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(IT_POINTER); + ains->mConst.mType = IT_POINTER; ains->mConst.mOperandSize = procType->mBase->mSize; ains->mConst.mIntConst = 0; ains->mConst.mVarIndex = inlineMapper->mResult; @@ -1386,6 +1393,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* pins = new InterInstruction(exp->mLocation, IC_CONSTANT); pins->mDst.mType = IT_POINTER; pins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + pins->mConst.mType = IT_POINTER; pins->mConst.mVarIndex = 0; pins->mConst.mIntConst = 0; pins->mConst.mOperandSize = 2; @@ -1426,6 +1434,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = InterTypeOf(dec->mBase); ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ins->mConst.mType = ins->mDst.mType; + if (ins->mDst.mType == IT_INT8) { if (dec->mBase->mFlags & DTF_SIGNED) @@ -1485,6 +1495,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = InterTypeOf(dec->mBase); ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ins->mConst.mType = ins->mDst.mType; ins->mConst.mFloatConst = dec->mNumber; block->Append(ins); return ExValue(dec->mBase, ins->mDst.mTemp); @@ -1496,6 +1507,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = IT_POINTER; ins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + ins->mConst.mType = IT_POINTER; ins->mConst.mIntConst = dec->mInteger; ins->mConst.mMemory = IM_ABSOLUTE; block->Append(ins); @@ -1513,6 +1525,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = InterTypeOf(dec->mBase); ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ins->mConst.mType = ins->mDst.mType; ins->mConst.mVarIndex = dec->mVarIndex; ins->mConst.mLinkerObject = dec->mLinkerObject; ins->mConst.mMemory = IM_PROCEDURE; @@ -1530,6 +1543,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = IT_POINTER; ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ins->mConst.mType = IT_POINTER; ins->mConst.mVarIndex = dec->mVarIndex; ins->mConst.mLinkerObject = dec->mLinkerObject; ins->mConst.mMemory = IM_PROCEDURE; @@ -1566,6 +1580,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = IT_POINTER; ins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + ins->mConst.mType = IT_POINTER; ins->mConst.mIntConst = 0; ins->mConst.mVarIndex = dec->mVarIndex; assert(dec->mVarIndex >= 0); @@ -1599,6 +1614,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = IT_POINTER; ins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + ins->mConst.mType = IT_POINTER; ins->mConst.mIntConst = 0; ins->mConst.mVarIndex = dec->mVarIndex; assert(dec->mVarIndex >= 0); @@ -1823,6 +1839,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (vl.mType->mType == DT_TYPE_POINTER) { InterInstruction * cins = new InterInstruction(exp->mLocation, IC_CONSTANT); + cins->mConst.mType = IT_INT16; if (exp->mToken == TK_ASSIGN_ADD) { @@ -2002,6 +2019,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vr = CoerceType(proc, exp, block, vr, TheSignedIntTypeDeclaration); InterInstruction * cins = new InterInstruction(exp->mLocation, IC_CONSTANT); + cins->mConst.mType = IT_INT16; cins->mConst.mIntConst = stride; cins->mDst.mType = IT_INT16; cins->mDst.mTemp = proc->AddTemporary(cins->mDst.mType); @@ -2042,6 +2060,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* mErrors->Error(exp->mLocation, EERR_NOT_AN_LVALUE, "Not an addressable expression"); InterInstruction * cins = new InterInstruction(exp->mLocation, IC_CONSTANT); + cins->mConst.mType = IT_INT16; cins->mConst.mIntConst = exp->mDecValue->mOffset; cins->mDst.mType = IT_INT16; cins->mDst.mTemp = proc->AddTemporary(cins->mDst.mType); @@ -2090,6 +2109,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (vr.mType->IsIntegerType()) { InterInstruction * cins = new InterInstruction(exp->mLocation, IC_CONSTANT); + cins->mConst.mType = IT_INT16; if (exp->mToken == TK_ADD) { @@ -2160,6 +2180,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } InterInstruction * cins = new InterInstruction(exp->mLocation, IC_CONSTANT); + cins->mConst.mType = IT_INT16; cins->mConst.mIntConst = s; cins->mDst.mType = IT_INT16; cins->mDst.mTemp = proc->AddTemporary(cins->mDst.mType); @@ -2209,6 +2230,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (vl.mType->IsIntegerType()) { InterInstruction* cins = new InterInstruction(exp->mLocation, IC_CONSTANT); + cins->mConst.mType = IT_INT16; if (exp->mToken == TK_ADD) { @@ -2394,10 +2416,15 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* cins->mDst.mType = ftype ? IT_FLOAT : IT_INT16; cins->mDst.mTemp = proc->AddTemporary(cins->mDst.mType); + cins->mConst.mType = cins->mDst.mType; + if (vdl.mType->mType == DT_TYPE_POINTER) cins->mConst.mIntConst = exp->mToken == TK_INC ? vdl.mType->Stride() : -(vdl.mType->Stride()); else if (vdl.mType->IsNumericType()) + { cins->mConst.mIntConst = exp->mToken == TK_INC ? 1 : -1; + cins->mConst.mFloatConst = double(cins->mConst.mIntConst); + } else mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric value or pointer"); @@ -2456,10 +2483,15 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* cins->mDst.mType = ftype ? IT_FLOAT : IT_INT16; cins->mDst.mTemp = proc->AddTemporary(cins->mDst.mType); + cins->mConst.mType = cins->mDst.mType; + if (vdl.mType->mType == DT_TYPE_POINTER) cins->mConst.mIntConst = exp->mToken == TK_INC ? vdl.mType->Stride() : -(vdl.mType->Stride()); else if (vdl.mType->IsNumericType()) + { cins->mConst.mIntConst = exp->mToken == TK_INC ? 1 : -1; + cins->mConst.mFloatConst = double(cins->mConst.mIntConst); + } else mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric value or pointer"); block->Append(cins); @@ -2838,6 +2870,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* mErrors->Error(sex->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); InterInstruction* ins = new InterInstruction(exp->mLocation, IC_STRCPY); + ins->mNumOperands = 2; + ins->mSrc[0].mType = IT_POINTER; ins->mSrc[0].mMemory = IM_INDIRECT; ins->mSrc[0].mTemp = vr.mTemp; @@ -3006,6 +3040,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* vins = new InterInstruction(exp->mLocation, IC_CONSTANT); vins->mDst.mType = IT_POINTER; vins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + vins->mConst.mType = IT_POINTER; vins->mConst.mMemory = IM_LOCAL; vins->mConst.mVarIndex = nindex; vins->mConst.mOperandSize = ftype->mBase->mSize; @@ -3017,6 +3052,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* ains = new InterInstruction(exp->mLocation, IC_CONSTANT); ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(IT_POINTER); + ains->mConst.mType = IT_POINTER; ains->mConst.mVarIndex = 0; ains->mConst.mIntConst = 0; ains->mConst.mOperandSize = 2; @@ -3055,6 +3091,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* while (pex) { InterInstruction * ains = new InterInstruction(exp->mLocation, IC_CONSTANT); + ains->mConst.mType = IT_POINTER; + ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(ains->mDst.mType); if (pdec) @@ -3285,6 +3323,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* vins = new InterInstruction(exp->mLocation, IC_CONSTANT); vins->mDst.mType = IT_POINTER; vins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + vins->mConst.mType = IT_POINTER; vins->mConst.mMemory = IM_LOCAL; vins->mConst.mVarIndex = decResult->mVarIndex; block->Append(vins); @@ -3314,6 +3353,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* ins = new InterInstruction(exp->mLocation, IC_CONSTANT); ins->mDst.mType = IT_POINTER; ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ins->mConst.mType = IT_POINTER; ins->mConst.mOperandSize = dec->mSize; ins->mConst.mIntConst = 0; ins->mConst.mMemory = IM_GLOBAL; @@ -3332,6 +3372,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* for (int i = 0; i < refvars.Size(); i++) { InterInstruction* vins = new InterInstruction(exp->mLocation, IC_CONSTANT); + vins->mConst.mType = IT_POINTER; + vins->mDst.mType = IT_POINTER; vins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); @@ -3425,6 +3467,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* ains = new InterInstruction(exp->mLocation, IC_CONSTANT); ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ains->mConst.mType = IT_POINTER; ains->mConst.mOperandSize = procType->mBase->mSize; ains->mConst.mIntConst = 0; ains->mConst.mVarIndex = inlineMapper->mResult;; @@ -3461,6 +3504,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* ains->mCode = IC_CONSTANT; ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(IT_POINTER); + ains->mConst.mType = IT_POINTER; ains->mConst.mOperandSize = procType->mBase->mSize; ains->mConst.mIntConst = 0; ains->mConst.mVarIndex = inlineMapper->mResult; @@ -3475,6 +3519,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* pins = new InterInstruction(exp->mLocation, IC_CONSTANT); pins->mDst.mType = IT_POINTER; pins->mDst.mTemp = proc->AddTemporary(IT_POINTER); + pins->mConst.mType = IT_POINTER; pins->mConst.mVarIndex = 0; pins->mConst.mIntConst = 0; pins->mConst.mOperandSize = 2; @@ -3641,6 +3686,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction* ains = new InterInstruction(exp->mLocation, IC_CONSTANT); ains->mDst.mType = IT_POINTER; ains->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + ains->mConst.mType = IT_POINTER; ains->mConst.mOperandSize = procType->mBase->mSize; ains->mConst.mIntConst = 0; ains->mConst.mVarIndex = inlineMapper->mResult;; @@ -3751,6 +3797,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InterInstruction * zins = new InterInstruction(exp->mLocation, IC_CONSTANT); zins->mDst.mType = InterTypeOf(vl.mType); zins->mDst.mTemp = proc->AddTemporary(zins->mDst.mType); + zins->mConst.mType = zins->mDst.mType; zins->mConst.mIntConst = 0; block->Append(zins); @@ -4079,12 +4126,14 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* int ttemp = proc->AddTemporary(IT_BOOL); InterInstruction* tins = new InterInstruction(exp->mLocation, IC_CONSTANT); + tins->mConst.mType = IT_BOOL; tins->mConst.mIntConst = 1; tins->mDst.mType = IT_BOOL; tins->mDst.mTemp = ttemp; tblock->Append(tins); InterInstruction* fins = new InterInstruction(exp->mLocation, IC_CONSTANT); + fins->mConst.mType = IT_BOOL; fins->mConst.mIntConst = 0; fins->mDst.mType = IT_BOOL; fins->mDst.mTemp = ttemp; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 8bd9f33..dae74a9 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -25065,6 +25065,8 @@ bool NativeCodeBasicBlock::MoveZeroPageCrossBlockUp(int at, const NativeCodeInst return false; else if (mIns[i].ReferencesZeroPage(sins.mAddress)) return false; + else if (mIns[i].mType == ASMIT_JSR && mIns[i].ReferencesZeroPage(lins.mAddress)) + return false; } } @@ -40393,7 +40395,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) { mInterProc = proc; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "getchar"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "main"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks]; @@ -41688,7 +41690,6 @@ void NativeCodeProcedure::Optimize(void) else cnt++; - } while (changed); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index a2a5f9d..92cdf6c 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -5002,6 +5002,7 @@ Expression* Parser::ParsePostfixExpression(bool lhs) mScanner->NextToken(); } + bool parentCall = false; if ((exp->mDecType->mFlags & DTF_FUNC_THIS) && mThisPointer && mThisPointer->mType == DT_ARGUMENT) { Expression* texp = new Expression(mScanner->mLocation, EX_VARIABLE); @@ -5017,13 +5018,20 @@ Expression* Parser::ParsePostfixExpression(bool lhs) } else nexp->mRight = texp; + + parentCall = true; } nexp = ResolveOverloadCall(nexp); nexp->mDecType = exp->mDecType->mBase; if (nexp->mLeft->mDecType->mFlags & DTF_VIRTUAL) - nexp->mType = EX_VCALL; + { + if (parentCall) + exp->mDecType->mFlags |= DTF_STACKCALL; + else + nexp->mType = EX_VCALL; + } exp = nexp; }