location_descriptor: Provide operator<< string overload (#24)

This commit is contained in:
Mat M 2016-09-05 16:31:25 -04:00 committed by Merry
parent 5c8bf5a15d
commit b40d19c3b7
4 changed files with 39 additions and 13 deletions

View file

@ -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

View file

@ -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<IR::Term::Interpret>(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<IR::Term::LinkBlock>(terminal_variant);
return fmt::format("LinkBlock{{{}}}", LocDescToString(terminal.next));
return fmt::format("LinkBlock{{{}}}", terminal.next);
}
case 4: {
auto terminal = boost::get<IR::Term::LinkBlockFast>(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';

View file

@ -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 <ostream>
#include <fmt/format.h>
#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

View file

@ -7,6 +7,7 @@
#pragma once
#include <functional>
#include <iosfwd>
#include <tuple>
#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