diff options
-rw-r--r-- | src/passes/Print.cpp | 28 | ||||
-rw-r--r-- | test/lit/nominal-named-field.wast | 30 |
2 files changed, 44 insertions, 14 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 8c7b221fd..1c9eccd56 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2429,27 +2429,28 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { visitExpression(curr); } // Module-level visitors - void handleSignature(Signature curr, Name name = Name()) { + void handleSignature(HeapType curr, Name name = Name()) { + Signature sig = curr.getSignature(); o << "(func"; if (name.is()) { o << " $" << name; } - if (curr.params.size() > 0) { + if (sig.params.size() > 0) { o << maybeSpace; o << "(param "; auto sep = ""; - for (auto type : curr.params) { + for (auto type : sig.params) { o << sep; printType(o, type, currModule); sep = " "; } o << ')'; } - if (curr.results.size() > 0) { + if (sig.results.size() > 0) { o << maybeSpace; o << "(result "; auto sep = ""; - for (auto type : curr.results) { + for (auto type : sig.results) { o << sep; printType(o, type, currModule); sep = " "; @@ -2477,19 +2478,18 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << ')'; } } - void handleArray(const Array& curr) { + void handleArray(HeapType curr) { o << "(array "; - handleFieldBody(curr.element); + handleFieldBody(curr.getArray().element); o << ')'; } - void handleStruct(const Struct& curr) { - auto type = HeapType(curr); - const auto& fields = curr.fields; + void handleStruct(HeapType curr) { + const auto& fields = curr.getStruct().fields; o << "(struct "; auto sep = ""; for (Index i = 0; i < fields.size(); i++) { o << sep << "(field "; - processFieldName(currModule, type, i, [&](Name name) { + processFieldName(currModule, curr, i, [&](Name name) { if (name.is()) { o << '$' << name << ' '; } @@ -2502,11 +2502,11 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } void handleHeapType(HeapType type, Module* module) { if (type.isSignature()) { - handleSignature(type.getSignature()); + handleSignature(type); } else if (type.isArray()) { - handleArray(type.getArray()); + handleArray(type); } else if (type.isStruct()) { - handleStruct(type.getStruct()); + handleStruct(type); } else { o << type; } diff --git a/test/lit/nominal-named-field.wast b/test/lit/nominal-named-field.wast new file mode 100644 index 000000000..5dd33d99e --- /dev/null +++ b/test/lit/nominal-named-field.wast @@ -0,0 +1,30 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; Regression test for a bug in which field names were not printed in nominal mode. + +;; RUN: wasm-opt %s -all --nominal -S -o - | filecheck %s +;; RUN: wasm-opt %s -all --nominal --roundtrip -S -o - | filecheck %s + +(module + ;; CHECK: (type $struct (struct (field (mut i32)) (field f32) (field $named f64))) + (type $struct (struct + (field (mut i32)) + (field f32) + (field $named f64) + )) + + ;; CHECK: (func $foo (param $0 (ref $struct)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.get $struct $named + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $foo (param (ref $struct)) + (drop + (struct.get $struct $named + (local.get 0) + ) + ) + ) +) |