Просмотр исходного кода

Fixed backend error vreg handling, softer fails, fixed a forcelink issue

Brian Fiete 5 лет назад
Родитель
Сommit
8b71f8d49a
4 измененных файлов с 58 добавлено и 38 удалено
  1. 33 28
      IDEHelper/Backend/BeMCContext.cpp
  2. 1 1
      IDEHelper/Backend/BeMCContext.h
  3. 2 2
      IDEHelper/Compiler/BfModule.cpp
  4. 22 7
      IDEHelper/DbgModule.cpp

+ 33 - 28
IDEHelper/Backend/BeMCContext.cpp

@@ -4031,7 +4031,7 @@ bool BeMCContext::CheckForce(BeMCVRegInfo * vregInfo)
 	if (!vregInfo->mIsRetVal)
 	if (!vregInfo->mIsRetVal)
 	{
 	{
 		if (vregInfo->mForceMem && vregInfo->mForceReg)
 		if (vregInfo->mForceMem && vregInfo->mForceReg)
-			Fail("vreg forceMem/forceReg collision");
+			SoftFail("vreg forceMem/forceReg collision");
 	}
 	}
 	return false;
 	return false;
 }
 }
@@ -4467,12 +4467,12 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC
 							if (vregInfo->mDoConservativeLife)
 							if (vregInfo->mDoConservativeLife)
 								BF_ASSERT(mVRegInitializedContext.IsSet(vregsInitialized, vregIdx, BeTrackKind_Uninitialized));
 								BF_ASSERT(mVRegInitializedContext.IsSet(vregsInitialized, vregIdx, BeTrackKind_Uninitialized));
 							else
 							else
-								Fail("VReg lifetime error");
+								SoftFail("VReg lifetime error");
 						}
 						}
 					}
 					}
 					else
 					else
 					{
 					{
-						Fail("VReg lifetime error");
+						SoftFail("VReg lifetime error");
 					}					
 					}					
 				}
 				}
 			}			
 			}			
@@ -5340,7 +5340,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum)
 	case X64Reg_XMM15_f64:
 	case X64Reg_XMM15_f64:
 		return 7;
 		return 7;
 	}
 	}
-	Fail("Invalid reg");
+	SoftFail("Invalid reg");
 	return -1;
 	return -1;
 }
 }
 
 
@@ -5945,7 +5945,7 @@ void BeMCContext::EmitModRM(int rx, BeMCOperand rm, int relocOfs)
 	}
 	}
 	else
 	else
 	{
 	{
-		Fail("Invalid rm");
+		SoftFail("Invalid rm");
 	}
 	}
 	mOut.Write(modRM);
 	mOut.Write(modRM);
 }
 }
@@ -6038,12 +6038,12 @@ void BeMCContext::EmitModRM_Addr(BeMCOperand r, BeMCOperand rm)
 		}
 		}
 		else
 		else
 		{
 		{
-			Fail("Illegal");
+			SoftFail("Illegal expression in EmitModRM_Addr");
 		}
 		}
 	}
 	}
 	else
 	else
 	{
 	{
-		Fail("Invalid rm");
+		SoftFail("Invalid rm in EmitModRM_Addr");
 	}
 	}
 	mOut.Write(modRM);
 	mOut.Write(modRM);
 }
 }
