summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/binaryen.js/exception-handling.js.txt8
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt42
-rw-r--r--test/lit/table-operations.wast108
-rw-r--r--test/spec/table_get.wast79
4 files changed, 212 insertions, 25 deletions
diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt
index 823b638f5..a1a1879bd 100644
--- a/test/binaryen.js/exception-handling.js.txt
+++ b/test/binaryen.js/exception-handling.js.txt
@@ -34,7 +34,7 @@
)
)
-getExpressionInfo(throw) = {"id":46,"type":1,"tag":"e"}
-getExpressionInfo(rethrow) = {"id":47,"type":1,"target":"l0"}
-getExpressionInfo(try_catch) = {"id":45,"type":1,"name":"l0","hasCatchAll":0,"delegateTarget":"","isDelegate":0}
-getExpressionInfo(try_delegate) = {"id":45,"type":0,"name":"try_outer","hasCatchAll":1,"delegateTarget":"","isDelegate":0}
+getExpressionInfo(throw) = {"id":47,"type":1,"tag":"e"}
+getExpressionInfo(rethrow) = {"id":48,"type":1,"target":"l0"}
+getExpressionInfo(try_catch) = {"id":46,"type":1,"name":"l0","hasCatchAll":0,"delegateTarget":"","isDelegate":0}
+getExpressionInfo(try_delegate) = {"id":46,"type":0,"name":"try_outer","hasCatchAll":1,"delegateTarget":"","isDelegate":0}
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index 21413d87a..f971e1a07 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -88,27 +88,27 @@ RefNullId: 41
RefIsId: 42
RefFuncId: 43
RefEqId: 44
-TryId: 45
-ThrowId: 46
-RethrowId: 47
-TupleMakeId: 48
-TupleExtractId: 49
-I31NewId: 50
-I31GetId: 51
-CallRefId: 52
-RefTestId: 53
-RefCastId: 54
-BrOnId: 55
-RttCanonId: 56
-RttSubId: 57
-StructNewId: 58
-StructGetId: 59
-StructSetId: 60
-ArrayNewId: 61
-ArrayInitId: 62
-ArrayGetId: 63
-ArraySetId: 64
-ArrayLenId: 65
+TryId: 46
+ThrowId: 47
+RethrowId: 48
+TupleMakeId: 49
+TupleExtractId: 50
+I31NewId: 51
+I31GetId: 52
+CallRefId: 53
+RefTestId: 54
+RefCastId: 55
+BrOnId: 56
+RttCanonId: 57
+RttSubId: 58
+StructNewId: 59
+StructGetId: 60
+StructSetId: 61
+ArrayNewId: 62
+ArrayInitId: 63
+ArrayGetId: 64
+ArraySetId: 65
+ArrayLenId: 66
getExpressionInfo={"id":15,"type":4,"op":6}
(f32.neg
(f32.const -33.61199951171875)
diff --git a/test/lit/table-operations.wast b/test/lit/table-operations.wast
new file mode 100644
index 000000000..6e303b495
--- /dev/null
+++ b/test/lit/table-operations.wast
@@ -0,0 +1,108 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: wasm-as %s -all -g -o %t.wasm
+;; RUN: wasm-dis %t.wasm -all -o %t.wast
+;; RUN: wasm-as %s -all -o %t.nodebug.wasm
+;; RUN: wasm-dis %t.nodebug.wasm -all -o %t.nodebug.wast
+;; RUN: wasm-opt %t.wast -all -o %t.text.wast -g -S
+;; RUN: cat %t.wast | filecheck %s --check-prefix=CHECK-BINARY
+;; RUN: cat %t.nodebug.wast | filecheck %s --check-prefix=CHECK-NODEBUG
+;; RUN: cat %t.text.wast | filecheck %s --check-prefix=CHECK-TEXT
+
+(module
+ ;; CHECK-BINARY: (type $none_=>_none (func))
+
+ ;; CHECK-BINARY: (table $table-1 1 1 funcref)
+ ;; CHECK-TEXT: (type $none_=>_none (func))
+
+ ;; CHECK-TEXT: (table $table-1 1 1 funcref)
+ (table $table-1 funcref
+ (elem $foo)
+ )
+
+ ;; CHECK-BINARY: (table $table-2 3 3 funcref)
+ ;; CHECK-TEXT: (table $table-2 3 3 funcref)
+ (table $table-2 funcref
+ (elem $bar $bar $bar)
+ )
+
+ ;; CHECK-BINARY: (elem $0 (table $table-1) (i32.const 0) func $foo)
+
+ ;; CHECK-BINARY: (elem $1 (table $table-2) (i32.const 0) func $bar $bar $bar)
+
+ ;; CHECK-BINARY: (func $foo
+ ;; CHECK-BINARY-NEXT: (nop)
+ ;; CHECK-BINARY-NEXT: )
+ ;; CHECK-TEXT: (elem $0 (table $table-1) (i32.const 0) func $foo)
+
+ ;; CHECK-TEXT: (elem $1 (table $table-2) (i32.const 0) func $bar $bar $bar)
+
+ ;; CHECK-TEXT: (func $foo
+ ;; CHECK-TEXT-NEXT: (nop)
+ ;; CHECK-TEXT-NEXT: )
+ (func $foo
+ (nop)
+ )
+ ;; CHECK-BINARY: (func $bar
+ ;; CHECK-BINARY-NEXT: (drop
+ ;; CHECK-BINARY-NEXT: (table.get $table-1
+ ;; CHECK-BINARY-NEXT: (i32.const 0)
+ ;; CHECK-BINARY-NEXT: )
+ ;; CHECK-BINARY-NEXT: )
+ ;; CHECK-BINARY-NEXT: (drop
+ ;; CHECK-BINARY-NEXT: (table.get $table-2
+ ;; CHECK-BINARY-NEXT: (i32.const 100)
+ ;; CHECK-BINARY-NEXT: )
+ ;; CHECK-BINARY-NEXT: )
+ ;; CHECK-BINARY-NEXT: )
+ ;; CHECK-TEXT: (func $bar
+ ;; CHECK-TEXT-NEXT: (drop
+ ;; CHECK-TEXT-NEXT: (table.get $table-1
+ ;; CHECK-TEXT-NEXT: (i32.const 0)
+ ;; CHECK-TEXT-NEXT: )
+ ;; CHECK-TEXT-NEXT: )
+ ;; CHECK-TEXT-NEXT: (drop
+ ;; CHECK-TEXT-NEXT: (table.get $table-2
+ ;; CHECK-TEXT-NEXT: (i32.const 100)
+ ;; CHECK-TEXT-NEXT: )
+ ;; CHECK-TEXT-NEXT: )
+ ;; CHECK-TEXT-NEXT: )
+ (func $bar
+ (drop
+ (table.get $table-1
+ (i32.const 0)
+ )
+ )
+ (drop
+ (table.get $table-2
+ (i32.const 100)
+ )
+ )
+ )
+)
+;; CHECK-NODEBUG: (type $none_=>_none (func))
+
+;; CHECK-NODEBUG: (table $0 1 1 funcref)
+
+;; CHECK-NODEBUG: (table $1 3 3 funcref)
+
+;; CHECK-NODEBUG: (elem $0 (table $0) (i32.const 0) func $0)
+
+;; CHECK-NODEBUG: (elem $1 (table $1) (i32.const 0) func $1 $1 $1)
+
+;; CHECK-NODEBUG: (func $0
+;; CHECK-NODEBUG-NEXT: (nop)
+;; CHECK-NODEBUG-NEXT: )
+
+;; CHECK-NODEBUG: (func $1
+;; CHECK-NODEBUG-NEXT: (drop
+;; CHECK-NODEBUG-NEXT: (table.get $0
+;; CHECK-NODEBUG-NEXT: (i32.const 0)
+;; CHECK-NODEBUG-NEXT: )
+;; CHECK-NODEBUG-NEXT: )
+;; CHECK-NODEBUG-NEXT: (drop
+;; CHECK-NODEBUG-NEXT: (table.get $1
+;; CHECK-NODEBUG-NEXT: (i32.const 100)
+;; CHECK-NODEBUG-NEXT: )
+;; CHECK-NODEBUG-NEXT: )
+;; CHECK-NODEBUG-NEXT: )
diff --git a/test/spec/table_get.wast b/test/spec/table_get.wast
new file mode 100644
index 000000000..de5f6622a
--- /dev/null
+++ b/test/spec/table_get.wast
@@ -0,0 +1,79 @@
+(module
+ (table $t2 2 externref)
+ (table $t3 3 funcref)
+ (elem (table $t3) (i32.const 1) func $dummy)
+ (func $dummy)
+
+ (func (export "get-externref") (param $i i32) (result externref)
+ (table.get $t2 (local.get $i))
+ )
+ (func $f3 (export "get-funcref") (param $i i32) (result funcref)
+ (table.get $t3 (local.get $i))
+ )
+
+ (func (export "is_null-funcref") (param $i i32) (result i32)
+ (ref.is_null (call $f3 (local.get $i)))
+ )
+)
+
+(assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern))
+
+(assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func))
+(assert_return (invoke "is_null-funcref" (i32.const 1)) (i32.const 0))
+
+(assert_trap (invoke "get-externref" (i32.const 2)) "out of bounds")
+(assert_trap (invoke "get-funcref" (i32.const 3)) "out of bounds")
+(assert_trap (invoke "get-externref" (i32.const -1)) "out of bounds")
+(assert_trap (invoke "get-funcref" (i32.const -1)) "out of bounds")
+
+
+;; Type errors
+
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-index-empty-vs-i32 (result externref)
+ (table.get $t)
+ )
+ )
+ "type mismatch"
+)
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-index-f32-vs-i32 (result externref)
+ (table.get $t (f32.const 1))
+ )
+ )
+ "type mismatch"
+)
+
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-result-externref-vs-empty
+ (table.get $t (i32.const 0))
+ )
+ )
+ "type mismatch"
+)
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-result-externref-vs-funcref (result funcref)
+ (table.get $t (i32.const 1))
+ )
+ )
+ "type mismatch"
+)
+
+(assert_invalid
+ (module
+ (table $t1 1 funcref)
+ (table $t2 1 externref)
+ (func $type-result-externref-vs-funcref-multi (result funcref)
+ (table.get $t2 (i32.const 0))
+ )
+ )
+ "type mismatch"
+)