assert: Use fmt in ASSERT_MSG

This commit is contained in:
MerryMage 2018-01-27 23:42:30 +00:00
parent b60c7f31c1
commit d7044bc751
17 changed files with 68 additions and 38 deletions

View file

@ -7,6 +7,8 @@
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <fmt/ostream.h>
#include <dynarmic/A32/coprocessor.h> #include <dynarmic/A32/coprocessor.h>
#include "backend_x64/a32_emit_x64.h" #include "backend_x64/a32_emit_x64.h"
@ -108,7 +110,7 @@ A32EmitX64::BlockDescriptor A32EmitX64::Emit(IR::Block& block) {
#undef A64OPC #undef A64OPC
default: default:
ASSERT_MSG(false, "Invalid opcode %zu", static_cast<size_t>(inst->GetOpcode())); ASSERT_MSG(false, "Invalid opcode: {}", inst->GetOpcode());
break; break;
} }

View file

@ -7,6 +7,8 @@
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <fmt/ostream.h>
#include "backend_x64/a64_emit_x64.h" #include "backend_x64/a64_emit_x64.h"
#include "backend_x64/a64_jitstate.h" #include "backend_x64/a64_jitstate.h"
#include "backend_x64/abi.h" #include "backend_x64/abi.h"
@ -89,7 +91,7 @@ A64EmitX64::BlockDescriptor A64EmitX64::Emit(IR::Block& block) {
#undef A64OPC #undef A64OPC
default: default:
ASSERT_MSG(false, "Invalid opcode %zu", static_cast<size_t>(inst->GetOpcode())); ASSERT_MSG(false, "Invalid opcode: {}", inst->GetOpcode());
break; break;
} }

View file

@ -240,7 +240,7 @@ Xbyak::Label EmitX64::EmitCond(IR::Cond cond) {
break; break;
} }
default: default:
ASSERT_MSG(false, "Unknown cond %zu", static_cast<size_t>(cond)); ASSERT_MSG(false, "Unknown cond {}", static_cast<size_t>(cond));
break; break;
} }

View file

@ -162,7 +162,7 @@ static void EmitConditionalSelect(BlockOfCode* code, EmitContext& ctx, IR::Inst*
code->mov(else_, then_); code->mov(else_, then_);
break; break;
default: default:
ASSERT_MSG(false, "Invalid cond %zu", static_cast<size_t>(args[0].GetImmediateCond())); ASSERT_MSG(false, "Invalid cond {}", static_cast<size_t>(args[0].GetImmediateCond()));
} }
ctx.reg_alloc.DefineValue(inst, else_); ctx.reg_alloc.DefineValue(inst, else_);

View file

