mirror of
https://github.com/open-goal/jak-project
synced 2026-08-10 19:17:55 -04:00
clean up config (#456)
This commit is contained in:
@@ -529,74 +529,6 @@ void LinkedObjectFile::process_fp_relative_links() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string LinkedObjectFile::to_asm_json(const std::string& obj_file_name) {
|
||||
nlohmann::json data;
|
||||
std::vector<nlohmann::json::object_t> functions;
|
||||
|
||||
std::unordered_map<std::string, int> functions_seen;
|
||||
for (int seg = segments; seg-- > 0;) {
|
||||
for (size_t fi = functions_by_seg.at(seg).size(); fi--;) {
|
||||
auto& func = functions_by_seg.at(seg).at(fi);
|
||||
auto fname = func.guessed_name.to_string();
|
||||
if (functions_seen.find(fname) != functions_seen.end()) {
|
||||
lg::warn(
|
||||
"Function {} appears multiple times in the same object file {} - it cannot be uniquely "
|
||||
"referenced from config",
|
||||
func.guessed_name.to_string(), obj_file_name);
|
||||
functions_seen[fname]++;
|
||||
fname += "-v" + std::to_string(functions_seen[fname]);
|
||||
} else {
|
||||
functions_seen[fname] = 0;
|
||||
}
|
||||
|
||||
nlohmann::json::object_t f;
|
||||
f["name"] = fname;
|
||||
f["type"] = func.type.print();
|
||||
f["segment"] = seg;
|
||||
f["warnings"] = func.warnings.get_warning_text(false);
|
||||
f["parent_object"] = obj_file_name;
|
||||
std::vector<nlohmann::json::object_t> ops;
|
||||
|
||||
for (int i = 1; i < func.end_word - func.start_word; i++) {
|
||||
nlohmann::json::object_t op;
|
||||
auto label_id = get_label_at(seg, (func.start_word + i) * 4);
|
||||
if (label_id != -1) {
|
||||
op["label"] = labels.at(label_id).name;
|
||||
}
|
||||
auto& instr = func.instructions.at(i);
|
||||
op["id"] = i;
|
||||
op["asm_op"] = instr.to_string(labels);
|
||||
|
||||
if (func.has_basic_ops() && func.instr_starts_basic_op(i)) {
|
||||
op["basic_op"] = func.get_basic_op_at_instr(i)->print(*this);
|
||||
// if (func.has_typemaps()) {
|
||||
// auto& tm = func.get_typemap_by_instr_idx(i);
|
||||
// auto& json_type_map = op["type_map"];
|
||||
// for (auto& kv : tm) {
|
||||
// json_type_map[kv.first.to_charp()] = kv.second.print();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
for (int iidx = 0; iidx < instr.n_src; iidx++) {
|
||||
if (instr.get_src(iidx).is_label()) {
|
||||
auto lab = labels.at(instr.get_src(iidx).get_label());
|
||||
if (is_string(lab.target_segment, lab.offset)) {
|
||||
op["referenced_string"] = get_goal_string(lab.target_segment, lab.offset / 4 - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ops.push_back(op);
|
||||
}
|
||||
f["asm"] = ops;
|
||||
functions.push_back(f);
|
||||
}
|
||||
}
|
||||
data["functions"] = functions;
|
||||
return data.dump();
|
||||
}
|
||||
|
||||
std::string LinkedObjectFile::print_function_disassembly(Function& func,
|
||||
int seg,
|
||||
bool write_hex,
|
||||
|
||||
@@ -54,7 +54,6 @@ class LinkedObjectFile {
|
||||
std::string print_disassembly();
|
||||
bool has_any_functions();
|
||||
void append_word_to_string(std::string& dest, const LinkedWord& word) const;
|
||||
std::string to_asm_json(const std::string& obj_file_name);
|
||||
std::string print_function_disassembly(Function& func,
|
||||
int seg,
|
||||
bool write_hex,
|
||||
|
||||
@@ -423,18 +423,17 @@ void ObjectFileDB::process_labels() {
|
||||
/*!
|
||||
* Dump object files and their linking data to text files for debugging
|
||||
*/
|
||||
void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool dump_v3_only) {
|
||||
if (dump_v3_only) {
|
||||
lg::info("- Writing object file dumps (v3 only)...");
|
||||
} else {
|
||||
lg::info("- Writing object file dumps (all)...");
|
||||
}
|
||||
void ObjectFileDB::write_object_file_words(const std::string& output_dir,
|
||||
bool dump_data,
|
||||
bool dump_code) {
|
||||
lg::info("- Writing object file dumps (code? {} data? {})...", dump_code, dump_data);
|
||||
|
||||
Timer timer;
|
||||
uint32_t total_bytes = 0, total_files = 0;
|
||||
|
||||
for_each_obj([&](ObjectFileData& obj) {
|
||||
if (obj.linked_data.segments == 3 || !dump_v3_only) {
|
||||
if ((obj.linked_data.segments == 3 && dump_code) ||
|
||||
(obj.linked_data.segments != 3 && dump_data)) {
|
||||
auto file_text = obj.linked_data.print_words();
|
||||
auto file_name = file_util::combine_path(output_dir, obj.to_unique_name() + ".txt");
|
||||
total_bytes += file_text.size();
|
||||
@@ -448,16 +447,14 @@ void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool d
|
||||
lg::info(" Total {:.3f} MB", total_bytes / ((float)(1u << 20u)));
|
||||
lg::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(),
|
||||
total_bytes / ((1u << 20u) * timer.getSeconds()));
|
||||
// printf("\n");
|
||||
}
|
||||
|
||||
/*!
|
||||
* Dump disassembly for object files containing code. Data zones will also be dumped.
|
||||
*/
|
||||
void ObjectFileDB::write_disassembly(const std::string& output_dir,
|
||||
bool disassemble_objects_without_functions,
|
||||
bool write_json,
|
||||
const std::string& file_suffix) {
|
||||
bool disassemble_data,
|
||||
bool disassemble_code) {
|
||||
lg::info("- Writing functions...");
|
||||
Timer timer;
|
||||
uint32_t total_bytes = 0, total_files = 0;
|
||||
@@ -465,20 +462,10 @@ void ObjectFileDB::write_disassembly(const std::string& output_dir,
|
||||
std::string asm_functions;
|
||||
|
||||
for_each_obj([&](ObjectFileData& obj) {
|
||||
if (obj.linked_data.has_any_functions() || disassemble_objects_without_functions) {
|
||||
if ((obj.obj_version == 3 && disassemble_code) || (obj.obj_version != 3 && disassemble_data)) {
|
||||
auto file_text = obj.linked_data.print_disassembly();
|
||||
asm_functions += obj.linked_data.print_asm_function_disassembly(obj.to_unique_name());
|
||||
auto file_name =
|
||||
file_util::combine_path(output_dir, obj.to_unique_name() + file_suffix + ".asm");
|
||||
|
||||
if (get_config().analyze_functions && write_json) {
|
||||
auto json_asm_text = obj.linked_data.to_asm_json(obj.to_unique_name());
|
||||
auto json_asm_file_name =
|
||||
file_util::combine_path(output_dir, obj.to_unique_name() + "_asm.json");
|
||||
file_util::write_text_file(json_asm_file_name, json_asm_text);
|
||||
total_files++;
|
||||
total_bytes += json_asm_text.size();
|
||||
}
|
||||
auto file_name = file_util::combine_path(output_dir, obj.to_unique_name() + ".asm");
|
||||
|
||||
total_bytes += file_text.size();
|
||||
file_util::write_text_file(file_name, file_text);
|
||||
|
||||
@@ -58,11 +58,10 @@ class ObjectFileDB {
|
||||
void find_and_write_scripts(const std::string& output_dir);
|
||||
void dump_raw_objects(const std::string& output_dir);
|
||||
|
||||
void write_object_file_words(const std::string& output_dir, bool dump_v3_only);
|
||||
void write_object_file_words(const std::string& output_dir, bool dump_data, bool dump_code);
|
||||
void write_disassembly(const std::string& output_dir,
|
||||
bool disassemble_objects_without_functions,
|
||||
bool write_json,
|
||||
const std::string& file_suffix = "");
|
||||
bool disassemble_data,
|
||||
bool disassemble_code);
|
||||
|
||||
void analyze_functions_ir1();
|
||||
void analyze_functions_ir2(const std::string& output_dir);
|
||||
|
||||
@@ -47,20 +47,19 @@ void ObjectFileDB::analyze_functions_ir2(const std::string& output_dir) {
|
||||
ir2_variable_pass();
|
||||
lg::info("Initial structuring...");
|
||||
ir2_cfg_build_pass();
|
||||
if (get_config().analyze_expressions) {
|
||||
lg::info("Storing temporary form result...");
|
||||
ir2_store_current_forms();
|
||||
lg::info("Expression building...");
|
||||
ir2_build_expressions();
|
||||
lg::info("Re-writing inline asm instructions...");
|
||||
ir2_rewrite_inline_asm_instructions();
|
||||
if (get_config().insert_lets) {
|
||||
lg::info("Inserting lets...");
|
||||
ir2_insert_lets();
|
||||
}
|
||||
lg::info("Inserting anonymous function definitions...");
|
||||
ir2_insert_anonymous_functions();
|
||||
}
|
||||
|
||||
lg::info("Storing temporary form result...");
|
||||
ir2_store_current_forms();
|
||||
lg::info("Expression building...");
|
||||
ir2_build_expressions();
|
||||
lg::info("Re-writing inline asm instructions...");
|
||||
ir2_rewrite_inline_asm_instructions();
|
||||
|
||||
lg::info("Inserting lets...");
|
||||
ir2_insert_lets();
|
||||
|
||||
lg::info("Inserting anonymous function definitions...");
|
||||
ir2_insert_anonymous_functions();
|
||||
|
||||
if (!output_dir.empty()) {
|
||||
lg::info("Writing results...");
|
||||
@@ -213,14 +212,6 @@ void ObjectFileDB::ir2_basic_block_pass() {
|
||||
func.guessed_name.to_string(), data.to_unique_name());
|
||||
failed_to_build_cfg++;
|
||||
}
|
||||
|
||||
// if we got an inspect method, inspect it.
|
||||
if (func.is_inspect_method) {
|
||||
auto result = inspect_inspect_method(func, func.method_of_type, dts, data.linked_data);
|
||||
all_type_defs += ";; " + data.to_unique_name() + "\n";
|
||||
all_type_defs += result.print_as_deftype() + "\n";
|
||||
inspect_methods++;
|
||||
}
|
||||
}
|
||||
|
||||
if (func.suspected_asm) {
|
||||
|
||||
Reference in New Issue
Block a user