Add non constant structured initializers

This commit is contained in:
drmortalwombat 2024-09-29 14:31:05 +02:00
parent bf5f5a807c
commit daeb3ddfdd
9 changed files with 824 additions and 248 deletions

View File

@ -124,8 +124,8 @@ public:
{ {
head.succ = l.head.succ; head.succ = l.head.succ;
head.pred = l.head.pred; head.pred = l.head.pred;
head.succ->pred = head; head.succ->pred = (listnode<T> *)&head;
head.pred->succ = head; head.pred->succ = (listnode<T> *)&head;
l.head.succ = (listnode<T> *)&(l.head); l.head.succ = (listnode<T> *)&(l.head);
l.head.pred = (listnode<T> *)&(l.head); l.head.pred = (listnode<T> *)&(l.head);
} }
@ -136,8 +136,8 @@ public:
{ {
head.succ = l.head.succ; head.succ = l.head.succ;
head.pred = l.head.pred; head.pred = l.head.pred;
head.succ->pred = head; head.succ->pred = (listnode<T> *)&head;
head.pred->succ = head; head.pred->succ = (listnode<T> *)&head;
l.head.succ = (listnode<T> *)&(l.head); l.head.succ = (listnode<T> *)&(l.head);
l.head.pred = (listnode<T> *)&(l.head); l.head.pred = (listnode<T> *)&(l.head);
return *this; return *this;

View File

@ -156,6 +156,21 @@ Expression::~Expression(void)
} }
Expression* Expression::ListAppend(Expression* lexp)
{
if (lexp)
{
Expression* nexp = new Expression(mLocation, EX_LIST);
nexp->mLeft = lexp;
nexp->mRight = this;
nexp->mDecType = mDecType;
return nexp;
}
else
return this;
}
void Expression::Dump(int ident) const void Expression::Dump(int ident) const
{ {
for (int i = 0; i < ident; i++) for (int i = 0; i < ident; i++)

View File

@ -259,6 +259,7 @@ public:
Expression* ConstantFold(Errors * errors, LinkerSection* dataSection, Linker * linker = nullptr); Expression* ConstantFold(Errors * errors, LinkerSection* dataSection, Linker * linker = nullptr);
Expression* ConstantDereference(Errors* errors, LinkerSection* dataSection); Expression* ConstantDereference(Errors* errors, LinkerSection* dataSection);
bool HasSideEffects(void) const; bool HasSideEffects(void) const;
Expression* ListAppend(Expression* lexp);
bool IsSame(const Expression* exp) const; bool IsSame(const Expression* exp) const;
bool IsRValue(void) const; bool IsRValue(void) const;

View File

@ -101,6 +101,8 @@ enum ErrorID
EERR_INVALID_FOLD_EXPRESSION, EERR_INVALID_FOLD_EXPRESSION,
ERRR_INSTANTIATE_ABSTRACT_CLASS, ERRR_INSTANTIATE_ABSTRACT_CLASS,
ERRR_INVALID_GOTO, ERRR_INVALID_GOTO,
EERR_INVALID_INITIALIZER,
EERR_INVALID_CONSTEXPR, EERR_INVALID_CONSTEXPR,
EERR_DOUBLE_FREE, EERR_DOUBLE_FREE,

View File

@ -4486,6 +4486,13 @@ bool InterInstruction::RemoveUnusedResultInstructions(InterInstruction* pre, Num
changed = true; changed = true;
} }
else if (mCode == IC_COPY && !mVolatile && mSrc[0].mTemp < 0 && mSrc[1].mTemp < 0 && mSrc[0].mMemory == mSrc[1].mMemory &&
mSrc[0].mVarIndex == mSrc[1].mVarIndex && mSrc[0].mLinkerObject == mSrc[1].mLinkerObject && mSrc[0].mIntConst == mSrc[1].mIntConst)
{
mNumOperands = 0;
mCode = IC_NONE;
changed = true;
}
else if (mDst.mTemp != -1) else if (mDst.mTemp != -1)
{ {
if (!requiredTemps[mDst.mTemp] && mDst.mTemp >= 0) if (!requiredTemps[mDst.mTemp] && mDst.mTemp >= 0)
@ -4632,7 +4639,14 @@ bool InterInstruction::RemoveUnusedStoreInstructions(const GrowingVariableArray&
} }
else if (mCode == IC_COPY) else if (mCode == IC_COPY)
{ {
if (mSrc[1].mMemory == IM_LOCAL) if (!mVolatile && mSrc[0].mTemp < 0 && mSrc[1].mTemp < 0 && mSrc[0].mMemory == mSrc[1].mMemory &&
mSrc[0].mVarIndex == mSrc[1].mVarIndex && mSrc[0].mLinkerObject == mSrc[1].mLinkerObject && mSrc[0].mIntConst == mSrc[1].mIntConst)
{
mSrc[0].mTemp = -1;
mCode = IC_NONE;
changed = true;
}
else if (mSrc[1].mMemory == IM_LOCAL)
{ {
if (localVars[mSrc[1].mVarIndex]->mAliased) if (localVars[mSrc[1].mVarIndex]->mAliased)
; ;
@ -8015,8 +8029,8 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSetsForward(const GrowingVariab
case IC_LOAD: case IC_LOAD:
vr = ins->mDst.mRange; vr = ins->mDst.mRange;
if (ins->mSrc[0].mTemp < 0 && ins->mSrc[0].mMemory == IM_FPARAM) if (ins->mSrc[0].mTemp < 0 && ins->mSrc[0].mMemory == IM_FPARAM && ins->mSrc[0].mIntConst == 0)
vr.Limit(mLocalParamValueRange[ins->mSrc[0].mVarIndex + int(ins->mSrc[0].mIntConst)]); vr.Limit(mLocalParamValueRange[ins->mSrc[0].mVarIndex]);
#if 1 #if 1
if (ins->mDst.mType == IT_INT8) if (ins->mDst.mType == IT_INT8)
{ {
@ -8721,8 +8735,8 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSetsForward(const GrowingVariab
} }
else if (ins->mCode == IC_STORE) else if (ins->mCode == IC_STORE)
{ {
if (ins->mSrc[1].mTemp < 0 && ins->mSrc[1].mMemory == IM_FPARAM) if (ins->mSrc[1].mTemp < 0 && ins->mSrc[1].mMemory == IM_FPARAM && ins->mSrc[0].mIntConst == 0)
mLocalParamValueRange[ins->mSrc[1].mVarIndex + int(ins->mSrc[1].mIntConst)] = ins->mSrc[0].mRange; mLocalParamValueRange[ins->mSrc[1].mVarIndex] = ins->mSrc[0].mRange;
} }
assert(mProc->mLocalValueRange.Size() == mExitRequiredTemps.Size()); assert(mProc->mLocalValueRange.Size() == mExitRequiredTemps.Size());
@ -22554,7 +22568,7 @@ void InterCodeProcedure::Close(void)
{ {
GrowingTypeArray tstack(IT_NONE); GrowingTypeArray tstack(IT_NONE);
CheckFunc = !strcmp(mIdent->mString, "bm_init"); CheckFunc = !strcmp(mIdent->mString, "foo");
CheckCase = false; CheckCase = false;
mEntryBlock = mBlocks[0]; mEntryBlock = mBlocks[0];

View File

@ -558,7 +558,43 @@ InterCodeGenerator::ExValue InterCodeGenerator::CoerceType(InterCodeProcedure* p
if (ins->mConst.mIntConst < min || ins->mConst.mIntConst > max) if (ins->mConst.mIntConst < min || ins->mConst.mIntConst > max)
{ {
mErrors->Error(exp->mLocation, EWARN_CONSTANT_TRUNCATED, "Integer constant truncated"); int64 min = 0, max = 0;
if (type->mFlags & DTF_SIGNED)
{
switch (type->mSize)
{
case 1:
min = -128; max = 127;
break;
case 2:
min = -32768; max = 32767;
break;
case 4:
min = -2147483648LL; max = 2147483647LL;
break;
}
}
else
{
switch (type->mSize)
{
case 1:
max = 255;
break;
case 2:
max = 65535;
break;
case 4:
max = 429467295LL;
break;
}
}
if (ins->mConst.mIntConst < min || ins->mConst.mIntConst > max)
{
mErrors->Error(exp->mLocation, EWARN_CONSTANT_TRUNCATED, "Integer constant truncated");
}
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -72,8 +72,11 @@ protected:
Declaration* ParseStructDeclaration(uint64 flags, DecType dt, Declaration* ptempl = nullptr); Declaration* ParseStructDeclaration(uint64 flags, DecType dt, Declaration* ptempl = nullptr);
Declaration* CopyConstantInitializer(int offset, Declaration* dtype, Expression* exp); Declaration* CopyConstantInitializer(int offset, Declaration* dtype, Expression* exp);
Expression* ParseInitExpression(Declaration* dtype, bool inner = false); Expression* ParseConstInitExpression(Declaration* dtype, bool inner = false);
Expression* ParseDeclarationExpression(Declaration* pdec); Expression* ParseDeclarationExpression(Declaration* pdec);
Expression* DefaultInitExpression(Expression* vexp);
Expression* ParseVarInitExpression(Expression* lexp, bool inner = false);
Expression* CloneVarInitExpression(Expression* vexp, Expression* iexp, Expression * qexp);
Declaration* ParsePostfixDeclaration(void); Declaration* ParsePostfixDeclaration(void);
Declaration* ReverseDeclaration(Declaration* odec, Declaration* bdec); Declaration* ReverseDeclaration(Declaration* odec, Declaration* bdec);

View File

@ -534,7 +534,7 @@ int main2(int argc, const char** argv)
printf("Starting %s %s\n", strProductName, strProductVersion); printf("Starting %s %s\n", strProductName, strProductVersion);
} }
compiler->WriteErrorFile(targetPath); compiler->RemoveErrorFile(targetPath);
{ {
char dstring[100], tstring[100]; char dstring[100], tstring[100];
@ -569,8 +569,6 @@ int main2(int argc, const char** argv)
if (diskPath[0]) if (diskPath[0])
d64 = new DiskImage(diskPath); d64 = new DiskImage(diskPath);
compiler->RemoveErrorFile(targetPath);
compiler->WriteOutputFile(targetPath, d64); compiler->WriteOutputFile(targetPath, d64);
if (d64) if (d64)