@@ -7789,7 +7789,7 @@ void BeMCContext::DoRegAssignPass()
 			continue;
 			continue;
 		if ((vregInfo->mForceReg) && (!vregInfo->mRelTo) && (vregInfo->mReg == X64Reg_None))
 		if ((vregInfo->mForceReg) && (!vregInfo->mRelTo) && (vregInfo->mReg == X64Reg_None))
 		{			
 		{			
-			Fail("Failed to assign register to ForceReg vreg");
+			SoftFail("Failed to assign register to ForceReg vreg");
 		}
 		}
 		if (vregInfo->mDisableRAX)
 		if (vregInfo->mDisableRAX)
 		{
 		{
@@ -8729,7 +8729,7 @@ bool BeMCContext::DoLegalization()
 				break;
 				break;
 			case BeMCInstKind_DefLoad:
 			case BeMCInstKind_DefLoad:
 				{
 				{
-					Fail("DefLoad- DoLoads should have removed these");
+					SoftFail("DefLoad- DoLoads should have removed these");
 				}
 				}
 				break;
 				break;
 			case BeMCInstKind_Def:			
 			case BeMCInstKind_Def:			
@@ -8846,6 +8846,13 @@ bool BeMCContext::DoLegalization()
 							int disp = 0;
 							int disp = 0;
 							int errorVRegIdx = -1;
 							int errorVRegIdx = -1;
 							bool isValid = GetRMParams(inst->mArg0, regA, regB, bScale, disp, &errorVRegIdx) != BeMCRMMode_Invalid;
 							bool isValid = GetRMParams(inst->mArg0, regA, regB, bScale, disp, &errorVRegIdx) != BeMCRMMode_Invalid;
+							if (mDebugging)
+							{
+								if ((inst->mArg0.mVRegIdx == 272) || (inst->mArg0.mVRegIdx == 274))
+								{
+									NOP;
+								}
+							}
 
 
 							if (!isValid)
 							if (!isValid)
 							{
 							{
@@ -9001,9 +9008,9 @@ bool BeMCContext::DoLegalization()
 										else
 										else
 										{
 										{
 											// This should be impossible - a previous def for an inner expr should have caught this case
 											// This should be impossible - a previous def for an inner expr should have caught this case
-											if (vregExprChangeSet.IsEmpty())
+											if ((vregExprChangeSet.IsEmpty()) && (!hasPendingActualizations))
 											{
 											{
-												Fail("Error");
+												SoftFail("Error legalizing vreg expression", NULL);
 											}
 											}
 										}
 										}
 									}
 									}
@@ -9377,7 +9384,7 @@ bool BeMCContext::DoLegalization()
 							// The 3-op form of MUL must be in "reg, r/m64, imm" form		
 							// The 3-op form of MUL must be in "reg, r/m64, imm" form		
 							if (!inst->mArg1.IsImmediateInt())
 							if (!inst->mArg1.IsImmediateInt())
 							{
 							{
-								Fail("Not supported");
+								SoftFail("Not supported");
 								//isFinalRun = false;
 								//isFinalRun = false;
 								break;
 								break;
 							}
 							}
@@ -9508,7 +9515,7 @@ bool BeMCContext::DoLegalization()
 						{
 						{
 							if (!arg0.IsNativeReg())
 							if (!arg0.IsNativeReg())
 							{
 							{
-								Fail("xmm reg required");
+								SoftFail("xmm reg required");
 							}
 							}
 						}
 						}
 					}
 					}
@@ -9557,7 +9564,7 @@ bool BeMCContext::DoLegalization()
 							else if ((checkInst->mKind != BeMCInstKind_Def) && (checkInst->mKind != BeMCInstKind_DbgDecl) &&
 							else if ((checkInst->mKind != BeMCInstKind_Def) && (checkInst->mKind != BeMCInstKind_DbgDecl) &&
 								(checkInst->mKind != BeMCInstKind_ValueScopeSoftEnd) && (checkInst->mKind != BeMCInstKind_ValueScopeHardEnd))
 								(checkInst->mKind != BeMCInstKind_ValueScopeSoftEnd) && (checkInst->mKind != BeMCInstKind_ValueScopeHardEnd))
 							{
 							{
-								Fail("Malformed");
+								SoftFail("Malformed");
 							}
 							}
 						}
 						}
 						break;
 						break;
@@ -9615,7 +9622,7 @@ bool BeMCContext::DoLegalization()
 						auto vregInfo = mVRegInfo[inst->mArg1.mVRegIdx];
 						auto vregInfo = mVRegInfo[inst->mArg1.mVRegIdx];
 						if ((!vregInfo->mIsExpr) && (!vregInfo->mForceMem))
 						if ((!vregInfo->mIsExpr) && (!vregInfo->mForceMem))
 						{
 						{
-							Fail("VRegAddr used without ForceMem");
+							SoftFail("VRegAddr used without ForceMem");
 						}
 						}
 					}
 					}
 
 
@@ -10066,7 +10073,7 @@ void BeMCContext::DoSanityChecking()
 					{
 					{
 						// It's possible during legalization to extend the usage of a dynLife value 'upward', and we need
 						// It's possible during legalization to extend the usage of a dynLife value 'upward', and we need
 						//  to ensure we also extend the init flags up as well
 						//  to ensure we also extend the init flags up as well
-						Fail("Invalid liveness - from init flag not being set properly?");
+						SoftFail("Invalid liveness - from init flag not being set properly?");
 					}
 					}
 				}
 				}
 			}
 			}
@@ -10732,7 +10739,7 @@ void BeMCContext::DoRegFinalization()
 								if (inst->mKind == BeMCInstKind_Def)
 								if (inst->mKind == BeMCInstKind_Def)
 								{
 								{
 									// If we have a Def here, it's because of a legalization that introduced a variable in a non-safe position
 									// If we have a Def here, it's because of a legalization that introduced a variable in a non-safe position
-									Fail("Illegal def");
+									SoftFail("Illegal def");
 								}
 								}
 
 
 								if (inst->mKind == BeMCInstKind_Mov)
 								if (inst->mKind == BeMCInstKind_Mov)
