From 54d5884213a4516ca64f69d640651d936e3fbae1 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 24 Sep 2019 08:58:04 -0700 Subject: [PATCH] Fixes for ShowWrongHash, looking into debug info issues in opt llvm --- .../Beefy2D/src/theme/dark/DarkTooltip.bf | 4 +- IDE/src/IDEApp.bf | 7 +++- IDE/src/ui/AutoComplete.bf | 2 +- IDE/src/ui/SourceEditWidgetContent.bf | 4 +- IDE/src/ui/SourceViewPanel.bf | 38 ++++++++++++++++++- IDEHelper/COFF.cpp | 2 +- IDEHelper/Compiler/BfIRCodeGen.cpp | 14 +++++++ IDEHelper/Compiler/BfStmtEvaluator.cpp | 32 +++------------- 8 files changed, 69 insertions(+), 34 deletions(-) diff --git a/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf b/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf index 3104e3a1..0b000c18 100644 --- a/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf +++ b/BeefLibs/Beefy2D/src/theme/dark/DarkTooltip.bf @@ -34,7 +34,7 @@ namespace Beefy.theme.dark public bool mHasClosed; public Insets mRelWidgetMouseInsets ~ delete _; public bool mAllowMouseInsideSelf; - public bool mRequireMouseInside; + public bool mAllowMouseOutside; public const float cShadowSize = 8; @@ -224,7 +224,7 @@ namespace Beefy.theme.dark if (mWidgetWindow == null) return; - if (!mRequireMouseInside) + if (mAllowMouseOutside) return; float rootX; diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index 4e5b46e6..0c4b0373 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -6182,6 +6182,10 @@ namespace IDE sourceViewPanel.SetLoadCmd(loadCmd); } } + else if ((hash != .None) && (hash != sourceViewPanel.mLoadedHash)) + { + sourceViewPanel.ShowWrongHash(); + } int showHotIdx = -1; if (!onlyShowCurrent) @@ -11408,7 +11412,8 @@ namespace IDE continue; //TODO: Check to see if this file is in the dependency list of the executing project - mHaveSourcesChangedExternallySinceLastCompile = true; + if (!editData.mProjectSources.IsEmpty) + mHaveSourcesChangedExternallySinceLastCompile = true; editData.SetSavedData(null, IdSpan()); if (editData.mQueuedContent == null) diff --git a/IDE/src/ui/AutoComplete.bf b/IDE/src/ui/AutoComplete.bf index 397ce29a..0090875b 100644 --- a/IDE/src/ui/AutoComplete.bf +++ b/IDE/src/ui/AutoComplete.bf @@ -2022,7 +2022,7 @@ namespace IDE.ui if (!mClosed) { - if ((DarkTooltipManager.sTooltip != null) && (!DarkTooltipManager.sTooltip.mRequireMouseInside)) + if ((DarkTooltipManager.sTooltip != null) && (DarkTooltipManager.sTooltip.mAllowMouseOutside)) DarkTooltipManager.CloseTooltip(); if (IsInPanel()) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index c5184081..1200a26c 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2729,7 +2729,7 @@ namespace IDE.ui { if (mWidgetWindow.IsKeyDown(.Control)) { - if ((DarkTooltipManager.sTooltip != null) && (!DarkTooltipManager.sTooltip.mRequireMouseInside)) + if ((DarkTooltipManager.sTooltip != null) && (DarkTooltipManager.sTooltip.mAllowMouseOutside)) DarkTooltipManager.CloseTooltip(); gApp.mSettings.mTutorialsFinished.mCtrlCursor = true; } @@ -2739,7 +2739,7 @@ namespace IDE.ui let tooltip = DarkTooltipManager.ShowTooltip("Hold CTRL when using UP and DOWN", this, cursorX - GS!(24), cursorY - GS!(40)); if (tooltip != null) - tooltip.mRequireMouseInside = false; + tooltip.mAllowMouseOutside = true; return; } } diff --git a/IDE/src/ui/SourceViewPanel.bf b/IDE/src/ui/SourceViewPanel.bf index 52a23ac8..1c389831 100644 --- a/IDE/src/ui/SourceViewPanel.bf +++ b/IDE/src/ui/SourceViewPanel.bf @@ -303,6 +303,8 @@ namespace IDE.ui { switch (lhs) { + case .None: + return rhs case .None; case .MD5(let lhsMD5): if (rhs case .MD5(let rhsMD5)) return lhsMD5 == rhsMD5; @@ -3106,7 +3108,7 @@ namespace IDE.ui ResizeComponents(); } - void ShowWrongHash() + public void ShowWrongHash() { CloseHeader(); @@ -3335,6 +3337,38 @@ namespace IDE.ui CheckBinary(); } + void CheckAdjustFile() + { + if (mLoadedHash == .None) + return; + + String text = scope .(); + if (File.ReadAllText(mFilePath, text, true) case .Err) + return; + + SourceHash textHash = SourceHash.Create(mLoadedHash.GetKind(), text); + if (textHash == mLoadedHash) + return; + + if (text.Contains('\r')) + { + text.Replace("\r", ""); + } + else + { + text.Replace("\n", "\r\n"); + } + textHash = SourceHash.Create(mLoadedHash.GetKind(), text); + if (textHash == mLoadedHash) + { + if (File.WriteAllText(mFilePath, text) case .Err) + { + gApp.mFileWatcher.OmitFileChange(mFilePath, text); + return; + } + } + } + void RetryLoad() { var prevHash = mLoadedHash; @@ -5386,6 +5420,7 @@ namespace IDE.ui { if ((int)mOldVerLoadExecutionInstance.mExitCode == 0) { + CheckAdjustFile(); RetryLoad(); } else @@ -5403,6 +5438,7 @@ namespace IDE.ui if (result == .Failed) gApp.OutputErrorLine("Failed to retrieve source from {}", mOldVerLoadCmd); + CheckAdjustFile(); RetryLoad(); DeleteAndNullify!(mOldVerHTTPRequest); } diff --git a/IDEHelper/COFF.cpp b/IDEHelper/COFF.cpp index ad5263d6..94fb695c 100644 --- a/IDEHelper/COFF.cpp +++ b/IDEHelper/COFF.cpp @@ -4989,7 +4989,7 @@ void COFF::CvParseIPI() int offset = dataOffset; for (int idx = 0; idx < recordCount; idx++) { - BF_ASSERT(((offset) & 3) == 0); + //BF_ASSERT(((offset) & 3) == 0); uint8* data = mCvIPIReader.GetTempPtr(offset, 4); uint16 trLength = GET(uint16); int offsetStart = offset; diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index 7880bd6a..c9b1445f 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -1,5 +1,6 @@ #include "BfIRCodeGen.h" #include "BfModule.h" +#include "BeefySysLib/util/BeefPerf.h" #pragma warning(push) #pragma warning(disable:4141) @@ -4057,6 +4058,19 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen } bool success = PM.run(*mLLVMModule); + + if ((codeGenOptions.mOptLevel > BfOptLevel_O0) && (codeGenOptions.mWriteLLVMIR)) + { + BP_ZONE("BfCodeGen::RunLoop.LLVM.IR"); + String fileName = outFileName; + int dotPos = (int)fileName.LastIndexOf('.'); + if (dotPos != -1) + fileName.RemoveToEnd(dotPos); + + fileName += "_OPT.ll"; + String irError; + WriteIR(fileName, irError); + } } return true; diff --git a/IDEHelper/Compiler/BfStmtEvaluator.cpp b/IDEHelper/Compiler/BfStmtEvaluator.cpp index c74f8fa8..ca2498b3 100644 --- a/IDEHelper/Compiler/BfStmtEvaluator.cpp +++ b/IDEHelper/Compiler/BfStmtEvaluator.cpp @@ -1611,30 +1611,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD localDef->mAddr = AllocLocalVariable(resolvedType, localDef->mName); } -// if ((!hadVarType) && (varDecl->mInitializer != NULL)) -// { -// if (exprEvaluator != NULL) -// { -// if ((initValue) && (initValue.mType->IsNullable())) -// { -// auto boolType = GetPrimitiveType(BfTypeCode_Boolean); -// initValue = LoadValue(initValue); -// exprEvaluator->mResult = BfTypedValue(mBfIRBuilder->CreateExtractValue(initValue.mValue, 2), boolType); -// handledExprBoolResult = true; -// -// if (!resolvedType->IsNullable()) -// initValue = BfTypedValue(mBfIRBuilder->CreateExtractValue(initValue.mValue, 1), initValue.mType->GetUnderlyingType()); -// } -// else if (initValue) -// { -// TryInitVar(varDecl, &localDef, initValue, exprEvaluator->mResult); -// handledExprBoolResult = true; -// handledVarStore = true; -// handledVarInit = true; -// } -// } -// } - + bool wantsStore = false; if ((initValue) && (!handledVarStore) && (!isConst) && (!initHandled)) { initValue = LoadValue(initValue); @@ -1651,7 +1628,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD localDef->mValue = initValue.mValue; if ((localDef->mAddr) && (!localDef->mResolvedType->IsValuelessType())) { - mBfIRBuilder->CreateStore(initValue.mValue, localDef->mAddr); + wantsStore = true; } else { @@ -1727,7 +1704,10 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD if (localDef->mConstValue) initType = BfIRInitType_NotNeeded; - return AddLocalVariableDef(localDef, true, false, BfIRValue(), initType); + BfLocalVariable* localVar = AddLocalVariableDef(localDef, true, false, BfIRValue(), initType); + if (wantsStore) + mBfIRBuilder->CreateStore(initValue.mValue, localVar->mAddr); + return localVar; } BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varDecl, BfTypedValue val, bool updateSrcLoc, bool forceAddr)