From b40d19c3b70b44bce7aa90b4f4e14de5ba97415a Mon Sep 17 00:00:00 2001 From: Mat M Date: Mon, 5 Sep 2016 16:31:25 -0400 Subject: [PATCH] location_descriptor: Provide operator<< string overload (#24) --- src/CMakeLists.txt | 1 + src/frontend/ir/basic_block.cpp | 18 +++++------------- src/frontend/ir/location_descriptor.cpp | 24 ++++++++++++++++++++++++ src/frontend/ir/location_descriptor.h | 9 +++++++++ 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 src/frontend/ir/location_descriptor.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5cbbfc2..df331a92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ set(SRCS frontend/disassembler/disassembler_thumb.cpp frontend/ir/basic_block.cpp frontend/ir/ir_emitter.cpp + frontend/ir/location_descriptor.cpp frontend/ir/microinstruction.cpp frontend/ir/opcodes.cpp frontend/ir/value.cpp diff --git a/src/frontend/ir/basic_block.cpp b/src/frontend/ir/basic_block.cpp index 0952aa52..d8bc56b9 100644 --- a/src/frontend/ir/basic_block.cpp +++ b/src/frontend/ir/basic_block.cpp @@ -91,30 +91,22 @@ const size_t& Block::CycleCount() const { return cycle_count; } -static std::string LocDescToString(const LocationDescriptor& loc) { - return fmt::format("{{{},{},{},{}}}", - loc.PC(), - loc.TFlag() ? "T" : "!T", - loc.EFlag() ? "E" : "!E", - loc.FPSCR().Value()); -} - static std::string TerminalToString(const Terminal& terminal_variant) { switch (terminal_variant.which()) { case 1: { auto terminal = boost::get(terminal_variant); - return fmt::format("Interpret{{{}}}", LocDescToString(terminal.next)); + return fmt::format("Interpret{{{}}}", terminal.next); } case 2: { return "ReturnToDispatch{}"; } case 3: { auto terminal = boost::get(terminal_variant); - return fmt::format("LinkBlock{{{}}}", LocDescToString(terminal.next)); + return fmt::format("LinkBlock{{{}}}", terminal.next); } case 4: { auto terminal = boost::get(terminal_variant); - return fmt::format("LinkBlockFast{{{}}}", LocDescToString(terminal.next)); + return fmt::format("LinkBlockFast{{{}}}", terminal.next); } case 5: { return "PopRSBHint{}"; @@ -135,11 +127,11 @@ static std::string TerminalToString(const Terminal& terminal_variant) { std::string DumpBlock(const IR::Block& block) { std::string ret; - ret += fmt::format("Block: location={}\n", LocDescToString(block.Location())); + ret += fmt::format("Block: location={}\n", block.Location()); ret += fmt::format("cycles={}", block.CycleCount()); ret += fmt::format(", entry_cond={}", Arm::CondToString(block.GetCondition(), true)); if (block.GetCondition() != Arm::Cond::AL) { - ret += fmt::format(", cond_fail={}", LocDescToString(block.ConditionFailedLocation())); + ret += fmt::format(", cond_fail={}", block.ConditionFailedLocation()); } ret += '\n'; diff --git a/src/frontend/ir/location_descriptor.cpp b/src/frontend/ir/location_descriptor.cpp new file mode 100644 index 00000000..e697322d --- /dev/null +++ b/src/frontend/ir/location_descriptor.cpp @@ -0,0 +1,24 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2016 MerryMage + * This software may be used and distributed according to the terms of the GNU + * General Public License version 2 or any later version. + */ + +#include +#include +#include "frontend/ir/location_descriptor.h" + +namespace Dynarmic { +namespace IR { + +std::ostream& operator<<(std::ostream& o, const LocationDescriptor& loc) { + o << fmt::format("{{{},{},{},{}}}", + loc.PC(), + loc.TFlag() ? "T" : "!T", + loc.EFlag() ? "E" : "!E", + loc.FPSCR().Value()); + return o; +} + +} // namespace IR +} // namespace Dynarmic diff --git a/src/frontend/ir/location_descriptor.h b/src/frontend/ir/location_descriptor.h index 43ec0786..3089bf5c 100644 --- a/src/frontend/ir/location_descriptor.h +++ b/src/frontend/ir/location_descriptor.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include "common/common_types.h" #include "frontend/arm/FPSCR.h" @@ -87,6 +88,14 @@ private: Arm::FPSCR fpscr; ///< Floating point status control register. }; +/** + * Provides a string representation of a LocationDescriptor. + * + * @param o Output stream + * @param descriptor The descriptor to get a string representation of + */ +std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor); + } // namespace IR } // namespace Dynarmic