mirror of
https://github.com/open-goal/jak-project
synced 2026-05-23 06:54:31 -04:00
decompiler: some hacks to allow running decompiler on jak 3 v5 code files, improve all-types generation (#2526)
Co-authored-by: water <awaterford111445@gmail.com>
This commit is contained in:
@@ -321,7 +321,7 @@ void ObjectFileDB::ir2_analyze_all_types(const fs::path& output_file,
|
||||
const std::unordered_set<std::string>& bad_types) {
|
||||
std::vector<PerObjectAllTypeInfo> per_object;
|
||||
|
||||
DecompilerTypeSystem previous_game_ts(GameVersion::Jak1); // version here doesn't matter.
|
||||
DecompilerTypeSystem previous_game_ts(GameVersion::Jak2); // version here doesn't matter.
|
||||
if (previous_game_types) {
|
||||
previous_game_ts.parse_type_defs({*previous_game_types});
|
||||
}
|
||||
@@ -329,44 +329,43 @@ void ObjectFileDB::ir2_analyze_all_types(const fs::path& output_file,
|
||||
TypeInspectorCache ti_cache;
|
||||
|
||||
for_each_obj([&](ObjectFileData& data) {
|
||||
if (data.obj_version != 3) {
|
||||
return;
|
||||
}
|
||||
if (data.obj_version == 3 || (data.obj_version == 5 && data.linked_data.has_any_functions())) {
|
||||
auto& object_result = per_object.emplace_back();
|
||||
object_result.object_name = data.to_unique_name();
|
||||
|
||||
auto& object_result = per_object.emplace_back();
|
||||
object_result.object_name = data.to_unique_name();
|
||||
// Go through the top-level segment first to identify the type names associated with each
|
||||
// symbol def
|
||||
for_each_function_in_seg_in_obj(TOP_LEVEL_SEGMENT, data, [&](Function& f) {
|
||||
inspect_top_level_for_metadata(f, data.linked_data, dts, previous_game_ts, object_result);
|
||||
});
|
||||
|
||||
// Go through the top-level segment first to identify the type names associated with each symbol
|
||||
// def
|
||||
for_each_function_in_seg_in_obj(TOP_LEVEL_SEGMENT, data, [&](Function& f) {
|
||||
inspect_top_level_for_metadata(f, data.linked_data, dts, previous_game_ts, object_result);
|
||||
});
|
||||
|
||||
// Handle the top level last, which is fine as all symbol_defs are always written after typedefs
|
||||
for_each_function_def_order_in_obj(data, [&](Function& f, int seg) {
|
||||
if (seg != TOP_LEVEL_SEGMENT) {
|
||||
if (f.is_inspect_method && bad_types.find(f.guessed_name.type_name) == bad_types.end()) {
|
||||
auto deftype_from_inspect =
|
||||
inspect_inspect_method(f, f.guessed_name.type_name, dts, data.linked_data,
|
||||
previous_game_ts, ti_cache, object_result);
|
||||
bool already_seen = object_result.type_info.count(f.guessed_name.type_name) > 0;
|
||||
if (!already_seen) {
|
||||
object_result.type_names_in_order.push_back(f.guessed_name.type_name);
|
||||
// Handle the top level last, which is fine as all symbol_defs are always written after
|
||||
// typedefs
|
||||
for_each_function_def_order_in_obj(data, [&](Function& f, int seg) {
|
||||
if (seg != TOP_LEVEL_SEGMENT) {
|
||||
if (f.is_inspect_method && bad_types.find(f.guessed_name.type_name) == bad_types.end()) {
|
||||
auto deftype_from_inspect =
|
||||
inspect_inspect_method(f, f.guessed_name.type_name, dts, data.linked_data,
|
||||
previous_game_ts, ti_cache, object_result);
|
||||
bool already_seen = object_result.type_info.count(f.guessed_name.type_name) > 0;
|
||||
if (!already_seen) {
|
||||
object_result.type_names_in_order.push_back(f.guessed_name.type_name);
|
||||
}
|
||||
auto& info = object_result.type_info[f.guessed_name.type_name];
|
||||
info.from_inspect_method = true;
|
||||
info.type_definition = deftype_from_inspect;
|
||||
} else {
|
||||
// no inspect methods
|
||||
// - can we solve custom print methods in a generic way? ie `entity-links`
|
||||
}
|
||||
auto& info = object_result.type_info[f.guessed_name.type_name];
|
||||
info.from_inspect_method = true;
|
||||
info.type_definition = deftype_from_inspect;
|
||||
} else {
|
||||
// no inspect methods
|
||||
// - can we solve custom print methods in a generic way? ie `entity-links`
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
for_each_function_in_seg_in_obj(TOP_LEVEL_SEGMENT, data, [&](Function& f) {
|
||||
object_result.symbol_defs += inspect_top_level_symbol_defines(
|
||||
f, data.linked_data, dts, previous_game_ts, object_result);
|
||||
});
|
||||
for_each_function_in_seg_in_obj(TOP_LEVEL_SEGMENT, data, [&](Function& f) {
|
||||
object_result.symbol_defs += inspect_top_level_symbol_defines(
|
||||
f, data.linked_data, dts, previous_game_ts, object_result);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
std::string result;
|
||||
@@ -1180,7 +1179,7 @@ bool ObjectFileDB::lookup_function_type(const FunctionName& name,
|
||||
std::string ObjectFileDB::ir2_final_out(ObjectFileData& data,
|
||||
const std::vector<std::string>& imports,
|
||||
const std::unordered_set<std::string>& skip_functions) {
|
||||
if (data.obj_version == 3) {
|
||||
if (data.obj_version == 3 || (data.obj_version == 5 && data.linked_data.has_any_functions())) {
|
||||
std::string result;
|
||||
result += ";;-*-Lisp-*-\n";
|
||||
result += "(in-package goal)\n\n";
|
||||
|
||||
Reference in New Issue
Block a user