@@ -11269,7 +11276,7 @@ void BeMCContext::EmitInst(BeMCInstForm instForm, uint16 codeBytes, BeMCInst* in
 	case BeMCInstForm_RM64_IMM32:
 	case BeMCInstForm_RM64_IMM32:
 		break;
 		break;
 	default:
 	default:
-		Fail("Notimpl EmitInst");
+		SoftFail("Notimpl EmitInst");
 	}
 	}
 }
 }
 
 
@@ -11306,7 +11313,7 @@ void BeMCContext::EmitInst(BeMCInstForm instForm, uint16 codeBytes, uint8 rx, Be
 		mOut.Write((int64)inst->mArg1.GetImmediateInt());
 		mOut.Write((int64)inst->mArg1.GetImmediateInt());
 		break;
 		break;
 	default:
 	default:
-		Fail("Notimpl EmitInst");
+		SoftFail("Notimpl EmitInst");
 	}
 	}
 }
 }
 
 
@@ -12055,7 +12062,7 @@ void BeMCContext::DoCodeEmission()
 					}
 					}
 					else if (vregInfo->mRelTo.mKind == BeMCOperandKind_SymbolAddr)
 					else if (vregInfo->mRelTo.mKind == BeMCOperandKind_SymbolAddr)
 					{
 					{
-						Fail("Not supported SymbolAddr");
+						SoftFail("Not supported SymbolAddr");
 						//dbgVar->mPrimaryLoc.mKind = BeDbgVariableLoc::Kind_SymbolAddr;
 						//dbgVar->mPrimaryLoc.mKind = BeDbgVariableLoc::Kind_SymbolAddr;
 						//dbgVar->mPrimaryLoc.mOfs = vregInfo->mRelTo.mSymbolIdx;
 						//dbgVar->mPrimaryLoc.mOfs = vregInfo->mRelTo.mSymbolIdx;
 					}
 					}
@@ -12473,7 +12480,7 @@ void BeMCContext::DoCodeEmission()
 								}
 								}
 								else
 								else
 								{
 								{
-									Fail("Error in Mov");
+									SoftFail("Error in Mov");
 								}
 								}
 
 
 								switch (useTypeCode)
 								switch (useTypeCode)
@@ -12882,7 +12889,7 @@ void BeMCContext::DoCodeEmission()
 						Emit(0x0F); Emit(0xB1); EmitModRM(inst->mArg1, inst->mArg0);
 						Emit(0x0F); Emit(0xB1); EmitModRM(inst->mArg1, inst->mArg0);
 						break;
 						break;
 					default:
 					default:
-						Fail("Invalid CmpXChg args");
+						SoftFail("Invalid CmpXChg args");
 					}
 					}
 				}
 				}
 				break;
 				break;
@@ -12932,7 +12939,7 @@ void BeMCContext::DoCodeEmission()
 						Emit(0x0F); Emit(0xC1); EmitModRM(inst->mArg1, inst->mArg0);
 						Emit(0x0F); Emit(0xC1); EmitModRM(inst->mArg1, inst->mArg0);
 						break;
 						break;
 					default:
 					default:
-						Fail("Invalid XAdd args");
+						SoftFail("Invalid XAdd args");
 					}
 					}
 				}
 				}
 				break;
 				break;
@@ -14740,10 +14747,8 @@ void BeMCContext::Generate(BeFunction* function)
 	mDbgPreferredRegs[32] = X64Reg_R8;*/
 	mDbgPreferredRegs[32] = X64Reg_R8;*/
 
 
 	//mDbgPreferredRegs[8] = X64Reg_RAX;
 	//mDbgPreferredRegs[8] = X64Reg_RAX;
-	mDebugging = function->mName ==
-	//"?TestPrimitives@Nullable@Tests@bf@@SAXXZ"
-
-		"?Hey@Blurg@bf@@SAHXZ";
+	//mDebugging = function->mName ==	
+		//"?ColorizeCodeString@IDEUtils@IDE@bf@@SAXPEAVString@System@3@W4CodeKind@123@@Z";
 	//"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z";
 	//"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z";
 
 
 		//"?Hey@Blurg@bf@@SAXXZ";
 		//"?Hey@Blurg@bf@@SAXXZ";
@@ -15669,7 +15674,7 @@ void BeMCContext::Generate(BeFunction* function)
 
 
 							}
 							}
 							else
 							else
