Forráskód Böngészése

Improved handling of mGhostDependencies. Codegen Abort

Brian Fiete 6 hónapja
szülő
commit
a82cc0534d

+ 16 - 1
IDEHelper/Backend/BeIRCodeGen.cpp

@@ -1123,7 +1123,10 @@ void BeIRCodeGen::Read(BeMDNode*& llvmMD)
 }
 
 void BeIRCodeGen::HandleNextCmd()
-{
+{	
+	if (mFailed)
+		return;
+
 	int curId = mCmdCount;
 
 	BfIRCmd cmd = (BfIRCmd)mStream->Read();
@@ -1192,6 +1195,11 @@ void BeIRCodeGen::HandleNextCmd()
 				mBeModule->print(outStream, NULL);*/
 		}
 		break;
+	case BfIRCmd_Abort:
+		{
+			Fail("Stream aborted");			
+		}
+		break;
 	case BfIRCmd_SetType:
 		{
 			CMD_PARAM(int, typeId);
@@ -1236,6 +1244,13 @@ void BeIRCodeGen::HandleNextCmd()
 			CMD_PARAM(int, instSize);
 			CMD_PARAM(int, instAlign);
 			CMD_PARAM(bool, isPacked);
+
+			if ((type == NULL) || (type->mTypeCode != BeTypeCode_Struct))
+			{
+				Fail("StructSetBody invalid type");
+				break;
+			}
+
 			BF_ASSERT(type->mTypeCode == BeTypeCode_Struct);
 			auto structType = (BeStructType*)type;
 			mBeContext->SetStructBody(structType, members, isPacked);

+ 1 - 1
IDEHelper/Backend/BeIRCodeGen.h

@@ -82,7 +82,7 @@ public:
 	BeContext* mBeContext;
 	BeModule* mBeModule;
 	Array<BeDbgLoc*> mSavedDebugLocs;
-	bool mHasDebugLoc;
+	bool mHasDebugLoc;	
 
 	int mCmdCount;
 	Dictionary<int, BeIRCodeGenEntry> mResults;

+ 11 - 1
IDEHelper/Compiler/BfIRBuilder.cpp

@@ -2217,6 +2217,12 @@ void BfIRBuilder::WriteIR(const StringImpl& fileName)
 	NEW_CMD_INSERTED;
 }
 
+void BfIRBuilder::AbortStream()
+{
+	WriteCmd(BfIRCmd_Abort);
+	NEW_CMD_INSERTED;
+}
+
 void BfIRBuilder::Module_SetTargetTriple(const StringImpl& targetTriple, const StringImpl& targetCPU)
 {
 	WriteCmd(BfIRCmd_Module_SetTargetTriple, targetTriple, targetCPU);
@@ -2774,7 +2780,11 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine)
 	if (!type->IsDeclared())
 		populateModule->PopulateType(type, BfPopulateType_Declaration);
 
-	BF_ASSERT(type->IsDeclared());
+	if (!type->IsDeclared())
+	{
+		AbortStream();
+		return;
+	}
 
 #ifdef BFIR_RENTRY_CHECK
 	ReEntryCheck reEntryCheck(&mDeclReentrySet, type);

+ 2 - 0
IDEHelper/Compiler/BfIRBuilder.h

@@ -161,6 +161,7 @@ enum BfIRCmd : uint8
 	BfIRCmd_Module_SetTargetTriple,
 	BfIRCmd_Module_AddModuleFlag,
 	BfIRCmd_WriteIR,
+	BfIRCmd_Abort,
 
 	BfIRCmd_SetType,
 	BfIRCmd_SetInstType,
@@ -1199,6 +1200,7 @@ public:
 	void SetBackend(bool isBeefBackend);
 	void RemoveIRCodeGen();
 	void WriteIR(const StringImpl& fileName);
+	void AbortStream();
 
 	void Module_SetTargetTriple(const StringImpl& targetTriple, const StringImpl& targetCPU);
 	void Module_AddModuleFlag(const StringImpl& flag, int val);

+ 6 - 0
IDEHelper/Compiler/BfIRCodeGen.cpp

@@ -2029,6 +2029,9 @@ void BfIRCodeGen::InitTarget()
 
 void BfIRCodeGen::HandleNextCmd()
 {
+	if (mFailed)
+		return;
+
 	int curId = mCmdCount;
 
 	BfIRCmd cmd = (BfIRCmd)mStream->Read();
@@ -2091,6 +2094,9 @@ void BfIRCodeGen::HandleNextCmd()
 				mLLVMModule->print(outStream, NULL);
 		}
 		break;
+	case BfIRCmd_Abort:
+		Fail("Stream aborted");
+		break;
 	case BfIRCmd_SetType:
 		{
 			CMD_PARAM(int, typeId);

+ 1 - 1
IDEHelper/Compiler/BfModule.cpp

@@ -11097,7 +11097,7 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan
 	{
 		if (mCompiler->EnsureCeUnpaused(typeInstance))
 		{
-			BF_FATAL("OOB in GetRawMethodInstanceAtIdx");
+			InternalError("OOB in GetRawMethodInstanceAtIdx");
 		}
 		return NULL;
 	}