diff options
Diffstat (limited to 'src/mir')
-rw-r--r-- | src/mir/from_hir.cpp | 5 | ||||
-rw-r--r-- | src/mir/mir.cpp | 43 | ||||
-rw-r--r-- | src/mir/mir.hpp | 2 |
3 files changed, 50 insertions, 0 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 800398b7..f54ead5a 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -1348,6 +1348,7 @@ void MirBuilder::set_cur_block(unsigned int new_block) if( m_block_active ) { BUG(Span(), "Updating block when previous is active"); } + DEBUG("BB" << new_block << " START"); m_current_block = new_block; m_block_active = true; } @@ -1356,6 +1357,7 @@ void MirBuilder::end_block(::MIR::Terminator term) if( !m_block_active ) { BUG(Span(), "Terminating block when none active"); } + DEBUG("BB" << m_current_block << " END -> " << term); m_output.blocks.at(m_current_block).terminator = mv$(term); m_block_active = false; m_current_block = 0; @@ -1365,12 +1367,14 @@ void MirBuilder::pause_cur_block() if( !m_block_active ) { BUG(Span(), "Pausing block when none active"); } + DEBUG("BB" << m_current_block << " PAUSE"); m_block_active = false; m_current_block = 0; } ::MIR::BasicBlockId MirBuilder::new_bb_linked() { auto rv = new_bb_unlinked(); + DEBUG("BB" << rv); end_block( ::MIR::Terminator::make_Goto(rv) ); set_cur_block(rv); return rv; @@ -1378,6 +1382,7 @@ void MirBuilder::pause_cur_block() ::MIR::BasicBlockId MirBuilder::new_bb_unlinked() { auto rv = m_output.blocks.size(); + DEBUG("BB" << rv); m_output.blocks.push_back({}); return rv; } diff --git a/src/mir/mir.cpp b/src/mir/mir.cpp index 8789abce..df6e1cde 100644 --- a/src/mir/mir.cpp +++ b/src/mir/mir.cpp @@ -35,6 +35,49 @@ namespace MIR { ) return os; } + + ::std::ostream& operator<<(::std::ostream& os, const LValue& x) + { + return os; + } + + ::std::ostream& operator<<(::std::ostream& os, const Terminator& x) + { + TU_MATCHA( (x), (e), + (Incomplete, + os << "Invalid"; + ), + (Return, + os << "Return"; + ), + (Diverge, + os << "Diverge"; + ), + (Goto, + os << "Goto(" << e << ")"; + ), + (Panic, + os << "Panic(" << e.dst << ";)"; + ), + (If, + os << "If( ? : " << e.bb0 << ", " << e.bb1 << ")"; + ), + (Switch, + os << "Switch( ? : "; + for(unsigned int j = 0; j < e.targets.size(); j ++) + os << j << " => bb" << e.targets[j] << ", "; + os << ")"; + ), + (Call, + os << "Call( ? = ?( "; + for(const auto& arg : e.args) + os << arg << ", "; + os << "), bb" << e.ret_block << ", bb" << e.panic_block << ")"; + ) + ) + + return os; + } } ::MIR::LValue MIR::LValue::clone() const diff --git a/src/mir/mir.hpp b/src/mir/mir.hpp index 8c94e749..2b9a0a81 100644 --- a/src/mir/mir.hpp +++ b/src/mir/mir.hpp @@ -53,6 +53,7 @@ TAGGED_UNION_EX(LValue, (), Variable, ( LValue clone() const; ) ); +extern ::std::ostream& operator<<(::std::ostream& os, const LValue& x); enum class eBinOp { @@ -158,6 +159,7 @@ TAGGED_UNION(Terminator, Incomplete, ::std::vector<LValue> args; }) ); +extern ::std::ostream& operator<<(::std::ostream& os, const Terminator& x); enum class eDropKind { SHALLOW, |