-								Fail("Invalid GEP");
+								SoftFail("Invalid GEP");
 						}
 						}
 						else
 						else
 						{
 						{

+ 1 - 1
IDEHelper/Backend/BeMCContext.h

@@ -1265,7 +1265,7 @@ public:
 public:		
 public:		
 	void NotImpl();
 	void NotImpl();
 	void Fail(const StringImpl& str);
 	void Fail(const StringImpl& str);
-	void SoftFail(const StringImpl& str, BeDbgLoc* dbgLoc);
+	void SoftFail(const StringImpl& str, BeDbgLoc* dbgLoc = NULL);
 	void ToString(BeMCInst* inst, String& str, bool showVRegFlags, bool showVRegDetails);
 	void ToString(BeMCInst* inst, String& str, bool showVRegFlags, bool showVRegDetails);
 	String ToString(const BeMCOperand& operand);
 	String ToString(const BeMCOperand& operand);
 	String ToString(bool showVRegFlags = true, bool showVRegDetails = false);
 	String ToString(bool showVRegFlags = true, bool showVRegDetails = false);

+ 2 - 2
IDEHelper/Compiler/BfModule.cpp

@@ -1097,7 +1097,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
 			//  code as we walk the AST
 			//  code as we walk the AST
 			//mBfIRBuilder->mDbgVerifyCodeGen = true;			
 			//mBfIRBuilder->mDbgVerifyCodeGen = true;			
 			if (
 			if (
-                (mModuleName == "Blurg")
+                (mModuleName == "-")
 				//|| (mModuleName == "System_Internal")
 				//|| (mModuleName == "System_Internal")
 				//|| (mModuleName == "vdata")
 				//|| (mModuleName == "vdata")
 				//|| (mModuleName == "Hey_Dude_Bro_TestClass")
 				//|| (mModuleName == "Hey_Dude_Bro_TestClass")
@@ -3747,7 +3747,7 @@ void BfModule::CreateFakeCallerMethod(const String& funcName)
 		auto paramType = mCurMethodInstance->GetParamType(paramIdx);
 		auto paramType = mCurMethodInstance->GetParamType(paramIdx);
 		if (paramType->IsValuelessType())
 		if (paramType->IsValuelessType())
 			continue;				
 			continue;				
-		exprEvaluator.PushArg(GetDefaultTypedValue(paramType, true), args);
+		exprEvaluator.PushArg(GetDefaultTypedValue(paramType, true, paramType->IsComposite() ? BfDefaultValueKind_Addr : BfDefaultValueKind_Const), args);
 	}
 	}
 
 
 	mBfIRBuilder->CreateCall(mCurMethodInstance->mIRFunction, args);
 	mBfIRBuilder->CreateCall(mCurMethodInstance->mIRFunction, args);

+ 22 - 7
IDEHelper/DbgModule.cpp

@@ -989,7 +989,17 @@ bool DbgType::Equals(DbgType* dbgType)
 	if (dbgType == NULL)
 	if (dbgType == NULL)
 		return false;
 		return false;
 	if (mTypeCode != dbgType->mTypeCode)
 	if (mTypeCode != dbgType->mTypeCode)
-		return false;
+	{
+		if ((mTypeCode == DbgType_Enum) || (dbgType->mTypeCode == DbgType_Enum))
+		{
+			// These may change mTypeCode, so redo the check afterward
+			GetPrimaryType();
+			dbgType->GetPrimaryType();
+		}
+
+		if (mTypeCode != dbgType->mTypeCode)
+			return false;
+	}
 	if ((mName == NULL) != (dbgType->mName == NULL))
 	if ((mName == NULL) != (dbgType->mName == NULL))
 		return false;
 		return false;
 	if (mName != NULL)
 	if (mName != NULL)
@@ -1212,11 +1222,16 @@ void DbgType::FixName()
 
 
 			if ((c == ':') && (inPtr[0] == ':'))
 			if ((c == ':') && (inPtr[0] == ':'))
 			{
 			{
-				modified = true;
-				inPtr++;
-				*(outPtr++) = '.';			
-				if (depthCount == 0)
-					typeNamePtr = outPtr;
+				if (mLanguage == DbgLanguage_Beef)
+				{
+					modified = true;
+					inPtr++;
+					*(outPtr++) = '.';
+					if (depthCount == 0)
+						typeNamePtr = outPtr;
+				}
+				else if (depthCount == 0)
+					mTypeName = inPtr + 1;
 			}
 			}
 			else if (modified)
 			else if (modified)
 				*(outPtr++) = c;
 				*(outPtr++) = c;
@@ -1658,7 +1673,7 @@ void DbgType::ToString(StringImpl& str, DbgLanguage language, bool allowDirectBf
 			nameP = combName.c_str();
 			nameP = combName.c_str();
 		}*/
 		}*/
 
 
-		if ((!mFixedName) && (language == DbgLanguage_Beef))
+		if ((!mFixedName) /*&& (language == DbgLanguage_Beef)*/)
 		{
 		{
 			FixName();
 			FixName();
 		}		
 		}