mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Better ToString support for values
This commit is contained in:
parent
cbacf99a61
commit
014ce28195
5 changed files with 43 additions and 34 deletions
|
@ -2128,7 +2128,6 @@ String BeMCContext::ToString(const BeMCOperand& operand)
|
|||
if (operand.mKind == BeMCOperandKind_ConstAgg)
|
||||
{
|
||||
BeDumpContext dumpContext;
|
||||
dumpContext.mModule = mBeFunction->mModule;
|
||||
String str = "const ";
|
||||
str += dumpContext.ToString(operand.mConstant);
|
||||
return str;
|
||||
|
|
|
@ -28,6 +28,19 @@ void bpt(Beefy::BeType* t)
|
|||
}
|
||||
}
|
||||
|
||||
void bpv(Beefy::BeValue* val)
|
||||
{
|
||||
BeDumpContext dumpCtx;
|
||||
String str;
|
||||
dumpCtx.ToString(str, val);
|
||||
str += "\n";
|
||||
OutputDebugStr(str);
|
||||
|
||||
auto type = val->GetType();
|
||||
if (type != NULL)
|
||||
bpt(type);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void BeValueVisitor::VisitChild(BeValue* value)
|
||||
|
@ -1229,11 +1242,12 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
|
|||
|
||||
if (auto arg = BeValueDynCast<BeArgument>(value))
|
||||
{
|
||||
auto& typeParam = mModule->mActiveFunction->GetFuncType()->mParams[arg->mArgIdx];
|
||||
auto& param = mModule->mActiveFunction->mParams[arg->mArgIdx];
|
||||
auto activeFunction = arg->mModule->mActiveFunction;
|
||||
auto& typeParam = activeFunction->GetFuncType()->mParams[arg->mArgIdx];
|
||||
auto& param = activeFunction->mParams[arg->mArgIdx];
|
||||
if (showType)
|
||||
{
|
||||
mModule->ToString(str, typeParam.mType);
|
||||
BeModule::ToString(str, typeParam.mType);
|
||||
str += " %";
|
||||
str += param.mName;
|
||||
}
|
||||
|
@ -1242,6 +1256,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
|
|||
str += "%";
|
||||
str += param.mName;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1255,7 +1270,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
|
|||
{
|
||||
if (showType)
|
||||
{
|
||||
mModule->ToString(str, constant->mType);
|
||||
BeModule::ToString(str, constant->mType);
|
||||
str += " ";
|
||||
}
|
||||
|
||||
|
@ -1323,7 +1338,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
|
|||
|
||||
if (auto constant = BeValueDynCast<BeConstant>(value))
|
||||
{
|
||||
mModule->ToString(str, constant->mType);
|
||||
BeModule::ToString(str, constant->mType);
|
||||
str += " ";
|
||||
|
||||
switch (constant->mType->mTypeCode)
|
||||
|
@ -1403,7 +1418,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
|
|||
{
|
||||
if (resultType != NULL)
|
||||
{
|
||||
mModule->ToString(str, resultType);
|
||||
BeModule::ToString(str, resultType);
|
||||
str += " %";
|
||||
}
|
||||
else
|
||||
|
@ -1437,7 +1452,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
|
|||
mValueNameMap[value] = useName;
|
||||
if ((showType) && (resultType != NULL))
|
||||
{
|
||||
mModule->ToString(str, resultType);
|
||||
BeModule::ToString(str, resultType);
|
||||
str += " %";
|
||||
str += useName;
|
||||
return;
|
||||
|
@ -1460,13 +1475,13 @@ String BeDumpContext::ToString(BeValue* value, bool showType, bool mdDrillDown)
|
|||
String BeDumpContext::ToString(BeType* type)
|
||||
{
|
||||
String str;
|
||||
mModule->ToString(str, type);
|
||||
BeModule::ToString(str, type);
|
||||
return str;
|
||||
}
|
||||
|
||||
void BeDumpContext::ToString(StringImpl& str, BeType* type)
|
||||
{
|
||||
mModule->ToString(str, type);
|
||||
BeModule::ToString(str, type);
|
||||
}
|
||||
|
||||
void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool showScope)
|
||||
|
@ -1755,8 +1770,7 @@ String BeModule::ToString(BeFunction* wantFunc)
|
|||
SetAndRestoreValue<BeFunction*> prevActiveFunc(mActiveFunction, NULL);
|
||||
|
||||
BeDumpContext dc;
|
||||
dc.mModule = this;
|
||||
|
||||
|
||||
if (wantFunc == NULL)
|
||||
{
|
||||
str += "Module: "; str += mModuleName; str += "\n";
|
||||
|
@ -2448,8 +2462,7 @@ void BeModule::Print(BeFunction* func)
|
|||
|
||||
void BeModule::PrintValue(BeValue* val)
|
||||
{
|
||||
BeDumpContext dumpCtx;
|
||||
dumpCtx.mModule = this;
|
||||
BeDumpContext dumpCtx;
|
||||
String str;
|
||||
dumpCtx.ToString(str, val);
|
||||
str += "\n";
|
||||
|
@ -2991,7 +3004,7 @@ void BeModule::SetActiveFunction(BeFunction* function)
|
|||
mActiveFunction = function;
|
||||
}
|
||||
|
||||
BeArgument * BeModule::GetArgument(int argIdx)
|
||||
BeArgument* BeModule::GetArgument(int argIdx)
|
||||
{
|
||||
while ((int)argIdx >= mArgs.size())
|
||||
{
|
||||
|
@ -3371,8 +3384,7 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx)
|
|||
hashCtx.MixinStr(mDirectory);
|
||||
hashCtx.MixinStr(mProducer);
|
||||
|
||||
BeDumpContext dc;
|
||||
dc.mModule = mBeModule;
|
||||
BeDumpContext dc;
|
||||
String lhsName;
|
||||
String rhsName;
|
||||
|
||||
|
|
|
@ -1291,8 +1291,7 @@ public:
|
|||
|
||||
struct BeDumpContext
|
||||
{
|
||||
public:
|
||||
BeModule* mModule;
|
||||
public:
|
||||
Dictionary<BeValue*, String> mValueNameMap;
|
||||
Dictionary<String, int> mSeenNames;
|
||||
|
||||
|
@ -1309,12 +1308,6 @@ public:
|
|||
static String ToString(int val);
|
||||
static String ToString(BeCmpKind cmpKind);
|
||||
static String ToString(BeBinaryOpKind opKind);
|
||||
|
||||
public:
|
||||
BeDumpContext()
|
||||
{
|
||||
mModule = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1197,9 +1197,16 @@ String BfIRBuilder::ToString(BfIRValue irValue)
|
|||
{
|
||||
auto val = mBeIRCodeGen->GetBeValue(irValue.mId);
|
||||
String str;
|
||||
BeDumpContext dc;
|
||||
dc.mModule = mBeIRCodeGen->mBeModule;
|
||||
BeDumpContext dc;
|
||||
dc.ToString(str, val);
|
||||
|
||||
auto type = val->GetType();
|
||||
if (type != NULL)
|
||||
{
|
||||
str += "\n";
|
||||
dc.ToString(str, type);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
@ -1267,8 +1274,7 @@ String BfIRBuilder::ToString(BfIRType irType)
|
|||
}
|
||||
|
||||
String str;
|
||||
BeDumpContext dc;
|
||||
dc.mModule = mBeIRCodeGen->mBeModule;
|
||||
BeDumpContext dc;
|
||||
dc.ToString(str, beType);
|
||||
return str;
|
||||
}
|
||||
|
@ -1302,8 +1308,7 @@ String BfIRBuilder::ToString(BfIRFunction irFunc)
|
|||
return "null";
|
||||
|
||||
String str;
|
||||
BeDumpContext dc;
|
||||
dc.mModule = mBeIRCodeGen->mBeModule;
|
||||
BeDumpContext dc;
|
||||
dc.ToString(str, val);
|
||||
return str;
|
||||
}
|
||||
|
@ -1349,8 +1354,7 @@ String BfIRBuilder::ToString(BfIRMDNode irMDNode)
|
|||
if (md == NULL)
|
||||
return "null";
|
||||
String str;
|
||||
BeDumpContext dc;
|
||||
dc.mModule = mBeIRCodeGen->mBeModule;
|
||||
BeDumpContext dc;
|
||||
dc.ToString(str, md);
|
||||
return str;
|
||||
}
|
||||
|
@ -5060,3 +5064,4 @@ void BfIRBuilder::DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name,
|
|||
NEW_CMD_INSERTED;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1260,7 +1260,7 @@ public:
|
|||
void DbgCreateGlobalVariable(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNumber,
|
||||
BfIRMDNode type, bool isLocalToUnit, BfIRValue val, BfIRMDNode Decl = BfIRMDNode());
|
||||
BfIRMDNode DbgCreateLexicalBlock(BfIRMDNode scope, BfIRMDNode file, int line, int col);
|
||||
void DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name, BfIRValue value);
|
||||
void DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name, BfIRValue value);
|
||||
};
|
||||
|
||||
NS_BF_END
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue