From 743510b54eb1254b0c4a632fe73a97657bb3b8bc Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 26 Dec 2021 11:31:04 +0100 Subject: [PATCH] Add verbose option -v to compiler --- oscar64/Compiler.cpp | 23 ++++-- oscar64/CompilerTypes.h | 2 + oscar64/InterCode.cpp | 20 ++++- oscar64/InterCode.h | 2 + oscar64/Preprocessor.cpp | 9 ++- oscar64/Preprocessor.h | 3 + oscar64/oscar64.cpp | 17 ++-- samples/fractals/make.bat | 1 + samples/fractals/mbhires.c | 7 ++ samples/fractals/mbmulti3d.c | 151 +++++++++++++++++++++++++++++++++++ 10 files changed, 218 insertions(+), 17 deletions(-) create mode 100644 samples/fractals/mbmulti3d.c diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 517e1f5..4b53142 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -47,6 +47,8 @@ void Compiler::AddDefine(const Ident* ident, const char* value) bool Compiler::ParseSource(void) { + mPreprocessor->mCompilerOptions = mCompilerOptions; + CompilationUnit* cunit; while (mErrors->mErrorCount == 0 && (cunit = mCompilationUnits->PendingUnit())) { @@ -364,31 +366,38 @@ bool Compiler::WriteOutputFile(const char* targetPath) if (mCompilerOptions & COPT_TARGET_PRG) { - printf("Writing <%s>\n", prgPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", prgPath); mLinker->WritePrgFile(prgPath); } else if (mCompilerOptions & COPT_TARGET_CRT16) { - printf("Writing <%s>\n", crtPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", crtPath); mLinker->WriteCrtFile(crtPath); } - printf("Writing <%s>\n", mapPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", mapPath); mLinker->WriteMapFile(mapPath); - printf("Writing <%s>\n", asmPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", asmPath); mLinker->WriteAsmFile(asmPath); - printf("Writing <%s>\n", lblPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", lblPath); mLinker->WriteLblFile(lblPath); - printf("Writing <%s>\n", intPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", intPath); mInterCodeModule->Disassemble(intPath); if (!(mCompilerOptions & COPT_NATIVE)) { - printf("Writing <%s>\n", bcsPath); + if (mCompilerOptions & COPT_VERBOSE) + printf("Writing <%s>\n", bcsPath); mByteCodeGenerator->WriteByteCodeStats(bcsPath); } diff --git a/oscar64/CompilerTypes.h b/oscar64/CompilerTypes.h index f9210e3..7bde944 100644 --- a/oscar64/CompilerTypes.h +++ b/oscar64/CompilerTypes.h @@ -13,6 +13,8 @@ static const uint64 COPT_TARGET_CRT16 = 0x200000000ULL; static const uint64 COPT_TARGET_CRT512 = 0x400000000ULL; static const uint64 COPT_TARGET_COPY = 0x800000000ULL; +static const uint64 COPT_VERBOSE = 0x1000000000ULL; + static const uint64 COPT_NATIVE = 0x01000000; static const uint64 COPT_DEFAULT = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 142c132..d591834 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -4932,6 +4932,18 @@ bool InterCodeBasicBlock::MergeCommonPathInstructions(void) return changed; } +bool InterCodeBasicBlock::IsTempModifiedOnPath(int temp, int at) const +{ + while (at < mInstructions.Size()) + { + if (mInstructions[at]->mDst.mTemp == temp) + return true; + at++; + } + + return false; +} + bool InterCodeBasicBlock::PushSinglePathResultInstructions(void) { int i; @@ -4960,7 +4972,7 @@ bool InterCodeBasicBlock::PushSinglePathResultInstructions(void) if (ins->mDst.mTemp >= 0 && !providedTemps[ins->mDst.mTemp] && !requiredTemps[ins->mDst.mTemp]) { int j = 0; - while (j < ins->mNumOperands && !(ins->mSrc[j].mTemp >= 0 && providedTemps[ins->mSrc[j].mTemp])) + while (j < ins->mNumOperands && !(ins->mSrc[j].mTemp >= 0 && providedTemps[ins->mSrc[j].mTemp]) && !IsTempModifiedOnPath(ins->mSrc[j].mTemp, i + 1)) j++; if (j == ins->mNumOperands && IsMoveable(ins->mCode) && (ins->mCode != IC_LOAD || !hadStore)) @@ -6586,6 +6598,8 @@ void InterCodeProcedure::Close(void) DisassembleDebug("Peephole optimized"); + BuildDataFlowSets(); + TempForwarding(); RemoveUnusedInstructions(); @@ -6612,6 +6626,8 @@ void InterCodeProcedure::Close(void) ResetVisited(); changed = mEntryBlock->PushSinglePathResultInstructions(); + DisassembleDebug("Pushed single path result"); + } while (changed); @@ -7030,6 +7046,7 @@ void InterCodeProcedure::Disassemble(FILE* file) void InterCodeProcedure::Disassemble(const char* name, bool dumpSets) { +#ifdef _WIN32 FILE* file; static bool initial = true; @@ -7063,6 +7080,7 @@ void InterCodeProcedure::Disassemble(const char* name, bool dumpSets) fclose(file); } +#endif } InterCodeModule::InterCodeModule(void) diff --git a/oscar64/InterCode.h b/oscar64/InterCode.h index dc3e843..f065e7d 100644 --- a/oscar64/InterCode.h +++ b/oscar64/InterCode.h @@ -543,6 +543,8 @@ public: void MarkRelevantStatics(void); void RemoveNonRelevantStatics(void); + bool IsTempModifiedOnPath(int temp, int at) const; + bool PushSinglePathResultInstructions(void); bool MergeCommonPathInstructions(void); diff --git a/oscar64/Preprocessor.cpp b/oscar64/Preprocessor.cpp index 3c57f6a..5fb7bd0 100644 --- a/oscar64/Preprocessor.cpp +++ b/oscar64/Preprocessor.cpp @@ -210,7 +210,8 @@ bool Preprocessor::EmbedData(const char* reason, const char* name, bool local, i if (ok) { - printf("%s \"%s\"\n", reason, source->mFileName); + if (mCompilerOptions & COPT_VERBOSE) + printf("%s \"%s\"\n", reason, source->mFileName); source->Limit(skip, limit); @@ -271,7 +272,9 @@ bool Preprocessor::OpenSource(const char * reason, const char* name, bool local) if (ok) { - printf("%s \"%s\"\n", reason, source->mFileName); + if (mCompilerOptions & COPT_VERBOSE) + printf("%s \"%s\"\n", reason, source->mFileName); + source->mUp = mSource; mSource = source; mLocation.mFileName = mSource->mFileName; @@ -318,7 +321,7 @@ bool Preprocessor::DropSource(void) } Preprocessor::Preprocessor(Errors* errors) - : mSource(nullptr), mSourceList(nullptr), mPaths(nullptr), mErrors(errors) + : mSource(nullptr), mSourceList(nullptr), mPaths(nullptr), mErrors(errors), mCompilerOptions(COPT_DEFAULT) { } diff --git a/oscar64/Preprocessor.h b/oscar64/Preprocessor.h index 711fcd6..dcded8e 100644 --- a/oscar64/Preprocessor.h +++ b/oscar64/Preprocessor.h @@ -3,6 +3,7 @@ #include "Errors.h" #include #include "MachineTypes.h" +#include "CompilerTypes.h" class SourceStack { @@ -64,6 +65,8 @@ public: SourceFile* mSource, * mSourceList; SourcePath* mPaths; + uint64 mCompilerOptions; + void AddPath(const char* path); bool NextLine(void); diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 8343aaf..e202c12 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -67,15 +67,13 @@ int main(int argc, const char** argv) char strProductName[100], strProductVersion[200]; #ifdef _WIN32 - if (GetProductAndVersion(strProductName, strProductVersion)) - { - printf("Starting %s %s\n", strProductName, strProductVersion); - } + GetProductAndVersion(strProductName, strProductVersion); DWORD length = ::GetModuleFileNameA(NULL, basePath, sizeof(basePath)); #else - printf("Starting oscar64 1.1.50\n"); + strcpy(strProductName, "oscar64"); + strcpy(strProductVersion, "1.1.50"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); @@ -177,6 +175,8 @@ int main(int argc, const char** argv) else compiler->AddDefine(Ident::Unique(def), ""); } + else if (arg[1] == 'v') + compiler->mCompilerOptions |= COPT_VERBOSE; else compiler->mErrors->Error(loc, EERR_COMMAND_LINE, "Invalid command line argument", arg); } @@ -203,6 +203,11 @@ int main(int argc, const char** argv) if (compiler->mErrors->mErrorCount == 0) { + if (compiler->mCompilerOptions & COPT_VERBOSE) + { + printf("Starting %s %s\n", strProductName, strProductVersion); + } + // Add runtime module compiler->mCompilationUnits->AddUnit(loc, crtPath, nullptr); @@ -221,7 +226,7 @@ int main(int argc, const char** argv) } else { - printf("oscar64 {-i=includePath} [-o=output.prg] [-rt=runtime.c] [-e] [-n] [-dSYMBOL[=value]] {source.c}\n"); + printf("oscar64 {-i=includePath} [-o=output.prg] [-rt=runtime.c] [-e] [-n] [-dSYMBOL[=value]] [-v] {source.c}\n"); return 0; } diff --git a/samples/fractals/make.bat b/samples/fractals/make.bat index 153ac95..d8650c8 100644 --- a/samples/fractals/make.bat +++ b/samples/fractals/make.bat @@ -1,4 +1,5 @@ ..\..\bin\oscar64 mbtext.c -n ..\..\bin\oscar64 mbhires.c -n ..\..\bin\oscar64 mbmulti.c -n +..\..\bin\oscar64 mbmulti3d.c -n diff --git a/samples/fractals/mbhires.c b/samples/fractals/mbhires.c index c463587..60f2fef 100644 --- a/samples/fractals/mbhires.c +++ b/samples/fractals/mbhires.c @@ -1,6 +1,7 @@ #include #include #include +#include #define Screen ((char *)0xe000) #define Color ((char *)0xc800) @@ -41,5 +42,11 @@ int main(void) } } + mmap_set(MMAP_NO_BASIC); + + getch(); + + vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000); + return 0; } diff --git a/samples/fractals/mbmulti3d.c b/samples/fractals/mbmulti3d.c new file mode 100644 index 0000000..a956c4c --- /dev/null +++ b/samples/fractals/mbmulti3d.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include + +#define Screen ((char *)0xe000) +#define Color1 ((char *)0xc800) +#define Color2 ((char *)0xd800) + +byte colors[2][17] = +{ + {0x00, + 0x44, 0x44, 0x55, 0x55, 0xdd, 0xdd, 0xff, 0xff, + 0x88, 0x88, 0xaa, 0xaa, 0xee, 0xee, 0xff, 0xff, + }, + {0x00, + 0x00, 0x11, 0x11, 0x55, 0x55, 0x77, 0x77, 0xff, + 0x00, 0x22, 0x22, 0xaa, 0xaa, 0xbb, 0xbb, 0xff, + } +}; + +void VLine(int x, int py, int ty, char c) +{ + if (py < 0) + py = 0; + if (ty > 100) + ty = 100; + + if (py < ty) + { + char mask = 0xc0 >> (2 * (x & 3)); + char * dp = Screen + 320 * (py >> 2) + 2 * (py & 3) + 2 * (x & ~3); + + + char c0 = colors[0][c] & mask, c1 = colors[1][c] & mask; + mask = ~mask; + char h = ty - py; + while (h) + { + dp[0] = (dp[0] & mask) | c0; + dp[1] = (dp[1] & mask) | c1; + + dp += 2; + if (!((int)dp & 7)) + dp += 312; + + h--; + } + } +} + +float iter(float xz, float yz) +{ + float x = 0.0, y = 0.0, r; + int i; + for(i=0; i<32; i++) + { + r = x * x + y * y; + if (r > 64.0) break; + + float xt = x * x - y * y + xz; + y = 2 * x * y + yz; + x = xt; + } + + + if (i == 32) + return 32; + else + return i - log(log(r)/log(64.0))/log(2.0) +} + +int light(float hl, float hu, float h) +{ + float dx = h - hl, dz = h - hu, dy = 0.1; + + float dd = sqrt(dx * dx + dy * dy + dz * dz); + int ni = (int)floor((-2 * dx + dy + dz) / dd * 0.408 * 8); + if (ni < 0) ni = 0; else if (ni > 7) ni = 7; + + return ni; +} + +int main(void) +{ + mmap_trampoline(); + + mmap_set(MMAP_NO_ROM); + + vic_setmode(VICM_HIRES_MC, Color1, Screen); + + vic.color_back = 0x00; + vic.color_border = 0x00; + + memset(Screen, 0, 8000); + memset(Color1, 0x26, 1000); + memset(Color2, 0x0f, 1000); + + float hl[200]; + + float w = -0.7; + float co = cos(w), si = sin(w); + + for(int x=-1; x<160; x+= 1) + { + int py = 20; + float hu = 0; + for(int y=1; y<200; y+= 1) + { + float fz = 2.0 / (float)y; + float fx = (float)(x - 80) * fz / 100.0; + + float mz = fz * 100.0 - 3.0, mx = fx * 100.0; + + float rx = mx * co - mz * si, rz = mx * si + mz * co; + float dp = iter(rx, rz); + float v = 2 * dp; + if (v < 1.0) v = 1.0; + + float fy = 5.0 * pow(2.0, - v * 0.4); + + int ni = light(hl[y], hu, fy); + + hl[y] = fy; + hu = fy; + + int ty = 20 + y / 2 + (int)(floor(fy / fz)); + + int c; + + if (dp != 32) + c = 1 + ni + 8 * ((int)floor(dp) & 1); + else + c = 0; + + if (x >= 0) + VLine(x, py, ty, c); + + py = ty; + } + } + + mmap_set(MMAP_NO_BASIC); + + getch(); + + vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000); + + return 0; +}