1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Better ToString support for values

This commit is contained in:
Brian Fiete 2020-06-16 07:50:40 -07:00
parent cbacf99a61
commit 014ce28195
5 changed files with 43 additions and 34 deletions

View file

@ -2128,7 +2128,6 @@ String BeMCContext::ToString(const BeMCOperand& operand)
if (operand.mKind == BeMCOperandKind_ConstAgg) if (operand.mKind == BeMCOperandKind_ConstAgg)
{ {
BeDumpContext dumpContext; BeDumpContext dumpContext;
dumpContext.mModule = mBeFunction->mModule;
String str = "const "; String str = "const ";
str += dumpContext.ToString(operand.mConstant); str += dumpContext.ToString(operand.mConstant);
return str; return str;

View file

@ -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) 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)) if (auto arg = BeValueDynCast<BeArgument>(value))
{ {
auto& typeParam = mModule->mActiveFunction->GetFuncType()->mParams[arg->mArgIdx]; auto activeFunction = arg->mModule->mActiveFunction;
auto& param = mModule->mActiveFunction->mParams[arg->mArgIdx]; auto& typeParam = activeFunction->GetFuncType()->mParams[arg->mArgIdx];
auto& param = activeFunction->mParams[arg->mArgIdx];
if (showType) if (showType)
{ {
mModule->ToString(str, typeParam.mType); BeModule::ToString(str, typeParam.mType);
str += " %"; str += " %";
str += param.mName; str += param.mName;
} }
@ -1242,6 +1256,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
str += "%"; str += "%";
str += param.mName; str += param.mName;
} }
return; return;
} }
@ -1255,7 +1270,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
{ {
if (showType) if (showType)
{ {
mModule->ToString(str, constant->mType); BeModule::ToString(str, constant->mType);
str += " "; str += " ";
} }
@ -1323,7 +1338,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
if (auto constant = BeValueDynCast<BeConstant>(value)) if (auto constant = BeValueDynCast<BeConstant>(value))
{ {
mModule->ToString(str, constant->mType); BeModule::ToString(str, constant->mType);
str += " "; str += " ";
switch (constant->mType->mTypeCode) switch (constant->mType->mTypeCode)
@ -1403,7 +1418,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
{ {
if (resultType != NULL) if (resultType != NULL)
{ {
mModule->ToString(str, resultType); BeModule::ToString(str, resultType);
str += " %"; str += " %";
} }
else else
@ -1437,7 +1452,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
mValueNameMap[value] = useName; mValueNameMap[value] = useName;
if ((showType) && (resultType != NULL)) if ((showType) && (resultType != NULL))
{ {
mModule->ToString(str, resultType); BeModule::ToString(str, resultType);
str += " %"; str += " %";
str += useName; str += useName;
return; return;
@ -1460,13 +1475,13 @@ String BeDumpContext::ToString(BeValue* value, bool showType, bool mdDrillDown)
String BeDumpContext::ToString(BeType* type) String BeDumpContext::ToString(BeType* type)
{ {
String str; String str;
mModule->ToString(str, type); BeModule::ToString(str, type);
return str; return str;
} }
void BeDumpContext::ToString(StringImpl& str, BeType* type) void BeDumpContext::ToString(StringImpl& str, BeType* type)
{ {
mModule->ToString(str, type); BeModule::ToString(str, type);
} }
void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool showScope) void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool showScope)
@ -1755,7 +1770,6 @@ String BeModule::ToString(BeFunction* wantFunc)
SetAndRestoreValue<BeFunction*> prevActiveFunc(mActiveFunction, NULL); SetAndRestoreValue<BeFunction*> prevActiveFunc(mActiveFunction, NULL);
BeDumpContext dc; BeDumpContext dc;
dc.mModule = this;
if (wantFunc == NULL) if (wantFunc == NULL)
{ {
@ -2449,7 +2463,6 @@ void BeModule::Print(BeFunction* func)
void BeModule::PrintValue(BeValue* val) void BeModule::PrintValue(BeValue* val)
{ {
BeDumpContext dumpCtx; BeDumpContext dumpCtx;
dumpCtx.mModule = this;
String str; String str;
dumpCtx.ToString(str, val); dumpCtx.ToString(str, val);
str += "\n"; str += "\n";
@ -2991,7 +3004,7 @@ void BeModule::SetActiveFunction(BeFunction* function)
mActiveFunction = function; mActiveFunction = function;
} }
BeArgument * BeModule::GetArgument(int argIdx) BeArgument* BeModule::GetArgument(int argIdx)
{ {
while ((int)argIdx >= mArgs.size()) while ((int)argIdx >= mArgs.size())
{ {
@ -3372,7 +3385,6 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx)
hashCtx.MixinStr(mProducer); hashCtx.MixinStr(mProducer);
BeDumpContext dc; BeDumpContext dc;
dc.mModule = mBeModule;
String lhsName; String lhsName;
String rhsName; String rhsName;

View file

@ -1292,7 +1292,6 @@ public:
struct BeDumpContext struct BeDumpContext
{ {
public: public:
BeModule* mModule;
Dictionary<BeValue*, String> mValueNameMap; Dictionary<BeValue*, String> mValueNameMap;
Dictionary<String, int> mSeenNames; Dictionary<String, int> mSeenNames;
@ -1309,12 +1308,6 @@ public:
static String ToString(int val); static String ToString(int val);
static String ToString(BeCmpKind cmpKind); static String ToString(BeCmpKind cmpKind);
static String ToString(BeBinaryOpKind opKind); static String ToString(BeBinaryOpKind opKind);
public:
BeDumpContext()
{
mModule = NULL;
}
}; };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View file

@ -1198,8 +1198,15 @@ String BfIRBuilder::ToString(BfIRValue irValue)
auto val = mBeIRCodeGen->GetBeValue(irValue.mId); auto val = mBeIRCodeGen->GetBeValue(irValue.mId);
String str; String str;
BeDumpContext dc; BeDumpContext dc;
dc.mModule = mBeIRCodeGen->mBeModule;
dc.ToString(str, val); dc.ToString(str, val);
auto type = val->GetType();
if (type != NULL)
{
str += "\n";
dc.ToString(str, type);
}
return str; return str;
} }
#endif #endif
@ -1268,7 +1275,6 @@ String BfIRBuilder::ToString(BfIRType irType)
String str; String str;
BeDumpContext dc; BeDumpContext dc;
dc.mModule = mBeIRCodeGen->mBeModule;
dc.ToString(str, beType); dc.ToString(str, beType);
return str; return str;
} }
@ -1303,7 +1309,6 @@ String BfIRBuilder::ToString(BfIRFunction irFunc)
String str; String str;
BeDumpContext dc; BeDumpContext dc;
dc.mModule = mBeIRCodeGen->mBeModule;
dc.ToString(str, val); dc.ToString(str, val);
return str; return str;
} }
@ -1350,7 +1355,6 @@ String BfIRBuilder::ToString(BfIRMDNode irMDNode)
return "null"; return "null";
String str; String str;
BeDumpContext dc; BeDumpContext dc;
dc.mModule = mBeIRCodeGen->mBeModule;
dc.ToString(str, md); dc.ToString(str, md);
return str; return str;
} }
@ -5060,3 +5064,4 @@ void BfIRBuilder::DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name,
NEW_CMD_INSERTED; NEW_CMD_INSERTED;
} }