mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Better diagnostics of backend errors
This commit is contained in:
parent
b09364cd34
commit
6ac1496eaa
2 changed files with 78 additions and 9 deletions
|
@ -285,6 +285,28 @@ bool BeIRCodeGen::IsModuleEmpty()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BeIRCodeGen::FatalError(const StringImpl& err)
|
||||||
|
{
|
||||||
|
String failStr = "Fatal Error in Module: ";
|
||||||
|
if (mBeModule != NULL)
|
||||||
|
failStr += mBeModule->mModuleName;
|
||||||
|
failStr += "\n";
|
||||||
|
if (mBeModule != NULL)
|
||||||
|
{
|
||||||
|
BeDumpContext dumpCtx;
|
||||||
|
|
||||||
|
if (mBeModule->mCurDbgLoc != NULL)
|
||||||
|
{
|
||||||
|
failStr += "DbgLoc: ";
|
||||||
|
dumpCtx.ToString(failStr, mBeModule->mCurDbgLoc);
|
||||||
|
failStr += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
failStr += err;
|
||||||
|
BF_FATAL(failStr);
|
||||||
|
}
|
||||||
|
|
||||||
void BeIRCodeGen::NotImpl()
|
void BeIRCodeGen::NotImpl()
|
||||||
{
|
{
|
||||||
BF_FATAL("Not implemented");
|
BF_FATAL("Not implemented");
|
||||||
|
@ -1584,8 +1606,18 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
auto ptrType = ptr->GetType();
|
auto ptrType = ptr->GetType();
|
||||||
auto valType = val->GetType();
|
auto valType = val->GetType();
|
||||||
BF_ASSERT(ptrType->IsPointer());
|
|
||||||
BF_ASSERT(mBeContext->AreTypesEqual(((BePointerType*)ptrType)->mElementType, valType));
|
if ((!ptrType->IsPointer()) || (!mBeContext->AreTypesEqual(((BePointerType*)ptrType)->mElementType, valType)))
|
||||||
|
{
|
||||||
|
String errStr;
|
||||||
|
errStr += "BfIRCmd_Store Match Failure:\n";
|
||||||
|
BeDumpContext dumpCtx;
|
||||||
|
errStr += "Val: ";
|
||||||
|
dumpCtx.ToString(errStr, val);
|
||||||
|
errStr += "\nPtr: ";
|
||||||
|
dumpCtx.ToString(errStr, ptr);
|
||||||
|
FatalError(errStr);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CMD_PARAM(bool, isVolatile);
|
CMD_PARAM(bool, isVolatile);
|
||||||
|
@ -1602,8 +1634,17 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
auto ptrType = ptr->GetType();
|
auto ptrType = ptr->GetType();
|
||||||
auto valType = val->GetType();
|
auto valType = val->GetType();
|
||||||
BF_ASSERT(ptrType->IsPointer());
|
if ((!ptrType->IsPointer()) || (!mBeContext->AreTypesEqual(((BePointerType*)ptrType)->mElementType, valType)))
|
||||||
BF_ASSERT(mBeContext->AreTypesEqual(((BePointerType*)ptrType)->mElementType, valType));
|
{
|
||||||
|
String errStr;
|
||||||
|
errStr += "BfIRCmd_Store Match Failure:\n";
|
||||||
|
BeDumpContext dumpCtx;
|
||||||
|
errStr += "Val: ";
|
||||||
|
dumpCtx.ToString(errStr, val);
|
||||||
|
errStr += "\nPtr: ";
|
||||||
|
dumpCtx.ToString(errStr, ptr);
|
||||||
|
FatalError(errStr);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SetResult(curId, mBeModule->CreateAlignedStore(val, ptr, alignment, isVolatile));
|
SetResult(curId, mBeModule->CreateAlignedStore(val, ptr, alignment, isVolatile));
|
||||||
|
@ -2070,14 +2111,41 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
BF_ASSERT(funcPtrType->IsPointer());
|
BF_ASSERT(funcPtrType->IsPointer());
|
||||||
auto funcType = (BeFunctionType*)((BePointerType*)funcPtrType)->mElementType;
|
auto funcType = (BeFunctionType*)((BePointerType*)funcPtrType)->mElementType;
|
||||||
BF_ASSERT(funcType->mTypeCode == BeTypeCode_Function);
|
BF_ASSERT(funcType->mTypeCode == BeTypeCode_Function);
|
||||||
|
|
||||||
|
bool argsMatched = true;
|
||||||
if (!funcType->mIsVarArg)
|
if (!funcType->mIsVarArg)
|
||||||
{
|
{
|
||||||
BF_ASSERT(funcType->mParams.size() == args.size());
|
if (funcType->mParams.size() != args.size())
|
||||||
int argIdx = 0;
|
{
|
||||||
|
argsMatched = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int argIdx = 0;
|
||||||
|
for (int argIdx = 0; argIdx < (int)args.size(); argIdx++)
|
||||||
|
{
|
||||||
|
if (funcType->mParams[argIdx].mType != args[argIdx]->GetType())
|
||||||
|
argsMatched = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!argsMatched)
|
||||||
|
{
|
||||||
|
String errStr;
|
||||||
|
errStr += "BfIRCmd_CreateCall Match Failure:\n";
|
||||||
|
BeDumpContext dumpCtx;
|
||||||
|
dumpCtx.ToString(errStr, func);
|
||||||
|
errStr += "\n";
|
||||||
|
dumpCtx.ToString(errStr, funcType);
|
||||||
|
errStr += "\n";
|
||||||
for (int argIdx = 0; argIdx < (int)args.size(); argIdx++)
|
for (int argIdx = 0; argIdx < (int)args.size(); argIdx++)
|
||||||
{
|
{
|
||||||
BF_ASSERT(funcType->mParams[argIdx].mType == args[argIdx]->GetType());
|
errStr += StrFormat("ARG #%d: ", argIdx);
|
||||||
|
dumpCtx.ToString(errStr, args[argIdx]);
|
||||||
|
errStr += "\n";
|
||||||
}
|
}
|
||||||
|
FatalError(errStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -74,6 +74,7 @@ public:
|
||||||
Array<int> mConfigConsts;
|
Array<int> mConfigConsts;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void FatalError(const StringImpl& str);
|
||||||
void NotImpl();
|
void NotImpl();
|
||||||
BfTypeCode GetTypeCode(BeType* type, bool isSigned);
|
BfTypeCode GetTypeCode(BeType* type, bool isSigned);
|
||||||
void SetResult(int id, BeValue* value);
|
void SetResult(int id, BeValue* value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue