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.js2
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt44
-rw-r--r--test/binaryen.js/sideffects.js2
-rw-r--r--test/binaryen.js/sideffects.js.txt14
-rw-r--r--test/example/c-api-kitchen-sink.c14
-rw-r--r--test/example/c-api-kitchen-sink.txt7
-rw-r--r--test/lit/table-operations.wast46
-rw-r--r--test/spec/table_set.wast119
9 files changed, 225 insertions, 31 deletions
diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt
index a1a1879bd..75ca8b5cb 100644
--- a/test/binaryen.js/exception-handling.js.txt
+++ b/test/binaryen.js/exception-handling.js.txt
@@ -34,7 +34,7 @@
)
)
-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}
+getExpressionInfo(throw) = {"id":48,"type":1,"tag":"e"}
+getExpressionInfo(rethrow) = {"id":49,"type":1,"target":"l0"}
+getExpressionInfo(try_catch) = {"id":47,"type":1,"name":"l0","hasCatchAll":0,"delegateTarget":"","isDelegate":0}
+getExpressionInfo(try_delegate) = {"id":47,"type":0,"name":"try_outer","hasCatchAll":1,"delegateTarget":"","isDelegate":0}
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index be7363ae5..f2da5d0a0 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -164,6 +164,8 @@ function test_ids() {
console.log("RefIsId: " + binaryen.RefIsId);
console.log("RefFuncId: " + binaryen.RefFuncId);
console.log("RefEqId: " + binaryen.RefEqId);
+ console.log("TableGetId: " + binaryen.TableGetId);
+ console.log("TableSetId: " + binaryen.TableSetId);
console.log("TryId: " + binaryen.TryId);
console.log("ThrowId: " + binaryen.ThrowId);
console.log("RethrowId: " + binaryen.RethrowId);
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index f971e1a07..54a18cd54 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -88,27 +88,29 @@ RefNullId: 41
RefIsId: 42
RefFuncId: 43
RefEqId: 44
-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
+TableGetId: 45
+TableSetId: 46
+TryId: 47
+ThrowId: 48
+RethrowId: 49
+TupleMakeId: 50
+TupleExtractId: 51
+I31NewId: 52
+I31GetId: 53
+CallRefId: 54
+RefTestId: 55
+RefCastId: 56
+BrOnId: 57
+RttCanonId: 58
+RttSubId: 59
+StructNewId: 60
+StructGetId: 61
+StructSetId: 62
+ArrayNewId: 63
+ArrayInitId: 64
+ArrayGetId: 65
+ArraySetId: 66
+ArrayLenId: 67
getExpressionInfo={"id":15,"type":4,"op":6}
(f32.neg
(f32.const -33.61199951171875)
diff --git a/test/binaryen.js/sideffects.js b/test/binaryen.js/sideffects.js
index eb6f4fc63..654c51608 100644
--- a/test/binaryen.js/sideffects.js
+++ b/test/binaryen.js/sideffects.js
@@ -7,6 +7,8 @@ console.log("SideEffects.ReadsGlobal=" + binaryen.SideEffects.ReadsGlobal);
console.log("SideEffects.WritesGlobal=" + binaryen.SideEffects.WritesGlobal);
console.log("SideEffects.ReadsMemory=" + binaryen.SideEffects.ReadsMemory);
console.log("SideEffects.WritesMemory=" + binaryen.SideEffects.WritesMemory);
+console.log("SideEffects.ReadsTable=" + binaryen.SideEffects.ReadsTable);
+console.log("SideEffects.WritesTable=" + binaryen.SideEffects.WritesTable);
console.log("SideEffects.ImplicitTrap=" + binaryen.SideEffects.ImplicitTrap);
console.log("SideEffects.IsAtomic=" + binaryen.SideEffects.IsAtomic);
console.log("SideEffects.Throws=" + binaryen.SideEffects.Throws);
diff --git a/test/binaryen.js/sideffects.js.txt b/test/binaryen.js/sideffects.js.txt
index 8e511d089..b582d70bd 100644
--- a/test/binaryen.js/sideffects.js.txt
+++ b/test/binaryen.js/sideffects.js.txt
@@ -7,9 +7,11 @@ SideEffects.ReadsGlobal=16
SideEffects.WritesGlobal=32
SideEffects.ReadsMemory=64
SideEffects.WritesMemory=128
-SideEffects.ImplicitTrap=256
-SideEffects.IsAtomic=512
-SideEffects.Throws=1024
-SideEffects.DanglingPop=2048
-SideEffects.TrapsNeverHappen=4096
-SideEffects.Any=8191
+SideEffects.ReadsTable=256
+SideEffects.WritesTable=512
+SideEffects.ImplicitTrap=1024
+SideEffects.IsAtomic=2048
+SideEffects.Throws=4096
+SideEffects.DanglingPop=8192
+SideEffects.TrapsNeverHappen=16384
+SideEffects.Any=32767
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index 5db1d28dc..894fc1454 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -1012,6 +1012,20 @@ void test_core() {
BinaryenAddPassiveElementSegment(module, "p2", funcNames, 1);
BinaryenRemoveElementSegment(module, "p2");
+ BinaryenExpressionRef funcrefExpr1 =
+ BinaryenRefFunc(module, "kitchen()sinker", BinaryenTypeFuncref());
+
+ BinaryenExpressionPrint(BinaryenTableSet(
+ module, "0", BinaryenConst(module, BinaryenLiteralInt32(0)), funcrefExpr1));
+
+ BinaryenExpressionRef funcrefExpr2 =
+ BinaryenTableGet(module,
+ "0",
+ BinaryenConst(module, BinaryenLiteralInt32(0)),
+ BinaryenTypeFuncref());
+
+ BinaryenExpressionPrint(funcrefExpr2);
+
// Memory. One per module
const char* segments[] = {"hello, world", "I am passive"};
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 3372ba8b6..c28e0536d 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -31,6 +31,13 @@ BinaryenFeatureAll: 32767
(f32.neg
(f32.const -33.61199951171875)
)
+(table.set $0
+ (i32.const 0)
+ (ref.func "$kitchen()sinker")
+)
+(table.get $0
+ (i32.const 0)
+)
(module
(type $i32_i64_f32_f64_=>_i32 (func (param i32 i64 f32 f64) (result i32)))
(type $i32_=>_none (func (param i32)))
diff --git a/test/lit/table-operations.wast b/test/lit/table-operations.wast
index 6e303b495..555708c07 100644
--- a/test/lit/table-operations.wast
+++ b/test/lit/table-operations.wast
@@ -79,6 +79,40 @@
)
)
)
+
+ ;; CHECK-BINARY: (func $set-get
+ ;; CHECK-BINARY-NEXT: (table.set $table-1
+ ;; CHECK-BINARY-NEXT: (i32.const 0)
+ ;; CHECK-BINARY-NEXT: (ref.func $foo)
+ ;; CHECK-BINARY-NEXT: )
+ ;; 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: )
+ ;; CHECK-TEXT: (func $set-get
+ ;; CHECK-TEXT-NEXT: (table.set $table-1
+ ;; CHECK-TEXT-NEXT: (i32.const 0)
+ ;; CHECK-TEXT-NEXT: (ref.func $foo)
+ ;; CHECK-TEXT-NEXT: )
+ ;; 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: )
+ (func $set-get
+ (table.set $table-1
+ (i32.const 0)
+ (ref.func $foo)
+ )
+ (drop
+ (table.get $table-1
+ (i32.const 0)
+ )
+ )
+ )
)
;; CHECK-NODEBUG: (type $none_=>_none (func))
@@ -106,3 +140,15 @@
;; CHECK-NODEBUG-NEXT: )
;; CHECK-NODEBUG-NEXT: )
;; CHECK-NODEBUG-NEXT: )
+
+;; CHECK-NODEBUG: (func $2
+;; CHECK-NODEBUG-NEXT: (table.set $0
+;; CHECK-NODEBUG-NEXT: (i32.const 0)
+;; CHECK-NODEBUG-NEXT: (ref.func $0)
+;; CHECK-NODEBUG-NEXT: )
+;; 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: )
diff --git a/test/spec/table_set.wast b/test/spec/table_set.wast
new file mode 100644
index 000000000..6034f146f
--- /dev/null
+++ b/test/spec/table_set.wast
@@ -0,0 +1,119 @@
+(module
+ (table $t2 1 externref)
+ (table $t3 2 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 "set-externref") (param $i i32) (param $r externref)
+ (table.set $t2 (local.get $i) (local.get $r))
+ )
+ (func (export "set-funcref") (param $i i32) (param $r funcref)
+ (table.set $t3 (local.get $i) (local.get $r))
+ )
+ (func (export "set-funcref-from") (param $i i32) (param $j i32)
+ (table.set $t3 (local.get $i) (table.get $t3 (local.get $j)))
+ )
+
+ (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 "set-externref" (i32.const 0) (ref.extern 1)))
+;; (assert_return (invoke "get-externref" (i32.const 0)) (ref.extern 1))
+(assert_return (invoke "set-externref" (i32.const 0) (ref.null extern)))
+(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 "set-funcref-from" (i32.const 0) (i32.const 1)))
+(assert_return (invoke "is_null-funcref" (i32.const 0)) (i32.const 0))
+(assert_return (invoke "set-funcref" (i32.const 0) (ref.null func)))
+(assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func))
+
+(assert_trap (invoke "set-externref" (i32.const 2) (ref.null extern)) "out of bounds table access")
+(assert_trap (invoke "set-funcref" (i32.const 3) (ref.null func)) "out of bounds table access")
+(assert_trap (invoke "set-externref" (i32.const -1) (ref.null extern)) "out of bounds table access")
+(assert_trap (invoke "set-funcref" (i32.const -1) (ref.null func)) "out of bounds table access")
+
+;; (assert_trap (invoke "set-externref" (i32.const 2) (ref.extern 0)) "out of bounds table access")
+(assert_trap (invoke "set-funcref-from" (i32.const 3) (i32.const 1)) "out of bounds table access")
+;; (assert_trap (invoke "set-externref" (i32.const -1) (ref.extern 0)) "out of bounds table access")
+(assert_trap (invoke "set-funcref-from" (i32.const -1) (i32.const 1)) "out of bounds table access")
+
+
+;; Type errors
+
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-index-value-empty-vs-i32-externref
+ (table.set $t)
+ )
+ )
+ "type mismatch"
+)
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-index-empty-vs-i32
+ (table.set $t (ref.null extern))
+ )
+ )
+ "type mismatch"
+)
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-value-empty-vs-externref
+ (table.set $t (i32.const 1))
+ )
+ )
+ "type mismatch"
+)
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-size-f32-vs-i32
+ (table.set $t (f32.const 1) (ref.null extern))
+ )
+ )
+ "type mismatch"
+)
+(assert_invalid
+ (module
+ (table $t 10 funcref)
+ (func $type-value-externref-vs-funcref (param $r externref)
+ (table.set $t (i32.const 1) (local.get $r))
+ )
+ )
+ "type mismatch"
+)
+
+(assert_invalid
+ (module
+ (table $t1 1 externref)
+ (table $t2 1 funcref)
+ (func $type-value-externref-vs-funcref-multi (param $r externref)
+ (table.set $t2 (i32.const 0) (local.get $r))
+ )
+ )
+ "type mismatch"
+)
+
+(assert_invalid
+ (module
+ (table $t 10 externref)
+ (func $type-result-empty-vs-num (result i32)
+ (table.set $t (i32.const 0) (ref.null extern))
+ )
+ )
+ "type mismatch"
+)