summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/decompiler.cc19
-rw-r--r--test/decompile/basic.txt6
2 files changed, 23 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";
diff --git a/test/decompile/basic.txt b/test/decompile/basic.txt
index 34c6f578..e7a4c9db 100644
--- a/test/decompile/basic.txt
+++ b/test/decompile/basic.txt
@@ -15,6 +15,7 @@
(table (export "tab2") 0 11 funcref)
(data 0 (offset (i32.const 0)) "Hello, World!\n\00")
+ (data 0 (offset (i32.const 100)) "abcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyz")
(func $f (param i32 i32) (result i32) (local i64 f32 f64)
i64.const 8
@@ -119,6 +120,11 @@ table T_b:funcref(min: 0, max: 10);
export table tab2:funcref(min: 0, max: 11);
data d_a(offset: 0) = "Hello, World!\0a\00";
+data d_b(offset: 100) =
+ "abcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstu"
+ "vwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmno"
+ "qrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghij"
+ "klmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoqrstuvwxyz";
import function ns_fi();