replace bit_cast with as_type
This commit is contained in:
+14
-3
@@ -1,9 +1,9 @@
|
||||
#include "QuestScript.hh"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <phosg/Strings.hh>
|
||||
@@ -17,6 +17,17 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
// bit_cast isn't in the standard place on macOS (it is apparently implicitly
|
||||
// included by resource_dasm, but newserv can be built without resource_dasm)
|
||||
// and I'm too lazy to go find the right header to include
|
||||
template <typename ToT, typename FromT>
|
||||
ToT as_type(const FromT& v) {
|
||||
static_assert(sizeof(FromT) == sizeof(ToT), "types are not the same size");
|
||||
ToT ret;
|
||||
memcpy(&ret, &v, sizeof(ToT));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static string format_and_indent_data(const void* data, size_t size, uint64_t start_address) {
|
||||
struct iovec iov;
|
||||
iov.iov_base = const_cast<void*>(data);
|
||||
@@ -1199,7 +1210,7 @@ std::string disassemble_quest_script(const void* data, size_t size, GameVersion
|
||||
case Type::FLOAT32: {
|
||||
float v = cmd_r.get_f32l();
|
||||
if (def->flags & QuestScriptOpcodeDefinition::Flag::PRESERVE_ARG_STACK) {
|
||||
arg_stack_values.emplace_back(ArgStackValue::Type::INT, bit_cast<uint32_t>(v));
|
||||
arg_stack_values.emplace_back(ArgStackValue::Type::INT, as_type<uint32_t>(v));
|
||||
}
|
||||
dasm_arg = string_printf("%g", v);
|
||||
break;
|
||||
@@ -1321,7 +1332,7 @@ std::string disassemble_quest_script(const void* data, size_t size, GameVersion
|
||||
dasm_arg = string_printf("(float)r%" PRIu32, arg_value.as_int);
|
||||
break;
|
||||
case ArgStackValue::Type::INT:
|
||||
dasm_arg = string_printf("%g", bit_cast<float>(arg_value.as_int));
|
||||
dasm_arg = string_printf("%g", as_type<float>(arg_value.as_int));
|
||||
break;
|
||||
default:
|
||||
dasm_arg = "/* invalid-type */";
|
||||
|
||||
Reference in New Issue
Block a user