[decompiler] Fix rlet in top level and detect matrix and stack inline construction (#547)

* top level in rlet

* detect matrix and vector inline 0

* pretty print the symbol map
This commit is contained in:
water111
2021-05-31 18:14:18 -04:00
committed by GitHub
parent 84c0522102
commit 3d8013633a
19 changed files with 422 additions and 458 deletions
+41
View File
@@ -141,6 +141,26 @@ std::string careful_function_to_string(
}
} // namespace
std::string add_indent(const std::string& in, int indent, bool indent_first_line) {
if (in.empty()) {
return in;
}
std::string indent_str(indent, ' ');
std::string result;
char prev_char = indent_first_line ? '\n' : ' ';
for (char c : in) {
if (prev_char == '\n') {
result += indent_str;
}
result += c;
prev_char = c;
}
return result;
}
std::string write_from_top_level(const Function& top_level,
const DecompilerTypeSystem& dts,
const LinkedObjectFile& file,
@@ -198,6 +218,23 @@ std::string write_from_top_level(const Function& top_level,
}
}
// look for the whole thing being in an rlet
bool in_rlet = false;
if (forms.size() == 1) {
auto as_rlet = dynamic_cast<RLetElement*>(forms.at(0));
if (as_rlet) {
forms = as_rlet->body->elts();
in_rlet = true;
result += "(rlet ";
result += add_indent(pretty_print::to_string(as_rlet->reg_list()), 6, false);
result += '\n';
if (as_rlet->needs_vf0_init()) {
result += "(init-vf0-vector)\n";
}
result += '\n';
}
}
// (set! identity L312)
constexpr int func_name = 1;
constexpr int label = 2;
@@ -370,6 +407,10 @@ std::string write_from_top_level(const Function& top_level,
result += ")\n";
}
if (in_rlet) {
result += ")\n";
}
return result;
}
} // namespace decompiler