From 253be26335b3b0b77df761bdece00a03b83be4ae Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 18 Apr 2022 22:23:13 +0200 Subject: [PATCH] Constant pointer arithmetic for pointer initializers --- oscar64/Declaration.cpp | 5 +++++ oscar64/NativeCodeGenerator.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 8a978d4..7da13b7 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -464,6 +464,11 @@ Expression* Expression::ConstantFold(Errors * errors) ex->mDecType = mLeft->mDecType; return ex; } + else if (mType == EX_BINARY && mToken == TK_ADD && mLeft->mType == EX_VARIABLE && mLeft->mDecValue->mType == DT_VARIABLE && (mLeft->mDecValue->mFlags & DTF_CONST) && mLeft->mDecType->mType == DT_TYPE_POINTER && mRight->mType == EX_CONSTANT && mRight->mDecValue->mType == DT_CONST_INTEGER) + { + mLeft = mLeft->mDecValue->mValue; + return this->ConstantFold(errors); + } else if (mType == EX_QUALIFY && mLeft->mType == EX_VARIABLE && mLeft->mDecValue->mType == DT_VARIABLE && (mLeft->mDecValue->mFlags & DTF_GLOBAL) && mLeft->mDecType->mType == DT_TYPE_STRUCT) { Expression* ex = new Expression(mLocation, EX_VARIABLE); diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index df31a00..936966e 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -5653,7 +5653,7 @@ int NativeCodeBasicBlock::ShortMultiply(InterCodeProcedure* proc, NativeCodeProc lshift++; } - if (mul > 1 && (lshift > 3 || lmul != 1) && ins->mSrc[index].IsUByte() && ins->mSrc[index].mRange.mMaxValue < 16) + if (mul > 1 && ((lshift & 7) > 3 || lmul != 1) && ins->mSrc[index].IsUByte() && ins->mSrc[index].mRange.mMaxValue < 16) { int dreg = BC_REG_TMP + proc->mTempOffset[ins->mDst.mTemp];