diff --git a/oscar64/Constexpr.cpp b/oscar64/Constexpr.cpp index fe92fb8..c04ffae 100644 --- a/oscar64/Constexpr.cpp +++ b/oscar64/Constexpr.cpp @@ -2,7 +2,7 @@ #include ConstexprInterpreter::Value::Value(void) - : mDecType(TheVoidTypeDeclaration), + : mDecType(TheVoidTypeDeclaration), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mData(mShortData), mDataSize(0) { @@ -10,7 +10,7 @@ ConstexprInterpreter::Value::Value(void) ConstexprInterpreter::Value::Value(const Location & location) : mLocation(location), - mDecType(TheVoidTypeDeclaration), + mDecType(TheVoidTypeDeclaration), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mData(mShortData), mDataSize(0) { @@ -18,7 +18,7 @@ ConstexprInterpreter::Value::Value(const Location & location) ConstexprInterpreter::Value::Value(Expression* exp) : mLocation(exp->mLocation), - mDecType(exp->mDecType), + mDecType(exp->mDecType), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mDataSize(exp->mDecType->mSize) { @@ -51,12 +51,15 @@ void ConstexprInterpreter::Value::PutConst(int offset, Declaration* dec) for (int i = 0; i < dec->mBase->mSize; i++) PutIntAt(dec->mData[i], offset + i, TheConstCharTypeDeclaration); break; + case DT_CONST_POINTER: + PutPtrAt(new Value(mLocation, dec->mValue->mDecValue, dec->mBase, 0), offset, dec); + break; } } ConstexprInterpreter::Value::Value(const Location& location, Declaration* dec) : mLocation(location), - mDecType(dec), + mDecType(dec), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mDataSize(dec->mSize) { @@ -68,7 +71,7 @@ ConstexprInterpreter::Value::Value(const Location& location, Declaration* dec) ConstexprInterpreter::Value::Value(const Location& location, Declaration* dec, int size) : mLocation(location), - mDecType(dec), + mDecType(dec), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mDataSize(size) { @@ -80,7 +83,7 @@ ConstexprInterpreter::Value::Value(const Location& location, Declaration* dec, i ConstexprInterpreter::Value::Value(const Value& value) : mLocation(value.mLocation), - mDecType(value.mDecType), + mDecType(value.mDecType), mDecValue(nullptr), mBaseValue(value.mBaseValue), mOffset(value.mOffset), mDataSize(value.mDataSize) @@ -96,7 +99,7 @@ ConstexprInterpreter::Value::Value(const Value& value) ConstexprInterpreter::Value::Value(Value&& value) : mLocation(value.mLocation), - mDecType(value.mDecType), + mDecType(value.mDecType), mDecValue(nullptr), mBaseValue(value.mBaseValue), mOffset(value.mOffset), mDataSize(value.mDataSize) { @@ -115,7 +118,7 @@ ConstexprInterpreter::Value::Value(Value&& value) ConstexprInterpreter::Value::Value(Value* value) : mLocation(value->mLocation), - mDecType(value->mDecType), + mDecType(value->mDecType), mDecValue(value->mDecValue), mBaseValue(value), mOffset(0), mDataSize(0), mData(mShortData) { @@ -123,15 +126,23 @@ ConstexprInterpreter::Value::Value(Value* value) ConstexprInterpreter::Value::Value(const Location& location, Value* value, Declaration* type, int offset) : mLocation(location), - mDecType(type), + mDecType(type), mDecValue(nullptr), mBaseValue(value), mOffset(offset), mDataSize(0), mData(mShortData) { } +ConstexprInterpreter::Value::Value(const Location& location, Declaration* value, Declaration* type, int offset) + : mLocation(location), + mDecType(type), mDecValue(value), + mBaseValue(nullptr), mOffset(offset), + mDataSize(0), mData(mShortData) +{ +} + ConstexprInterpreter::Value::Value(const Location& location, const uint8* data, Declaration* type) : mLocation(location), - mDecType(type), + mDecType(type), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mDataSize(type->mSize) { @@ -146,7 +157,7 @@ ConstexprInterpreter::Value::Value(const Location& location, const uint8* data, ConstexprInterpreter::Value::Value(const Location& location, const ValueItem* data, Declaration* type) : mLocation(location), - mDecType(type), + mDecType(type), mDecValue(nullptr), mBaseValue(nullptr), mOffset(0), mDataSize(type->mSize) { @@ -339,6 +350,14 @@ ConstexprInterpreter::Value ConstexprInterpreter::Value::GetPtrAt(int at, Declar return Value(mLocation, dp->mBaseValue, type, uint16(dp[0].mByte | ((uint32)(dp[1].mByte) << 8))); } +void ConstexprInterpreter::Value::PutVarAt(Declaration* var, int64 v, int at, Declaration* type) +{ + ValueItem* dp = GetAddr() + at; + dp[0].mByte = uint8(v & 0xff); + dp[1].mByte = uint8((v >> 8) & 0xff); + mDecValue = var; +} + void ConstexprInterpreter::Value::PutIntAt(int64 v, int at, Declaration* type) { if (type->mType == DT_TYPE_FLOAT) @@ -521,7 +540,26 @@ Declaration* ConstexprInterpreter::Value::GetConst(int offset, Declaration* type Declaration* target; - if (vp.mBaseValue->mDecType->mType == DT_TYPE_ARRAY) + if (vp.mBaseValue->mDecValue) + { + target = new Declaration(mLocation, DT_VARIABLE_REF); + + if (vp.mBaseValue->mDecValue->mType == DT_VARIABLE_REF) + { + target->mBase = vp.mBaseValue->mDecValue->mBase; + target->mOffset = vp.mBaseValue->mDecValue->mOffset; + } + else + target->mBase = vp.mBaseValue->mDecValue; + + target->mOffset += vp.mOffset; + + dec->mValue = new Expression(mLocation, EX_CONSTANT); + dec->mValue->mDecType = type; + dec->mValue->mDecValue = target; + return dec; + } + else if (vp.mBaseValue->mDecType->mType == DT_TYPE_ARRAY) { target = new Declaration(mLocation, DT_CONST_DATA); target->mSize = vp.mBaseValue->mDataSize; @@ -540,6 +578,14 @@ Declaration* ConstexprInterpreter::Value::GetConst(int offset, Declaration* type dec->mValue->mDecType = target->mBase; dec->mValue->mDecValue = target; } + else if (vp.mDecValue) + { + dec = new Declaration(mLocation, DT_VARIABLE_REF); + dec->mBase = vp.mDecValue; + dec->mFlags = 0; + dec->mSize = type->mSize; + dec->mOffset = vp.mOffset; + } else { dec = new Declaration(mLocation, DT_CONST_ADDRESS); @@ -690,7 +736,12 @@ bool ConstexprInterpreter::AddParam(int& pos, Expression* pex, Declaration* dec) { mParams[pos] = Value(pex->mLocation, pex->mDecValue->mBase); if (pex->mDecValue->mSize > 0) - mParams[pos].PutConst(0, pex->mDecValue->mValue->mDecValue); + { + if (pex->mDecValue->mValue) + mParams[pos].PutConst(0, pex->mDecValue->mValue->mDecValue); + else + return false; + } } else return false; diff --git a/oscar64/Constexpr.h b/oscar64/Constexpr.h index 7cfc825..dd9cd86 100644 --- a/oscar64/Constexpr.h +++ b/oscar64/Constexpr.h @@ -19,8 +19,8 @@ protected: struct ValueItem { - uint8 mByte; - Value* mBaseValue; + uint8 mByte; + Value * mBaseValue; ValueItem(void); }; @@ -35,6 +35,7 @@ protected: Value(const Value& value); Value(Value&& value); Value(const Location& location, Value * value, Declaration * type, int offset); + Value(const Location& location, Declaration * value, Declaration* type, int offset); Value(Value* value); Value(const Location& location, const uint8 * data, Declaration* type); Value(const Location& location, const ValueItem* data, Declaration* type); @@ -48,7 +49,7 @@ protected: void Assign(const Value& v); Location mLocation; - Declaration * mDecType; + Declaration * mDecType, * mDecValue; Value * mBaseValue; int mOffset; ValueItem * mData; @@ -71,6 +72,7 @@ protected: void PutIntAt(int64 v, int at, Declaration* type); void PutFloatAt(double v, int at, Declaration* type); void PutPtrAt(const Value& v, int at, Declaration* type); + void PutVarAt(Declaration* var, int64 v, int at, Declaration* type); void PutConst(int offset, Declaration * dec); Declaration* GetConst(int offset, Declaration* type, LinkerSection* dataSection) const; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index fcedf8a..50e0486 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -21840,6 +21840,9 @@ bool NativeCodeBasicBlock::LoopRegisterXYMap(void) if (xfree) { pblock->mIns.Push(NativeCodeInstruction(pblock->mBranchIns, ASMIT_LDX, ASMIM_ZERO_PAGE, mini)); + if (pblock->mExitRequiredRegs[CPU_REG_Z]) + pblock->mIns.Push(NativeCodeInstruction(pblock->mBranchIns, ASMIT_ORA, ASMIM_IMMEDIATE, 0)); + pblock->mExitRequiredRegs += CPU_REG_X; for (int i = 0; i < eblocks.Size(); i++) { @@ -21850,6 +21853,9 @@ bool NativeCodeBasicBlock::LoopRegisterXYMap(void) else { pblock->mIns.Push(NativeCodeInstruction(pblock->mBranchIns, ASMIT_LDY, ASMIM_ZERO_PAGE, mini)); + if (pblock->mExitRequiredRegs[CPU_REG_Z]) + pblock->mIns.Push(NativeCodeInstruction(pblock->mBranchIns, ASMIT_ORA, ASMIM_IMMEDIATE, 0)); + pblock->mExitRequiredRegs += CPU_REG_Y; for (int i = 0; i < eblocks.Size(); i++) { @@ -50373,7 +50379,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) mInterProc = proc; mInterProc->mLinkerObject->mNativeProc = this; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "opp::vector>::reserve"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "screen_flip"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks]; @@ -51525,7 +51531,6 @@ void NativeCodeProcedure::Optimize(void) CheckBlocks(); - if (step > 4 && !changed) { ResetVisited();