Fix float param to const propagation
This commit is contained in:
parent
0184a550c5
commit
fbfd597306
|
@ -923,16 +923,78 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio
|
||||||
mLeft->mDecType->mType == DT_TYPE_ARRAY && mLeft->mDecType->mStride == 0 &&
|
mLeft->mDecType->mType == DT_TYPE_ARRAY && mLeft->mDecType->mStride == 0 &&
|
||||||
mRight->mType == EX_CONSTANT && mRight->mDecValue->mType == DT_CONST_INTEGER)
|
mRight->mType == EX_CONSTANT && mRight->mDecValue->mType == DT_CONST_INTEGER)
|
||||||
{
|
{
|
||||||
|
int offset = int(mDecType->mSize * mRight->mDecValue->mInteger);
|
||||||
|
|
||||||
|
if (mDecType->IsSimpleType() && (mLeft->mDecValue->mFlags & DTF_CONST) && mLeft->mDecValue->mValue && mLeft->mDecValue->mValue->mType == EX_CONSTANT && mLeft->mDecValue->mValue->mDecValue->mType == DT_CONST_STRUCT)
|
||||||
|
{
|
||||||
|
Declaration* mdec = mLeft->mDecValue->mValue->mDecValue->mParams;
|
||||||
|
while (mdec && mdec->mOffset != offset)
|
||||||
|
mdec = mdec->mNext;
|
||||||
|
|
||||||
|
if (mdec)
|
||||||
|
{
|
||||||
|
Expression* ex = new Expression(mLocation, EX_CONSTANT);
|
||||||
|
ex->mDecValue = mdec;
|
||||||
|
ex->mDecType = mDecType;
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Expression* ex = new Expression(mLocation, EX_VARIABLE);
|
Expression* ex = new Expression(mLocation, EX_VARIABLE);
|
||||||
Declaration* dec = new Declaration(mLocation, DT_VARIABLE_REF);
|
Declaration* dec = new Declaration(mLocation, DT_VARIABLE_REF);
|
||||||
dec->mFlags = mLeft->mDecValue->mFlags;
|
dec->mFlags = mLeft->mDecValue->mFlags;
|
||||||
dec->mBase = mLeft->mDecValue;
|
dec->mBase = mLeft->mDecValue;
|
||||||
dec->mOffset = int(mDecType->mSize * mRight->mDecValue->mInteger);
|
dec->mOffset = offset;
|
||||||
dec->mSize = mDecType->mSize;
|
dec->mSize = mDecType->mSize;
|
||||||
ex->mDecValue = dec;
|
ex->mDecValue = dec;
|
||||||
ex->mDecType = mDecType;
|
ex->mDecType = mDecType;
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
else if (mType == EX_INDEX && mLeft->mType == EX_VARIABLE && mLeft->mDecValue->mType == DT_VARIABLE_REF && (mLeft->mDecValue->mFlags & DTF_GLOBAL) &&
|
||||||
|
mLeft->mDecType->mType == DT_TYPE_ARRAY && mLeft->mDecType->mStride == 0 &&
|
||||||
|
mRight->mType == EX_CONSTANT && mRight->mDecValue->mType == DT_CONST_INTEGER)
|
||||||
|
{
|
||||||
|
int offset = mLeft->mDecValue->mOffset + int(mDecType->mSize * mRight->mDecValue->mInteger);
|
||||||
|
|
||||||
|
if (mDecType->IsSimpleType() && (mLeft->mDecValue->mFlags & DTF_CONST) && mLeft->mDecValue->mBase->mValue && mLeft->mDecValue->mBase->mValue->mType == EX_CONSTANT && mLeft->mDecValue->mBase->mValue->mDecValue->mType == DT_CONST_STRUCT)
|
||||||
|
{
|
||||||
|
Declaration* mdec = mLeft->mDecValue->mBase->mValue->mDecValue->mParams;
|
||||||
|
|
||||||
|
int coffset = offset;
|
||||||
|
while (mdec)
|
||||||
|
{
|
||||||
|
if (mdec->mType == DT_CONST_STRUCT)
|
||||||
|
{
|
||||||
|
if (mdec->mOffset > coffset || mdec->mOffset + mdec->mSize <= coffset)
|
||||||
|
mdec = mdec->mNext;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
coffset -= mdec->mOffset;
|
||||||
|
mdec = mdec->mParams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mdec->mOffset != coffset)
|
||||||
|
mdec = mdec->mNext;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Expression* ex = new Expression(mLocation, EX_CONSTANT);
|
||||||
|
ex->mDecValue = mdec;
|
||||||
|
ex->mDecType = mDecType;
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Expression* ex = new Expression(mLocation, EX_VARIABLE);
|
||||||
|
Declaration* dec = new Declaration(mLocation, DT_VARIABLE_REF);
|
||||||
|
dec->mFlags = mLeft->mDecValue->mFlags;
|
||||||
|
dec->mBase = mLeft->mDecValue->mBase;
|
||||||
|
dec->mOffset = offset;
|
||||||
|
dec->mSize = mDecType->mSize;
|
||||||
|
ex->mDecValue = dec;
|
||||||
|
ex->mDecType = mDecType;
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
else if (mType == EX_CALL && mLeft->mType == EX_CONSTANT && (mLeft->mDecValue->mFlags & DTF_INTRINSIC) && mRight->mType == EX_CONSTANT)
|
else if (mType == EX_CALL && mLeft->mType == EX_CONSTANT && (mLeft->mDecValue->mFlags & DTF_INTRINSIC) && mRight->mType == EX_CONSTANT)
|
||||||
{
|
{
|
||||||
Declaration* decf = mLeft->mDecValue, * decp = mRight->mDecValue;
|
Declaration* decf = mLeft->mDecValue, * decp = mRight->mDecValue;
|
||||||
|
@ -1116,9 +1178,10 @@ Declaration* Declaration::ConstCast(Declaration* ntype)
|
||||||
}
|
}
|
||||||
else if (ntype->mType == DT_TYPE_INTEGER || ntype->mType == DT_TYPE_BOOL || ntype->mType == DT_TYPE_ENUM)
|
else if (ntype->mType == DT_TYPE_INTEGER || ntype->mType == DT_TYPE_BOOL || ntype->mType == DT_TYPE_ENUM)
|
||||||
{
|
{
|
||||||
if (mType == DT_TYPE_FLOAT)
|
if (mType == DT_CONST_FLOAT)
|
||||||
{
|
{
|
||||||
Declaration* pdec = this->Clone();
|
Declaration* pdec = this->Clone();
|
||||||
|
pdec->mType = DT_CONST_INTEGER;
|
||||||
pdec->mInteger = int64(mNumber);
|
pdec->mInteger = int64(mNumber);
|
||||||
pdec->mBase = ntype;
|
pdec->mBase = ntype;
|
||||||
pdec->mSize = ntype->mSize;
|
pdec->mSize = ntype->mSize;
|
||||||
|
@ -1134,7 +1197,7 @@ Declaration* Declaration::ConstCast(Declaration* ntype)
|
||||||
}
|
}
|
||||||
else if (ntype->mType == DT_TYPE_FLOAT)
|
else if (ntype->mType == DT_TYPE_FLOAT)
|
||||||
{
|
{
|
||||||
if (mType == DT_TYPE_FLOAT)
|
if (mType == DT_CONST_FLOAT)
|
||||||
{
|
{
|
||||||
Declaration* pdec = this->Clone();
|
Declaration* pdec = this->Clone();
|
||||||
pdec->mBase = ntype;
|
pdec->mBase = ntype;
|
||||||
|
@ -1143,6 +1206,7 @@ Declaration* Declaration::ConstCast(Declaration* ntype)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Declaration* pdec = this->Clone();
|
Declaration* pdec = this->Clone();
|
||||||
|
pdec->mType = DT_CONST_FLOAT;
|
||||||
pdec->mNumber = float(mInteger);
|
pdec->mNumber = float(mInteger);
|
||||||
pdec->mBase = ntype;
|
pdec->mBase = ntype;
|
||||||
pdec->mSize = ntype->mSize;
|
pdec->mSize = ntype->mSize;
|
||||||
|
|
|
@ -11638,6 +11638,7 @@ bool InterCodeBasicBlock::LoadStoreForwarding(const GrowingInstructionPtrArray&
|
||||||
{
|
{
|
||||||
InterInstruction* tins = sins->Clone();
|
InterInstruction* tins = sins->Clone();
|
||||||
tins->mSrc[1] = ins->mSrc[1];
|
tins->mSrc[1] = ins->mSrc[1];
|
||||||
|
tins->mSrc[1].mOperandSize = sins->mSrc[1].mOperandSize;
|
||||||
tins->mSrc[1].mIntConst = sins->mSrc[1].mIntConst - ins->mSrc[0].mIntConst + ins->mSrc[1].mIntConst;
|
tins->mSrc[1].mIntConst = sins->mSrc[1].mIntConst - ins->mSrc[0].mIntConst + ins->mSrc[1].mIntConst;
|
||||||
n++;
|
n++;
|
||||||
mInstructions.Insert(i + n, tins);
|
mInstructions.Insert(i + n, tins);
|
||||||
|
@ -20502,7 +20503,7 @@ void InterCodeProcedure::Close(void)
|
||||||
{
|
{
|
||||||
GrowingTypeArray tstack(IT_NONE);
|
GrowingTypeArray tstack(IT_NONE);
|
||||||
|
|
||||||
CheckFunc = !strcmp(mIdent->mString, "main");
|
CheckFunc = !strcmp(mIdent->mString, "addGameObjectCannon");
|
||||||
CheckCase = false;
|
CheckCase = false;
|
||||||
|
|
||||||
mEntryBlock = mBlocks[0];
|
mEntryBlock = mBlocks[0];
|
||||||
|
|
|
@ -5408,7 +5408,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod
|
||||||
proc->mLinkerObject->mFullIdent = dec->FullIdent();
|
proc->mLinkerObject->mFullIdent = dec->FullIdent();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (proc->mIdent && !strcmp(proc->mIdent->mString, "main"))
|
if (proc->mIdent && !strcmp(proc->mIdent->mString, "addGameObjectCircle"))
|
||||||
exp->Dump(0);
|
exp->Dump(0);
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -42727,7 +42727,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mIns.Insert(i + 2, NativeCodeInstruction(mIns[i + 0].mIns, ASMIT_LDY, ASMIM_ZERO_PAGE, ireg));
|
mIns.Insert(i + 2, NativeCodeInstruction(mIns[i + 0].mIns, ASMIT_LDY, ASMIM_ZERO_PAGE, ireg));
|
||||||
mIns[i + 2].mLive = mIns[i + 3].mLive | LIVE_CPU_REG_Y | LIVE_MEM;
|
mIns[i + 2].mLive = mIns[i + 1].mLive | LIVE_CPU_REG_Y | LIVE_MEM;
|
||||||
ypos = i + 2;
|
ypos = i + 2;
|
||||||
mIns[i + 3].mAddress = breg;
|
mIns[i + 3].mAddress = breg;
|
||||||
}
|
}
|
||||||
|
@ -42753,7 +42753,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
|
||||||
if (FindImmediateStore(i, mIns[i + 2].mAddress + 1, ains))
|
if (FindImmediateStore(i, mIns[i + 2].mAddress + 1, ains))
|
||||||
{
|
{
|
||||||
mIns.Insert(i + 2, NativeCodeInstruction(mIns[i + 0].mIns, ASMIT_LDX, ASMIM_ZERO_PAGE, mIns[i + 2].mAddress));
|
mIns.Insert(i + 2, NativeCodeInstruction(mIns[i + 0].mIns, ASMIT_LDX, ASMIM_ZERO_PAGE, mIns[i + 2].mAddress));
|
||||||
mIns[i + 2].mLive = mIns[i + 3].mLive | LIVE_CPU_REG_X;
|
mIns[i + 2].mLive = mIns[i + 1].mLive | LIVE_CPU_REG_X;
|
||||||
mIns[i + 3].mMode = ASMIM_ABSOLUTE_X;
|
mIns[i + 3].mMode = ASMIM_ABSOLUTE_X;
|
||||||
|
|
||||||
if (ains->mMode == ASMIM_IMMEDIATE)
|
if (ains->mMode == ASMIM_IMMEDIATE)
|
||||||
|
|
|
@ -6576,7 +6576,7 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
|
|
||||||
if (!nexp->mDecType)
|
if (!nexp->mDecType)
|
||||||
nexp->mDecType = TheVoidTypeDeclaration;
|
nexp->mDecType = TheVoidTypeDeclaration;
|
||||||
exp = nexp;
|
exp = nexp->ConstantFold(mErrors, mDataSection, mCompilationUnits->mLinker);
|
||||||
}
|
}
|
||||||
else if (mScanner->mToken == TK_OPEN_PARENTHESIS)
|
else if (mScanner->mToken == TK_OPEN_PARENTHESIS)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue