diff options
-rw-r--r-- | src/passes/Print.cpp | 47 | ||||
-rw-r--r-- | test/heap-types.wast | 14 | ||||
-rw-r--r-- | test/heap-types.wast.from-wast | 16 | ||||
-rw-r--r-- | test/heap-types.wast.fromBinary | 8 | ||||
-rw-r--r-- | test/heap-types.wast.fromBinary.noDebugInfo | 10 |
5 files changed, 73 insertions, 22 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 1c9eccd56..3b072a469 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -1932,7 +1932,26 @@ struct PrintExpressionContents } TypeNamePrinter(o, wasm).print(curr->type.getRtt().heapType); } + + // If we cannot print a valid unreachable instruction (say, a struct.get, + // where if the ref is unreachable, we don't know what heap type to print), + // then print the children in a block, which is good enough as this + // instruction is never reached anyhow. + // + // This function checks if the input is in fact unreachable, and if so, begins + // to emit a replacement for it and returns true. + bool printUnreachableReplacement(Expression* curr) { + if (curr->type == Type::unreachable) { + printMedium(o, "block"); + return true; + } + return false; + } + void visitStructNew(StructNew* curr) { + if (printUnreachableReplacement(curr->rtt)) { + return; + } printMedium(o, "struct.new_"); if (curr->isWithDefault()) { o << "default_"; @@ -1940,13 +1959,7 @@ struct PrintExpressionContents o << "with_rtt "; TypeNamePrinter(o, wasm).print(curr->rtt->type.getHeapType()); } - void printUnreachableReplacement() { - // If we cannot print a valid unreachable instruction (say, a struct.get, - // where if the ref is unreachable, we don't know what heap type to print), - // then print the children in a block, which is good enough as this - // instruction is never reached anyhow. - printMedium(o, "block"); - } + void printFieldName(HeapType type, Index index) { processFieldName(wasm, type, index, [&](Name name) { if (name.is()) { @@ -1957,8 +1970,7 @@ struct PrintExpressionContents }); } void visitStructGet(StructGet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(); + if (printUnreachableReplacement(curr->ref)) { return; } auto heapType = curr->ref->type.getHeapType(); @@ -1977,8 +1989,7 @@ struct PrintExpressionContents printFieldName(heapType, curr->index); } void visitStructSet(StructSet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(); + if (printUnreachableReplacement(curr->ref)) { return; } printMedium(o, "struct.set "); @@ -1996,8 +2007,7 @@ struct PrintExpressionContents TypeNamePrinter(o, wasm).print(curr->rtt->type.getHeapType()); } void visitArrayGet(ArrayGet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(); + if (printUnreachableReplacement(curr->ref)) { return; } const auto& element = curr->ref->type.getHeapType().getArray().element; @@ -2013,21 +2023,22 @@ struct PrintExpressionContents TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType()); } void visitArraySet(ArraySet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(); + if (printUnreachableReplacement(curr->ref)) { return; } printMedium(o, "array.set "); TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType()); } void visitArrayLen(ArrayLen* curr) { + if (printUnreachableReplacement(curr->ref)) { + return; + } printMedium(o, "array.len "); TypeNamePrinter(o, wasm).print(curr->ref->type.getHeapType()); } void visitArrayCopy(ArrayCopy* curr) { - if (curr->srcRef->type == Type::unreachable || - curr->destRef->type == Type::unreachable) { - printUnreachableReplacement(); + if (printUnreachableReplacement(curr->srcRef) || + printUnreachableReplacement(curr->destRef)) { return; } printMedium(o, "array.copy "); diff --git a/test/heap-types.wast b/test/heap-types.wast index 0f8c3840c..f62003da5 100644 --- a/test/heap-types.wast +++ b/test/heap-types.wast @@ -356,6 +356,20 @@ (unreachable) ) ) + (func $unreachables-array-6 + (drop + (array.len $vector + (unreachable) + ) + ) + ) + (func $unreachables-7 + (drop + (struct.new_default_with_rtt $struct.A + (unreachable) + ) + ) + ) (func $array-copy (param $x (ref $vector)) (param $y (ref null $vector)) (array.copy $vector $vector (local.get $x) diff --git a/test/heap-types.wast.from-wast b/test/heap-types.wast.from-wast index e6bd0f31e..ddc590ce7 100644 --- a/test/heap-types.wast.from-wast +++ b/test/heap-types.wast.from-wast @@ -1,8 +1,8 @@ (module (type $struct.A (struct (field i32) (field f32) (field $named f64))) + (type $none_=>_none (func)) (type $struct.B (struct (field i8) (field (mut i16)) (field (ref $struct.A)) (field (mut (ref $struct.A))))) (type $vector (array (mut f64))) - (type $none_=>_none (func)) (type $grandchild (struct (field i32) (field i64))) (type $struct.C (struct (field $named-mut (mut f32)))) (type $matrix (array (mut (ref null $vector)))) @@ -445,6 +445,20 @@ (unreachable) ) ) + (func $unreachables-array-6 + (drop + (block + (unreachable) + ) + ) + ) + (func $unreachables-7 + (drop + (block + (unreachable) + ) + ) + ) (func $array-copy (param $x (ref $vector)) (param $y (ref null $vector)) (array.copy $vector $vector (local.get $x) diff --git a/test/heap-types.wast.fromBinary b/test/heap-types.wast.fromBinary index d50532334..74c47eddf 100644 --- a/test/heap-types.wast.fromBinary +++ b/test/heap-types.wast.fromBinary @@ -1,8 +1,8 @@ (module (type $struct.A (struct (field i32) (field f32) (field $named f64))) + (type $none_=>_none (func)) (type $struct.B (struct (field i8) (field (mut i16)) (field (ref $struct.A)) (field (mut (ref $struct.A))))) (type $vector (array (mut f64))) - (type $none_=>_none (func)) (type $grandchild (struct (field i32) (field i64))) (type $matrix (array (mut (ref null $vector)))) (type $struct.C (struct (field $named-mut (mut f32)))) @@ -408,6 +408,12 @@ ) (unreachable) ) + (func $unreachables-array-6 + (unreachable) + ) + (func $unreachables-7 + (unreachable) + ) (func $array-copy (param $x (ref $vector)) (param $y (ref null $vector)) (array.copy $vector $vector (local.get $x) diff --git a/test/heap-types.wast.fromBinary.noDebugInfo b/test/heap-types.wast.fromBinary.noDebugInfo index 3d1f00a7c..66caa798a 100644 --- a/test/heap-types.wast.fromBinary.noDebugInfo +++ b/test/heap-types.wast.fromBinary.noDebugInfo @@ -1,8 +1,8 @@ (module (type ${i32_f32_f64} (struct (field i32) (field f32) (field f64))) + (type $none_=>_none (func)) (type ${i8_mut:i16_ref|{i32_f32_f64}|_mut:ref|{i32_f32_f64}|} (struct (field i8) (field (mut i16)) (field (ref ${i32_f32_f64})) (field (mut (ref ${i32_f32_f64}))))) (type $[mut:f64] (array (mut f64))) - (type $none_=>_none (func)) (type ${i32_i64} (struct (field i32) (field i64))) (type $[mut:ref?|[mut:f64]|] (array (mut (ref null $[mut:f64])))) (type ${mut:f32} (struct (field (mut f32)))) @@ -408,7 +408,13 @@ ) (unreachable) ) - (func $17 (param $0 (ref $[mut:f64])) (param $1 (ref null $[mut:f64])) + (func $17 + (unreachable) + ) + (func $18 + (unreachable) + ) + (func $19 (param $0 (ref $[mut:f64])) (param $1 (ref null $[mut:f64])) (array.copy $[mut:f64] $[mut:f64] (local.get $0) (i32.const 11) |