diff options
author | Alon Zakai <azakai@google.com> | 2022-12-15 14:02:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 22:02:53 +0000 |
commit | a9ebf0dd842dc5b239a233177cfc9ccbd675fba7 (patch) | |
tree | aadf98032ac8c13bc1d466492072961907bb3ab9 /test/lit/binary/stacky-eh.test | |
parent | bead42c46d48e4c5584f035f7a805911dc59ae35 (diff) | |
download | binaryen-a9ebf0dd842dc5b239a233177cfc9ccbd675fba7.tar.gz binaryen-a9ebf0dd842dc5b239a233177cfc9ccbd675fba7.tar.bz2 binaryen-a9ebf0dd842dc5b239a233177cfc9ccbd675fba7.zip |
In --debug mode, print partial wasm data that was read (#5356)
If wasm-opt or wasm-dis are given an invalid binary, after the error
message we can also print out the wasm we did manage to read. That
includes global stuff like imports and also all the functions up until
there. This can help debugging in some situations.
Only do this when --debug is passed as it can be very verbose and
in general users might not want it.
This is technically easy to do, it turns out, since we already use a
thrown exception on an error in parsing, and we fill up the wasm as
we go, so it just contains what we've read so far, and we can just
print it.
Fixes #5344
Also switch an existing test's comments to ;; from # which was
noticed here.
Diffstat (limited to 'test/lit/binary/stacky-eh.test')
-rw-r--r-- | test/lit/binary/stacky-eh.test | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/test/lit/binary/stacky-eh.test b/test/lit/binary/stacky-eh.test index 09406bfea..0811b28ff 100644 --- a/test/lit/binary/stacky-eh.test +++ b/test/lit/binary/stacky-eh.test @@ -1,66 +1,66 @@ -# Verify stacky EH binary can be parsed correctly. -# -# stacky-eh.test.wasm contains below: -# try -# nop -# catch 0 # tag type i32 -# i32.const 3 -# local.set 1 -# local.set 2 -# -# (This binary was generated by -# 'wasm-opt --optimize-level=3 --generate-stack-ir -optimize-stack-ir') -# -# This code is 'stacky' in Binaryen parlance. In the binary reader, Binaryen has -# a special routine of creating a block and a local.get/local.set to read stacky -# code into Binaryen AST. So if we don't do any post-fixup, the 'catch' block -# becomes: -# (catch $e-i32 -# (local.set 2 -# (block (result i32) -# (local.set $new -# (pop i32) -# ) -# (local.set 1 -# (i32.const 3) -# ) -# (local.get $new) -# ) -# ) -# ) -# Here the 'block' and `local $new' are newly created to read the stacky code. -# But now the 'pop' ends up nested within the 'block', which is invalid. This -# test tests if this invalid code is correctly fixed up in the binary reader. -# The fixup will hoist the 'pop' and create another local to store it right -# after 'catch'. +;; Verify stacky EH binary can be parsed correctly. +;; +;; stacky-eh.test.wasm contains below: +;; try +;; nop +;; catch 0 # tag type i32 +;; i32.const 3 +;; local.set 1 +;; local.set 2 +;; +;; (This binary was generated by +;; 'wasm-opt --optimize-level=3 --generate-stack-ir -optimize-stack-ir') +;; +;; This code is 'stacky' in Binaryen parlance. In the binary reader, Binaryen has +;; a special routine of creating a block and a local.get/local.set to read stacky +;; code into Binaryen AST. So if we don't do any post-fixup, the 'catch' block +;; becomes: +;; (catch $e-i32 +;; (local.set 2 +;; (block (result i32) +;; (local.set $new +;; (pop i32) +;; ) +;; (local.set 1 +;; (i32.const 3) +;; ) +;; (local.get $new) +;; ) +;; ) +;; ) +;; Here the 'block' and `local $new' are newly created to read the stacky code. +;; But now the 'pop' ends up nested within the 'block', which is invalid. This +;; test tests if this invalid code is correctly fixed up in the binary reader. +;; The fixup will hoist the 'pop' and create another local to store it right +;; after 'catch'. RUN: wasm-opt -all %s.wasm --print | filecheck %s -# CHECK: (func $0 -# CHECK-NEXT: (local $0 i32) -# CHECK-NEXT: (local $1 i32) -# CHECK-NEXT: (local $2 i32) -# CHECK-NEXT: (local $3 i32) -# CHECK-NEXT: (local $4 i32) -# CHECK-NEXT: (try $label$3 -# CHECK-NEXT: (do -# CHECK-NEXT: (nop) -# CHECK-NEXT: ) -# CHECK-NEXT: (catch $tag$0 -# CHECK-NEXT: (local.set $4 -# CHECK-NEXT: (pop i32) -# CHECK-NEXT: ) -# CHECK-NEXT: (local.set $2 -# CHECK-NEXT: (block (result i32) -# CHECK-NEXT: (local.set $3 -# CHECK-NEXT: (local.get $4) -# CHECK-NEXT: ) -# CHECK-NEXT: (local.set $1 -# CHECK-NEXT: (i32.const 3) -# CHECK-NEXT: ) -# CHECK-NEXT: (local.get $3) -# CHECK-NEXT: ) -# CHECK-NEXT: ) -# CHECK-NEXT: ) -# CHECK-NEXT: ) -# CHECK-NEXT: ) +;; CHECK: (func $0 +;; CHECK-NEXT: (local $0 i32) +;; CHECK-NEXT: (local $1 i32) +;; CHECK-NEXT: (local $2 i32) +;; CHECK-NEXT: (local $3 i32) +;; CHECK-NEXT: (local $4 i32) +;; CHECK-NEXT: (try $label$3 +;; CHECK-NEXT: (do +;; CHECK-NEXT: (nop) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (catch $tag$0 +;; CHECK-NEXT: (local.set $4 +;; CHECK-NEXT: (pop i32) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (local.set $2 +;; CHECK-NEXT: (block (result i32) +;; CHECK-NEXT: (local.set $3 +;; CHECK-NEXT: (local.get $4) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (local.set $1 +;; CHECK-NEXT: (i32.const 3) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (local.get $3) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) |