diff options
author | Thomas Lively <tlively@google.com> | 2021-06-17 07:28:44 -0700 |
---|---|---|
committer | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-06-17 14:35:56 -0400 |
commit | ea0b9ee1e1083962da9bfa52fa09870fcc4f72bb (patch) | |
tree | 57503487eaf47f18d93e5601f402084c94b7ad46 /test | |
parent | 8de4349ebdb6ce398ef4939f9f375a7413d99b09 (diff) | |
download | binaryen-ea0b9ee1e1083962da9bfa52fa09870fcc4f72bb.tar.gz binaryen-ea0b9ee1e1083962da9bfa52fa09870fcc4f72bb.tar.bz2 binaryen-ea0b9ee1e1083962da9bfa52fa09870fcc4f72bb.zip |
Add a extract-function-index pass
This is a useful alternative to extract-function when you don't know the
function's name.
Also moves the extract-function tests to be lit tests and re-uses them as
extract-function-index tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/extract-function.wast | 72 | ||||
-rw-r--r-- | test/passes/extract-function=foo.txt | 28 | ||||
-rw-r--r-- | test/passes/extract-function=foo.wast | 36 | ||||
-rw-r--r-- | test/passes/extract-function_pass-arg=extract-function@foo.txt | 28 | ||||
-rw-r--r-- | test/passes/extract-function_pass-arg=extract-function@foo.wast | 36 |
5 files changed, 72 insertions, 128 deletions
diff --git a/test/lit/passes/extract-function.wast b/test/lit/passes/extract-function.wast new file mode 100644 index 000000000..1a8970598 --- /dev/null +++ b/test/lit/passes/extract-function.wast @@ -0,0 +1,72 @@ +;; RUN: foreach %s %t wasm-opt --extract-function=foo -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --extract-function --pass-arg=extract-function@foo -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --extract-function-index=0 -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --extract-function-index --pass-arg=extract-function-index@0 -S -o - | filecheck %s + +;; CHECK: (module +;; CHECK-NEXT: (type $none_=>_none (func)) +;; CHECK-NEXT: (import "env" "bar" (func $bar)) +;; CHECK-NEXT: (export "foo" (func $foo)) +;; CHECK-NEXT: (func $foo +;; CHECK-NEXT: (call $bar) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +(module + (func $foo + (call $bar) + ) + (func $bar + (call $foo) + ) + (func $other + (drop (i32.const 1)) + ) +) + +;; CHECK: (module +;; CHECK-NEXT: (type $none_=>_none (func)) +;; CHECK-NEXT: (import "env" "other" (func $other)) +;; CHECK-NEXT: (export "foo" (func $foo)) +;; CHECK-NEXT: (func $foo +;; CHECK-NEXT: (nop) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +(module + ;; Use another function in the table, but the table is not used in the + ;; extracted function + (table $t 10 funcref) + (elem $0 (table $t) (i32.const 0) func $other) + (func $foo + (nop) + ) + (func $other + (drop (i32.const 1)) + ) +) + +;; CHECK: (module +;; CHECK-NEXT: (type $none (func)) +;; CHECK-NEXT: (import "env" "other" (func $other)) +;; CHECK-NEXT: (table $t 10 funcref) +;; CHECK-NEXT: (elem $0 (i32.const 0) $other) +;; CHECK-NEXT: (export "foo" (func $foo)) +;; CHECK-NEXT: (func $foo +;; CHECK-NEXT: (call_indirect (type $none) +;; CHECK-NEXT: (i32.const 10) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +(module + ;; Use another function in the table, and the table *is* used. As a result, + ;; the table and its elements will remain. The called function, $other, will + ;; remain as an import that is placed in the table. + (type $none (func)) + (table $t 10 funcref) + (elem $0 (table $t) (i32.const 0) func $other) + (func $foo + (call_indirect (type $none) (i32.const 10)) + ) + (func $other + (drop (i32.const 1)) + ) +) diff --git a/test/passes/extract-function=foo.txt b/test/passes/extract-function=foo.txt deleted file mode 100644 index 3caf274c3..000000000 --- a/test/passes/extract-function=foo.txt +++ /dev/null @@ -1,28 +0,0 @@ -(module - (type $none_=>_none (func)) - (import "env" "bar" (func $bar)) - (export "foo" (func $foo)) - (func $foo - (call $bar) - ) -) -(module - (type $none_=>_none (func)) - (import "env" "other" (func $other)) - (export "foo" (func $foo)) - (func $foo - (nop) - ) -) -(module - (type $none (func)) - (import "env" "other" (func $other)) - (table $t 10 funcref) - (elem $0 (i32.const 0) $other) - (export "foo" (func $foo)) - (func $foo - (call_indirect (type $none) - (i32.const 10) - ) - ) -) diff --git a/test/passes/extract-function=foo.wast b/test/passes/extract-function=foo.wast deleted file mode 100644 index ab1d8b269..000000000 --- a/test/passes/extract-function=foo.wast +++ /dev/null @@ -1,36 +0,0 @@ -(module - (func $foo - (call $bar) - ) - (func $bar - (call $foo) - ) - (func $other - (drop (i32.const 1)) - ) -) -(module - ;; Use another function in the table, but the table is not used in the - ;; extracted function - (table $t 10 funcref) - (elem $0 (table $t) (i32.const 0) func $other) - (func $foo - ) - (func $other - (drop (i32.const 1)) - ) -) -(module - ;; Use another function in the table, and the table *is* used. As a result, - ;; the table and its elements will remain. The called function, $other, will - ;; remain as an import that is placed in the table. - (type $none (func)) - (table $t 10 funcref) - (elem $0 (table $t) (i32.const 0) func $other) - (func $foo - (call_indirect (type $none) (i32.const 10)) - ) - (func $other - (drop (i32.const 1)) - ) -) diff --git a/test/passes/extract-function_pass-arg=extract-function@foo.txt b/test/passes/extract-function_pass-arg=extract-function@foo.txt deleted file mode 100644 index 3caf274c3..000000000 --- a/test/passes/extract-function_pass-arg=extract-function@foo.txt +++ /dev/null @@ -1,28 +0,0 @@ -(module - (type $none_=>_none (func)) - (import "env" "bar" (func $bar)) - (export "foo" (func $foo)) - (func $foo - (call $bar) - ) -) -(module - (type $none_=>_none (func)) - (import "env" "other" (func $other)) - (export "foo" (func $foo)) - (func $foo - (nop) - ) -) -(module - (type $none (func)) - (import "env" "other" (func $other)) - (table $t 10 funcref) - (elem $0 (i32.const 0) $other) - (export "foo" (func $foo)) - (func $foo - (call_indirect (type $none) - (i32.const 10) - ) - ) -) diff --git a/test/passes/extract-function_pass-arg=extract-function@foo.wast b/test/passes/extract-function_pass-arg=extract-function@foo.wast deleted file mode 100644 index ab1d8b269..000000000 --- a/test/passes/extract-function_pass-arg=extract-function@foo.wast +++ /dev/null @@ -1,36 +0,0 @@ -(module - (func $foo - (call $bar) - ) - (func $bar - (call $foo) - ) - (func $other - (drop (i32.const 1)) - ) -) -(module - ;; Use another function in the table, but the table is not used in the - ;; extracted function - (table $t 10 funcref) - (elem $0 (table $t) (i32.const 0) func $other) - (func $foo - ) - (func $other - (drop (i32.const 1)) - ) -) -(module - ;; Use another function in the table, and the table *is* used. As a result, - ;; the table and its elements will remain. The called function, $other, will - ;; remain as an import that is placed in the table. - (type $none (func)) - (table $t 10 funcref) - (elem $0 (table $t) (i32.const 0) func $other) - (func $foo - (call_indirect (type $none) (i32.const 10)) - ) - (func $other - (drop (i32.const 1)) - ) -) |