diff --git a/.gitignore b/.gitignore index e542be2281..996672906e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # for clion cmake-build-debug/* .idea/* -build/* \ No newline at end of file +build/* +decompiler_out/* \ No newline at end of file diff --git a/.vs/launch.vs.json b/.vs/launch.vs.json index deec64e337..a4cfea3d40 100644 --- a/.vs/launch.vs.json +++ b/.vs/launch.vs.json @@ -1,57 +1,44 @@ { - "version": "0.2.1", - "defaults": {}, - "configurations": [ + "version" : "0.2.1", "defaults" : {}, "configurations" : [ { - "type": "default", - "project": "CMakeLists.txt", - "projectTarget": "goalc-test.exe (bin\\goalc-test.exe)", - "name": "Run Tests - Summary", - "args": [ - "--gtest_brief=1" - ] + "type" : "default", + "project" : "CMakeLists.txt", + "projectTarget" : "goalc-test.exe (bin\\goalc-test.exe)", + "name" : "Run Tests - Summary", + "args" : ["--gtest_brief=1"] }, { - "type": "default", - "project": "CMakeLists.txt", - "projectTarget": "goalc-test.exe (bin\\goalc-test.exe)", - "name": "Run Tests - Verbose", - "args": [ - "--gtest_brief=0" - ] + "type" : "default", + "project" : "CMakeLists.txt", + "projectTarget" : "goalc-test.exe (bin\\goalc-test.exe)", + "name" : "Run Tests - Verbose", + "args" : ["--gtest_brief=0"] }, { - "type": "default", - "project": "CMakeLists.txt", - "projectTarget": "gk.exe (bin\\gk.exe)", - "name": "Run Runtime (no kernel)", - "args": [ - "-fakeiso", - "-debug", - "-nokernel" - ] + "type" : "default", + "project" : "CMakeLists.txt", + "projectTarget" : "gk.exe (bin\\gk.exe)", + "name" : "Run Runtime (no kernel)", + "args" : [ "-fakeiso", "-debug", "-nokernel" ] }, { - "type": "default", - "project": "CMakeLists.txt", - "projectTarget": "gk.exe (bin\\gk.exe)", - "name": "Run Runtime (with kernel)", - "args": [ - "-fakeiso", - "-debug" - ] + "type" : "default", + "project" : "CMakeLists.txt", + "projectTarget" : "gk.exe (bin\\gk.exe)", + "name" : "Run Runtime (with kernel)", + "args" : [ "-fakeiso", "-debug" ] }, { - "type": "default", - "project": "CMakeLists.txt", - "projectTarget": "goalc.exe (bin\\goalc.exe)", - "name": "Build Compiler" + "type" : "default", + "project" : "CMakeLists.txt", + "projectTarget" : "goalc.exe (bin\\goalc.exe)", + "name" : "Build Compiler" }, { - "type": "default", - "project": "CMakeLists.txt", - "projectTarget": "decompiler.exe (bin\\decompiler.exe)", - "name": "Build Decompiler" + "type" : "default", + "project" : "CMakeLists.txt", + "projectTarget" : "decompiler.exe (bin\\decompiler.exe)", + "name" : "Build Decompiler" } ] -} \ No newline at end of file +} diff --git a/CMakeSettings.json b/CMakeSettings.json index fcd25ae01f..0340e270f2 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -4,7 +4,7 @@ "name": "Debug", "generator": "Ninja", "configurationType": "Debug", - "inheritEnvironments": ["msvc_x64_x64"], + "inheritEnvironments": [ "msvc_x64_x64" ], "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", "cmakeCommandArgs": "", @@ -19,4 +19,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index f10c05f070..f7b1642526 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -107,4 +107,4 @@ std::string file_util::read_text_file(const std::string& path) { bool file_util::is_printable_char(char c) { return c >= ' ' && c <= '~'; -} \ No newline at end of file +} diff --git a/decompiler/CMakeLists.txt b/decompiler/CMakeLists.txt index 211efaaa62..ef18e73cb8 100644 --- a/decompiler/CMakeLists.txt +++ b/decompiler/CMakeLists.txt @@ -23,4 +23,5 @@ target_link_libraries(decompiler minilzo common_util type_system + spdlog fmt) \ No newline at end of file diff --git a/decompiler/Disasm/InstructionDecode.cpp b/decompiler/Disasm/InstructionDecode.cpp index 6fb1b6571c..ba2c83da91 100644 --- a/decompiler/Disasm/InstructionDecode.cpp +++ b/decompiler/Disasm/InstructionDecode.cpp @@ -1170,4 +1170,4 @@ Instruction decode_instruction(LinkedWord& word, LinkedObjectFile& file, int seg } return i; -} \ No newline at end of file +} diff --git a/decompiler/Disasm/InstructionMatching.cpp b/decompiler/Disasm/InstructionMatching.cpp index 05d5c437a1..a05c26f92c 100644 --- a/decompiler/Disasm/InstructionMatching.cpp +++ b/decompiler/Disasm/InstructionMatching.cpp @@ -347,4 +347,4 @@ bool is_always_branch(const Instruction& instr) { } return false; -} \ No newline at end of file +} diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index 70c6210b78..1d4735dd90 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -20,6 +20,7 @@ #include "decompiler/Function/BasicBlocks.h" #include "decompiler/IR/BasicOpBuilder.h" #include "decompiler/IR/CfgBuilder.h" +#include "third-party/spdlog/include/spdlog/spdlog.h" /*! * Get a unique name for this object file. @@ -66,24 +67,24 @@ ObjectFileData& ObjectFileDB::lookup_record(ObjectFileRecord rec) { */ ObjectFileDB::ObjectFileDB(const std::vector& _dgos) { Timer timer; - printf("- Loading Types...\n"); + + spdlog::info("-Loading types..."); dts.parse_type_defs({"decompiler", "config", "all-types.gc"}); - printf("- Initializing ObjectFileDB...\n"); + spdlog::info("-Initializing ObjectFileDB..."); for (auto& dgo : _dgos) { get_objs_from_dgo(dgo); } - printf("ObjectFileDB Initialized:\n"); - printf(" total dgos: %d\n", int(_dgos.size())); - printf(" total data: %d bytes\n", stats.total_dgo_bytes); - printf(" total objs: %d\n", stats.total_obj_files); - printf(" unique objs: %d\n", stats.unique_obj_files); - printf(" unique data: %d bytes\n", stats.unique_obj_bytes); - printf(" total %.1f ms (%.3f MB/sec, %.3f obj/sec)\n", timer.getMs(), - stats.total_dgo_bytes / ((1u << 20u) * timer.getSeconds()), - stats.total_obj_files / timer.getSeconds()); - printf("\n"); + spdlog::info("ObjectFileDB Initialized:"); + spdlog::info("Total DGOs: {}", int(_dgos.size())); + spdlog::info("Total data: {} bytes", stats.total_dgo_bytes); + spdlog::info("Total objs: {}", stats.total_obj_files); + spdlog::info("Unique objs: {}", stats.unique_obj_files); + spdlog::info("Unique data: {} bytes", stats.unique_obj_bytes); + spdlog::info("Total {} ms ({:3f} MB/sec, {} obj/sec", timer.getMs(), + stats.total_dgo_bytes / ((1u << 20u) * timer.getSeconds()), + stats.total_obj_files / timer.getSeconds()); } // Header for a DGO file @@ -354,7 +355,7 @@ std::string ObjectFileDB::generate_obj_listing() { * Process all of the linking data of all objects. */ void ObjectFileDB::process_link_data() { - printf("- Processing Link Data...\n"); + spdlog::info("- Processing Link Data..."); Timer process_link_timer; LinkedObjectFile::Stats combined_stats; @@ -364,42 +365,42 @@ void ObjectFileDB::process_link_data() { combined_stats.add(obj.linked_data.stats); }); - printf("Processed Link Data:\n"); - printf(" code %d bytes\n", combined_stats.total_code_bytes); - printf(" v2 code %d bytes\n", combined_stats.total_v2_code_bytes); - printf(" v2 link data %d bytes\n", combined_stats.total_v2_link_bytes); - printf(" v2 pointers %d\n", combined_stats.total_v2_pointers); - printf(" v2 pointer seeks %d\n", combined_stats.total_v2_pointer_seeks); - printf(" v2 symbols %d\n", combined_stats.total_v2_symbol_count); - printf(" v2 symbol links %d\n", combined_stats.total_v2_symbol_links); + spdlog::info("Processed Link Data:"); + spdlog::info(" Code {} bytes", combined_stats.total_code_bytes); + spdlog::info(" v2 Code {} bytes", combined_stats.total_v2_code_bytes); + spdlog::info(" v2 Link Data {} bytes", combined_stats.total_v2_link_bytes); + spdlog::info(" v2 Pointers {}", combined_stats.total_v2_pointers); + spdlog::info(" v2 Pointer Seeks {}", combined_stats.total_v2_pointer_seeks); + spdlog::info(" v2 Symbols {}", combined_stats.total_v2_symbol_count); + spdlog::info(" v2 Symbol Links {}", combined_stats.total_v2_symbol_links); - printf(" v3 code %d bytes\n", combined_stats.v3_code_bytes); - printf(" v3 link data %d bytes\n", combined_stats.v3_link_bytes); - printf(" v3 pointers %d\n", combined_stats.v3_pointers); - printf(" split %d\n", combined_stats.v3_split_pointers); - printf(" word %d\n", combined_stats.v3_word_pointers); - printf(" v3 pointer seeks %d\n", combined_stats.v3_pointer_seeks); - printf(" v3 symbols %d\n", combined_stats.v3_symbol_count); - printf(" v3 offset symbol links %d\n", combined_stats.v3_symbol_link_offset); - printf(" v3 word symbol links %d\n", combined_stats.v3_symbol_link_word); + spdlog::info(" v3 Code {} bytes", combined_stats.v3_code_bytes); + spdlog::info(" v3 Link Data {} bytes", combined_stats.v3_link_bytes); + spdlog::info(" v3 Pointers {}", combined_stats.v3_pointers); + spdlog::info(" Split {}", combined_stats.v3_split_pointers); + spdlog::info(" Word {}", combined_stats.v3_word_pointers); + spdlog::info(" v3 Pointer Seeks {}", combined_stats.v3_pointer_seeks); + spdlog::info(" v3 Symbols {}", combined_stats.v3_symbol_count); + spdlog::info(" v3 Offset Symbol Links {}", combined_stats.v3_symbol_link_offset); + spdlog::info(" v3 Word Symbol Links {}", combined_stats.v3_symbol_link_word); - printf(" total %.3f ms\n", process_link_timer.getMs()); - printf("\n"); + spdlog::info(" Total {} ms\n", process_link_timer.getMs()); + // printf("\n"); } /*! * Process all of the labels generated from linking and give them reasonable names. */ void ObjectFileDB::process_labels() { - printf("- Processing Labels...\n"); + spdlog::info("- Processing Labels..."); Timer process_label_timer; uint32_t total = 0; for_each_obj([&](ObjectFileData& obj) { total += obj.linked_data.set_ordered_label_names(); }); - printf("Processed Labels:\n"); - printf(" total %d labels\n", total); - printf(" total %.3f ms\n", process_label_timer.getMs()); - printf("\n"); + spdlog::info("Processed Labels:"); + spdlog::info(" Total {} labels", total); + spdlog::info(" Total {} ms", process_label_timer.getMs()); + // printf("\n"); } /*! @@ -407,9 +408,9 @@ void ObjectFileDB::process_labels() { */ void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool dump_v3_only) { if (dump_v3_only) { - printf("- Writing object file dumps (v3 only)...\n"); + spdlog::info("- Writing object file dumps (v3 only)..."); } else { - printf("- Writing object file dumps (all)...\n"); + spdlog::info("- Writing object file dumps (all)..."); } Timer timer; @@ -425,12 +426,12 @@ void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool d } }); - printf("Wrote object file dumps:\n"); - printf(" total %d files\n", total_files); - printf(" total %.3f MB\n", total_bytes / ((float)(1u << 20u))); - printf(" total %.3f ms (%.3f MB/sec)\n", timer.getMs(), - total_bytes / ((1u << 20u) * timer.getSeconds())); - printf("\n"); + spdlog::info("Wrote object file dumps:"); + spdlog::info(" Total {} files", total_files); + spdlog::info(" Total {:3f} MB", total_bytes / ((float)(1u << 20u))); + spdlog::info(" Total {} ms ({:3f} MB/sec)", timer.getMs(), + total_bytes / ((1u << 20u) * timer.getSeconds())); + // printf("\n"); } /*! @@ -438,7 +439,7 @@ void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool d */ void ObjectFileDB::write_disassembly(const std::string& output_dir, bool disassemble_objects_without_functions) { - printf("- Writing functions...\n"); + spdlog::info("- Writing functions..."); Timer timer; uint32_t total_bytes = 0, total_files = 0; @@ -452,19 +453,19 @@ void ObjectFileDB::write_disassembly(const std::string& output_dir, } }); - printf("Wrote functions dumps:\n"); - printf(" total %d files\n", total_files); - printf(" total %.3f MB\n", total_bytes / ((float)(1u << 20u))); - printf(" total %.3f ms (%.3f MB/sec)\n", timer.getMs(), - total_bytes / ((1u << 20u) * timer.getSeconds())); - printf("\n"); + spdlog::info("Wrote functions dumps:"); + spdlog::info(" Total {} files", total_files); + spdlog::info(" Total {} MB", total_bytes / ((float)(1u << 20u))); + spdlog::info(" Total {} ms ({:3f} MB/sec)", timer.getMs(), + total_bytes / ((1u << 20u) * timer.getSeconds())); + // printf("\n"); } /*! * Find code/data zones, identify functions, and disassemble */ void ObjectFileDB::find_code() { - printf("- Finding code in object files...\n"); + spdlog::info("- Finding code in object files..."); LinkedObjectFile::Stats combined_stats; Timer timer; @@ -477,29 +478,29 @@ void ObjectFileDB::find_code() { if (get_config().game_version == 1 || obj.record.to_unique_name() != "effect-control-v0") { obj.linked_data.process_fp_relative_links(); } else { - printf("skipping process_fp_relative_links in %s\n", obj.record.to_unique_name().c_str()); + spdlog::warn("Skipping process_fp_relative_links in {}", obj.record.to_unique_name().c_str()); } auto& obj_stats = obj.linked_data.stats; if (obj_stats.code_bytes / 4 > obj_stats.decoded_ops) { - printf("Failed to decode all in %s (%d / %d)\n", obj.record.to_unique_name().c_str(), - obj_stats.decoded_ops, obj_stats.code_bytes / 4); + spdlog::warn("Failed to decode all in {} ({} / {})", obj.record.to_unique_name().c_str(), + obj_stats.decoded_ops, obj_stats.code_bytes / 4); } combined_stats.add(obj.linked_data.stats); }); - printf("Found code:\n"); - printf(" code %.3f MB\n", combined_stats.code_bytes / (float)(1 << 20)); - printf(" data %.3f MB\n", combined_stats.data_bytes / (float)(1 << 20)); - printf(" functions: %d\n", combined_stats.function_count); - printf(" fp uses resolved: %d / %d (%.3f %%)\n", combined_stats.n_fp_reg_use_resolved, - combined_stats.n_fp_reg_use, - 100.f * (float)combined_stats.n_fp_reg_use_resolved / combined_stats.n_fp_reg_use); + spdlog::info("Found code:"); + spdlog::info(" Code {} MB", combined_stats.code_bytes / (float)(1 << 20)); + spdlog::info(" Data {} MB", combined_stats.data_bytes / (float)(1 << 20)); + spdlog::info(" Functions: {}", combined_stats.function_count); + spdlog::info(" fp uses resolved: {} / {} ({} %)", combined_stats.n_fp_reg_use_resolved, + combined_stats.n_fp_reg_use, + 100.f * (float)combined_stats.n_fp_reg_use_resolved / combined_stats.n_fp_reg_use); auto total_ops = combined_stats.code_bytes / 4; - printf(" decoded %d / %d (%.3f %%)\n", combined_stats.decoded_ops, total_ops, - 100.f * (float)combined_stats.decoded_ops / total_ops); - printf(" total %.3f ms\n", timer.getMs()); - printf("\n"); + spdlog::info(" Decoded {} / {} ({} %)", combined_stats.decoded_ops, total_ops, + 100.f * (float)combined_stats.decoded_ops / total_ops); + spdlog::info(" Total {} ms", timer.getMs()); + // printf("\n"); } /*! @@ -507,7 +508,7 @@ void ObjectFileDB::find_code() { * Doesn't change any state in ObjectFileDB. */ void ObjectFileDB::find_and_write_scripts(const std::string& output_dir) { - printf("- Finding scripts in object files...\n"); + spdlog::info("- Finding scripts in object files..."); Timer timer; std::string all_scripts; @@ -524,13 +525,12 @@ void ObjectFileDB::find_and_write_scripts(const std::string& output_dir) { auto file_name = combine_path(output_dir, "all_scripts.lisp"); file_util::write_text_file(file_name, all_scripts); - printf("Found scripts:\n"); - printf(" total %.3f ms\n", timer.getMs()); - printf("\n"); + spdlog::info("Found scripts:"); + spdlog::info(" Total {} ms\n", timer.getMs()); } void ObjectFileDB::analyze_functions() { - printf("- Analyzing Functions...\n"); + spdlog::info("- Analyzing Functions..."); Timer timer; int total_functions = 0; @@ -608,13 +608,12 @@ void ObjectFileDB::analyze_functions() { timer.start(); int total_basic_blocks = 0; for_each_function([&](Function& func, int segment_id, ObjectFileData& data) { - // printf("in %s\n", func.guessed_name.to_string().c_str()); + // printf("in %s\n", func.guessed_name.to_string().c_str()); auto blocks = find_blocks_in_function(data.linked_data, segment_id, func); total_basic_blocks += blocks.size(); func.basic_blocks = blocks; total_functions++; - if (!func.suspected_asm) { func.analyze_prologue(data.linked_data); func.cfg = build_cfg(data.linked_data, segment_id, func); @@ -660,25 +659,25 @@ void ObjectFileDB::analyze_functions() { // } }); - printf("Found %d functions (%d with no control flow)\n", total_functions, - total_trivial_cfg_functions); - printf("Named %d/%d functions (%.2f%%)\n", total_named_functions, total_functions, - 100.f * float(total_named_functions) / float(total_functions)); - printf("Excluding %d asm functions\n", asm_funcs); - printf("Found %d basic blocks in %.3f ms\n", total_basic_blocks, timer.getMs()); - printf(" %d/%d functions passed cfg analysis stage (%.2f%%)\n", resolved_cfg_functions, - non_asm_funcs, 100.f * float(resolved_cfg_functions) / float(non_asm_funcs)); + spdlog::info("Found {} functions ({} with no control flow)", total_functions, + total_trivial_cfg_functions); + spdlog::info("Named {}/{} functions ({}%)", total_named_functions, total_functions, + 100.f * float(total_named_functions) / float(total_functions)); + spdlog::info("Excluding {} asm functions", asm_funcs); + spdlog::info("Found {} basic blocks in {} ms", total_basic_blocks, timer.getMs()); + spdlog::info(" {}/{} functions passed cfg analysis stage ({}%)", resolved_cfg_functions, + non_asm_funcs, 100.f * float(resolved_cfg_functions) / float(non_asm_funcs)); int successful_basic_ops = total_basic_ops - total_failed_basic_ops; - printf(" %d/%d basic ops converted successfully (%.2f%%)\n", successful_basic_ops, - total_basic_ops, 100.f * float(successful_basic_ops) / float(total_basic_ops)); - printf(" %d/%d cfgs converted to ir (%.2f%%)\n", successful_cfg_irs, non_asm_funcs, - 100.f * float(successful_cfg_irs) / float(non_asm_funcs)); + spdlog::info(" {}/{} basic ops converted successfully ({}%)", successful_basic_ops, + total_basic_ops, 100.f * float(successful_basic_ops) / float(total_basic_ops)); + spdlog::info(" {}/{} cfgs converted to ir ({}%)\n", successful_cfg_irs, non_asm_funcs, + 100.f * float(successful_cfg_irs) / float(non_asm_funcs)); - for (auto& kv : unresolved_by_length) { - printf("LEN %d\n", kv.first); - for (auto& x : kv.second) { - printf(" %s\n", x.c_str()); - } - } + // for (auto& kv : unresolved_by_length) { + // printf("LEN %d\n", kv.first); + // for (auto& x : kv.second) { + // printf(" %s\n", x.c_str()); + // } + // } } } diff --git a/decompiler/config.cpp b/decompiler/config.cpp index 9f67840882..6d6a57e8ea 100644 --- a/decompiler/config.cpp +++ b/decompiler/config.cpp @@ -2,6 +2,7 @@ #include "third-party/json.hpp" #include "util/FileIO.h" #include "common/util/FileUtil.h" +#include "third-party/spdlog/include/spdlog/spdlog.h" Config gConfig; @@ -30,4 +31,4 @@ void set_config(const std::string& path_to_config_file) { for (const auto& x : asm_functions_by_name) { gConfig.asm_functions_by_name.insert(x); } -} \ No newline at end of file +} diff --git a/decompiler/config/jak1_ntsc_black_label.jsonc b/decompiler/config/jak1_ntsc_black_label.jsonc index 46af6b7cf4..13852f0465 100644 --- a/decompiler/config/jak1_ntsc_black_label.jsonc +++ b/decompiler/config/jak1_ntsc_black_label.jsonc @@ -1,232 +1,232 @@ { - "game_version":1, - // the order here matters. KERNEL and GAME should go first - "dgo_names":["CGO/KERNEL.CGO", "CGO/GAME.CGO"], - /*, "CGO/ENGINE.CGO" - , "CGO/ART.CGO", "DGO/BEA.DGO", "DGO/CIT.DGO", "CGO/COMMON.CGO", "DGO/DAR.DGO", "DGO/DEM.DGO", - "DGO/FIN.DGO", "DGO/INT.DGO", "DGO/JUB.DGO", "DGO/JUN.DGO", "CGO/JUNGLE.CGO", "CGO/L1.CGO", "DGO/FIC.DGO", - "DGO/LAV.DGO", "DGO/MAI.DGO", "CGO/MAINCAVE.CGO", "DGO/MIS.DGO", "DGO/OGR.DGO", "CGO/RACERP.CGO", "DGO/ROB.DGO", "DGO/ROL.DGO", - "DGO/SNO.DGO", "DGO/SUB.DGO", "DGO/SUN.DGO", "CGO/SUNKEN.CGO", "DGO/SWA.DGO", "DGO/TIT.DGO", "DGO/TRA.DGO", "DGO/VI1.DGO", - "DGO/VI2.DGO", "DGO/VI3.DGO", "CGO/VILLAGEP.CGO", "CGO/WATER-AN.CGO" - ],*/ + "game_version":1, + // the order here matters. KERNEL and GAME should go first + "dgo_names":["CGO/KERNEL.CGO", "CGO/GAME.CGO"], + /*, "CGO/ENGINE.CGO" + , "CGO/ART.CGO", "DGO/BEA.DGO", "DGO/CIT.DGO", "CGO/COMMON.CGO", "DGO/DAR.DGO", "DGO/DEM.DGO", + "DGO/FIN.DGO", "DGO/INT.DGO", "DGO/JUB.DGO", "DGO/JUN.DGO", "CGO/JUNGLE.CGO", "CGO/L1.CGO", "DGO/FIC.DGO", + "DGO/LAV.DGO", "DGO/MAI.DGO", "CGO/MAINCAVE.CGO", "DGO/MIS.DGO", "DGO/OGR.DGO", "CGO/RACERP.CGO", "DGO/ROB.DGO", "DGO/ROL.DGO", + "DGO/SNO.DGO", "DGO/SUB.DGO", "DGO/SUN.DGO", "CGO/SUNKEN.CGO", "DGO/SWA.DGO", "DGO/TIT.DGO", "DGO/TRA.DGO", "DGO/VI1.DGO", + "DGO/VI2.DGO", "DGO/VI3.DGO", "CGO/VILLAGEP.CGO", "CGO/WATER-AN.CGO" + ],*/ - "write_disassembly":true, - "write_hex_near_instructions":false, - // if false, skips disassembling object files without functions, as these are usually large and not interesting yet. - "disassemble_objects_without_functions":false, + "write_disassembly":true, + "write_hex_near_instructions":false, + // if false, skips disassembling object files without functions, as these are usually large and not interesting yet. + "disassemble_objects_without_functions":false, - // to write out data of each object file - "write_hexdump":false, - // to write out hexdump on the v3 only, to avoid the huge level data files - "write_hexdump_on_v3_only":true, + // to write out data of each object file + "write_hexdump":false, + // to write out hexdump on the v3 only, to avoid the huge level data files + "write_hexdump_on_v3_only":true, - // to write out "scripts", which are currently just all the linked lists found - "write_scripts":true, + // to write out "scripts", which are currently just all the linked lists found + "write_scripts":true, - // Experimental Stuff - "find_basic_blocks":true, + // Experimental Stuff + "find_basic_blocks":true, - "asm_functions_by_name":[ - // functions which have inline assembly - "unpack-comp-huf", "(method 29 collide-shape-prim-group)","find-knot-span","dma-send-no-scratch", - "raw-ray-sphere-intersect","(method 9 bounding-box)","(method 9 matrix)","shadow-find-single-edges", - "generic-tie-dma-to-spad-sync","ray-cylinder-intersect","shadow-scissor-edges","(method 42 collide-shape)", - "(method 9 texture-page-dir)", - "(method 24 collide-shape-prim)", - "(method 23 collide-shape-prim-group)", - "shadow-find-double-edges", - "(method 16 collide-shape-prim)", - "(method 15 collide-shape-prim-group)", - "generic-tie-upload-next", - "(method 17 collide-edge-work)", - "(method 16 drawable-tree)", - "(method 10 collide-mesh)", - "particle-adgif", - "(method 14 collide-shape-prim-group)", - "(method 12 collide-shape-prim-group)", - "(method 14 bounding-box)", - "process-drawable-birth-fuel-cell", - "(method 13 collide-shape-prim-group)", - "ray-triangle-intersect", - "(method 20 collide-shape-prim-group)", - "(method 10 collide-puss-work)", - "setup-blerc-chains-for-one-fragment", - "curve-evaluate!", - "(method 16 collide-edge-work)", - "(method 9 collide-cache-prim)", - "(method 11 collide-mesh)", - "stats-tfrag-asm", - "(method 10 collide-cache-prim)", - "high-speed-reject", - "(method 12 collide-mesh)", - "(method 19 collide-cache)", - "(method 9 collide-puss-work)", - "(method 29 collide-cache)", - "time-of-day-interp-colors-scratch", - "(method 30 collide-cache)", - "calc-animation-from-spr", - "(method 14 collide-shape-prim-mesh)", - "(method 12 collide-shape-prim-mesh)", - "(method 19 process-drawable)", - "(method 13 collide-shape-prim-mesh)", - "moving-sphere-triangle-intersect", - "(method 14 collide-mesh)", - "circle-circle-xz-intersect", - "get-string-length", - "draw-node-cull", - "collide-probe-node", - "(method 28 collide-cache)", - "(method 26 collide-cache)", - "load-game-text-info", - "(method 27 collide-cache)", - "clip-polygon-against-positive-hyperplane", - "sp-process-block-2d", - "sp-init-fields!", - "clip-polygon-against-negative-hyperplane", - "(method 9 edge-grab-info)", - "(method 18 collide-edge-work)", - "sp-process-block-3d", - "time-of-day-interp-colors", - "(method 23 collide-shape-prim-sphere)", - "(method 15 collide-edge-work)", - "(method 15 collide-mesh)", - "(method 21 collide-cache)", - "mercneric-shader-asm", - "shadow-execute", - "(method 16 level)", - "(method 40 collide-shape)", - "(method 32 collide-cache)", - "bones-mtx-calc", - "draw-inline-array-prototype-tie-near-asm", - "decompress-fixed-data-to-accumulator", - "draw-inline-array-prototype-tie-asm", - "(method 10 external-art-buffer)", - "level-update-after-load", - "draw-inline-array-prototype-tie-generic-asm", - "draw-inline-array-tfrag-near", - "collide-probe-instance-tie", - "draw-inline-array-tfrag", - "mercneric-matrix-asm", - "(method 32 nav-control)", - "(method 11 fact-info-target)", - "mercneric-convert", - "generic-envmap-only-proc", - "draw-inline-array-instance-tie", - "generic-tie-convert-proc", - "draw-string", - "draw-inline-array-instance-shrub", - "generic-tie-convert", - "(anon-function 2503)", - "(anon-function 5635)", - "(anon-function 2504)", - "(anon-function 2502)", - "(anon-function 2501)", - "(anon-function 2505)", - "(anon-function 2500)", - "(anon-function 3717)", - "rand-uint31-gen", - "dma-sync-with-count", - "ripple-create-wave-table", - "generic-debug-light-proc", - "draw-bones-hud", - "(method 27 ropebridge)", - "ocean-interp-wave", - "ocean-generate-verts", - "draw-large-polygon-ocean", - "(method 23 collide-shape-prim-mesh)", - "(method 13 collide-mesh)", - "draw-boundary-polygon", - "draw-large-polygon", - "update-mood-lava", - "update-mood-lightning", - "memcpy", - "background-upload-vu0", - "upload-vis-bits", - "generic-envmap-dproc", - "generic-prepare-dma-double", - "generic-envmap-proc", - "generic-light-proc", - "generic-merc-execute-asm", - "generic-merc-init-asm", - "shadow-calc-dual-verts", - "shadow-scissor-top", - "shadow-find-facing-single-tris", - "shadow-find-facing-double-tris", - "shadow-add-verts", - "shadow-add-facing-single-tris", - "shadow-add-single-edges", - "shadow-add-double-tris", - "shadow-add-double-edges", - "test-func", - "(method 14 collide-cache)", - "symlink2", - "draw-bones-merc", - "dma-count-until-done", - "symlink3", - "blerc-execute", - "merc-dma-chain-to-spr", - "ripple-matrix-scale", - "ripple-apply-wave-table", - "ripple-execute-init", - "bones-mtx-calc-execute", - "texscroll-execute", - "generic-light", - "generic-no-light", - "generic-no-light+envmap", - "generic-dma-from-spr", - "upload-vu0-program", - "generic-merc-execute-all", - "closest-pt-in-triangle", - "(method 11 sparticle-launch-control)", - "(anon-function 3751)", - "look-for-points-of-interest", + "asm_functions_by_name":[ + // functions which have inline assembly + "unpack-comp-huf", "(method 29 collide-shape-prim-group)","find-knot-span","dma-send-no-scratch", + "raw-ray-sphere-intersect","(method 9 bounding-box)","(method 9 matrix)","shadow-find-single-edges", + "generic-tie-dma-to-spad-sync","ray-cylinder-intersect","shadow-scissor-edges","(method 42 collide-shape)", + "(method 9 texture-page-dir)", + "(method 24 collide-shape-prim)", + "(method 23 collide-shape-prim-group)", + "shadow-find-double-edges", + "(method 16 collide-shape-prim)", + "(method 15 collide-shape-prim-group)", + "generic-tie-upload-next", + "(method 17 collide-edge-work)", + "(method 16 drawable-tree)", + "(method 10 collide-mesh)", + "particle-adgif", + "(method 14 collide-shape-prim-group)", + "(method 12 collide-shape-prim-group)", + "(method 14 bounding-box)", + "process-drawable-birth-fuel-cell", + "(method 13 collide-shape-prim-group)", + "ray-triangle-intersect", + "(method 20 collide-shape-prim-group)", + "(method 10 collide-puss-work)", + "setup-blerc-chains-for-one-fragment", + "curve-evaluate!", + "(method 16 collide-edge-work)", + "(method 9 collide-cache-prim)", + "(method 11 collide-mesh)", + "stats-tfrag-asm", + "(method 10 collide-cache-prim)", + "high-speed-reject", + "(method 12 collide-mesh)", + "(method 19 collide-cache)", + "(method 9 collide-puss-work)", + "(method 29 collide-cache)", + "time-of-day-interp-colors-scratch", + "(method 30 collide-cache)", + "calc-animation-from-spr", + "(method 14 collide-shape-prim-mesh)", + "(method 12 collide-shape-prim-mesh)", + "(method 19 process-drawable)", + "(method 13 collide-shape-prim-mesh)", + "moving-sphere-triangle-intersect", + "(method 14 collide-mesh)", + "circle-circle-xz-intersect", + "get-string-length", + "draw-node-cull", + "collide-probe-node", + "(method 28 collide-cache)", + "(method 26 collide-cache)", + "load-game-text-info", + "(method 27 collide-cache)", + "clip-polygon-against-positive-hyperplane", + "sp-process-block-2d", + "sp-init-fields!", + "clip-polygon-against-negative-hyperplane", + "(method 9 edge-grab-info)", + "(method 18 collide-edge-work)", + "sp-process-block-3d", + "time-of-day-interp-colors", + "(method 23 collide-shape-prim-sphere)", + "(method 15 collide-edge-work)", + "(method 15 collide-mesh)", + "(method 21 collide-cache)", + "mercneric-shader-asm", + "shadow-execute", + "(method 16 level)", + "(method 40 collide-shape)", + "(method 32 collide-cache)", + "bones-mtx-calc", + "draw-inline-array-prototype-tie-near-asm", + "decompress-fixed-data-to-accumulator", + "draw-inline-array-prototype-tie-asm", + "(method 10 external-art-buffer)", + "level-update-after-load", + "draw-inline-array-prototype-tie-generic-asm", + "draw-inline-array-tfrag-near", + "collide-probe-instance-tie", + "draw-inline-array-tfrag", + "mercneric-matrix-asm", + "(method 32 nav-control)", + "(method 11 fact-info-target)", + "mercneric-convert", + "generic-envmap-only-proc", + "draw-inline-array-instance-tie", + "generic-tie-convert-proc", + "draw-string", + "draw-inline-array-instance-shrub", + "generic-tie-convert", + "(anon-function 2503)", + "(anon-function 5635)", + "(anon-function 2504)", + "(anon-function 2502)", + "(anon-function 2501)", + "(anon-function 2505)", + "(anon-function 2500)", + "(anon-function 3717)", + "rand-uint31-gen", + "dma-sync-with-count", + "ripple-create-wave-table", + "generic-debug-light-proc", + "draw-bones-hud", + "(method 27 ropebridge)", + "ocean-interp-wave", + "ocean-generate-verts", + "draw-large-polygon-ocean", + "(method 23 collide-shape-prim-mesh)", + "(method 13 collide-mesh)", + "draw-boundary-polygon", + "draw-large-polygon", + "update-mood-lava", + "update-mood-lightning", + "memcpy", + "background-upload-vu0", + "upload-vis-bits", + "generic-envmap-dproc", + "generic-prepare-dma-double", + "generic-envmap-proc", + "generic-light-proc", + "generic-merc-execute-asm", + "generic-merc-init-asm", + "shadow-calc-dual-verts", + "shadow-scissor-top", + "shadow-find-facing-single-tris", + "shadow-find-facing-double-tris", + "shadow-add-verts", + "shadow-add-facing-single-tris", + "shadow-add-single-edges", + "shadow-add-double-tris", + "shadow-add-double-edges", + "test-func", + "(method 14 collide-cache)", + "symlink2", + "draw-bones-merc", + "dma-count-until-done", + "symlink3", + "blerc-execute", + "merc-dma-chain-to-spr", + "ripple-matrix-scale", + "ripple-apply-wave-table", + "ripple-execute-init", + "bones-mtx-calc-execute", + "texscroll-execute", + "generic-light", + "generic-no-light", + "generic-no-light+envmap", + "generic-dma-from-spr", + "upload-vu0-program", + "generic-merc-execute-all", + "closest-pt-in-triangle", + "(method 11 sparticle-launch-control)", + "(anon-function 3751)", + "look-for-points-of-interest", - // gcommon - "(method 2 vec4s)", "quad-copy!", "(method 3 vec4s)", "breakpoint-range-set!", + // gcommon + "(method 2 vec4s)", "quad-copy!", "(method 3 vec4s)", "breakpoint-range-set!", - // pskernel - "resend-exception", "kernel-set-interrupt-vector", "kernel-set-exception-vector", "return-from-exception", - "kernel-read", "kernel-read-function", "kernel-write", "kernel-write-function", "kernel-copy-to-kernel-ram", + // pskernel + "resend-exception", "kernel-set-interrupt-vector", "kernel-set-exception-vector", "return-from-exception", + "kernel-read", "kernel-read-function", "kernel-write", "kernel-write-function", "kernel-copy-to-kernel-ram", - // this one needs more investigation. nothing looks weird about it but it fails... - "camera-change-to", + // this one needs more investigation. nothing looks weird about it but it fails... + "camera-change-to", - // two back to back arithmetic shifts... - "texture-relocate", + // two back to back arithmetic shifts... + "texture-relocate", - // this one fails due to false compaction where an else case has only a not expression in it. - "master-is-hopeful-better?", + // this one fails due to false compaction where an else case has only a not expression in it. + "master-is-hopeful-better?", - // fails for unknown reason - "target-falling-anim-trans", "change-brother", + // fails for unknown reason + "target-falling-anim-trans", "change-brother", - // merged right typecase... can probably handle this - "cspace-inspect-tree", + // merged right typecase... can probably handle this + "cspace-inspect-tree", - // these are all valid, but use short circuiting branches in strange ways. There's probably a few compiler uses that we're not - "(method 21 actor-link-info)","(method 20 actor-link-info)","(method 28 collide-shape-prim-mesh)", "(method 35 collide-shape)", - "debug-menu-item-var-render", "(method 14 level)","add-blue-motion","anim-tester-add-newobj","(method 27 orb-cache-top)", + // these are all valid, but use short circuiting branches in strange ways. There's probably a few compiler uses that we're not + "(method 21 actor-link-info)","(method 20 actor-link-info)","(method 28 collide-shape-prim-mesh)", "(method 35 collide-shape)", + "debug-menu-item-var-render", "(method 14 level)","add-blue-motion","anim-tester-add-newobj","(method 27 orb-cache-top)", - // real asm - "cspace<-parented-transformq-joint!", "blerc-a-fragment", "render-boundary-tri", "render-boundary-quad", - "(method 19 collide-shape-prim-sphere)","vector-segment-distance-point!", "exp", "(method 11 collide-mesh-cache)", - "(method 13 collide-edge-work)", "ambient-inspect", + // real asm + "cspace<-parented-transformq-joint!", "blerc-a-fragment", "render-boundary-tri", "render-boundary-quad", + "(method 19 collide-shape-prim-sphere)","vector-segment-distance-point!", "exp", "(method 11 collide-mesh-cache)", + "(method 13 collide-edge-work)", "ambient-inspect", - "(method 11 cpu-thread)", "atan0", "sincos!", "sincos-rad!", "disasm-dma-list", "vblank-handler", "vif1-handler", - "vif1-handler-debug", "entity-actor-count", "decompress-frame-data-pair-to-accumulator", - "decompress-frame-data-to-accumulator", "normalize-frame-quaternions", "clear-frame-accumulator", - "generic-copy-vtx-dclr-dtex", "generic-no-light-dproc-only", "generic-no-light-proc", "mercneric-bittable-asm", - "generic-tie-decompress", "matrix-axis-sin-cos!", "matrix-axis-sin-cos-vu!", "generic-prepare-dma-single", - "(method 13 collide-shape-prim-sphere)", "(method 14 collide-shape-prim-sphere)", "(method 12 collide-shape-prim-sphere)", - "adgif-shader<-texture-with-update!", "generic-interp-dproc", "sprite-draw-distorters", "draw-bones", "(method 9 collide-mesh-cache)", - "(method 18 collide-shape-prim-sphere)","birth-pickup-at-point", + "(method 11 cpu-thread)", "atan0", "sincos!", "sincos-rad!", "disasm-dma-list", "vblank-handler", "vif1-handler", + "vif1-handler-debug", "entity-actor-count", "decompress-frame-data-pair-to-accumulator", + "decompress-frame-data-to-accumulator", "normalize-frame-quaternions", "clear-frame-accumulator", + "generic-copy-vtx-dclr-dtex", "generic-no-light-dproc-only", "generic-no-light-proc", "mercneric-bittable-asm", + "generic-tie-decompress", "matrix-axis-sin-cos!", "matrix-axis-sin-cos-vu!", "generic-prepare-dma-single", + "(method 13 collide-shape-prim-sphere)", "(method 14 collide-shape-prim-sphere)", "(method 12 collide-shape-prim-sphere)", + "adgif-shader<-texture-with-update!", "generic-interp-dproc", "sprite-draw-distorters", "draw-bones", "(method 9 collide-mesh-cache)", + "(method 18 collide-shape-prim-sphere)","birth-pickup-at-point", - "collide-do-primitives", "draw-bones-check-longest-edge-asm", - "sp-launch-particles-var", "(method 15 collide-shape-prim-mesh)", "(method 15 collide-shape-prim-sphere)", - "(method 45 collide-shape)", "cam-layout-save-cam-trans", "kernel-copy-function", "dma-sync-hang", "generic-no-light-dproc", - "dma-sync-fast", "bsp-camera-asm", - "generic-none-dma-wait", "unpack-comp-rle", "level-remap-texture", "(method 10 collide-edge-hold-list)" - ] -} + "collide-do-primitives", "draw-bones-check-longest-edge-asm", + "sp-launch-particles-var", "(method 15 collide-shape-prim-mesh)", "(method 15 collide-shape-prim-sphere)", + "(method 45 collide-shape)", "cam-layout-save-cam-trans", "kernel-copy-function", "dma-sync-hang", "generic-no-light-dproc", + "dma-sync-fast", "bsp-camera-asm", + "generic-none-dma-wait", "unpack-comp-rle", "level-remap-texture", "(method 10 collide-edge-hold-list)" + ] +} \ No newline at end of file diff --git a/decompiler/main.cpp b/decompiler/main.cpp index 1119924e4b..cbbe154bf4 100644 --- a/decompiler/main.cpp +++ b/decompiler/main.cpp @@ -4,16 +4,23 @@ #include "ObjectFile/ObjectFileDB.h" #include "config.h" #include "util/FileIO.h" - +#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "third-party/spdlog/include/spdlog/sinks/basic_file_sink.h" #include "common/util/FileUtil.h" int main(int argc, char** argv) { - printf("Jak Disassembler\n"); + spdlog::info("Beginning disassembly. This may take a few minutes..."); + + spdlog::set_level(spdlog::level::debug); + auto lu = spdlog::basic_logger_mt("GOAL Decompiler", "logs/decompiler.log"); + spdlog::set_default_logger(lu); + spdlog::flush_on(spdlog::level::info); + init_crc(); init_opcode_info(); if (argc != 4) { - printf("usage: jak_disassembler \n"); + printf("Usage: jak_disassembler \n"); return 1; } @@ -52,5 +59,6 @@ int main(int argc, char** argv) { // printf("%s\n", get_type_info().get_summary().c_str()); file_util::write_text_file(combine_path(out_folder, "all-syms.gc"), db.dts.dump_symbol_types()); + spdlog::info("Disassembly has completed successfully."); return 0; }