From 43b69023f6b64bffd425ff518f2105dc14cb2f07 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 29 Oct 2019 04:56:42 -0700 Subject: [PATCH] Added bitcode emission, additional logging --- BeefLibs/Beefy2D/src/widgets/EditWidget.bf | 2 +- BeefySysLib/platform/win/Platform.cpp | 3 ++- IDE/src/Compiler/BfCompiler.bf | 12 ++++++++---- IDE/src/Compiler/BfParser.bf | 4 ---- IDE/src/Compiler/BfSystem.bf | 8 ++++++++ IDE/src/IDEApp.bf | 16 ++++++++++++++++ IDE/src/Workspace.bf | 7 +++++-- IDEHelper/Compiler/BfCompiler.cpp | 2 ++ IDEHelper/Compiler/BfCompiler.h | 5 +++-- IDEHelper/Compiler/BfIRCodeGen.cpp | 18 ++++++++++-------- IDEHelper/Compiler/BfModule.cpp | 3 ++- IDEHelper/Compiler/BfParser.cpp | 2 +- IDEHelper/Compiler/BfSystem.cpp | 8 +++++++- IDEHelper/Compiler/BfSystem.h | 15 +++++++++------ 14 files changed, 74 insertions(+), 31 deletions(-) diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index 870fc023..421d8098 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf @@ -1148,7 +1148,7 @@ namespace Beefy.widgets doCheck = false; for (char32 c in theString.DecodedChars) { - if (c <= (char32)128) + if (c < (char32)128) hasChar[(int)c] = true; else if (!AllowChar(c)) { diff --git a/BeefySysLib/platform/win/Platform.cpp b/BeefySysLib/platform/win/Platform.cpp index 8ea5afa1..531980bd 100644 --- a/BeefySysLib/platform/win/Platform.cpp +++ b/BeefySysLib/platform/win/Platform.cpp @@ -2435,7 +2435,8 @@ BFP_EXPORT void BFP_CALLTYPE BfpDirectory_Create(const char* path, BfpFileResult UTF16String wPath = UTF8Decode(path); if (!::CreateDirectoryW(wPath.c_str(), NULL)) { - switch (::GetLastError()) + int lastError = ::GetLastError(); + switch (lastError) { case ERROR_ALREADY_EXISTS: OUTRESULT(BfpFileResult_AlreadyExists); diff --git a/IDE/src/Compiler/BfCompiler.bf b/IDE/src/Compiler/BfCompiler.bf index d03f19bf..5cd0b7ff 100644 --- a/IDE/src/Compiler/BfCompiler.bf +++ b/IDE/src/Compiler/BfCompiler.bf @@ -21,7 +21,7 @@ namespace IDE.Compiler EmitLineInfo = 2, WriteIR = 4, GenerateOBJ = 8, - NoFramePointerElim = 0x10, + GenerateBitcode = 0x10, ClearLocalVars = 0x20, RuntimeChecks = 0x40, EmitDynamicCastCheck = 0x80, @@ -32,7 +32,9 @@ namespace IDE.Compiler EnableSideStack = 0x1000, EnableHotSwapping = 0x2000, IncrementalBuild = 0x4000, - DebugAlloc = 0x8000 + DebugAlloc = 0x8000, + OmitDebugHelpers = 0x10000, + NoFramePointerElim = 0x20000, } [StdCall, CLink] @@ -491,8 +493,10 @@ namespace IDE.Compiler } else { - SetOpt((options.mIntermediateType == .IRCode) || (options.mIntermediateType == .ObjectAndIRCode), .WriteIR); - SetOpt((options.mIntermediateType == .Object) || (options.mIntermediateType == .ObjectAndIRCode), .GenerateOBJ); + SetOpt((options.mIntermediateType == .IRCode) || (options.mIntermediateType == .ObjectAndIRCode) || (options.mIntermediateType == .BitcodeAndIRCode), .WriteIR); + SetOpt((options.mIntermediateType == .Object) || (options.mIntermediateType == .ObjectAndIRCode) || + (options.mIntermediateType == .Bitcode) || (options.mIntermediateType == .BitcodeAndIRCode), .GenerateOBJ); + SetOpt((options.mIntermediateType == .Bitcode) || (options.mIntermediateType == .BitcodeAndIRCode), .GenerateBitcode); } SetOpt(options.mNoOmitFramePointers, .NoFramePointerElim); SetOpt(options.mInitLocalVariables, .ClearLocalVars); diff --git a/IDE/src/Compiler/BfParser.bf b/IDE/src/Compiler/BfParser.bf index 34338aff..297cfff1 100644 --- a/IDE/src/Compiler/BfParser.bf +++ b/IDE/src/Compiler/BfParser.bf @@ -158,10 +158,6 @@ namespace IDE.Compiler public void SetSource(String data, String fileName) { - if (fileName.Contains("main4.cs")) - { - } - Debug.Assert(!mIsUsed); mIsUsed = true; BfParser_SetSource(mNativeBfParser, data, (int32)data.Length, fileName); diff --git a/IDE/src/Compiler/BfSystem.bf b/IDE/src/Compiler/BfSystem.bf index 15d49780..8508a339 100644 --- a/IDE/src/Compiler/BfSystem.bf +++ b/IDE/src/Compiler/BfSystem.bf @@ -79,6 +79,9 @@ namespace IDE.Compiler [StdCall, CLink] extern static void BfSystem_DbgPrintTimings(); + [StdCall, CLink] + extern static void BfSystem_Log(void* bfSystem, char8* str); + public void* mNativeBfSystem; public bool mIsTiming; public Monitor mMonitor = new Monitor() ~ delete _; @@ -360,5 +363,10 @@ namespace IDE.Compiler AddTypeOptions(typeOption.mFilter, typeOption.mBfSIMDSetting, typeOption.mBfOptimizationLevel, typeOption.mEmitDebugInfo, typeOption.mRuntimeChecks, typeOption.mInitLocalVariables, typeOption.mEmitDynamicCastCheck, typeOption.mEmitObjectAccessCheck, typeOption.mAllocStackTraceDepth); } + + public void Log(String str) + { + BfSystem_Log(mNativeBfSystem, str); + } } } diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index d8093d0f..d351ec11 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -3775,6 +3775,8 @@ namespace IDE [IDECommand] void Compile() { + CompilerLog("IDEApp.Compile"); + if (AreTestsRunning()) return; if (mHotResolveState != .None) @@ -6500,6 +6502,16 @@ namespace IDE mOutputPanel.Write(outStr); } + public void CompilerLog(String format, params Object[] args) + { + var str = scope String(); + str..AppendF(format, params args); + if (mBfBuildSystem != null) + mBfBuildSystem.Log(str); + if (mBfResolveSystem != null) + mBfResolveSystem.Log(str); + } + public void OutputLine(String format, params Object[] args) { String outStr; @@ -8162,6 +8174,8 @@ namespace IDE BfPassInstance CompileBeef(Project hotProject, int32 hotIdx, bool lastCompileHadMessages, out bool hadBeef) { + CompilerLog("IDEApp.CompileBeef"); + hadBeef = false; mCompilingBeef = true; BeefCompileStarted(); @@ -11484,6 +11498,8 @@ namespace IDE public void OnWatchedFileChanged(ProjectItem projectItem, WatcherChangeTypes changeType, String newPath) { + CompilerLog("IDEApp.OnWatchedFileChanged {} {} {}", projectItem.mName, changeType, newPath); + ProjectListViewItem listViewItem; mProjectPanel.mProjectToListViewMap.TryGetValue(projectItem, out listViewItem); diff --git a/IDE/src/Workspace.bf b/IDE/src/Workspace.bf index dadb99f7..262c5819 100644 --- a/IDE/src/Workspace.bf +++ b/IDE/src/Workspace.bf @@ -1,3 +1,4 @@ + using System; using System.Collections.Generic; using System.Text; @@ -17,7 +18,9 @@ namespace IDE { Object, IRCode, - ObjectAndIRCode + ObjectAndIRCode, + Bitcode, + BitcodeAndIRCode, } public enum PlatformType @@ -748,7 +751,7 @@ namespace IDE options.mIncrementalBuild = !isRelease; options.mAllocStackTraceDepth = 1; - options.mIntermediateType = .Object; + options.mIntermediateType = (platformType == .iOS) ? .Bitcode : .Object; options.mCSIMDSetting = .SSE2; options.mCOptimizationLevel = isRelease ? .O2 : .O0; diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 45b63b8a..974432de 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -8207,6 +8207,7 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje options->mIncrementalBuild = (optionFlags & BfCompilerOptionFlag_IncrementalBuild) != 0; options->mWriteIR = (optionFlags & BfCompilerOptionFlag_WriteIR) != 0; options->mGenerateObj = (optionFlags & BfCompilerOptionFlag_GenerateOBJ) != 0; + options->mGenerateBitcode = (optionFlags & BfCompilerOptionFlag_GenerateBitcode) != 0; options->mNoFramePointerElim = (optionFlags & BfCompilerOptionFlag_NoFramePointerElim) != 0; options->mInitLocalVariables = (optionFlags & BfCompilerOptionFlag_ClearLocalVars) != 0; options->mRuntimeChecks = (optionFlags & BfCompilerOptionFlag_RuntimeChecks) != 0; @@ -8279,3 +8280,4 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_ForceRebuild(BfCompiler* bfCompiler) bfCompiler->mOptions.mForceRebuildIdx++; } + diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index fe6b6fa0..8f1d824b 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -98,8 +98,7 @@ public: BfMachineType mMachineType; int mCLongSize; BfToolsetType mToolsetType; - BfSIMDSetting mSIMDSetting; - int mMaxWorkerThreads; + BfSIMDSetting mSIMDSetting; String mMallocLinkName; String mFreeLinkName; bool mIncrementalBuild; @@ -127,6 +126,7 @@ public: bool mWriteIR; bool mGenerateObj; + bool mGenerateBitcode; int mAllocStackCount; bool mExtraResolveChecks; @@ -164,6 +164,7 @@ public: mEnableRealtimeLeakCheck = false; mWriteIR = false; mGenerateObj = true; + mGenerateBitcode = false; mEnableCustodian = false; mEnableSideStack = false; mHasVDataExtender = false; diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index cf2b248f..0d050522 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -3948,7 +3948,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen mHasDebugLoc = false; // So fails don't show a line number - bool enableLTO = codeGenOptions.mLTOType != BfLTOType_None; + bool enableLTO = codeGenOptions.mLTOType != BfLTOType_None; if (enableLTO) { @@ -4070,8 +4070,8 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen llvm::raw_fd_ostream* outStream = NULL; defer ( delete outStream; ); - - if (enableLTO) + + if ((enableLTO) || (codeGenOptions.mWriteBitcode)) { std::error_code ec; outStream = new llvm::raw_fd_ostream(outFileName.c_str(), ec, llvm::sys::fs::F_None); @@ -4079,10 +4079,12 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen { return false; } - - //PM.add() - PM.add(createWriteThinLTOBitcodePass(*outStream, NULL)); - } + + if (enableLTO) + PM.add(createWriteThinLTOBitcodePass(*outStream, NULL)); + else + PM.add(createBitcodeWriterPass(*outStream, false, false, false)); + } //TargetPassConfig *PassConfig = target->createPassConfig(PM); //PM.add(new BfPass()); @@ -4105,7 +4107,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen //WriteBitcode bool noVerify = false; // Option - if (!enableLTO) + if ((!enableLTO) && (!codeGenOptions.mWriteBitcode)) { // Ask the target to add backend passes as necessary. if (target->addPassesToEmitFile(PM, out, NULL, diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 59a9bce4..e0ed252e 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -20478,6 +20478,7 @@ bool BfModule::Finish() codeGenOptions.mSIMDSetting = moduleOptions.mSIMDSetting; codeGenOptions.mWriteLLVMIR = mCompiler->mOptions.mWriteIR; codeGenOptions.mWriteObj = mCompiler->mOptions.mGenerateObj; + codeGenOptions.mWriteBitcode = mCompiler->mOptions.mGenerateBitcode; codeGenOptions.mVirtualMethodOfs = 1 + mCompiler->GetDynCastVDataCount() + mCompiler->mMaxInterfaceSlots; codeGenOptions.mDynSlotOfs = mSystem->mPtrSize - mCompiler->GetDynCastVDataCount() * 4; @@ -20525,7 +20526,7 @@ bool BfModule::Finish() { moduleFileName.mFileName = irOutputPath; } - else if ((!mCompiler->mOptions.mGenerateObj) && (!mCompiler->mOptions.mWriteIR)) + else if ((!mCompiler->mOptions.mGenerateObj) && (!mCompiler->mOptions.mGenerateBitcode) && (!mCompiler->mOptions.mWriteIR)) { BF_FATAL("Neither obj nor IR specified"); } diff --git a/IDEHelper/Compiler/BfParser.cpp b/IDEHelper/Compiler/BfParser.cpp index 2cbe5643..a36560f1 100644 --- a/IDEHelper/Compiler/BfParser.cpp +++ b/IDEHelper/Compiler/BfParser.cpp @@ -458,7 +458,7 @@ void BfParser::Init(uint64 cacheHash) mParserData->mAstAllocManager = &gBfParserCache->mAstAllocManager; mParserData->mSrc = mSrc; mParserData->mSrcLength = mSrcLength; - + if (cacheHash != 0) { BfLogSysM("Creating cached parserData %p for %p %s\n", mParserData, this, mFileName.c_str()); diff --git a/IDEHelper/Compiler/BfSystem.cpp b/IDEHelper/Compiler/BfSystem.cpp index dd68f0c8..e77924f0 100644 --- a/IDEHelper/Compiler/BfSystem.cpp +++ b/IDEHelper/Compiler/BfSystem.cpp @@ -3290,7 +3290,7 @@ BF_EXPORT void BF_CALLTYPE BfSystem_DeleteParser(BfSystem* bfSystem, BfParser* b { for (auto typeDef : bfParser->mTypeDefs) { - BfLogSys(bfSystem, "BfSystem_DeleteParser deleting typeDef %p\n", typeDef); + BfLogSys(bfSystem, "BfSystem_DeleteParser %p deleting typeDef %p\n", bfParser, typeDef); typeDef->mDefState = BfTypeDef::DefState_Deleted; } } @@ -3815,3 +3815,9 @@ BF_EXPORT void BF_CALLTYPE BfSystem_FixTypes(BfSystem* bfSystem) fixTypesHelper.mBfSystem = bfSystem; fixTypesHelper.Fix(); } + +BF_EXPORT void BF_CALLTYPE BfSystem_Log(BfSystem* bfSystem, char* str) +{ + BfLogSys(bfSystem, str); + BfLogSys(bfSystem, "\n"); +} diff --git a/IDEHelper/Compiler/BfSystem.h b/IDEHelper/Compiler/BfSystem.h index 493daf1e..4e6a8606 100644 --- a/IDEHelper/Compiler/BfSystem.h +++ b/IDEHelper/Compiler/BfSystem.h @@ -143,7 +143,7 @@ enum BfCompilerOptionFlags BfCompilerOptionFlag_EmitLineInfo = 2, BfCompilerOptionFlag_WriteIR = 4, BfCompilerOptionFlag_GenerateOBJ = 8, - BfCompilerOptionFlag_NoFramePointerElim = 0x10, + BfCompilerOptionFlag_GenerateBitcode = 0x10, BfCompilerOptionFlag_ClearLocalVars = 0x20, BfCompilerOptionFlag_RuntimeChecks = 0x40, BfCompilerOptionFlag_EmitDynamicCastCheck = 0x80, @@ -151,11 +151,12 @@ enum BfCompilerOptionFlags BfCompilerOptionFlag_EmitObjectAccessCheck = 0x200, BfCompilerOptionFlag_EnableCustodian = 0x400, BfCompilerOptionFlag_EnableRealtimeLeakCheck = 0x800, - BfCompilerOptionFlag_EnableSideStack = 0x1000, - BfCompilerOptionFlag_EnableHotSwapping = 0x2000, - BfCompilerOptionFlag_IncrementalBuild = 0x4000, - BfCompilerOptionFlag_DebugAlloc = 0x8000, - BfCompilerOptionFlag_OmitDebugHelpers = 0x10000 + BfCompilerOptionFlag_EnableSideStack = 0x1000, + BfCompilerOptionFlag_EnableHotSwapping = 0x2000, + BfCompilerOptionFlag_IncrementalBuild = 0x4000, + BfCompilerOptionFlag_DebugAlloc = 0x8000, + BfCompilerOptionFlag_OmitDebugHelpers = 0x10000, + BfCompilerOptionFlag_NoFramePointerElim = 0x20000, }; enum BfTypeFlags @@ -300,6 +301,7 @@ struct BfCodeGenOptions bool mIsHotCompile; bool mWriteObj; + bool mWriteBitcode; BfAsmKind mAsmKind; bool mWriteToLib; bool mWriteLLVMIR; @@ -354,6 +356,7 @@ struct BfCodeGenOptions { mIsHotCompile = false; mWriteObj = true; + mWriteBitcode = false; mAsmKind = BfAsmKind_None; mWriteToLib = false; mWriteLLVMIR = false;