@ -8,6 +8,7 @@
#include <numeric> #include <numeric>
#include <utility> #include <utility>
#include <fmt/ostream.h>
#include <xbyak.h> #include <xbyak.h>
#include "backend_x64/abi.h" #include "backend_x64/abi.h"
@ -49,7 +50,7 @@ static size_t GetBitWidth(IR::Type type) {
case IR::Type::CoprocInfo: case IR::Type::CoprocInfo:
case IR::Type::Cond: case IR::Type::Cond:
case IR::Type::Void: case IR::Type::Void:
ASSERT_MSG(false, "Type %zu cannot be represented at runtime", static_cast<size_t>(type)); ASSERT_MSG(false, "Type {} cannot be represented at runtime", type);
return 0; return 0;
case IR::Type::Opaque: case IR::Type::Opaque:
ASSERT_MSG(false, "Not a concrete type"); ASSERT_MSG(false, "Not a concrete type");

View file

@ -6,6 +6,8 @@
#include <cstdio> #include <cstdio>
#include <fmt/format.h>
// For asserts we'd like to keep all the junk executed when an assert happens away from the // For asserts we'd like to keep all the junk executed when an assert happens away from the
// important code in the function. One way of doing this is to put all the relevant code inside a // important code in the function. One way of doing this is to put all the relevant code inside a
// lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to // lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to
@ -26,14 +28,14 @@ static void assert_noinline_call(const Fn& fn) {
#define ASSERT(_a_) \ #define ASSERT(_a_) \
do if (!(_a_)) { assert_noinline_call([] { \ do if (!(_a_)) { assert_noinline_call([] { \
fprintf(stderr, "Assertion Failed!: %s\n", #_a_); \ fmt::print(stderr, "Assertion Failed!: {}\n", #_a_); \
}); } while (false) }); } while (false)
#define ASSERT_MSG(_a_, ...) \ #define ASSERT_MSG(_a_, ...) \
do if (!(_a_)) { assert_noinline_call([&] { \ do if (!(_a_)) { assert_noinline_call([&] { \
fprintf(stderr, "Assertion Failed!: %s\n", #_a_); \ fmt::print(stderr, "Assertion Failed!: {}\n", #_a_); \
fprintf(stderr, "Message: " __VA_ARGS__); \ fmt::print(stderr, "Message: " __VA_ARGS__); \
fprintf(stderr, "\n"); \ fmt::print(stderr, "\n"); \
}); } while (false) }); } while (false)
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!") #define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")

View file

@ -164,7 +164,7 @@ IR::UAnyU128 TranslatorVisitor::Mem(IR::U64 address, size_t bytesize, AccType /*
case 16: case 16:
return ir.ReadMemory128(address); return ir.ReadMemory128(address);
default: default:
ASSERT_MSG(false, "Invalid bytesize parameter %zu", bytesize); ASSERT_MSG(false, "Invalid bytesize parameter {}", bytesize);
return {}; return {};
} }
} }
@ -187,7 +187,7 @@ void TranslatorVisitor::Mem(IR::U64 address, size_t bytesize, AccType /*acctype*
ir.WriteMemory128(address, value); ir.WriteMemory128(address, value);
return; return;
default: default:
ASSERT_MSG(false, "Invalid bytesize parameter %zu", bytesize); ASSERT_MSG(false, "Invalid bytesize parameter {}", bytesize);
return; return;
} }
} }
@ -199,7 +199,7 @@ IR::U32U64 TranslatorVisitor::SignExtend(IR::UAny value, size_t to_size) {
case 64: case 64:
return ir.SignExtendToLong(value); return ir.SignExtendToLong(value);
default: default:
ASSERT_MSG(false, "Invalid size parameter %zu", to_size); ASSERT_MSG(false, "Invalid size parameter {}", to_size);
return {}; return {};
} }
} }
@ -211,7 +211,7 @@ IR::U32U64 TranslatorVisitor::ZeroExtend(IR::UAny value, size_t to_size) {
case 64: case 64:
return ir.ZeroExtendToLong(value); return ir.ZeroExtendToLong(value);
default: default:
ASSERT_MSG(false, "Invalid size parameter %zu", to_size); ASSERT_MSG(false, "Invalid size parameter {}", to_size);
return {}; return {};
} }
} }

View file

@ -6,8 +6,13 @@
#include <array> #include <array>
#include <map> #include <map>
#include <ostream>
#include <string>
#include <vector> #include <vector>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include "frontend/ir/opcodes.h" #include "frontend/ir/opcodes.h"
namespace Dynarmic::IR { namespace Dynarmic::IR {
@ -48,19 +53,32 @@ Type GetArgTypeOf(Opcode op, size_t arg_index) {
return OpcodeInfo::opcode_info.at(op).arg_types.at(arg_index); return OpcodeInfo::opcode_info.at(op).arg_types.at(arg_index);
} }
const char* GetNameOf(Opcode op) { std::string GetNameOf(Opcode op) {
if (OpcodeInfo::opcode_info.count(op) == 0)
return fmt::format("Unknown Opcode {}", static_cast<Opcode>(op));
return OpcodeInfo::opcode_info.at(op).name; return OpcodeInfo::opcode_info.at(op).name;
} }
const char* GetNameOf(Type type) { std::string GetNameOf(Type type) {
static const std::array<const char*, 14> names = { static const std::array<const char*, 16> names = {
"Void", "A32Reg", "A32ExtReg", "A64Reg", "A64Vec", "Opaque", "U1", "U8", "U16", "U32", "U64", "F32", "F64", "CoprocInfo" "Void", "A32Reg", "A32ExtReg", "A64Reg", "A64Vec", "Opaque", "U1", "U8", "U16", "U32", "U64", "F32", "F64", "CoprocInfo", "NZCVFlags", "Cond"
}; };
return names.at(static_cast<size_t>(type)); const size_t index = static_cast<size_t>(type);
if (index > names.size())
return fmt::format("Unknown Type {}", index);
return names.at(index);
} }
bool AreTypesCompatible(Type t1, Type t2) { bool AreTypesCompatible(Type t1, Type t2) {
return t1 == t2 || t1 == Type::Opaque || t2 == Type::Opaque; return t1 == t2 || t1 == Type::Opaque || t2 == Type::Opaque;
} }
std::ostream& operator<<(std::ostream& o, Opcode opcode) {
return o << GetNameOf(opcode);
}
std::ostream& operator<<(std::ostream& o, Type type) {
return o << GetNameOf(type);
}
} // namespace Dynarmic::IR } // namespace Dynarmic::IR

View file

@ -6,6 +6,9 @@
#pragma once #pragma once
#include <iosfwd>
#include <string>
#include "common/common_types.h" #include "common/common_types.h"
namespace Dynarmic::IR { namespace Dynarmic::IR {
@ -66,12 +69,15 @@ size_t GetNumArgsOf(Opcode op);
Type GetArgTypeOf(Opcode op, size_t arg_index); Type GetArgTypeOf(Opcode op, size_t arg_index);
/// Get the name of an opcode. /// Get the name of an opcode.
const char* GetNameOf(Opcode op); std::string GetNameOf(Opcode op);
/// Get the name of a type. /// Get the name of a type.
const char* GetNameOf(Type type); std::string GetNameOf(Type type);
/// @returns true if t1 and t2 are compatible types /// @returns true if t1 and t2 are compatible types
bool AreTypesCompatible(Type t1, Type t2); bool AreTypesCompatible(Type t1, Type t2);
std::ostream& operator<<(std::ostream& o, Opcode opcode);
std::ostream& operator<<(std::ostream& o, Type type);
} // namespace Dynarmic::IR } // namespace Dynarmic::IR

View file

@ -822,8 +822,8 @@ static unsigned int InterpreterTranslateInstruction(const ARMul_State* cpu, cons
// std::string disasm = ARM_Disasm::Disassemble(phys_addr, inst); // std::string disasm = ARM_Disasm::Disassemble(phys_addr, inst);
// LOG_ERROR(Core_ARM11, "Decode failure.\tPC : [0x%x]\tInstruction : %s [%x]", phys_addr, disasm.c_str(), inst); // LOG_ERROR(Core_ARM11, "Decode failure.\tPC : [0x%x]\tInstruction : %s [%x]", phys_addr, disasm.c_str(), inst);
// LOG_ERROR(Core_ARM11, "cpsr=0x%x, cpu->TFlag=%d, r15=0x%x", cpu->Cpsr, cpu->TFlag, cpu->Reg[15]); // LOG_ERROR(Core_ARM11, "cpsr=0x%x, cpu->TFlag=%d, r15=0x%x", cpu->Cpsr, cpu->TFlag, cpu->Reg[15]);
ASSERT_MSG(false, "Decode failure.\tPC : [0x%x]\tInstruction : %s [%x]", phys_addr, "", inst); ASSERT_MSG(false, "Decode failure.\tPC : [0x{:x}]\tInstruction : {} [{:x}]", phys_addr, "", inst);
ASSERT_MSG(false, "cpsr=0x%x, cpu->TFlag=%d, r15=0x%x", cpu->Cpsr, cpu->TFlag, cpu->Reg[15]); ASSERT_MSG(false, "cpsr=0x{:x}, cpu->TFlag={}, r15=0x{:x}", cpu->Cpsr, cpu->TFlag, cpu->Reg[15]);
CITRA_IGNORE_EXIT(-1); CITRA_IGNORE_EXIT(-1);
} }
inst_base = arm_instruction_trans[idx](inst, idx); inst_base = arm_instruction_trans[idx](inst, idx);
@ -1960,7 +1960,7 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) {
// LOG_ERROR(Core_ARM11, "MCRR executed | Coprocessor: %u, CRm %u, opc1: %u, Rt: %u, Rt2: %u", // LOG_ERROR(Core_ARM11, "MCRR executed | Coprocessor: %u, CRm %u, opc1: %u, Rt: %u, Rt2: %u",
// inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2); // inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2);
ASSERT_MSG(false, "MCRR executed | Coprocessor: %u, CRm %u, opc1: %u, Rt: %u, Rt2: %u", ASSERT_MSG(false, "MCRR executed | Coprocessor: {}, CRm {}, opc1: {}, Rt: {}, Rt2: {}",
inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2); inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2);
} }
@ -2048,7 +2048,7 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) {
// LOG_ERROR(Core_ARM11, "MRRC executed | Coprocessor: %u, CRm %u, opc1: %u, Rt: %u, Rt2: %u", // LOG_ERROR(Core_ARM11, "MRRC executed | Coprocessor: %u, CRm %u, opc1: %u, Rt: %u, Rt2: %u",
// inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2); // inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2);
ASSERT_MSG(false, "MRRC executed | Coprocessor: %u, CRm %u, opc1: %u, Rt: %u, Rt2: %u", ASSERT_MSG(false, "MRRC executed | Coprocessor: {}, CRm {}, opc1: {}, Rt: {}, Rt2: {}",
inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2); inst_cream->cp_num, inst_cream->crm, inst_cream->opcode_1, inst_cream->rt, inst_cream->rt2);
} }

View file

@ -469,7 +469,7 @@ u32 ARMul_State::ReadCP15Register(u32 crn, u32 opcode_1, u32 crm, u32 opcode_2)
} }
// LOG_ERROR(Core_ARM11, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2); // LOG_ERROR(Core_ARM11, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2);
ASSERT_MSG(false, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2); ASSERT_MSG(false, "MRC CRn={}, CRm={}, OP1={} OP2={} is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2);
return 0; return 0;
} }

View file

@ -161,7 +161,7 @@ void vfp_raise_exceptions(ARMul_State* state, u32 exceptions, u32 inst, u32 fpsc
if (exceptions == VFP_EXCEPTION_ERROR) { if (exceptions == VFP_EXCEPTION_ERROR) {
// LOG_CRITICAL(Core_ARM11, "unhandled bounce %x", inst); // LOG_CRITICAL(Core_ARM11, "unhandled bounce %x", inst);
// Crash(); // Crash();
ASSERT_MSG(false, "unhandled bounce %x", inst); ASSERT_MSG(false, "unhandled bounce {:08x}", inst);
} }
/* /*

View file

@ -1295,7 +1295,7 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr)
if (!fop->fn) { if (!fop->fn) {
// LOG_CRITICAL(Core_ARM11, "could not find single op %d, inst=0x%x@0x%x", FEXT_TO_IDX(inst), inst, state->Reg[15]); // LOG_CRITICAL(Core_ARM11, "could not find single op %d, inst=0x%x@0x%x", FEXT_TO_IDX(inst), inst, state->Reg[15]);
// Crash(); // Crash();
ASSERT_MSG(false, "could not find single op %d, inst=0x%x@0x%x", FEXT_TO_IDX(inst), inst, state->Reg[15]); ASSERT_MSG(false, "could not find single op {}, inst=0x{:08x}@0x{:08x}", FEXT_TO_IDX(inst), inst, state->Reg[15]);
goto invalid; goto invalid;
} }

View file

@ -7,7 +7,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <cinttypes> #include <cstring>
#include <map> #include <map>
#include <dynarmic/A32/a32.h> #include <dynarmic/A32/a32.h>
@ -71,11 +71,11 @@ public:
MemoryWrite32(vaddr + 4, static_cast<u32>(value >> 32)); MemoryWrite32(vaddr + 4, static_cast<u32>(value >> 32));
} }
void InterpreterFallback(u32 pc, size_t num_instructions) override { ASSERT_MSG(false, "InterpreterFallback(%08x, %zu)", pc, num_instructions); } void InterpreterFallback(u32 pc, size_t num_instructions) override { ASSERT_MSG(false, "InterpreterFallback({:08x}, {})", pc, num_instructions); }
void CallSVC(std::uint32_t swi) override { ASSERT_MSG(false, "CallSVC(%u)", swi); } void CallSVC(std::uint32_t swi) override { ASSERT_MSG(false, "CallSVC({})", swi); }
void ExceptionRaised(u32 pc, Dynarmic::A32::Exception /*exception*/) override { ASSERT_MSG(false, "ExceptionRaised(%08x)", pc); } void ExceptionRaised(u32 pc, Dynarmic::A32::Exception /*exception*/) override { ASSERT_MSG(false, "ExceptionRaised({:08x})", pc); }
void AddTicks(std::uint64_t ticks) override { void AddTicks(std::uint64_t ticks) override {
if (ticks > ticks_left) { if (ticks > ticks_left) {

View file

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <array> #include <array>
#include <cinttypes>
#include <map> #include <map>
#include <dynarmic/A64/a64.h> #include <dynarmic/A64/a64.h>
@ -77,11 +76,11 @@ public:
MemoryWrite64(vaddr + 8, value[1]); MemoryWrite64(vaddr + 8, value[1]);
} }
void InterpreterFallback(u64 pc, size_t num_instructions) override { ASSERT_MSG(false, "InterpreterFallback(%" PRIx64 ", %zu)", pc, num_instructions); } void InterpreterFallback(u64 pc, size_t num_instructions) override { ASSERT_MSG(false, "InterpreterFallback({:016x}, {})", pc, num_instructions); }
void CallSVC(std::uint32_t swi) override { ASSERT_MSG(false, "CallSVC(%u)", swi); } void CallSVC(std::uint32_t swi) override { ASSERT_MSG(false, "CallSVC({})", swi); }
void ExceptionRaised(u64 pc, Dynarmic::A64::Exception /*exception*/) override { ASSERT_MSG(false, "ExceptionRaised(%" PRIx64 ")", pc); } void ExceptionRaised(u64 pc, Dynarmic::A64::Exception /*exception*/) override { ASSERT_MSG(false, "ExceptionRaised({:016x})", pc); }
void AddTicks(std::uint64_t ticks) override { void AddTicks(std::uint64_t ticks) override {
if (ticks > ticks_left) { if (ticks > ticks_left) {

View file

@ -10,7 +10,7 @@
#define CHECKED(expr) \ #define CHECKED(expr) \
do { \ do { \
if (auto cerr_ = (expr)) { \ if (auto cerr_ = (expr)) { \
ASSERT_MSG(false, "Call " #expr " failed with error: %u (%s)\n", cerr_, \ ASSERT_MSG(false, "Call " #expr " failed with error: {} ({})\n", cerr_, \
uc_strerror(cerr_)); \ uc_strerror(cerr_)); \
} \ } \
} while (0) } while (0)
@ -164,7 +164,7 @@ void Unicorn::InterruptHook(uc_engine* uc, u32 int_number, void* user_data) {
this_->testenv.CallSVC(iss); this_->testenv.CallSVC(iss);
break; break;
default: default:
ASSERT_MSG(false, "Unhandled interrupt: int_number: %#x, esr: %#x (ec: %#x, iss: %#x)", int_number, esr, ec, iss); ASSERT_MSG(false, "Unhandled interrupt: int_number: {:#x}, esr: {:#x} (ec: {:#x}, iss: {:#x})", int_number, esr, ec, iss);
} }
} }

View file

@ -47,7 +47,7 @@ endif()
include(CreateDirectoryGroups) include(CreateDirectoryGroups)
create_target_directory_groups(dynarmic_tests) create_target_directory_groups(dynarmic_tests)
target_link_libraries(dynarmic_tests PRIVATE dynarmic boost catch) target_link_libraries(dynarmic_tests PRIVATE dynarmic boost catch fmt)
target_include_directories(dynarmic_tests PRIVATE . ../src) target_include_directories(dynarmic_tests PRIVATE . ../src)
target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS}) target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS})