Skip to content

Commit ca62ec2

Browse files
authoredMay 1, 2024
Adds functionality to dump IR to stdout (shader-slang#4065)
Adds a member dump() to IRInst that can writes the immediate value or IR inst value to stdout to help with debugging
1 parent 2abd5bd commit ca62ec2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎source/slang/slang-ir.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "slang-ir-util.h"
55

66
#include "../core/slang-basic.h"
7+
#include "../core/slang-writer.h"
78

89
#include "slang-ir-dominators.h"
910

@@ -8605,6 +8606,25 @@ namespace Slang
86058606
}
86068607
}
86078608

8609+
void IRInst::dump()
8610+
{
8611+
if (auto intLit = as<IRIntLit>(this))
8612+
{
8613+
std::cout << intLit->getValue() << std::endl;
8614+
}
8615+
else if (auto stringLit = as<IRStringLit>(this))
8616+
{
8617+
std::cout << stringLit->getStringSlice().begin() << std::endl;
8618+
}
8619+
else
8620+
{
8621+
StringBuilder sb;
8622+
IRDumpOptions options;
8623+
StringWriter writer(&sb, Slang::WriterFlag::AutoFlush);
8624+
dumpIR(this, options, nullptr, &writer);
8625+
std::cout << sb.toString().begin() << std::endl;
8626+
}
8627+
}
86088628
} // namespace Slang
86098629

86108630
#if SLANG_VC

‎source/slang/slang-ir.h

+4
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,10 @@ struct IRInst
838838
/// If both `inPrev` and `inNext` are null, then `inParent` must have no (raw) children.
839839
///
840840
void _insertAt(IRInst* inPrev, IRInst* inNext, IRInst* inParent);
841+
842+
/// Print the IR to stdout for debugging purposes
843+
///
844+
void dump();
841845
};
842846

843847
enum class IRDynamicCastBehavior

0 commit comments

Comments
 (0)
Please sign in to comment.