mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-01-05 05:58:19 +01:00
assert: Use fmt in ASSERT_MSG
This commit is contained in:
parent
b60c7f31c1
commit
d7044bc751
17 changed files with 68 additions and 38 deletions
|
|
@ -7,6 +7,8 @@
|
|||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include <dynarmic/A32/coprocessor.h>
|
||||
|
||||
#include "backend_x64/a32_emit_x64.h"
|
||||
|
|
@ -108,7 +110,7 @@ A32EmitX64::BlockDescriptor A32EmitX64::Emit(IR::Block& block) {
|
|||
#undef A64OPC
|
||||
|
||||
default:
|
||||
ASSERT_MSG(false, "Invalid opcode %zu", static_cast<size_t>(inst->GetOpcode()));
|
||||
ASSERT_MSG(false, "Invalid opcode: {}", inst->GetOpcode());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include "backend_x64/a64_emit_x64.h"
|
||||
#include "backend_x64/a64_jitstate.h"
|
||||
#include "backend_x64/abi.h"
|
||||
|
|
@ -89,7 +91,7 @@ A64EmitX64::BlockDescriptor A64EmitX64::Emit(IR::Block& block) {
|
|||
#undef A64OPC
|
||||
|
||||
default:
|
||||
ASSERT_MSG(false, "Invalid opcode %zu", static_cast<size_t>(inst->GetOpcode()));
|
||||
ASSERT_MSG(false, "Invalid opcode: {}", inst->GetOpcode());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ Xbyak::Label EmitX64::EmitCond(IR::Cond cond) {
|
|||
break;
|
||||
}
|
||||
default:
|
||||
ASSERT_MSG(false, "Unknown cond %zu", static_cast<size_t>(cond));
|
||||
ASSERT_MSG(false, "Unknown cond {}", static_cast<size_t>(cond));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ static void EmitConditionalSelect(BlockOfCode* code, EmitContext& ctx, IR::Inst*
|
|||
code->mov(else_, then_);
|
||||
break;
|
||||
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_);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <numeric>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
#include <xbyak.h>
|
||||
|
||||
#include "backend_x64/abi.h"
|
||||
|
|
@ -49,7 +50,7 @@ static size_t GetBitWidth(IR::Type type) {
|
|||
case IR::Type::CoprocInfo:
|
||||
case IR::Type::Cond:
|
||||
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;
|
||||
case IR::Type::Opaque:
|
||||
ASSERT_MSG(false, "Not a concrete type");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <cstdio>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
// 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
|
||||
// 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_) \
|
||||
do if (!(_a_)) { assert_noinline_call([] { \
|
||||
fprintf(stderr, "Assertion Failed!: %s\n", #_a_); \
|
||||
fmt::print(stderr, "Assertion Failed!: {}\n", #_a_); \
|
||||
}); } while (false)
|
||||
|
||||
#define ASSERT_MSG(_a_, ...) \
|
||||
do if (!(_a_)) { assert_noinline_call([&] { \
|
||||
fprintf(stderr, "Assertion Failed!: %s\n", #_a_); \
|
||||
fprintf(stderr, "Message: " __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
fmt::print(stderr, "Assertion Failed!: {}\n", #_a_); \
|
||||
fmt::print(stderr, "Message: " __VA_ARGS__); \
|
||||
fmt::print(stderr, "\n"); \
|
||||
}); } while (false)
|
||||
|
||||
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ IR::UAnyU128 TranslatorVisitor::Mem(IR::U64 address, size_t bytesize, AccType /*
|
|||
case 16:
|
||||
return ir.ReadMemory128(address);
|
||||
default:
|
||||
ASSERT_MSG(false, "Invalid bytesize parameter %zu", bytesize);
|
||||
ASSERT_MSG(false, "Invalid bytesize parameter {}", bytesize);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ void TranslatorVisitor::Mem(IR::U64 address, size_t bytesize, AccType /*acctype*
|
|||
ir.WriteMemory128(address, value);
|
||||
return;
|
||||
default:
|
||||
ASSERT_MSG(false, "Invalid bytesize parameter %zu", bytesize);
|
||||
ASSERT_MSG(false, "Invalid bytesize parameter {}", bytesize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ IR::U32U64 TranslatorVisitor::SignExtend(IR::UAny value, size_t to_size) {
|
|||
case 64:
|
||||
return ir.SignExtendToLong(value);
|
||||
default:
|
||||
ASSERT_MSG(false, "Invalid size parameter %zu", to_size);
|
||||
ASSERT_MSG(false, "Invalid size parameter {}", to_size);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ IR::U32U64 TranslatorVisitor::ZeroExtend(IR::UAny value, size_t to_size) {
|
|||
case 64:
|
||||
return ir.ZeroExtendToLong(value);
|
||||
default:
|
||||
ASSERT_MSG(false, "Invalid size parameter %zu", to_size);
|
||||
ASSERT_MSG(false, "Invalid size parameter {}", to_size);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,13 @@
|
|||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include "frontend/ir/opcodes.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const char* GetNameOf(Type type) {
|
||||
static const std::array<const char*, 14> names = {
|
||||
"Void", "A32Reg", "A32ExtReg", "A64Reg", "A64Vec", "Opaque", "U1", "U8", "U16", "U32", "U64", "F32", "F64", "CoprocInfo"
|
||||
std::string GetNameOf(Type type) {
|
||||
static const std::array<const char*, 16> names = {
|
||||
"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) {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Dynarmic::IR {
|
||||
|
|
@ -66,12 +69,15 @@ size_t GetNumArgsOf(Opcode op);
|
|||
Type GetArgTypeOf(Opcode op, size_t arg_index);
|
||||
|
||||
/// Get the name of an opcode.
|
||||
const char* GetNameOf(Opcode op);
|
||||
std::string GetNameOf(Opcode op);
|
||||
|
||||
/// 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
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue