mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 19:50:05 +00:00
Add IR dumping functions to use during debugging.
When using lldb and/or gdb I frequently get odd std::string failures when using the IR printing instructions we have now. This adds the methods Instruction::Dump(), BasicBlock::Dump() and Function::Dump() to emit the output of the pretty print to stderr. With this I can now reliably print IR from gdb and lldb sessions.
This commit is contained in:
parent
63265097e5
commit
4a4632264e
@ -193,6 +193,10 @@ std::ostream& operator<<(std::ostream& str, const BasicBlock& block) {
|
||||
return str;
|
||||
}
|
||||
|
||||
void BasicBlock::Dump() const {
|
||||
std::cerr << "Basic block #" << id() << "\n" << *this << "\n ";
|
||||
}
|
||||
|
||||
std::string BasicBlock::PrettyPrint(uint32_t options) const {
|
||||
std::ostringstream str;
|
||||
ForEachInst([&str, options](const Instruction* inst) {
|
||||
|
@ -209,6 +209,10 @@ class BasicBlock {
|
||||
// is always added to |options|.
|
||||
std::string PrettyPrint(uint32_t options = 0u) const;
|
||||
|
||||
// Dump this basic block on stderr. Useful when running interactive
|
||||
// debuggers.
|
||||
void Dump() const;
|
||||
|
||||
private:
|
||||
// The enclosing function.
|
||||
Function* function_;
|
||||
|
@ -94,6 +94,10 @@ std::ostream& operator<<(std::ostream& str, const Function& func) {
|
||||
return str;
|
||||
}
|
||||
|
||||
void Function::Dump() const {
|
||||
std::cerr << "Function #" << result_id() << "\n" << *this << "\n";
|
||||
}
|
||||
|
||||
std::string Function::PrettyPrint(uint32_t options) const {
|
||||
std::ostringstream str;
|
||||
ForEachInst([&str, options](const Instruction* inst) {
|
||||
|
@ -125,6 +125,10 @@ class Function {
|
||||
// is always added to |options|.
|
||||
std::string PrettyPrint(uint32_t options = 0u) const;
|
||||
|
||||
// Dump this function on stderr. Useful when running interactive
|
||||
// debuggers.
|
||||
void Dump() const;
|
||||
|
||||
private:
|
||||
// The OpFunction instruction that begins the definition of this function.
|
||||
std::unique_ptr<Instruction> def_inst_;
|
||||
|
@ -540,6 +540,10 @@ std::ostream& operator<<(std::ostream& str, const Instruction& inst) {
|
||||
return str;
|
||||
}
|
||||
|
||||
void Instruction::Dump() const {
|
||||
std::cerr << "Instruction #" << unique_id() << "\n" << *this << "\n";
|
||||
}
|
||||
|
||||
bool Instruction::IsOpcodeCodeMotionSafe() const {
|
||||
switch (opcode_) {
|
||||
case SpvOpNop:
|
||||
|
@ -427,6 +427,10 @@ class Instruction : public utils::IntrusiveNodeBase<Instruction> {
|
||||
// rules for physical addressing.
|
||||
bool IsValidBasePointer() const;
|
||||
|
||||
// Dump this instruction on stderr. Useful when running interactive
|
||||
// debuggers.
|
||||
void Dump() const;
|
||||
|
||||
private:
|
||||
// Returns the total count of result type id and result id.
|
||||
uint32_t TypeResultIdCount() const {
|
||||
|
Loading…
Reference in New Issue
Block a user