diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/decompiler.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/decompiler.cc b/src/decompiler.cc index 679352d6..db71bf42 100644 --- a/src/decompiler.cc +++ b/src/decompiler.cc @@ -623,6 +623,7 @@ struct Decompiler { // FIXME: Merge with WatWriter::WriteQuotedData somehow. std::string BinaryToString(const std::vector<uint8_t> &in) { std::string s = "\""; + size_t line_start = 0; static const char s_hexdigits[] = "0123456789abcdef"; for (auto c : in) { if (c >= ' ' && c <= '~') { @@ -632,6 +633,14 @@ struct Decompiler { s += s_hexdigits[c >> 4]; s += s_hexdigits[c & 0xf]; } + if (s.size() - line_start > target_exp_width) { + if (line_start == 0) { + s = " " + s; + } + s += "\"\n "; + line_start = s.size(); + s += "\""; + } } s += '\"'; return s; @@ -688,8 +697,14 @@ struct Decompiler { // Data. for (auto dat : mc.module.data_segments) { - s += cat("data ", dat->name, "(offset: ", InitExp(dat->offset), - ") = ", BinaryToString(dat->data), ";\n"); + + s += cat("data ", dat->name, "(offset: ", InitExp(dat->offset), ") = "); + auto ds = BinaryToString(dat->data); + if (ds.size() > target_exp_width / 2) { + s += "\n"; + } + s += ds; + s += ";\n"; } if (!mc.module.data_segments.empty()) s += "\n"; |