mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 14:54:53 -04:00
update readme and fix always playing str (#1139)
* update readme deps * replace assert * bump timeout * fix memory corruption in kernel * use unknown if level name is invalid
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include "decompiler/IR2/Form.h"
|
||||
#include "decompiler/analysis/final_output.h"
|
||||
#include "decompiler/util/sparticle_decompile.h"
|
||||
#include "common/util/assert.h"
|
||||
#include "common/util/Assert.h"
|
||||
|
||||
namespace decompiler {
|
||||
|
||||
@@ -208,7 +208,7 @@ goos::Object decompile_string_at_label(const DecompilerLabel& label,
|
||||
throw std::runtime_error(fmt::format("Cannot get string at label {}, alignment of label is {}",
|
||||
label.name, label.offset));
|
||||
}
|
||||
assert(label.offset >= 4);
|
||||
ASSERT(label.offset >= 4);
|
||||
|
||||
const auto& type_ptr = words.at(label.target_segment).at((label.offset - 4) / 4);
|
||||
if (type_ptr.kind() != LinkedWord::TYPE_PTR) {
|
||||
@@ -248,7 +248,7 @@ goos::Object decompile_string_at_label(const DecompilerLabel& label,
|
||||
char cword[4];
|
||||
memcpy(cword, &word.data, 4);
|
||||
result += cword[byte_offset];
|
||||
assert(result.back() != 0);
|
||||
ASSERT(result.back() != 0);
|
||||
}
|
||||
return goos::StringObject::make_new(result);
|
||||
}
|
||||
@@ -274,7 +274,7 @@ goos::Object decompile_value_array(const TypeSpec& elt_type,
|
||||
}
|
||||
elt_bytes.push_back(word.get_byte(j % 4));
|
||||
}
|
||||
assert(elt_type != TypeSpec("uint128"));
|
||||
ASSERT(elt_type != TypeSpec("uint128"));
|
||||
array_def.push_back(decompile_value(elt_type, elt_bytes, ts));
|
||||
}
|
||||
|
||||
@@ -336,14 +336,14 @@ goos::Object decomp_ref_to_integer_array_guess_size(
|
||||
|
||||
// verify types
|
||||
auto elt_type_info = ts.lookup_type(array_elt_type);
|
||||
assert(stride == elt_type_info->get_size_in_memory());
|
||||
assert(!elt_type_info->is_reference());
|
||||
ASSERT(stride == elt_type_info->get_size_in_memory());
|
||||
ASSERT(!elt_type_info->is_reference());
|
||||
|
||||
// the input is the location of the data field.
|
||||
// we expect that to be a label:
|
||||
assert((field_location % 4) == 0);
|
||||
ASSERT((field_location % 4) == 0);
|
||||
auto pointer_to_data = words.at(field_location / 4);
|
||||
assert(pointer_to_data.kind() == LinkedWord::PTR);
|
||||
ASSERT(pointer_to_data.kind() == LinkedWord::PTR);
|
||||
|
||||
// the data shouldn't have any labels in the middle of it, so we can find the end of the array
|
||||
// by searching for the label after the start label.
|
||||
@@ -383,12 +383,12 @@ goos::Object decomp_ref_to_integer_array_guess_size(
|
||||
auto& word = all_words.at(my_seg).at(pad_byte_idx / 4);
|
||||
switch (word.kind()) {
|
||||
case LinkedWord::PLAIN_DATA:
|
||||
assert(word.get_byte(pad_byte_idx) == 0);
|
||||
ASSERT(word.get_byte(pad_byte_idx) == 0);
|
||||
break;
|
||||
case LinkedWord::TYPE_PTR:
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,13 +415,13 @@ goos::Object decomp_ref_to_inline_array_guess_size(
|
||||
auto elt_type_info = ts.lookup_type(array_elt_type);
|
||||
int ye = align(elt_type_info->get_size_in_memory(),
|
||||
elt_type_info->get_inline_array_stride_alignment());
|
||||
assert(stride == ye);
|
||||
ASSERT(stride == ye);
|
||||
|
||||
// the input is the location of the data field.
|
||||
// we expect that to be a label:
|
||||
assert((field_location % 4) == 0);
|
||||
ASSERT((field_location % 4) == 0);
|
||||
auto pointer_to_data = words.at(field_location / 4);
|
||||
assert(pointer_to_data.kind() == LinkedWord::PTR);
|
||||
ASSERT(pointer_to_data.kind() == LinkedWord::PTR);
|
||||
|
||||
// the data shouldn't have any labels in the middle of it, so we can find the end of the array
|
||||
// by searching for the label after the start label.
|
||||
@@ -461,12 +461,12 @@ goos::Object decomp_ref_to_inline_array_guess_size(
|
||||
auto& word = all_words.at(my_seg).at(pad_byte_idx / 4);
|
||||
switch (word.kind()) {
|
||||
case LinkedWord::PLAIN_DATA:
|
||||
assert(word.get_byte(pad_byte_idx) == 0);
|
||||
ASSERT(word.get_byte(pad_byte_idx) == 0);
|
||||
break;
|
||||
case LinkedWord::TYPE_PTR:
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +694,7 @@ goos::Object decompile_structure(const TypeSpec& type,
|
||||
continue;
|
||||
}
|
||||
if (is_basic && idx == 0) {
|
||||
assert(field.name() == "type" && field.offset() == 0);
|
||||
ASSERT(field.name() == "type" && field.offset() == 0);
|
||||
auto& word = obj_words.at(0);
|
||||
if (word.kind() != LinkedWord::TYPE_PTR) {
|
||||
throw std::runtime_error("Basic does not start with type pointer");
|
||||
@@ -702,7 +702,7 @@ goos::Object decompile_structure(const TypeSpec& type,
|
||||
|
||||
if (word.symbol_name() != actual_type.base_type()) {
|
||||
// the check above should have caught this.
|
||||
assert(false);
|
||||
ASSERT(false);
|
||||
}
|
||||
for (int k = 0; k < 4; k++) {
|
||||
field_status_per_byte.at(k) = HAS_DATA_READ;
|
||||
@@ -759,12 +759,12 @@ goos::Object decompile_structure(const TypeSpec& type,
|
||||
auto field_type_info = ts.lookup_type(field.type());
|
||||
if (!field_type_info->is_reference()) {
|
||||
// value type. need to get bytes.
|
||||
assert(!field.is_inline());
|
||||
ASSERT(!field.is_inline());
|
||||
if (field.is_array()) {
|
||||
// array of values.
|
||||
auto len = field.array_size();
|
||||
auto stride = ts.get_size_in_type(field) / len;
|
||||
assert(stride == field_type_info->get_size_in_memory());
|
||||
ASSERT(stride == field_type_info->get_size_in_memory());
|
||||
|
||||
field_defs_out.emplace_back(
|
||||
field.name(), decompile_value_array(field.type(), field_type_info, len, stride,
|
||||
@@ -850,8 +850,8 @@ goos::Object decompile_structure(const TypeSpec& type,
|
||||
auto len = field.array_size();
|
||||
auto total_size = ts.get_size_in_type(field);
|
||||
auto stride = total_size / len;
|
||||
assert(stride * len == total_size);
|
||||
assert(stride == align(field_type_info->get_size_in_memory(),
|
||||
ASSERT(stride * len == total_size);
|
||||
ASSERT(stride == align(field_type_info->get_size_in_memory(),
|
||||
field_type_info->get_inline_array_stride_alignment()));
|
||||
|
||||
std::vector<goos::Object> array_def = {pretty_print::to_symbol(fmt::format(
|
||||
@@ -872,8 +872,8 @@ goos::Object decompile_structure(const TypeSpec& type,
|
||||
auto len = field.array_size();
|
||||
auto total_size = ts.get_size_in_type(field);
|
||||
auto stride = total_size / len;
|
||||
assert(stride * len == total_size);
|
||||
assert(stride == 4);
|
||||
ASSERT(stride * len == total_size);
|
||||
ASSERT(stride == 4);
|
||||
|
||||
std::vector<goos::Object> array_def = {pretty_print::to_symbol(
|
||||
fmt::format("new 'static 'array {} {}", field.type().print(), field.array_size()))};
|
||||
@@ -920,7 +920,7 @@ goos::Object decompile_structure(const TypeSpec& type,
|
||||
field.name(), actual_type.print()));
|
||||
} else {
|
||||
// then we expect a label.
|
||||
assert(field_end - field_start == 4);
|
||||
ASSERT(field_end - field_start == 4);
|
||||
auto& word = obj_words.at(field_start / 4);
|
||||
|
||||
if (word.kind() == LinkedWord::PTR) {
|
||||
@@ -1020,8 +1020,8 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
const TypeSystem& ts) {
|
||||
auto as_enum = ts.try_enum_lookup(type);
|
||||
if (as_enum) {
|
||||
assert((int)bytes.size() == as_enum->get_load_size());
|
||||
assert(bytes.size() <= 8);
|
||||
ASSERT((int)bytes.size() == as_enum->get_load_size());
|
||||
ASSERT(bytes.size() <= 8);
|
||||
u64 value = 0;
|
||||
memcpy(&value, bytes.data(), bytes.size());
|
||||
if (as_enum->is_bitfield()) {
|
||||
@@ -1040,7 +1040,7 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
auto as_bitfield = dynamic_cast<BitFieldType*>(ts.lookup_type(type));
|
||||
if (as_bitfield) {
|
||||
if (as_bitfield->get_name() == "sound-name") {
|
||||
assert(bytes.size() == 16);
|
||||
ASSERT(bytes.size() == 16);
|
||||
char name[17];
|
||||
memcpy(name, bytes.data(), 16);
|
||||
name[16] = '\0';
|
||||
@@ -1051,14 +1051,14 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
got_zero = true;
|
||||
} else {
|
||||
if (got_zero) {
|
||||
assert(false);
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pretty_print::to_symbol(fmt::format("(static-sound-name \"{}\")", name));
|
||||
} else {
|
||||
assert((int)bytes.size() == as_bitfield->get_load_size());
|
||||
assert(bytes.size() <= 8);
|
||||
ASSERT((int)bytes.size() == as_bitfield->get_load_size());
|
||||
ASSERT(bytes.size() <= 8);
|
||||
u64 value = 0;
|
||||
memcpy(&value, bytes.data(), bytes.size());
|
||||
auto defs = decompile_bitfield_from_int(type, ts, value);
|
||||
@@ -1068,12 +1068,12 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
|
||||
// try as common integer types:
|
||||
if (ts.tc(TypeSpec("uint32"), type)) {
|
||||
assert(bytes.size() == 4);
|
||||
ASSERT(bytes.size() == 4);
|
||||
u32 value;
|
||||
memcpy(&value, bytes.data(), 4);
|
||||
return pretty_print::to_symbol(fmt::format("#x{:x}", u64(value)));
|
||||
} else if (ts.tc(TypeSpec("int32"), type)) {
|
||||
assert(bytes.size() == 4);
|
||||
ASSERT(bytes.size() == 4);
|
||||
s32 value;
|
||||
memcpy(&value, bytes.data(), 4);
|
||||
if (value > 100) {
|
||||
@@ -1082,12 +1082,12 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
return pretty_print::to_symbol(fmt::format("{}", value));
|
||||
}
|
||||
} else if (ts.tc(TypeSpec("uint16"), type)) {
|
||||
assert(bytes.size() == 2);
|
||||
ASSERT(bytes.size() == 2);
|
||||
u16 value;
|
||||
memcpy(&value, bytes.data(), 2);
|
||||
return pretty_print::to_symbol(fmt::format("#x{:x}", u64(value)));
|
||||
} else if (ts.tc(TypeSpec("int16"), type)) {
|
||||
assert(bytes.size() == 2);
|
||||
ASSERT(bytes.size() == 2);
|
||||
s16 value;
|
||||
memcpy(&value, bytes.data(), 2);
|
||||
if (value > 100) {
|
||||
@@ -1096,7 +1096,7 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
return pretty_print::to_symbol(fmt::format("{}", value));
|
||||
}
|
||||
} else if (ts.tc(TypeSpec("int8"), type)) {
|
||||
assert(bytes.size() == 1);
|
||||
ASSERT(bytes.size() == 1);
|
||||
s8 value;
|
||||
memcpy(&value, bytes.data(), 1);
|
||||
if (value > 5) {
|
||||
@@ -1105,7 +1105,7 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
return pretty_print::to_symbol(fmt::format("{}", value));
|
||||
}
|
||||
} else if (type == TypeSpec("seconds")) {
|
||||
assert(bytes.size() == 8);
|
||||
ASSERT(bytes.size() == 8);
|
||||
s64 value;
|
||||
memcpy(&value, bytes.data(), 8);
|
||||
|
||||
@@ -1120,12 +1120,12 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
}
|
||||
return pretty_print::to_symbol(fmt::format("#x{:x}", value));
|
||||
} else if (ts.tc(TypeSpec("uint64"), type)) {
|
||||
assert(bytes.size() == 8);
|
||||
ASSERT(bytes.size() == 8);
|
||||
u64 value;
|
||||
memcpy(&value, bytes.data(), 8);
|
||||
return pretty_print::to_symbol(fmt::format("#x{:x}", value));
|
||||
} else if (ts.tc(TypeSpec("int64"), type)) {
|
||||
assert(bytes.size() == 8);
|
||||
ASSERT(bytes.size() == 8);
|
||||
s64 value;
|
||||
memcpy(&value, bytes.data(), 8);
|
||||
if (value > 100) {
|
||||
@@ -1134,7 +1134,7 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
return pretty_print::to_symbol(fmt::format("{}", value));
|
||||
}
|
||||
} else if (type == TypeSpec("meters")) {
|
||||
assert(bytes.size() == 4);
|
||||
ASSERT(bytes.size() == 4);
|
||||
float value;
|
||||
memcpy(&value, bytes.data(), 4);
|
||||
double meters = (double)value / METER_LENGTH;
|
||||
@@ -1146,18 +1146,18 @@ goos::Object decompile_value(const TypeSpec& type,
|
||||
return pretty_print::build_list("meters", rep);
|
||||
}
|
||||
} else if (type == TypeSpec("degrees")) {
|
||||
assert(bytes.size() == 4);
|
||||
ASSERT(bytes.size() == 4);
|
||||
float value;
|
||||
memcpy(&value, bytes.data(), 4);
|
||||
double degrees = (double)value / DEGREES_LENGTH;
|
||||
return pretty_print::build_list("degrees", pretty_print::float_representation(degrees));
|
||||
} else if (ts.tc(TypeSpec("float"), type)) {
|
||||
assert(bytes.size() == 4);
|
||||
ASSERT(bytes.size() == 4);
|
||||
float value;
|
||||
memcpy(&value, bytes.data(), 4);
|
||||
return pretty_print::float_representation(value);
|
||||
} else if (ts.tc(TypeSpec("uint8"), type)) {
|
||||
assert(bytes.size() == 1);
|
||||
ASSERT(bytes.size() == 1);
|
||||
u8 value;
|
||||
memcpy(&value, bytes.data(), 1);
|
||||
return pretty_print::to_symbol(fmt::format("#x{:x}", value));
|
||||
@@ -1287,7 +1287,7 @@ goos::Object decompile_boxed_array(const DecompilerLabel& label,
|
||||
}
|
||||
elt_bytes.push_back(word.get_byte(j % 4));
|
||||
}
|
||||
assert(content_type != TypeSpec("uint128"));
|
||||
ASSERT(content_type != TypeSpec("uint128"));
|
||||
result.push_back(decompile_value(content_type, elt_bytes, ts));
|
||||
}
|
||||
return pretty_print::build_list(result);
|
||||
@@ -1441,7 +1441,7 @@ goos::Object decompile_bitfield(const TypeSpec& type,
|
||||
while (elt_bytes.size() < 8) {
|
||||
elt_bytes.push_back(0);
|
||||
}
|
||||
assert(elt_bytes.size() == 8);
|
||||
ASSERT(elt_bytes.size() == 8);
|
||||
|
||||
// read as u64
|
||||
u64 value = *(u64*)(elt_bytes.data());
|
||||
@@ -1459,7 +1459,7 @@ std::optional<std::vector<BitFieldConstantDef>> try_decompile_bitfield_from_int(
|
||||
std::vector<BitFieldConstantDef> result;
|
||||
|
||||
auto type_info = dynamic_cast<BitFieldType*>(ts.lookup_type(type));
|
||||
assert(type_info);
|
||||
ASSERT(type_info);
|
||||
|
||||
int start_bit = 0;
|
||||
|
||||
@@ -1539,8 +1539,8 @@ std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
|
||||
u64 reconstructed = 0;
|
||||
std::vector<std::string> result;
|
||||
auto type_info = ts.try_enum_lookup(type.base_type());
|
||||
assert(type_info);
|
||||
assert(type_info->is_bitfield());
|
||||
ASSERT(type_info);
|
||||
ASSERT(type_info->is_bitfield());
|
||||
|
||||
std::vector<std::string> bit_sorted_names;
|
||||
for (auto& field : type_info->entries()) {
|
||||
@@ -1594,8 +1594,8 @@ std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
|
||||
|
||||
std::string decompile_int_enum_from_int(const TypeSpec& type, const TypeSystem& ts, u64 value) {
|
||||
auto type_info = ts.try_enum_lookup(type.base_type());
|
||||
assert(type_info);
|
||||
assert(!type_info->is_bitfield());
|
||||
ASSERT(type_info);
|
||||
ASSERT(!type_info->is_bitfield());
|
||||
|
||||
std::vector<std::string> matches;
|
||||
for (auto& field : type_info->entries()) {
|
||||
|
||||
Reference in New Issue
Block a user