Fix compile order based on dependency graph

This commit is contained in:
drmortalwombat 2022-02-19 12:58:51 +01:00
parent 6bd3ecb689
commit 6ac606c91b
10 changed files with 58 additions and 27 deletions

View File

@ -108,6 +108,30 @@ void Compiler::RegisterRuntime(const Location & loc, const Ident* ident)
}
}
void Compiler::CompileProcedure(InterCodeProcedure* proc)
{
if (!proc->mCompiled)
{
proc->mCompiled = true;
for (int i = 0; i < proc->mCalledFunctions.Size(); i++)
CompileProcedure(proc->mCalledFunctions[i]);
if (proc->mNativeProcedure)
{
NativeCodeProcedure* ncproc = new NativeCodeProcedure(mNativeCodeGenerator);
ncproc->Compile(proc);
}
else
{
ByteCodeProcedure* bgproc = new ByteCodeProcedure();
bgproc->Compile(mByteCodeGenerator, proc);
mByteCodeFunctions.Push(bgproc);
}
}
}
bool Compiler::GenerateCode(void)
{
Location loc;
@ -274,7 +298,7 @@ bool Compiler::GenerateCode(void)
}
#endif
for (int i = mInterCodeModule->mProcedures.Size() - 1; i >=0; i--)
for (int i = 0; i < mInterCodeModule->mProcedures.Size(); i++)
{
InterCodeProcedure* proc = mInterCodeModule->mProcedures[i];
@ -284,19 +308,7 @@ bool Compiler::GenerateCode(void)
proc->Disassemble("final");
#endif
if (proc->mNativeProcedure)
{
NativeCodeProcedure* ncproc = new NativeCodeProcedure(mNativeCodeGenerator);
ncproc->Compile(proc);
}
else
{
ByteCodeProcedure* bgproc = new ByteCodeProcedure();
bgproc->Compile(mByteCodeGenerator, proc);
mByteCodeFunctions.Push(bgproc);
}
CompileProcedure(proc);
}
LinkerObject* byteCodeObject = nullptr;

View File

@ -46,4 +46,6 @@ public:
void AddDefine(const Ident* ident, const char* value);
void RegisterRuntime(const Location& loc, const Ident* ident);
void CompileProcedure(InterCodeProcedure* proc);
};

View File

@ -8320,7 +8320,8 @@ InterCodeProcedure::InterCodeProcedure(InterCodeModule * mod, const Location & l
mRenameTable(-1), mRenameUnionTable(-1), mGlobalRenameTable(-1),
mValueForwardingTable(nullptr), mLocalVars(nullptr), mParamVars(nullptr), mModule(mod),
mIdent(ident), mLinkerObject(linkerObject),
mNativeProcedure(false), mLeafProcedure(false), mCallsFunctionPointer(false), mCalledFunctions(nullptr), mFastCallProcedure(false), mInterrupt(false), mHardwareInterrupt(false)
mNativeProcedure(false), mLeafProcedure(false), mCallsFunctionPointer(false), mCalledFunctions(nullptr), mFastCallProcedure(false),
mInterrupt(false), mHardwareInterrupt(false), mCompiled(false)
{
mID = mModule->mProcedures.Size();
mModule->mProcedures.Push(this);

View File

@ -476,7 +476,7 @@ public:
GrowingTypeArray mTemporaries;
GrowingIntArray mTempOffset, mTempSizes;
int mTempSize, mCommonFrameSize, mCallerSavedTemps;
bool mLeafProcedure, mNativeProcedure, mCallsFunctionPointer, mHasDynamicStack, mHasInlineAssembler, mCallsByteCode, mFastCallProcedure, mInterrupt, mHardwareInterrupt;
bool mLeafProcedure, mNativeProcedure, mCallsFunctionPointer, mHasDynamicStack, mHasInlineAssembler, mCallsByteCode, mFastCallProcedure, mInterrupt, mHardwareInterrupt, mCompiled;
GrowingInterCodeProcedurePtrArray mCalledFunctions;
InterCodeModule * mModule;

View File

@ -11227,8 +11227,9 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc
{
bool changed = false;
int sz = mIns.Size();
if (mIns.Size() == 2 && (mBranch == ASMIT_BEQ || mBranch == ASMIT_BNE) && mIns[0].mType == ASMIT_LDA && mIns[1].mType == ASMIT_CMP && !(mIns[1].mFlags & NCIF_VOLATILE) && !(mIns[1].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C)))
if (sz == 2 && (mBranch == ASMIT_BEQ || mBranch == ASMIT_BNE) && mIns[0].mType == ASMIT_LDA && mIns[1].mType == ASMIT_CMP && !(mIns[1].mFlags & NCIF_VOLATILE) && !(mIns[1].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C)))
{
if (!prevBlock)
return OptimizeSimpleLoopInvariant(proc);
@ -11239,6 +11240,21 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc
return true;
}
if (sz >= 3 && mIns[0].mType == ASMIT_LDY && mIns[sz - 2].mType == ASMIT_LDA && mIns[0].SameEffectiveAddress(mIns[sz - 2]) &&
mIns[sz - 1].mType == ASMIT_CMP && HasAsmInstructionMode(ASMIT_CPY, mIns[sz - 1].mMode) && !(mIns[sz - 1].mLive & LIVE_CPU_REG_A))
{
if (!prevBlock)
return OptimizeSimpleLoopInvariant(proc);
mIns[sz - 2].mType = ASMIT_LDY;
mIns[sz - 1].mType = ASMIT_CPY;
prevBlock->mIns.Push(mIns[0]);
mIns.Remove(0);
return true;
}
int ai = 0;
while (ai < mIns.Size() && !mIns[ai].ChangesAccu())
ai++;

View File

@ -73,7 +73,7 @@ int main2(int argc, const char** argv)
#else
strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.4.91");
strcpy(strProductVersion, "1.4.92");
#ifdef __APPLE__
uint32_t length = sizeof(basePath);

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,91,0
PRODUCTVERSION 1,4,91,0
FILEVERSION 1,4,92,0
PRODUCTVERSION 1,4,92,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -43,12 +43,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.4.91.0"
VALUE "FileVersion", "1.4.92.0"
VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.4.91.0"
VALUE "ProductVersion", "1.4.92.0"
END
END
BLOCK "VarFileInfo"

View File

@ -3752,15 +3752,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64"
"ProductCode" = "8:{957F0E7A-5C0E-4F4D-B6B3-21C4459CA152}"
"PackageCode" = "8:{C53FBC0A-F69A-4403-AF50-EED9DCFBF363}"
"ProductCode" = "8:{D70ACED5-5DDD-460B-B934-8B2F6C3F112B}"
"PackageCode" = "8:{E84DF4CA-580F-413D-A830-4499B996E9EC}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.4.91"
"ProductVersion" = "8:1.4.92"
"Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
@ -4274,7 +4274,7 @@
{
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_FB2E467BC172457785F4279BB0BFE8B6"
{
"SourcePath" = "8:..\\Release\\oscar64.exe"
"SourcePath" = "8:..\\Debug\\oscar64.exe"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4"

View File

@ -833,7 +833,7 @@ int main(void)
// Build to multicolor highres at top of screen
rirq_build(&top, 3);
rirq_delay(&top, 10);
rirq_delay(&top, 9);
rirq_write(&top, 1, &vic.ctrl1, VIC_CTRL1_BMM | VIC_CTRL1_DEN | VIC_CTRL1_RSEL | 3);
rirq_write(&top, 2, &vic.memptr, 0x28);
rirq_set(0, 57, &top);

Binary file not shown.