[decompiler] support for jak 2 (#1781)

* [decompiler] suppport jak 2

* cleanpu

* remove brief from gtest options

* fix test
This commit is contained in:
water111
2022-08-22 18:53:51 -04:00
committed by GitHub
parent 5af36ac610
commit 06ef52cd25
51 changed files with 9934 additions and 4555 deletions
+3 -1
View File
@@ -25,7 +25,7 @@ namespace decompiler {
*/
class LinkedObjectFile {
public:
LinkedObjectFile() = default;
LinkedObjectFile(GameVersion version) : version(version){};
void set_segment_count(int n_segs);
void push_back_word_to_segment(uint32_t word, int segment);
int get_label_id_for(int seg, int offset);
@@ -137,6 +137,8 @@ class LinkedObjectFile {
std::unique_ptr<LabelDB> label_db;
GameVersion version;
private:
goos::Object to_form_script(int seg, int word_idx, std::vector<bool>& seen);
goos::Object to_form_script_object(int seg, int byte_idx, std::vector<bool>& seen);
@@ -816,7 +816,7 @@ LinkedObjectFile to_linked_object_file(const std::vector<uint8_t>& data,
const std::string& name,
DecompilerTypeSystem& dts,
GameVersion game_version) {
LinkedObjectFile result;
LinkedObjectFile result(game_version);
const auto* header = (const LinkHeaderCommon*)&data.at(0);
// use appropriate linker
+1 -1
View File
@@ -359,7 +359,7 @@ void ObjectFileDB::add_obj_from_dgo(const std::string& obj_name,
}
// nope, have to add a new one.
ObjectFileData data;
ObjectFileData data(config.game_version);
data.data.resize(obj_size);
memcpy(data.data.data(), obj_data, obj_size);
data.record.hash = hash;
+1
View File
@@ -37,6 +37,7 @@ struct ObjectFileRecord {
* All of the data for a single object file
*/
struct ObjectFileData {
ObjectFileData(GameVersion version) : linked_data(version) {}
std::vector<uint8_t> data; // raw bytes
LinkedObjectFile linked_data; // data including linking annotations
ObjectFileRecord record; // name
+26 -4
View File
@@ -29,6 +29,7 @@
#include "decompiler/analysis/symbol_def_map.h"
#include "decompiler/analysis/type_analysis.h"
#include "decompiler/analysis/variable_naming.h"
#include "decompiler/types2/types2.h"
namespace decompiler {
@@ -538,14 +539,33 @@ void ObjectFileDB::ir2_type_analysis_pass(int seg, const Config& config, ObjectF
func.ir2.env.set_art_group(obj_name + "-ag");
}
if (run_type_analysis_ir2(ts, dts, func)) {
func.ir2.env.types_succeeded = true;
constexpr bool kForceNewTypes = false;
if (config.game_version == GameVersion::Jak2 || kForceNewTypes) {
// use new types for jak 2 always
types2::Input in;
types2::Output out;
in.func = &func;
in.function_type = ts;
in.dts = &dts;
try {
types2::run(out, in);
func.ir2.env.set_types(out.block_init_types, out.op_end_types, *func.ir2.atomic_ops,
ts);
} catch (const std::exception& e) {
func.warnings.warning("Type analysis failed: {}", e.what());
}
func.ir2.env.types_succeeded = out.succeeded;
} else {
func.warnings.error("Type Propagation failed: Type analysis failed");
// old type pass
if (run_type_analysis_ir2(ts, dts, func)) {
func.ir2.env.types_succeeded = true;
} else {
func.warnings.warning("Type analysis failed");
}
}
} else {
lg::warn("Function {} didn't know its type", func.name());
func.warnings.error("Function {} has unknown type", func.name());
func.warnings.warning("Function {} has unknown type", func.name());
}
}
});
@@ -872,9 +892,11 @@ std::string ObjectFileDB::ir2_function_to_string(ObjectFileData& data, Function&
result += ";; Warnings:\n" + func.warnings.get_warning_text(true) + "\n";
}
/*
if (func.ir2.env.has_local_vars()) {
result += func.ir2.env.print_local_var_types(func.ir2.top_form);
}
*/
bool print_atomics = func.ir2.atomic_ops_succeeded;
// print each instruction in the function.