diff --git a/include/stdio.c b/include/stdio.c index 46491f9..29dc146 100644 --- a/include/stdio.c +++ b/include/stdio.c @@ -156,7 +156,10 @@ inline int nformi(const sinfo * si, char * str, int v, bool s) u = -v; } - char i = 10; + char b = si->width; + if (b < 10) + b = 10; + char i = b; while (u > 0) { int c = u % si->base; @@ -168,7 +171,7 @@ inline int nformi(const sinfo * si, char * str, int v, bool s) u /= si->base; } - char digits = si->precision != 255 ? 10 - si->precision : 9; + char digits = si->precision != 255 ? b - si->precision : b - 1; while (i > digits) sp[--i] = '0'; @@ -184,12 +187,21 @@ inline int nformi(const sinfo * si, char * str, int v, bool s) else if (si->sign) sp[--i] = '+'; - while (i > 10 - si->width) - sp[--i] = si->fill; - char j = 0; - while (i < 10) - sp[j++] = sp[i++]; + if (si->left) + { + while (i < b) + sp[j++] = sp[i++]; + while (j < si->width) + sp[j++] = si->fill; + } + else + { + while (i + si->width > b) + sp[--i] = si->fill; + while (i < b) + sp[j++] = sp[i++]; + } return j; } @@ -207,7 +219,11 @@ int nforml(const sinfo * si, char * str, long v, bool s) u = -v; } - char i = 16; + char b = si->width; + if (b < 16) + b = 16; + char i = b; + while (u > 0) { int c = u % si->base; @@ -219,7 +235,7 @@ int nforml(const sinfo * si, char * str, long v, bool s) u /= si->base; } - char digits = si->precision != 255 ? 16 - si->precision : 15; + char digits = si->precision != 255 ? b - si->precision : b - 1; while (i > digits) sp[--i] = '0'; @@ -235,12 +251,21 @@ int nforml(const sinfo * si, char * str, long v, bool s) else if (si->sign) sp[--i] = '+'; - while (i > 16 - si->width) - sp[--i] = si->fill; - char j = 0; - while (i < 16) - sp[j++] = sp[i++]; + if (si->left) + { + while (i < b) + sp[j++] = sp[i++]; + while (j < si->width) + sp[j++] = si->fill; + } + else + { + while (i + si->width > b) + sp[--i] = si->fill; + while (i < b) + sp[j++] = sp[i++]; + } return j; } @@ -371,10 +396,18 @@ int nformf(const sinfo * si, char * str, float f, char type) if (d < si->width) { - for(char i=1; i<=d; i++) - sp[si->width - i] = sp[d - i]; - for(char i=0; iwidth-d; i++) - sp[i] = ' '; + if (si->left) + { + for(char i=d; iwidth; i++) + sp[i] = ' '; + } + else + { + for(char i=1; i<=d; i++) + sp[si->width - i] = sp[d - i]; + for(char i=0; iwidth-d; i++) + sp[i] = ' '; + } d = si->width; } @@ -407,7 +440,7 @@ char * sformat(char * buff, const char * fmt, int * fps, bool print) c = *p++; si.base = 10; - si.width = 1; + si.width = 0; si.precision = 255; si.fill = ' '; si.sign = false; @@ -422,6 +455,8 @@ char * sformat(char * buff, const char * fmt, int * fps, bool print) si.fill = '0'; else if (c == '#') si.prefix = true; + else if (c == '-') + si.left = true; else break; c = *p++; @@ -497,12 +532,47 @@ char * sformat(char * buff, const char * fmt, int * fps, bool print) else if (c == 's') { char * sp = (char *)*fps++; + + char n = 0; + if (si.width) + { + while (sp[n]) + n++; + } + + if (!si.left) + { + while (n < si.width) + { + bp[bi++] = si.fill; + n++; + } + } + if (print) + { + if (bi) + { + bp[bi] = 0; + puts(bp); + bi = 0; + } puts(sp); + } else { while (char c = *sp++) - *bp++ = c; + bp[bi++] = c; + + } + + if (si.left) + { + while (n < si.width) + { + bp[bi++] = si.fill; + n++; + } } } else if (c == 'c') diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 63ce20e..a98871e 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -8177,6 +8177,34 @@ void InterCodeBasicBlock::SingleBlockLoopOptimisation(const NumberSet& aliasedPa for (int i = 0; i < mInstructions.Size(); i++) { + if (i + 1 < mInstructions.Size()) + { + InterInstruction* ins0 = mInstructions[i + 0]; + InterInstruction* ins1 = mInstructions[i + 1]; + if (ins0->mCode == IC_BINARY_OPERATOR && ins0->mOperator == IA_ADD && ins1->mCode == IC_BINARY_OPERATOR && ins1->mOperator == IA_ADD) + { + if (ins0->mDst.mTemp == ins1->mSrc[1].mTemp && IsIntegerType(ins1->mDst.mType) && ins1->mSrc[1].mFinal) + { + if (ins0->mSrc[0].mTemp >= 0 && ins0->mSrc[1].mTemp >= 0 && ins1->mSrc[0].mTemp >= 0) + { + if ((dep[ins0->mSrc[1].mTemp] == DEP_INDEX || dep[ins0->mSrc[1].mTemp] == DEP_INDEX_EXTENDED) && + (dep[ins0->mSrc[0].mTemp] == DEP_UNKNOWN || dep[ins0->mSrc[0].mTemp] == DEP_VARIABLE) && + (dep[ins1->mSrc[0].mTemp] == DEP_UNKNOWN || dep[ins1->mSrc[0].mTemp] == DEP_VARIABLE)) + { + InterOperand op = ins0->mSrc[1]; + ins0->mSrc[1] = ins1->mSrc[0]; + ins1->mSrc[0] = op; + if (dep[ins0->mSrc[0].mTemp] == DEP_UNKNOWN && dep[ins0->mSrc[1].mTemp] == DEP_UNKNOWN) + ins0->mInvariant = true; + dep[ins0->mDst.mTemp] = DEP_UNKNOWN; + dep[ins1->mDst.mTemp] = DEP_UNKNOWN; + changed = true; + } + } + } + } + } + InterInstruction* ins = mInstructions[i]; int t = ins->mDst.mTemp; if (t >= 0) @@ -9971,6 +9999,23 @@ void InterCodeProcedure::Close(void) #endif +#if 1 + BuildLoopPrefix(); + DisassembleDebug("added dominators"); + + BuildDataFlowSets(); + + ResetVisited(); + mEntryBlock->SingleBlockLoopOptimisation(mParamAliasedSet); + + DisassembleDebug("single block loop opt 3"); + + BuildDataFlowSets(); + + BuildTraces(false); + DisassembleDebug("Rebuilt traces"); +#endif + #if 1 ResetVisited(); if (mEntryBlock->CheckStaticStack()) diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 0aa2066..c1573f6 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -217,7 +217,8 @@ int main2(int argc, const char** argv) // Add runtime module - compiler->mCompilationUnits->AddUnit(loc, crtPath, nullptr); + if (crtPath[0]) + compiler->mCompilationUnits->AddUnit(loc, crtPath, nullptr); if (compiler->ParseSource() && compiler->GenerateCode()) {