From 398ed22b099bd9c0fb889b8884f3eec18aabbbc3 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 18 May 2025 18:41:37 +0200 Subject: [PATCH] Fix array member packing strategy --- oscar64/Declaration.cpp | 2 +- oscar64/Declaration.h | 7 ++ oscar64/GlobalAnalyzer.cpp | 126 ++++++++++++++++---------------- oscar64/GlobalAnalyzer.h | 2 +- oscar64/GlobalOptimizer.cpp | 4 - oscar64/InterCode.cpp | 89 ++++++++++++---------- oscar64/InterCodeGenerator.cpp | 22 +++++- oscar64/InterCodeGenerator.h | 2 +- oscar64/NativeCodeGenerator.cpp | 2 +- oscar64/Parser.cpp | 11 +++ 10 files changed, 153 insertions(+), 114 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 2616007..aebfd86 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -156,7 +156,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), mToken(TK_NONE) + : mLocation(loc), mEndLocation(loc), mType(type), mLeft(nullptr), mRight(nullptr), mConst(false), mDecType(nullptr), mDecValue(nullptr), mToken(TK_NONE), mFlags(0) { static uint32 gUID = 0; mUID = gUID++; diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 599a2d3..a5e1fc9 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -246,6 +246,12 @@ enum ExpressionType EX_AGGREGATE }; +static const uint32 ANAFL_LHS = (1U << 0); +static const uint32 ANAFL_RHS = (1U << 1); +static const uint32 ANAFL_ASSIGN = (1U << 2); +static const uint32 ANAFL_ALIAS = (1U << 3); + + class Expression { public: @@ -262,6 +268,7 @@ public: AsmInsType mAsmInsType; AsmInsMode mAsmInsMode; bool mConst; + uint32 mFlags; Expression* LogicInvertExpression(void); Expression* ConstantFold(Errors * errors, LinkerSection* dataSection, Linker * linker = nullptr); diff --git a/oscar64/GlobalAnalyzer.cpp b/oscar64/GlobalAnalyzer.cpp index d91abc5..92c1bc6 100644 --- a/oscar64/GlobalAnalyzer.cpp +++ b/oscar64/GlobalAnalyzer.cpp @@ -665,7 +665,7 @@ void GlobalAnalyzer::AnalyzeProcedure(Expression* cexp, Expression* exp, Declara if (mCompilerOptions & COPT_OPTIMIZE_CONST_EXPRESSIONS) dec->mFlags |= DTF_FUNC_CONSTEXPR; dec->mFlags |= DTF_FUNC_PURE; - Analyze(exp, dec, false, false); + Analyze(exp, dec, 0); Declaration* pdec = dec->mBase->mParams; int vi = 0; @@ -761,7 +761,7 @@ void GlobalAnalyzer::AnalyzeGlobalVariable(Declaration* dec) if (dec->mValue) { - Analyze(dec->mValue, dec, false, false); + Analyze(dec->mValue, dec, 0); } } } @@ -771,17 +771,19 @@ void GlobalAnalyzer::AnalyzeInit(Declaration* mdec) while (mdec) { if (mdec->mValue) - RegisterProc(Analyze(mdec->mValue, mdec, false, false)); + RegisterProc(Analyze(mdec->mValue, mdec, 0)); else if (mdec->mParams) AnalyzeInit(mdec->mParams); mdec = mdec->mNext; } } -Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, bool lhs, bool aliasing) +Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, uint32 flags) { Declaration* ldec, * rdec; + exp->mFlags = flags; + switch (exp->mType) { case EX_ERROR: @@ -799,7 +801,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo } else if (exp->mDecValue->mType == DT_CONST_POINTER) { - ldec = Analyze(exp->mDecValue->mValue, procDec, true, true); + ldec = Analyze(exp->mDecValue->mValue, procDec, ANAFL_LHS | ANAFL_ALIAS); if (ldec->mType == DT_VARIABLE) ldec->mFlags |= DTF_VAR_ALIASING; RegisterProc(ldec); @@ -823,7 +825,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo if (mCompilerOptions & COPT_DEBUGINFO) exp->mDecValue->mReferences.Push(exp); - if (aliasing) + if (flags & ANAFL_ALIAS) { Declaration* dec = exp->mDecValue; while (dec->mType == DT_VARIABLE_REF) @@ -840,14 +842,14 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo if (!(type->mFlags & DTF_CONST)) procDec->mFlags &= ~DTF_FUNC_CONSTEXPR; - if (lhs) + if (flags & ANAFL_LHS) procDec->mFlags &= ~DTF_FUNC_PURE; AnalyzeGlobalVariable(exp->mDecValue); } else { - if (lhs) + if (flags & ANAFL_LHS) exp->mDecValue->mFlags |= DTF_VAR_ADDRESS; if (!(exp->mDecValue->mFlags & DTF_ANALYZED)) @@ -861,8 +863,8 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_ASSIGNMENT: procDec->mComplexity += 5 * exp->mLeft->mDecType->mSize; - ldec = Analyze(exp->mLeft, procDec, true, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, ANAFL_LHS | ANAFL_RHS); + rdec = Analyze(exp->mRight, procDec, ANAFL_RHS); if (exp->mLeft->mType == EX_VARIABLE && exp->mRight->mType == EX_CALL && exp->mLeft->mDecType->mType == DT_TYPE_STRUCT) exp->mLeft->mDecValue->mFlags |= DTF_VAR_ALIASING; RegisterProc(rdec); @@ -871,33 +873,33 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_BINARY: procDec->mComplexity += 10 * exp->mDecType->mSize; - ldec = Analyze(exp->mLeft, procDec, lhs, false); - rdec = Analyze(exp->mRight, procDec, lhs, false); + ldec = Analyze(exp->mLeft, procDec, flags & ~ANAFL_ALIAS); + rdec = Analyze(exp->mRight, procDec, flags & ~ANAFL_ALIAS); return ldec; case EX_RELATIONAL: procDec->mComplexity += 10 * exp->mLeft->mDecType->mSize; - ldec = Analyze(exp->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, ANAFL_RHS); + rdec = Analyze(exp->mRight, procDec, ANAFL_RHS); return TheBoolTypeDeclaration; case EX_PREINCDEC: procDec->mComplexity += 10 * exp->mLeft->mDecType->mSize; - return Analyze(exp->mLeft, procDec, true, false); + return Analyze(exp->mLeft, procDec, ANAFL_LHS | ANAFL_RHS); case EX_PREFIX: if (exp->mToken == TK_BINARY_AND) { - ldec = Analyze(exp->mLeft, procDec, true, true); + ldec = Analyze(exp->mLeft, procDec, ANAFL_LHS | ANAFL_ALIAS); if (ldec->mType == DT_VARIABLE) ldec->mFlags |= DTF_VAR_ALIASING; } else if (exp->mToken == TK_MUL) { - ldec = Analyze(exp->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); procDec->mFlags &= ~DTF_FUNC_CONSTEXPR; - if (lhs) + if (flags & ANAFL_LHS) procDec->mFlags &= ~DTF_FUNC_PURE; return exp->mDecType; @@ -913,7 +915,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo else { procDec->mComplexity += 10 * exp->mLeft->mDecType->mSize; - return Analyze(exp->mLeft, procDec, false, false); + return Analyze(exp->mLeft, procDec, 0); } break; case EX_POSTFIX: @@ -922,31 +924,31 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_POSTINCDEC: procDec->mComplexity += 10 * exp->mLeft->mDecType->mSize; - return Analyze(exp->mLeft, procDec, true, false); + return Analyze(exp->mLeft, procDec, ANAFL_LHS | ANAFL_RHS); case EX_INDEX: procDec->mComplexity += 10 * exp->mRight->mDecType->mSize; - ldec = Analyze(exp->mLeft, procDec, lhs, false); + ldec = Analyze(exp->mLeft, procDec, flags & ~ANAFL_ALIAS); if (ldec->mType == DT_VARIABLE || ldec->mType == DT_ARGUMENT) { ldec = ldec->mBase; if (ldec->mType == DT_TYPE_POINTER) { - if (lhs) + if (flags & ANAFL_LHS) procDec->mFlags &= ~DTF_FUNC_PURE; procDec->mFlags &= ~DTF_FUNC_CONSTEXPR; } } - rdec = Analyze(exp->mRight, procDec, false, false); + rdec = Analyze(exp->mRight, procDec, 0); if (ldec->mBase) return ldec->mBase; break; case EX_QUALIFY: - Analyze(exp->mLeft, procDec, lhs, aliasing); + Analyze(exp->mLeft, procDec, flags); return exp->mDecValue->mBase; case EX_DISPATCH: procDec->mFlags |= DTF_PREVENT_INLINE; - Analyze(exp->mLeft, procDec, lhs, false); + Analyze(exp->mLeft, procDec, flags & ~ANAFL_ALIAS); // RegisterCall(procDec, exp->mLeft->mDecType); break; case EX_VCALL: @@ -957,7 +959,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_INLINE: procDec->mComplexity += 10; - ldec = Analyze(exp->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); if ((ldec->mFlags & DTF_INTRINSIC) && !ldec->mValue) { @@ -1044,7 +1046,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo if (pex->mType == EX_CALL && IsStackParam(pex->mDecType) && !(pdec && (pdec->mBase->mType == DT_TYPE_REFERENCE || pdec->mBase->mType == DT_TYPE_RVALUEREF))) ldec->mBase->mFlags |= DTF_STACKCALL; - RegisterProc(Analyze(pex, procDec, pdec && pdec->mBase->IsReference(), false)); + RegisterProc(Analyze(pex, procDec, (pdec && pdec->mBase->IsReference()) ? ANAFL_LHS : 0)); if (pdec) pdec = pdec->mNext; @@ -1058,12 +1060,12 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo break; case EX_LIST: case EX_COMMA: - RegisterProc(Analyze(exp->mLeft, procDec, false, false)); - return Analyze(exp->mRight, procDec, false, false); + RegisterProc(Analyze(exp->mLeft, procDec, 0)); + return Analyze(exp->mRight, procDec, 0); case EX_RETURN: if (exp->mLeft) { - RegisterProc(Analyze(exp->mLeft, procDec, procDec->mBase->mBase->IsReference(), false)); + RegisterProc(Analyze(exp->mLeft, procDec, procDec->mBase->mBase->IsReference() ? ANAFL_LHS : 0)); if (procDec->mBase->mBase && procDec->mBase->mBase->mType == DT_TYPE_STRUCT && procDec->mBase->mBase->mCopyConstructor) { if (procDec->mBase->mBase->mMoveConstructor) @@ -1084,47 +1086,47 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo if (exp->mType == EX_SEQUENCE) { if (exp->mLeft) - ldec = Analyze(exp->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); exp = exp->mRight; } else - return Analyze(exp, procDec, false, false); + return Analyze(exp, procDec, 0); } while (exp); break; case EX_SCOPE: - Analyze(exp->mLeft, procDec, false, false); + Analyze(exp->mLeft, procDec, 0); break; case EX_CONSTRUCT: if (exp->mLeft->mLeft) - Analyze(exp->mLeft->mLeft, procDec, false, false); + Analyze(exp->mLeft->mLeft, procDec, 0); if (exp->mLeft->mRight) - Analyze(exp->mLeft->mRight, procDec, false, false); + Analyze(exp->mLeft->mRight, procDec, 0); if (exp->mRight) - return Analyze(exp->mRight, procDec, false, false); + return Analyze(exp->mRight, procDec, 0); break; case EX_CLEANUP: - Analyze(exp->mRight, procDec, false, false); - return Analyze(exp->mLeft, procDec, lhs, false); + Analyze(exp->mRight, procDec, 0); + return Analyze(exp->mLeft, procDec, flags & ~ANAFL_ALIAS); case EX_WHILE: procDec->mFlags &= ~DTF_FUNC_CONSTEXPR; procDec->mComplexity += 20; - ldec = Analyze(exp->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); + rdec = Analyze(exp->mRight, procDec, 0); break; case EX_IF: procDec->mComplexity += 20; - ldec = Analyze(exp->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); + rdec = Analyze(exp->mRight->mLeft, procDec, 0); if (exp->mRight->mRight) - rdec = Analyze(exp->mRight->mRight, procDec, false, false); + rdec = Analyze(exp->mRight->mRight, procDec, 0); break; case EX_ELSE: break; @@ -1134,23 +1136,23 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo procDec->mComplexity += 30; if (exp->mLeft->mRight) - ldec = Analyze(exp->mLeft->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft->mRight, procDec, 0); if (exp->mLeft->mLeft->mLeft) - ldec = Analyze(exp->mLeft->mLeft->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft->mLeft->mLeft, procDec, 0); + rdec = Analyze(exp->mRight, procDec, 0); if (exp->mLeft->mLeft->mRight) - ldec = Analyze(exp->mLeft->mLeft->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft->mLeft->mRight, procDec, 0); break; case EX_FORBODY: - ldec = Analyze(exp->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); if (exp->mRight) - Analyze(exp->mRight, procDec, false, false); + Analyze(exp->mRight, procDec, 0); break; case EX_DO: procDec->mComplexity += 20; - ldec = Analyze(exp->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); + rdec = Analyze(exp->mRight, procDec, 0); break; case EX_BREAK: case EX_CONTINUE: @@ -1159,18 +1161,18 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_TYPE: break; case EX_TYPECAST: - return Analyze(exp->mLeft, procDec, false, false); + return Analyze(exp->mLeft, procDec, 0); break; case EX_LOGICAL_AND: - ldec = Analyze(exp->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); + rdec = Analyze(exp->mRight, procDec, 0); break; case EX_LOGICAL_OR: - ldec = Analyze(exp->mLeft, procDec, false, false); - rdec = Analyze(exp->mRight, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); + rdec = Analyze(exp->mRight, procDec, 0); break; case EX_LOGICAL_NOT: - ldec = Analyze(exp->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); break; case EX_ASSEMBLER: procDec->mFlags |= DTF_FUNC_ASSEMBLER; @@ -1181,14 +1183,14 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_UNDEFINED: break; case EX_SWITCH: - ldec = Analyze(exp->mLeft, procDec, false, false); + ldec = Analyze(exp->mLeft, procDec, 0); exp = exp->mRight; while (exp) { procDec->mComplexity += 10; if (exp->mLeft->mRight) - rdec = Analyze(exp->mLeft->mRight, procDec, false, false); + rdec = Analyze(exp->mLeft->mRight, procDec, 0); exp = exp->mRight; } break; @@ -1199,9 +1201,9 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_CONDITIONAL: procDec->mComplexity += exp->mDecType->mSize * 10; - ldec = Analyze(exp->mLeft, procDec, false, false); - RegisterProc(Analyze(exp->mRight->mLeft, procDec, lhs, aliasing)); - RegisterProc(Analyze(exp->mRight->mRight, procDec, lhs, aliasing)); + ldec = Analyze(exp->mLeft, procDec, 0); + RegisterProc(Analyze(exp->mRight->mLeft, procDec, flags)); + RegisterProc(Analyze(exp->mRight->mRight, procDec, flags)); break; } diff --git a/oscar64/GlobalAnalyzer.h b/oscar64/GlobalAnalyzer.h index 3f58960..d080dc5 100644 --- a/oscar64/GlobalAnalyzer.h +++ b/oscar64/GlobalAnalyzer.h @@ -35,7 +35,7 @@ protected: int CallerInvokes(Declaration* called); int CallerInvokes(Declaration* caller, Declaration* called); - Declaration* Analyze(Expression* exp, Declaration* procDec, bool lhs, bool aliasing); + Declaration* Analyze(Expression* exp, Declaration* procDec, uint32 flags); bool IsStackParam(const Declaration* pdec) const; bool MarkCycle(Declaration* rootDec, Declaration* procDec); diff --git a/oscar64/GlobalOptimizer.cpp b/oscar64/GlobalOptimizer.cpp index ef46333..9ff9c4d 100644 --- a/oscar64/GlobalOptimizer.cpp +++ b/oscar64/GlobalOptimizer.cpp @@ -614,10 +614,6 @@ void GlobalOptimizer::RegisterProc(Declaration* to) } } -static const uint32 ANAFL_LHS = (1U << 0); -static const uint32 ANAFL_RHS = (1U << 1); -static const uint32 ANAFL_ASSIGN = (1U << 2); - Declaration* GlobalOptimizer::Analyze(Expression* exp, Declaration* procDec, uint32 flags) { Declaration* ldec, * rdec; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 9b8b116..193d776 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -4,6 +4,8 @@ #include #include +#define DISASSEMBLE_OPT 0 + static bool CheckFunc; static bool CheckCase; @@ -27,6 +29,44 @@ static bool IsIntegerType(InterType type) return type >= IT_INT8 && type <= IT_INT32; } +static int64 SignedTypeMin(InterType type) +{ + switch (type) + { + case IT_INT8: + return -128; + case IT_INT16: + return -32768; + default: + return -0x80000000LL; + } +} + +static int64 SignedTypeMax(InterType type) +{ + switch (type) + { + case IT_INT8: + return 127; + case IT_INT16: + return 32767; + default: + return 0x7fffffff; + } +} + +static int64 BuildLowerBitsMask(int64 v) +{ + v |= v >> 32; + v |= v >> 16; + v |= v >> 8; + v |= v >> 4; + v |= v >> 2; + v |= v >> 1; + return v; +} + + IntegerValueRange::IntegerValueRange(void) : mMinState(S_UNKNOWN), mMaxState(S_UNKNOWN) { @@ -1224,7 +1264,10 @@ static int64 ConstantFolding(InterOperator oper, InterType type, int64 val1, int } break; case IA_SHL: - return ToTypedUnsigned(val1 << val2, type); + if (val1 < 0 && val2 < 16 && val1 << val2 >= SignedTypeMin(type)) + return ToTypedSigned(val1 << val2, type); + else + return ToTypedUnsigned(val1 << val2, type); case IA_SHR: return ToTypedUnsigned(val1, type) >> val2; case IA_SAR: @@ -6562,11 +6605,13 @@ void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingI if (iins->mSrc[0].mTemp >= 0 && iins->mSrc[1].mTemp < 0) { ins->mSrc[0].mTemp = iins->mSrc[0].mTemp; + ins->mSrc[0].mRange.AddConstValue(IT_INT16, -iins->mSrc[1].mIntConst); ins->mSrc[1].mIntConst += iins->mSrc[1].mIntConst; } else if (iins->mSrc[0].mTemp < 0 && iins->mSrc[1].mTemp >= 0) { ins->mSrc[0].mTemp = iins->mSrc[1].mTemp; + ins->mSrc[0].mRange.AddConstValue(IT_INT16, -iins->mSrc[0].mIntConst); ins->mSrc[1].mIntConst += iins->mSrc[0].mIntConst; } else @@ -6577,6 +6622,7 @@ void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingI if (iins->mSrc[0].mTemp < 0 && iins->mSrc[1].mTemp >= 0) { ins->mSrc[0].mTemp = iins->mSrc[1].mTemp; + ins->mSrc[0].mRange.AddConstValue(IT_INT16, iins->mSrc[0].mIntConst); ins->mSrc[1].mIntConst -= iins->mSrc[0].mIntConst; } else @@ -8067,43 +8113,6 @@ bool InterCodeBasicBlock::BuildGlobalIntegerRangeSets(bool initial, const Growin return changed; } -static int64 SignedTypeMin(InterType type) -{ - switch (type) - { - case IT_INT8: - return -128; - case IT_INT16: - return -32768; - default: - return -0x80000000LL; - } -} - -static int64 SignedTypeMax(InterType type) -{ - switch (type) - { - case IT_INT8: - return 127; - case IT_INT16: - return 32767; - default: - return 0x7fffffff; - } -} - -static int64 BuildLowerBitsMask(int64 v) -{ - v |= v >> 32; - v |= v >> 16; - v |= v >> 8; - v |= v >> 4; - v |= v >> 2; - v |= v >> 1; - return v; -} - void InterCodeBasicBlock::UnionIntegerRanges(const InterCodeBasicBlock* block) { if (mEntryValueRange.Size() > 0) @@ -23572,7 +23581,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "mbox::configure_animations"); + CheckFunc = !strcmp(mIdent->mString, "check_mulli"); CheckCase = false; mEntryBlock = mBlocks[0]; @@ -25523,7 +25532,7 @@ void InterCodeProcedure::Disassemble(FILE* file) void InterCodeProcedure::Disassemble(const char* name, bool dumpSets) { -#if 0 +#if DISASSEMBLE_OPT #ifdef _WIN32 FILE* file; static bool initial = true; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index c387831..42769b3 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -51,7 +51,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::ToValue(InterCodeProcedure* proc return v; } -InterCodeGenerator::ExValue InterCodeGenerator::Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level) +InterCodeGenerator::ExValue InterCodeGenerator::Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level, int limit) { while (v.mReference > level) { @@ -72,10 +72,18 @@ InterCodeGenerator::ExValue InterCodeGenerator::Dereference(InterCodeProcedure* ins->mSrc[0].mStride = v.mReference == 1 ? v.mType->mStripe : 1; - if (v.mReference == 1 && v.mType->mType == DT_TYPE_ENUM && !v.mBits) + if (v.mReference == 1) { - ins->mDst.mRange.LimitMin(v.mType->mMinValue); - ins->mDst.mRange.LimitMax(v.mType->mMaxValue); + if (v.mType->mType == DT_TYPE_ENUM && !v.mBits) + { + ins->mDst.mRange.LimitMin(v.mType->mMinValue); + ins->mDst.mRange.LimitMax(v.mType->mMaxValue); + } + else if (v.mType->mType == DT_TYPE_INTEGER && !v.mBits && limit > 0) + { + ins->mDst.mRange.LimitMin(0); + ins->mDst.mRange.LimitMax(limit - 1); + } } if (v.mType->mFlags & DTF_VOLATILE) @@ -2820,6 +2828,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } vl = Dereference(proc, exp, block, inlineMapper, vl, vl.mType->mType == DT_TYPE_POINTER ? 0 : 1); + vr = Dereference(proc, exp, block, inlineMapper, vr); if (vl.mType->mType != DT_TYPE_ARRAY && vl.mType->mType != DT_TYPE_POINTER) @@ -2854,6 +2863,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* ains->mSrc[1].mMemory = IM_INDIRECT; ains->mSrc[0].mType = IT_INT16; ains->mSrc[0].mTemp = mins->mDst.mTemp; + if (vl.mType->mType == DT_TYPE_ARRAY && vl.mType->mSize > vl.mType->mBase->mSize && (exp->mFlags & ANAFL_RHS)) + { + ains->mSrc[0].mRange.LimitMin(0); + ains->mSrc[0].mRange.LimitMax(vl.mType->mSize); + } ains->mSrc[1].mType = IT_POINTER; ains->mSrc[1].mTemp = vl.mTemp; ains->mDst.mType = IT_POINTER; diff --git a/oscar64/InterCodeGenerator.h b/oscar64/InterCodeGenerator.h index 55cfe04..2129972 100644 --- a/oscar64/InterCodeGenerator.h +++ b/oscar64/InterCodeGenerator.h @@ -94,7 +94,7 @@ protected: void BuildSwitchTree(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock* block, InlineMapper * inlineMapper, ExValue v, const SwitchNodeArray& nodes, int left, int right, int vleft, int vright, InterCodeBasicBlock* dblock); ExValue ToValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v); - ExValue Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level = 0); + ExValue Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level = 0, int limit = 0); ExValue CoerceType(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, Declaration * type, bool checkTrunc = true); ExValue TranslateExpression(Declaration * procType, InterCodeProcedure * proc, InterCodeBasicBlock*& block, Expression* exp, DestructStack*& destack, GotoNode*& gotos, const BranchTarget & breakBlock, const BranchTarget& continueBlock, InlineMapper * inlineMapper, ExValue * lrexp = nullptr); void TranslateLogic(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock* block, InterCodeBasicBlock* tblock, InterCodeBasicBlock* fblock, Expression* exp, DestructStack*& destack, GotoNode*& gotos, InlineMapper* inlineMapper); diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 5eec13e..c44a4e9 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -55021,7 +55021,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) mInterProc->mLinkerObject->mNativeProc = this; - CheckFunc = !strcmp(mIdent->mString, "show_floor"); + CheckFunc = !strcmp(mIdent->mString, "Test::run"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks]; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 45a6420..f41db17 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -516,8 +516,19 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio } else { + int alignment = mdec->mBase->mAlignment; + if (alignment == 0) + alignment = 1; + bitsleft = 0; + if (mdec->mBase->mType == DT_TYPE_ARRAY && mdec->mBase->mBase->IsSimpleType() && mdec->mBase->mBase->mSize > 1) + alignment = mdec->mBase->mBase->mSize; + + offset = (offset + alignment - 1) & ~(alignment - 1); offset += mdec->mBase->mSize; + + if (alignment > dec->mAlignment) + dec->mAlignment = alignment; } if (offset > dec->mSize)