From e10985d1799fa4d0bf25ea055cd2fa9d2ae96056 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 21 Mar 2020 13:17:43 +0000 Subject: [PATCH] ir/basic_block: Add FastDispatchHint to TerminalToString Use a boost::static_visitor to ensure this is caught at compile-time in the future. --- src/frontend/ir/basic_block.cpp | 68 ++++++++++++++++----------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/frontend/ir/basic_block.cpp b/src/frontend/ir/basic_block.cpp index 3e91d17d..aa61fe21 100644 --- a/src/frontend/ir/basic_block.cpp +++ b/src/frontend/ir/basic_block.cpp @@ -123,40 +123,40 @@ const size_t& Block::CycleCount() const { } static std::string TerminalToString(const Terminal& terminal_variant) { - switch (terminal_variant.which()) { - case 1: { - auto terminal = boost::get(terminal_variant); - return fmt::format("Interpret{{{}}}", terminal.next); - } - case 2: { - return "ReturnToDispatch{}"; - } - case 3: { - auto terminal = boost::get(terminal_variant); - return fmt::format("LinkBlock{{{}}}", terminal.next); - } - case 4: { - auto terminal = boost::get(terminal_variant); - return fmt::format("LinkBlockFast{{{}}}", terminal.next); - } - case 5: { - return "PopRSBHint{}"; - } - case 6: { - auto terminal = boost::get(terminal_variant); - return fmt::format("If{{{}, {}, {}}}", A64::CondToString(terminal.if_), TerminalToString(terminal.then_), TerminalToString(terminal.else_)); - } - case 7: { - auto terminal = boost::get(terminal_variant); - return fmt::format("CheckBit{{{}, {}}}", TerminalToString(terminal.then_), TerminalToString(terminal.else_)); - } - case 8: { - auto terminal = boost::get(terminal_variant); - return fmt::format("CheckHalt{{{}}}", TerminalToString(terminal.else_)); - } - default: - return ""; - } + struct : boost::static_visitor { + std::string operator()(const Term::Invalid&) const { + return ""; + } + std::string operator()(const Term::Interpret& terminal) const { + return fmt::format("Interpret{{{}}}", terminal.next); + } + std::string operator()(const Term::ReturnToDispatch&) const { + return "ReturnToDispatch{}"; + } + std::string operator()(const Term::LinkBlock& terminal) const { + return fmt::format("LinkBlock{{{}}}", terminal.next); + } + std::string operator()(const Term::LinkBlockFast& terminal) const { + return fmt::format("LinkBlockFast{{{}}}", terminal.next); + } + std::string operator()(const Term::PopRSBHint&) const { + return "PopRSBHint{}"; + } + std::string operator()(const Term::FastDispatchHint&) const { + return "FastDispatchHint{}"; + } + std::string operator()(const Term::If& terminal) const { + return fmt::format("If{{{}, {}, {}}}", A64::CondToString(terminal.if_), TerminalToString(terminal.then_), TerminalToString(terminal.else_)); + } + std::string operator()(const Term::CheckBit& terminal) const { + return fmt::format("CheckBit{{{}, {}}}", TerminalToString(terminal.then_), TerminalToString(terminal.else_)); + } + std::string operator()(const Term::CheckHalt& terminal) const { + return fmt::format("CheckHalt{{{}}}", TerminalToString(terminal.else_)); + } + } visitor; + + return boost::apply_visitor(visitor, terminal_variant); } std::string DumpBlock(const IR::Block& block) {