2016-08-17 15:53:36 +01:00
|
|
|
/* 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 <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "common/string_util.h"
|
|
|
|
#include "frontend/ir/basic_block.h"
|
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace IR {
|
|
|
|
|
|
|
|
std::string DumpBlock(const IR::Block& block) {
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
const auto loc_to_string = [](Arm::LocationDescriptor loc) -> std::string {
|
|
|
|
return Common::StringFromFormat("{%u,%s,%s,%u}",
|
|
|
|
loc.PC(),
|
|
|
|
loc.TFlag() ? "T" : "!T",
|
|
|
|
loc.EFlag() ? "E" : "!E",
|
|
|
|
loc.FPSCR());
|
|
|
|
};
|
|
|
|
|
|
|
|
ret += Common::StringFromFormat("Block: location=%s\n", loc_to_string(block.location).c_str());
|
|
|
|
ret += Common::StringFromFormat("cycles=%zu", block.cycle_count);
|
|
|
|
ret += Common::StringFromFormat(", entry_cond=%s", Arm::CondToString(block.cond, true));
|
|
|
|
if (block.cond != Arm::Cond::AL) {
|
|
|
|
ret += Common::StringFromFormat(", cond_fail=%s", loc_to_string(block.cond_failed.get()).c_str());
|
|
|
|
}
|
|
|
|
ret += "\n";
|
|
|
|
|
|
|
|
std::map<const IR::Inst*, size_t> inst_to_index;
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
const auto arg_to_string = [&inst_to_index](const IR::Value& arg) -> std::string {
|
|
|
|
if (arg.IsEmpty()) {
|
|
|
|
return "<null>";
|
|
|
|
} else if (!arg.IsImmediate()) {
|
|
|
|
return Common::StringFromFormat("%%%zu", inst_to_index.at(arg.GetInst()));
|
|
|
|
}
|
|
|
|
switch (arg.GetType()) {
|
|
|
|
case Type::U1:
|
|
|
|
return Common::StringFromFormat("#%s", arg.GetU1() ? "1" : "0");
|
|
|
|
case Type::U8:
|
|
|
|
return Common::StringFromFormat("#%u", arg.GetU8());
|
|
|
|
case Type::U32:
|
|
|
|
return Common::StringFromFormat("#%#x", arg.GetU32());
|
|
|
|
case Type::RegRef:
|
|
|
|
return Arm::RegToString(arg.GetRegRef());
|
|
|
|
case Type::ExtRegRef:
|
|
|
|
return Arm::ExtRegToString(arg.GetExtRegRef());
|
|
|
|
default:
|
|
|
|
return "<unknown immediate type>";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
basic_block: Add proxy member functions for the instruction list
Currently basic block kind of acts like a 'dumb struct' which makes things
a little more verbose to write (as opposed to keeping it all in one place,
I guess). It's also a little wonky conceptually, considering a block is
composed of instructions (i.e. 'contains' them).
So providing accessors that make it act more like a container can make working
with algorithms a little nicer. It also makes the API a little more
defined.
Ideally, the list would be only available through a function, but
currently, the pool allocator is exposed, which seems somewhat odd,
considering the block itself should manage its overall allocations
(with placement new, and regular new), rather than putting that
sanitizing directly on the IR emitter (it should just care about emission,
not block state). However, recontaining that can be followed up with,
as it's very trivial to do.
2016-08-21 17:35:30 +01:00
|
|
|
for (auto inst = block.begin(); inst != block.end(); ++inst) {
|
2016-08-17 15:53:36 +01:00
|
|
|
const Opcode op = inst->GetOpcode();
|
|
|
|
|
|
|
|
if (GetTypeOf(op) != Type::Void) {
|
|
|
|
ret += Common::StringFromFormat("%%%-5zu = ", index);
|
|
|
|
} else {
|
|
|
|
ret += " "; // '%00000 = ' -> 1 + 5 + 3 = 9 spaces
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += GetNameOf(op);
|
|
|
|
|
|
|
|
const size_t arg_count = GetNumArgsOf(op);
|
|
|
|
for (size_t arg_index = 0; arg_index < arg_count; arg_index++) {
|
2016-08-17 13:29:05 +01:00
|
|
|
const Value arg = inst->GetArg(arg_index);
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
ret += arg_index != 0 ? ", " : " ";
|
2016-08-17 13:29:05 +01:00
|
|
|
ret += arg_to_string(arg);
|
|
|
|
|
|
|
|
Type actual_type = arg.GetType();
|
|
|
|
Type expected_type = GetArgTypeOf(op, arg_index);
|
2016-08-19 01:34:14 +01:00
|
|
|
if (!AreTypesCompatible(actual_type, expected_type)) {
|
2016-08-17 13:29:05 +01:00
|
|
|
ret += Common::StringFromFormat("<type error: %s != %s>", GetNameOf(actual_type), GetNameOf(expected_type));
|
|
|
|
}
|
2016-08-17 15:53:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret += "\n";
|
|
|
|
inst_to_index[&*inst] = index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace IR
|
|
|
|
} // namespace Dynarmic
|