Convert formatting over to fmtlib

This commit is contained in:
Lioncash 2016-08-25 18:41:31 -04:00 committed by MerryMage
parent ee4b30eee4
commit 0102951bdd
9 changed files with 330 additions and 373 deletions

View file

@ -7,7 +7,6 @@ set(SRCS
backend_x64/jitstate.cpp
backend_x64/reg_alloc.cpp
common/memory_pool.cpp
common/string_util.cpp
frontend/arm_types.cpp
frontend/disassembler/disassembler_arm.cpp
frontend/disassembler/disassembler_thumb.cpp

View file

@ -6,6 +6,8 @@
#include <memory>
#include <fmt/format.h>
#ifdef DYNARMIC_USE_LLVM
#include <llvm-c/Disassembler.h>
#include <llvm-c/Target.h>
@ -18,7 +20,6 @@
#include "common/bit_util.h"
#include "common/common_types.h"
#include "common/scope_exit.h"
#include "common/string_util.h"
#include "dynarmic/dynarmic.h"
#include "frontend/arm_types.h"
#include "frontend/translate/translate.h"
@ -54,7 +55,7 @@ struct Jit::Impl {
std::string Disassemble(const Arm::LocationDescriptor& descriptor) {
auto block = GetBasicBlock(descriptor);
std::string result = Common::StringFromFormat("address: %p\nsize: %zu bytes\n", block.code_ptr, block.size);
std::string result = fmt::format("address: {}\nsize: {} bytes\n", block.code_ptr, block.size);
#ifdef DYNARMIC_USE_LLVM
CodePtr end = block.code_ptr + block.size;
@ -71,11 +72,11 @@ struct Jit::Impl {
size_t inst_size = LLVMDisasmInstruction(llvm_ctx, const_cast<u8*>(pos), remaining, (u64)pos, buffer, sizeof(buffer));
ASSERT(inst_size);
for (CodePtr i = pos; i < pos + inst_size; i++)
result.append(Common::StringFromFormat("%02x ", *i));
result += fmt::format("{:02x} ", *i);
for (size_t i = inst_size; i < 10; i++)
result.append(" ");
result.append(buffer);
result.append("\n");
result += " ";
result += buffer;
result += '\n';
pos += inst_size;
remaining -= inst_size;

View file

@ -1,36 +0,0 @@
/* 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 <cstdio>
#include <cstdarg>
#include <string>
#include "common/string_util.h"
namespace Dynarmic {
namespace Common {
std::string StringFromFormat(const char* format, ...) {
va_list args;
va_start(args, format);
int size = std::vsnprintf(nullptr, 0, format, args);
va_end(args);
std::string str;
str.resize(size+1);
va_start(args, format);
std::vsnprintf(&str[0], str.size(), format, args);
va_end(args);
str.resize(size);
return str;
}
} // namespace Common
} // namespace Dynarmic

View file

@ -6,22 +6,9 @@
#pragma once
#include <string>
namespace Dynarmic {
namespace Common {
#ifdef __MINGW32__
[[gnu::format(gnu_printf, 1, 2)]]
#elif !defined(_MSC_VER)
[[gnu::format(printf, 1, 2)]]
#endif
std::string StringFromFormat(
#ifdef _MSC_VER
_Printf_format_string_
#endif
const char* format, ...);
template <typename T>
constexpr char SignToChar(T value) {
return value >= 0 ? '+' : '-';

View file

@ -4,7 +4,9 @@
* General Public License version 2 or any later version.
*/
#include "common/string_util.h"
#include <array>
#include "common/bit_util.h"
#include "frontend/arm_types.h"
namespace Dynarmic {

View file

@ -6,12 +6,11 @@
#pragma once
#include <array>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include "common/assert.h"
#include "common/bit_util.h"
#include "common/common_types.h"
#include "frontend/arm/FPSCR.h"

File diff suppressed because it is too large Load diff

View file

@ -7,6 +7,8 @@
#include <cstdlib>
#include <string>
#include <fmt/format.h>
#include "common/bit_util.h"
#include "common/string_util.h"
#include "frontend/arm_types.h"
@ -18,236 +20,236 @@ namespace Arm {
class DisassemblerVisitor {
public:
std::string thumb16_LSL_imm(Imm5 imm5, Reg m, Reg d) {
return Common::StringFromFormat("lsls %s, %s, #%u", RegToString(d), RegToString(m), imm5);
return fmt::format("lsls {}, {}, #{}", RegToString(d), RegToString(m), imm5);
}
std::string thumb16_LSR_imm(Imm5 imm5, Reg m, Reg d) {
return Common::StringFromFormat("lsrs %s, %s, #%u", RegToString(d), RegToString(m), imm5 != 0 ? imm5 : 32);
return fmt::format("lsrs {}, {}, #{}", RegToString(d), RegToString(m), imm5 != 0 ? imm5 : 32);
}
std::string thumb16_ASR_imm(Imm5 imm5, Reg m, Reg d) {
return Common::StringFromFormat("asrs %s, %s, #%u", RegToString(d), RegToString(m), imm5 != 0 ? imm5 : 32);
return fmt::format("asrs {}, {}, #{}", RegToString(d), RegToString(m), imm5 != 0 ? imm5 : 32);
}
std::string thumb16_ADD_reg_t1(Reg m, Reg n, Reg d) {
return Common::StringFromFormat("adds %s, %s, %s", RegToString(d), RegToString(n), RegToString(m));
return fmt::format("adds {}, {}, {}", RegToString(d), RegToString(n), RegToString(m));
}
std::string thumb16_SUB_reg(Reg m, Reg n, Reg d) {
return Common::StringFromFormat("subs %s, %s, %s", RegToString(d), RegToString(n), RegToString(m));
return fmt::format("subs {}, {}, {}", RegToString(d), RegToString(n), RegToString(m));
}
std::string thumb16_ADD_imm_t1(Imm3 imm3, Reg n, Reg d) {
return Common::StringFromFormat("adds %s, %s, #%u", RegToString(d), RegToString(n), imm3);
return fmt::format("adds {}, {}, #{}", RegToString(d), RegToString(n), imm3);
}
std::string thumb16_SUB_imm_t1(Imm3 imm3, Reg n, Reg d) {
return Common::StringFromFormat("subs %s, %s, #%u", RegToString(d), RegToString(n), imm3);
return fmt::format("subs {}, {}, #{}", RegToString(d), RegToString(n), imm3);
}
std::string thumb16_MOV_imm(Reg d, Imm8 imm8) {
return Common::StringFromFormat("movs %s, #%u", RegToString(d), imm8);
return fmt::format("movs {}, #{}", RegToString(d), imm8);
}
std::string thumb16_CMP_imm(Reg n, Imm8 imm8) {
return Common::StringFromFormat("cmp %s, #%u", RegToString(n), imm8);
return fmt::format("cmp {}, #{}", RegToString(n), imm8);
}
std::string thumb16_ADD_imm_t2(Reg d_n, Imm8 imm8) {
return Common::StringFromFormat("adds %s, #%u", RegToString(d_n), imm8);
return fmt::format("adds {}, #{}", RegToString(d_n), imm8);
}
std::string thumb16_SUB_imm_t2(Reg d_n, Imm8 imm8) {
return Common::StringFromFormat("subs %s, #%u", RegToString(d_n), imm8);
return fmt::format("subs {}, #{}", RegToString(d_n), imm8);
}
std::string thumb16_AND_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("ands %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("ands {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_EOR_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("eors %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("eors {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_LSL_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("lsls %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("lsls {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_LSR_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("lsrs %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("lsrs {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_ASR_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("asrs %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("asrs {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_ADC_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("adcs %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("adcs {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_SBC_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("sbcs %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("sbcs {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_ROR_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("rors %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("rors {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_TST_reg(Reg m, Reg n) {
return Common::StringFromFormat("tst %s, %s", RegToString(n), RegToString(m));
return fmt::format("tst {}, {}", RegToString(n), RegToString(m));
}
std::string thumb16_RSB_imm(Reg n, Reg d) {
// Pre-UAL syntax: NEGS <Rd>, <Rn>
return Common::StringFromFormat("rsbs %s, %s, #0", RegToString(d), RegToString(n));
return fmt::format("rsbs {}, {}, #0", RegToString(d), RegToString(n));
}
std::string thumb16_CMP_reg_t1(Reg m, Reg n) {
return Common::StringFromFormat("cmp %s, %s", RegToString(n), RegToString(m));
return fmt::format("cmp {}, {}", RegToString(n), RegToString(m));
}
std::string thumb16_CMN_reg(Reg m, Reg n) {
return Common::StringFromFormat("cmn %s, %s", RegToString(n), RegToString(m));
return fmt::format("cmn {}, {}", RegToString(n), RegToString(m));
}
std::string thumb16_ORR_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("orrs %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("orrs {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_BIC_reg(Reg m, Reg d_n) {
return Common::StringFromFormat("bics %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("bics {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_MVN_reg(Reg m, Reg d) {
return Common::StringFromFormat("mvns %s, %s", RegToString(d), RegToString(m));
return fmt::format("mvns {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_ADD_reg_t2(bool d_n_hi, Reg m, Reg d_n_lo) {
Reg d_n = d_n_hi ? (d_n_lo + 8) : d_n_lo;
return Common::StringFromFormat("add %s, %s", RegToString(d_n), RegToString(m));
return fmt::format("add {}, {}", RegToString(d_n), RegToString(m));
}
std::string thumb16_CMP_reg_t2(bool n_hi, Reg m, Reg n_lo) {
Reg n = n_hi ? (n_lo + 8) : n_lo;
return Common::StringFromFormat("cmp %s, %s", RegToString(n), RegToString(m));
return fmt::format("cmp {}, {}", RegToString(n), RegToString(m));
}
std::string thumb16_MOV_reg(bool d_hi, Reg m, Reg d_lo) {
Reg d = d_hi ? (d_lo + 8) : d_lo;
return Common::StringFromFormat("mov %s, %s", RegToString(d), RegToString(m));
return fmt::format("mov {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_LDR_literal(Reg t, Imm8 imm8) {
u32 imm32 = imm8 << 2;
return Common::StringFromFormat("ldr %s, [pc, #%u]", RegToString(t), imm32);
return fmt::format("ldr {}, [pc, #{}]", RegToString(t), imm32);
}
std::string thumb16_STR_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("str %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("str {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_STRH_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("strh %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("strh {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_STRB_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("strb %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("strb {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_LDRSB_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("ldrsb %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("ldrsb {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_LDR_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("ldr %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("ldr {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_LDRH_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("ldrh %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("ldrh {}, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_LDRB_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("ldrb %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("ldrb {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_LDRSH_reg(Reg m, Reg n, Reg t) {
return Common::StringFromFormat("ldrsh %s, [%s, %s]", RegToString(t), RegToString(n), RegToString(m));
return fmt::format("ldrsh {}, [{}, {}]", RegToString(t), RegToString(n), RegToString(m));
}
std::string thumb16_STR_imm_t1(Imm5 imm5, Reg n, Reg t) {
u32 imm32 = imm5 << 2;
return Common::StringFromFormat("str %s, [%s, #%u]", RegToString(t), RegToString(n), imm32);
return fmt::format("str {}, [{}, #{}]", RegToString(t), RegToString(n), imm32);
}
std::string thumb16_LDR_imm_t1(Imm5 imm5, Reg n, Reg t) {
u32 imm32 = imm5 << 2;
return Common::StringFromFormat("ldr %s, [%s, #%u]", RegToString(t), RegToString(n), imm32);
return fmt::format("ldr {}, [{}, #{}]", RegToString(t), RegToString(n), imm32);
}
std::string thumb16_STRB_imm(Imm5 imm5, Reg n, Reg t) {
u32 imm32 = imm5;
return Common::StringFromFormat("strb %s, [%s, #%u]", RegToString(t), RegToString(n), imm32);
return fmt::format("strb {}, [{}, #{}]", RegToString(t), RegToString(n), imm32);
}
std::string thumb16_LDRB_imm(Imm5 imm5, Reg n, Reg t) {
u32 imm32 = imm5;
return Common::StringFromFormat("ldrb %s, [%s, #%u]", RegToString(t), RegToString(n), imm32);
return fmt::format("ldrb {}, [{}, #{}]", RegToString(t), RegToString(n), imm32);
}
std::string thumb16_STRH_imm(Imm5 imm5, Reg n, Reg t) {
u32 imm32 = imm5 << 1;
return Common::StringFromFormat("strh %s, [%s, #%u]", RegToString(t), RegToString(n), imm32);
return fmt::format("strh {}, [{}, #{}]", RegToString(t), RegToString(n), imm32);
}
std::string thumb16_LDRH_imm(Imm5 imm5, Reg n, Reg t) {
u32 imm32 = imm5 << 1;
return Common::StringFromFormat("ldrh %s, [%s, #%u]", RegToString(t), RegToString(n), imm32);
return fmt::format("ldrh {}, [{}, #{}]", RegToString(t), RegToString(n), imm32);
}
std::string thumb16_STR_imm_t2(Reg t, Imm5 imm5) {
u32 imm32 = imm5 << 2;
return Common::StringFromFormat("str %s, [sp, #%u]", RegToString(t), imm32);
return fmt::format("str {}, [sp, #{}]", RegToString(t), imm32);
}
std::string thumb16_LDR_imm_t2(Reg t, Imm5 imm5) {
u32 imm32 = imm5 << 2;
return Common::StringFromFormat("ldr %s, [sp, #%u]", RegToString(t), imm32);
return fmt::format("ldr {}, [sp, #{}]", RegToString(t), imm32);
}
std::string thumb16_ADR(Reg d, Imm8 imm8) {
u32 imm32 = imm8 << 2;
return Common::StringFromFormat("adr %s, +#%u", RegToString(d), imm32);
return fmt::format("adr {}, +#{}", RegToString(d), imm32);
}
std::string thumb16_ADD_sp_t1(Reg d, Imm8 imm8) {
u32 imm32 = imm8 << 2;
return Common::StringFromFormat("add %s, sp, #%u", RegToString(d), imm32);
return fmt::format("add {}, sp, #{}", RegToString(d), imm32);
}
std::string thumb16_ADD_sp_t2(Imm7 imm7) {
u32 imm32 = imm7 << 2;
return Common::StringFromFormat("add sp, sp, #%u", imm32);
return fmt::format("add sp, sp, #{}", imm32);
}
std::string thumb16_SUB_sp(Imm7 imm7) {
u32 imm32 = imm7 << 2;
return Common::StringFromFormat("sub sp, sp, #%u", imm32);
return fmt::format("sub sp, sp, #{}", imm32);
}
std::string thumb16_SXTH(Reg m, Reg d) {
return Common::StringFromFormat("sxth %s, %s", RegToString(d), RegToString(m));
return fmt::format("sxth {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_SXTB(Reg m, Reg d) {
return Common::StringFromFormat("sxtb %s, %s", RegToString(d), RegToString(m));
return fmt::format("sxtb {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_UXTH(Reg m, Reg d) {
return Common::StringFromFormat("uxth %s, %s", RegToString(d), RegToString(m));
return fmt::format("uxth {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_UXTB(Reg m, Reg d) {
return Common::StringFromFormat("uxtb %s, %s", RegToString(d), RegToString(m));
return fmt::format("uxtb {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_PUSH(bool M, RegList reg_list) {
@ -261,61 +263,61 @@ public:
}
std::string thumb16_SETEND(bool E) {
return Common::StringFromFormat("setend %s", E ? "BE" : "LE");
return fmt::format("setend {}", E ? "BE" : "LE");
}
std::string thumb16_REV(Reg m, Reg d) {
return Common::StringFromFormat("rev %s, %s", RegToString(d), RegToString(m));
return fmt::format("rev {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_REV16(Reg m, Reg d) {
return Common::StringFromFormat("rev16 %s, %s", RegToString(d), RegToString(m));
return fmt::format("rev16 {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_REVSH(Reg m, Reg d) {
return Common::StringFromFormat("revsh %s, %s", RegToString(d), RegToString(m));
return fmt::format("revsh {}, {}", RegToString(d), RegToString(m));
}
std::string thumb16_STMIA(Reg n, RegList reg_list) {
return Common::StringFromFormat("stm %s!, %s", RegToString(n), RegListToString(reg_list).c_str());
return fmt::format("stm {}!, {}", RegToString(n), RegListToString(reg_list));
}
std::string thumb16_LDMIA(Reg n, RegList reg_list) {
bool write_back = !Dynarmic::Common::Bit(static_cast<size_t>(n), reg_list);
return Common::StringFromFormat("ldm %s%s, %s", RegToString(n), write_back ? "!" : "", RegListToString(reg_list).c_str());
bool write_back = !Common::Bit(static_cast<size_t>(n), reg_list);
return fmt::format("ldm {}{}, {}", RegToString(n), write_back ? "!" : "", RegListToString(reg_list));
}
std::string thumb16_BX(Reg m) {
return Common::StringFromFormat("bx %s", RegToString(m));
return fmt::format("bx {}", RegToString(m));
}
std::string thumb16_BLX_reg(Reg m) {
return Common::StringFromFormat("blx %s", RegToString(m));
return fmt::format("blx {}", RegToString(m));
}
std::string thumb16_UDF() {
return Common::StringFromFormat("udf");
return fmt::format("udf");
}
std::string thumb16_SVC(Imm8 imm8) {
return Common::StringFromFormat("svc #%u", imm8);
return fmt::format("svc #{}", imm8);
}
std::string thumb16_B_t1(Cond cond, Imm8 imm8) {
s32 imm32 = Common::SignExtend<9, s32>(imm8 << 1) + 4;
return Common::StringFromFormat("b%s %c#%u", CondToString(cond), Common::SignToChar(imm32), abs(imm32));
return fmt::format("b{} {}#{}", CondToString(cond), Common::SignToChar(imm32), abs(imm32));
}
std::string thumb16_B_t2(Imm11 imm11) {
s32 imm32 = Common::SignExtend<12, s32>(imm11 << 1) + 4;
return Common::StringFromFormat("b %c#%u", Common::SignToChar(imm32), abs(imm32));
return fmt::format("b {}#{}", Common::SignToChar(imm32), abs(imm32));
}
};
std::string DisassembleThumb16(u16 instruction) {
DisassemblerVisitor visitor;
auto decoder = DecodeThumb16<DisassemblerVisitor>(instruction);
return !decoder ? Common::StringFromFormat("UNKNOWN: %x", instruction) : decoder->call(visitor, instruction);
return !decoder ? fmt::format("UNKNOWN: {:x}", instruction) : decoder->call(visitor, instruction);
}
} // namespace Arm

View file

@ -9,8 +9,9 @@
#include <map>
#include <string>
#include <fmt/format.h>
#include "common/assert.h"
#include "common/string_util.h"
#include "frontend/ir/basic_block.h"
#include "frontend/ir/opcodes.h"
@ -91,40 +92,40 @@ const size_t& Block::CycleCount() const {
}
static std::string LocDescToString(const Arm::LocationDescriptor& loc) {
return Common::StringFromFormat("{%u,%s,%s,%u}",
loc.PC(),
loc.TFlag() ? "T" : "!T",
loc.EFlag() ? "E" : "!E",
loc.FPSCR().Value());
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 Common::StringFromFormat("Interpret{%s}", LocDescToString(terminal.next).c_str());
return fmt::format("Interpret{{{}}}", LocDescToString(terminal.next));
}
case 2: {
return Common::StringFromFormat("ReturnToDispatch{}");
return "ReturnToDispatch{}";
}
case 3: {
auto terminal = boost::get<IR::Term::LinkBlock>(terminal_variant);
return Common::StringFromFormat("LinkBlock{%s}", LocDescToString(terminal.next).c_str());
return fmt::format("LinkBlock{{{}}}", LocDescToString(terminal.next));
}
case 4: {
auto terminal = boost::get<IR::Term::LinkBlockFast>(terminal_variant);
return Common::StringFromFormat("LinkBlockFast{%s}", LocDescToString(terminal.next).c_str());
return fmt::format("LinkBlockFast{{{}}}", LocDescToString(terminal.next));
}
case 5: {
return Common::StringFromFormat("PopRSBHint{}");
return "PopRSBHint{}";
}
case 6: {
auto terminal = boost::get<IR::Term::If>(terminal_variant);
return Common::StringFromFormat("If{%s, %s, %s}", CondToString(terminal.if_), TerminalToString(terminal.then_).c_str(), TerminalToString(terminal.else_).c_str());
return fmt::format("If{{{}, {}, {}}}", CondToString(terminal.if_), TerminalToString(terminal.then_), TerminalToString(terminal.else_));
}
case 7: {
auto terminal = boost::get<IR::Term::CheckHalt>(terminal_variant);
return Common::StringFromFormat("CheckHalt{%s}", TerminalToString(terminal.else_).c_str());
return fmt::format("CheckHalt{{{}}}", TerminalToString(terminal.else_));
}
default:
return "<invalid terminal>";
@ -134,13 +135,13 @@ static std::string TerminalToString(const Terminal& terminal_variant) {
std::string DumpBlock(const IR::Block& block) {
std::string ret;
ret += Common::StringFromFormat("Block: location=%s\n", LocDescToString(block.Location()).c_str());
ret += Common::StringFromFormat("cycles=%zu", block.CycleCount());
ret += Common::StringFromFormat(", entry_cond=%s", Arm::CondToString(block.GetCondition(), true));
ret += fmt::format("Block: location={}\n", LocDescToString(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 += Common::StringFromFormat(", cond_fail=%s", LocDescToString(block.ConditionFailedLocation()).c_str());
ret += fmt::format(", cond_fail={}", LocDescToString(block.ConditionFailedLocation()));
}
ret += "\n";
ret += '\n';
std::map<const IR::Inst*, size_t> inst_to_index;
size_t index = 0;
@ -149,15 +150,15 @@ std::string DumpBlock(const IR::Block& block) {
if (arg.IsEmpty()) {
return "<null>";
} else if (!arg.IsImmediate()) {
return Common::StringFromFormat("%%%zu", inst_to_index.at(arg.GetInst()));
return fmt::format("%{}", inst_to_index.at(arg.GetInst()));
}
switch (arg.GetType()) {
case Type::U1:
return Common::StringFromFormat("#%s", arg.GetU1() ? "1" : "0");
return fmt::format("#{}", arg.GetU1() ? '1' : '0');
case Type::U8:
return Common::StringFromFormat("#%u", arg.GetU8());
return fmt::format("#{}", arg.GetU8());
case Type::U32:
return Common::StringFromFormat("#%#x", arg.GetU32());
return fmt::format("#{:#x}", arg.GetU32());
case Type::RegRef:
return Arm::RegToString(arg.GetRegRef());
case Type::ExtRegRef:
@ -171,7 +172,7 @@ std::string DumpBlock(const IR::Block& block) {
const Opcode op = inst.GetOpcode();
if (GetTypeOf(op) != Type::Void) {
ret += Common::StringFromFormat("%%%-5zu = ", index);
ret += fmt::format("%{:<5} = ", index);
} else {
ret += " "; // '%00000 = ' -> 1 + 5 + 3 = 9 spaces
}
@ -188,15 +189,15 @@ std::string DumpBlock(const IR::Block& block) {
Type actual_type = arg.GetType();
Type expected_type = GetArgTypeOf(op, arg_index);
if (!AreTypesCompatible(actual_type, expected_type)) {
ret += Common::StringFromFormat("<type error: %s != %s>", GetNameOf(actual_type), GetNameOf(expected_type));
ret += fmt::format("<type error: {} != {}>", GetNameOf(actual_type), GetNameOf(expected_type));
}
}
ret += "\n";
ret += '\n';
inst_to_index[&inst] = index++;
}
ret += "terminal = " + TerminalToString(block.GetTerminal()) + "\n";
ret += "terminal = " + TerminalToString(block.GetTerminal()) + '\n';
return ret;
}