diff options
| author | Sriram Murali <85252063+sriramm-nv@users.noreply.github.com> | 2024-05-01 00:06:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-01 00:06:59 -0700 |
| commit | ca62ec2591de40e7c8226330670cc8c8d4840065 (patch) | |
| tree | dc02bfcd70623be6c8a00ff4ed260272ef41357e /source | |
| parent | 2abd5bd5770b8052b8e4ceed86ff4ced883d2af7 (diff) | |
Adds functionality to dump IR to stdout (#4065)
Adds a member dump() to IRInst that can writes the immediate value or IR
inst value to stdout to help with debugging
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ir.cpp | 20 | ||||
| -rw-r--r-- | source/slang/slang-ir.h | 4 |
2 files changed, 24 insertions, 0 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 5a917e88c..5f49d1966 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -4,6 +4,7 @@ #include "slang-ir-util.h" #include "../core/slang-basic.h" +#include "../core/slang-writer.h" #include "slang-ir-dominators.h" @@ -8605,6 +8606,25 @@ namespace Slang } } + void IRInst::dump() + { + if (auto intLit = as<IRIntLit>(this)) + { + std::cout << intLit->getValue() << std::endl; + } + else if (auto stringLit = as<IRStringLit>(this)) + { + std::cout << stringLit->getStringSlice().begin() << std::endl; + } + else + { + StringBuilder sb; + IRDumpOptions options; + StringWriter writer(&sb, Slang::WriterFlag::AutoFlush); + dumpIR(this, options, nullptr, &writer); + std::cout << sb.toString().begin() << std::endl; + } + } } // namespace Slang #if SLANG_VC diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index 50ed0096d..d3a4c8026 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -838,6 +838,10 @@ struct IRInst /// If both `inPrev` and `inNext` are null, then `inParent` must have no (raw) children. /// void _insertAt(IRInst* inPrev, IRInst* inNext, IRInst* inParent); + + /// Print the IR to stdout for debugging purposes + /// + void dump(); }; enum class IRDynamicCastBehavior |
