clang-format all the things

This commit is contained in:
Tyler Wilding
2020-08-26 01:21:33 -04:00
parent 50814f8529
commit 3c4fcbdd34
72 changed files with 772 additions and 795 deletions
+4 -6
View File
@@ -90,7 +90,7 @@ Function& LinkedObjectFile::get_function_at_label(int label_id) {
}
assert(false);
return functions_by_seg.front().front(); // to avoid error
return functions_by_seg.front().front(); // to avoid error
}
/*!
@@ -520,7 +520,7 @@ std::string LinkedObjectFile::print_disassembly() {
result += "; .function " + func.guessed_name.to_string() + "\n";
result += ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";
result += func.prologue.to_string(2) + "\n";
if(!func.warnings.empty()) {
if (!func.warnings.empty()) {
result += "Warnings: " + func.warnings + "\n";
}
@@ -581,11 +581,11 @@ std::string LinkedObjectFile::print_disassembly() {
// }
// hack
if(func.cfg && !func.cfg->is_fully_resolved()) {
if (func.cfg && !func.cfg->is_fully_resolved()) {
result += func.cfg->to_dot();
result += "\n";
}
if(func.cfg) {
if (func.cfg) {
result += func.cfg->to_form_string() + "\n";
// To debug block stuff.
@@ -614,7 +614,6 @@ std::string LinkedObjectFile::print_disassembly() {
*/
}
result += "\n\n\n";
}
@@ -636,7 +635,6 @@ std::string LinkedObjectFile::print_disassembly() {
if (word.kind == LinkedWord::TYPE_PTR && word.symbol_name == "string") {
result += "; " + get_goal_string(seg, i) + "\n";
}
}
}
+14 -11
View File
@@ -15,7 +15,6 @@
#include "decompiler/Function/Function.h"
#include "decompiler/util/LispPrint.h"
/*!
* A label to a location in this object file.
* Doesn't have to be word aligned.
@@ -23,14 +22,14 @@
struct Label {
std::string name;
int target_segment;
int offset; // in bytes
int offset; // in bytes
};
/*!
* An object file's data with linking information included.
*/
class LinkedObjectFile {
public:
public:
LinkedObjectFile() = default;
void set_segment_count(int n_segs);
void push_back_word_to_segment(uint32_t word, int segment);
@@ -38,8 +37,15 @@ public:
int get_label_at(int seg, int offset) const;
bool label_points_to_code(int label_id) const;
bool pointer_link_word(int source_segment, int source_offset, int dest_segment, int dest_offset);
void pointer_link_split_word(int source_segment, int source_hi_offset, int source_lo_offset, int dest_segment, int dest_offset);
void symbol_link_word(int source_segment, int source_offset, const char* name, LinkedWord::Kind kind);
void pointer_link_split_word(int source_segment,
int source_hi_offset,
int source_lo_offset,
int dest_segment,
int dest_offset);
void symbol_link_word(int source_segment,
int source_offset,
const char* name,
LinkedWord::Kind kind);
void symbol_link_offset(int source_segment, int source_offset, const char* name);
Function& get_function_at_label(int label_id);
std::string get_label_name(int label_id) const;
@@ -83,7 +89,6 @@ public:
uint32_t n_fp_reg_use = 0;
uint32_t n_fp_reg_use_resolved = 0;
void add(const Stats& other) {
total_code_bytes += other.total_code_bytes;
total_v2_code_bytes += other.total_v2_code_bytes;
@@ -116,9 +121,9 @@ public:
std::vector<std::vector<Function>> functions_by_seg;
std::vector<Label> labels;
private:
private:
std::shared_ptr<Form> to_form_script(int seg, int word_idx, std::vector<bool>& seen);
std::shared_ptr<Form> to_form_script_object(int seg, int byte_idx, std::vector<bool> &seen);
std::shared_ptr<Form> to_form_script_object(int seg, int byte_idx, std::vector<bool>& seen);
bool is_empty_list(int seg, int byte_idx);
bool is_string(int seg, int byte_idx);
std::string get_goal_string(int seg, int word_idx);
@@ -126,6 +131,4 @@ private:
std::vector<std::unordered_map<int, int>> label_per_seg_by_offset;
};
#endif //NEXT_LINKEDOBJECTFILE_H
#endif // NEXT_LINKEDOBJECTFILE_H
@@ -213,7 +213,6 @@ static uint32_t align16(uint32_t in) {
return (in + 15) & (~15);
}
/*!
* Process link data for a "V4" object file.
* In reality a V4 seems to be just a V2 object, but with the link data after the real data.
@@ -11,4 +11,4 @@
LinkedObjectFile to_linked_object_file(const std::vector<uint8_t>& data, const std::string& name);
#endif //NEXT_LINKEDOBJECTFILECREATION_H
#endif // NEXT_LINKEDOBJECTFILECREATION_H
+38 -35
View File
@@ -421,8 +421,8 @@ void ObjectFileDB::analyze_functions() {
(void)segment_id;
auto name = func.guessed_name.to_string();
if (func.guessed_name.expected_unique()) {
if(unique_names.find(name) != unique_names.end()) {
duplicated_functions[name].insert(data.record.to_unique_name());
if (unique_names.find(name) != unique_names.end()) {
duplicated_functions[name].insert(data.record.to_unique_name());
}
unique_names.insert(name);
@@ -435,22 +435,22 @@ void ObjectFileDB::analyze_functions() {
});
for_each_function([&](Function& func, int segment_id, ObjectFileData& data) {
(void)segment_id;
auto name = func.guessed_name.to_string();
if(func.guessed_name.expected_unique()) {
if(duplicated_functions.find(name) != duplicated_functions.end()) {
duplicated_functions[name].insert(data.record.to_unique_name());
func.warnings += "this function exists in multiple non-identical object files";
}
(void)segment_id;
auto name = func.guessed_name.to_string();
if (func.guessed_name.expected_unique()) {
if (duplicated_functions.find(name) != duplicated_functions.end()) {
duplicated_functions[name].insert(data.record.to_unique_name());
func.warnings += "this function exists in multiple non-identical object files";
}
}
});
// for(const auto& kv : duplicated_functions) {
// printf("Function %s is found in non-identical object files:\n", kv.first.c_str());
// for(const auto& obj : kv.second) {
// printf(" %s\n", obj.c_str());
// }
// }
// for(const auto& kv : duplicated_functions) {
// printf("Function %s is found in non-identical object files:\n", kv.first.c_str());
// for(const auto& obj : kv.second) {
// printf(" %s\n", obj.c_str());
// }
// }
}
int total_nontrivial_functions = 0;
@@ -466,45 +466,48 @@ void ObjectFileDB::analyze_functions() {
total_basic_blocks += blocks.size();
func.basic_blocks = blocks;
if(!func.suspected_asm) {
func.analyze_prologue(data.linked_data);
func.cfg = build_cfg(data.linked_data, segment_id, func);
total_functions++;
if (func.cfg->is_fully_resolved()) {
resolved_cfg_functions++;
}
if (!func.suspected_asm) {
func.analyze_prologue(data.linked_data);
func.cfg = build_cfg(data.linked_data, segment_id, func);
total_functions++;
if (func.cfg->is_fully_resolved()) {
resolved_cfg_functions++;
}
} else {
resolved_cfg_functions++;
}
if(func.basic_blocks.size() > 1 && !func.suspected_asm) {
if (func.basic_blocks.size() > 1 && !func.suspected_asm) {
total_nontrivial_functions++;
if(func.cfg->is_fully_resolved()) {
if (func.cfg->is_fully_resolved()) {
total_resolved_nontrivial_functions++;
} else {
if(!func.guessed_name.empty()) {
unresolved_by_length[func.end_word - func.start_word].push_back(func.guessed_name.to_string());
if (!func.guessed_name.empty()) {
unresolved_by_length[func.end_word - func.start_word].push_back(
func.guessed_name.to_string());
}
}
}
if(!func.guessed_name.empty()) {
if (!func.guessed_name.empty()) {
total_named_functions++;
}
});
printf("Found %d functions (%d with nontrivial cfgs)\n", total_functions, total_nontrivial_functions);
printf("Named %d/%d functions (%.2f%%)\n", total_named_functions, total_functions, 100.f * float(total_named_functions) / float(total_functions));
printf("Found %d functions (%d with nontrivial cfgs)\n", total_functions,
total_nontrivial_functions);
printf("Named %d/%d functions (%.2f%%)\n", total_named_functions, total_functions,
100.f * float(total_named_functions) / float(total_functions));
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, total_functions,
100.f * float(resolved_cfg_functions) / float(total_functions));
printf(" %d/%d nontrivial cfg's resolved (%.2f%%)\n", total_resolved_nontrivial_functions, total_nontrivial_functions,
printf(" %d/%d functions passed cfg analysis stage (%.2f%%)\n", resolved_cfg_functions,
total_functions, 100.f * float(resolved_cfg_functions) / float(total_functions));
printf(" %d/%d nontrivial cfg's resolved (%.2f%%)\n", total_resolved_nontrivial_functions,
total_nontrivial_functions,
100.f * float(total_resolved_nontrivial_functions) / float(total_nontrivial_functions));
for(auto& kv : unresolved_by_length) {
for (auto& kv : unresolved_by_length) {
printf("LEN %d\n", kv.first);
for(auto& x : kv.second) {
for (auto& x : kv.second) {
printf(" %s\n", x.c_str());
}
}
+5 -5
View File
@@ -60,8 +60,8 @@ class ObjectFileDB {
template <typename Func>
void for_each_obj(Func f) {
assert(obj_files_by_name.size() == obj_file_order.size());
for(const auto& name : obj_file_order) {
for(auto& obj : obj_files_by_name.at(name)) {
for (const auto& name : obj_file_order) {
for (auto& obj : obj_files_by_name.at(name)) {
f(obj);
}
}
@@ -75,12 +75,12 @@ class ObjectFileDB {
template <typename Func>
void for_each_function(Func f) {
for_each_obj([&](ObjectFileData& data) {
// printf("IN %s\n", data.record.to_unique_name().c_str());
// printf("IN %s\n", data.record.to_unique_name().c_str());
for (int i = 0; i < int(data.linked_data.segments); i++) {
// printf("seg %d\n", i);
// printf("seg %d\n", i);
int fn = 0;
for (auto& goal_func : data.linked_data.functions_by_seg.at(i)) {
// printf("fn %d\n", fn);
// printf("fn %d\n", fn);
f(goal_func, i, data);
fn++;
}