summaryrefslogtreecommitdiff
path: root/test/binaryen.js
diff options
context:
space:
mode:
authorAbbas Mashayekh <martianboy2005@gmail.com>2021-03-06 03:08:51 +0330
committerGitHub <noreply@github.com>2021-03-05 15:38:51 -0800
commit89b8af006bc56cb4bf68f12a80b1cfe8e7a353d4 (patch)
tree602bd8e24753b5e45c859a2c3672062ce07133fe /test/binaryen.js
parent57619b508d38677844cb482a4034dc985d2cecc6 (diff)
downloadbinaryen-89b8af006bc56cb4bf68f12a80b1cfe8e7a353d4.tar.gz
binaryen-89b8af006bc56cb4bf68f12a80b1cfe8e7a353d4.tar.bz2
binaryen-89b8af006bc56cb4bf68f12a80b1cfe8e7a353d4.zip
[reference-types] Support passive elem segments (#3572)
Passive element segments do not belong to any table, so the link between Table and elem needs to be weaker; i.e. an elem may have a table in case of active segments, or simply be a collection of function references in case of passive/declarative segments. This PR takes Table::Segment out and turns it into a first class module element just like tables and functions. It also implements early support for parsing, printing, encoding and decoding passive/declarative elem segments.
Diffstat (limited to 'test/binaryen.js')
-rw-r--r--test/binaryen.js/kitchen-sink.js40
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt20
-rw-r--r--test/binaryen.js/reloc.js4
-rw-r--r--test/binaryen.js/reloc.js.txt2
4 files changed, 37 insertions, 29 deletions
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index 3aebe0e61..084a7d47b 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -518,7 +518,7 @@ function test_core() {
)
),
module.i32.eqz( // check the output type of the call node
- module.call_indirect("0", makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32)
+ module.call_indirect("t0", makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32)
),
module.drop(module.local.get(0, binaryen.i32)),
module.local.set(0, makeInt32(101)),
@@ -533,7 +533,7 @@ function test_core() {
module.return(makeInt32(1337)),
// Tail Call
module.return_call("kitchen()sinker", [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], binaryen.i32),
- module.return_call_indirect("0", makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32),
+ module.return_call_indirect("t0", makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], iIfF, binaryen.i32),
// Reference types
module.ref.is_null(module.ref.null(binaryen.externref)),
@@ -665,7 +665,7 @@ function test_core() {
module.addEventExport("a-event", "a-event-exp");
// Tables
- module.addTable("t1", 0, 2, []);
+ module.addTable("t1", 0, 2);
var tablePtr = module.getTable("t1");
assert(tablePtr !== 0);
assert(tablePtr === module.getTableByIndex(0));
@@ -676,13 +676,14 @@ function test_core() {
assert(table.base === "");
assert(table.initial === 0);
assert(table.max === 2);
-
+
module.removeTable("t1");
assert(module.getNumTables() === 0);
-
- // Legacy
- module.setFunctionTable(1, 0xffffffff, [ binaryen.getFunctionInfo(sinker).name ]);
+
+ module.addTable("t0", 1, 0xffffffff);
+ module.addActiveElementSegment("t0", "e0", [ binaryen.getFunctionInfo(sinker).name ]);
assert(module.getNumTables() === 1);
+ assert(module.getNumElementSegments() === 1);
// Memory. One per module
@@ -1072,16 +1073,23 @@ function test_for_each() {
assert(expected_passive[i] === segment.passive);
}
+ module.addTable("t0", 1, 0xffffffff);
+ var ftable = module.getTable("t0");
var constExprRef = module.i32.const(0);
- module.setFunctionTable(1, 0xffffffff, funcNames, constExprRef);
-
- var ftable = module.getFunctionTable();
- assert(false === ftable.imported);
- assert(1 === ftable.segments.length);
- assert(constExprRef === ftable.segments[0].offset);
- assert(3 === ftable.segments[0].names.length);
- for (i = 0; i < ftable.segments[0].names.length; i++) {
- assert(funcNames[i] === ftable.segments[0].names[i]);
+ module.addActiveElementSegment("t0", "e0", funcNames, constExprRef);
+
+ var tableInfo = binaryen.getTableInfo(ftable);
+ assert("" === tableInfo.module);
+ assert("" === tableInfo.base);
+
+ var segments = module.getTableSegments(ftable);
+ assert(1 === segments.length);
+
+ var elemSegment = binaryen.getElementSegmentInfo(segments[0]);
+ assert(constExprRef === elemSegment.offset);
+ assert(3 === elemSegment.data.length);
+ for (i = 0; i < elemSegment.data.length; i++) {
+ assert(funcNames[i] === elemSegment.data[i]);
}
console.log(module.emitText());
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index aff1d1f2d..700e8507f 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -131,8 +131,8 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(memory $0 (shared 1 256))
(data (i32.const 10) "hello, world")
(data passive "I am passive")
- (table $0 1 funcref)
- (elem (i32.const 0) "$kitchen()sinker")
+ (table $t0 1 funcref)
+ (elem $e0 (i32.const 0) "$kitchen()sinker")
(global $a-global i32 (i32.const 1))
(event $a-event (attr 0) (param i32))
(export "kitchen_sinker" (func "$kitchen()sinker"))
@@ -1759,7 +1759,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
)
(drop
(i32.eqz
- (call_indirect $0 (type $i32_i64_f32_f64_=>_i32)
+ (call_indirect $t0 (type $i32_i64_f32_f64_=>_i32)
(i32.const 13)
(i64.const 37)
(f32.const 1.2999999523162842)
@@ -1823,7 +1823,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(f32.const 1.2999999523162842)
(f64.const 3.7)
)
- (return_call_indirect $0 (type $i32_i64_f32_f64_=>_i32)
+ (return_call_indirect $t0 (type $i32_i64_f32_f64_=>_i32)
(i32.const 13)
(i64.const 37)
(f32.const 1.2999999523162842)
@@ -1993,8 +1993,8 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(memory $0 (shared 1 256))
(data (i32.const 10) "hello, world")
(data passive "I am passive")
- (table $0 1 funcref)
- (elem (i32.const 0) "$kitchen()sinker")
+ (table $t0 1 funcref)
+ (elem $e0 (i32.const 0) "$kitchen()sinker")
(global $a-global i32 (i32.const 1))
(event $a-event (attr 0) (param i32))
(export "kitchen_sinker" (func "$kitchen()sinker"))
@@ -3621,7 +3621,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
)
(drop
(i32.eqz
- (call_indirect $0 (type $i32_i64_f32_f64_=>_i32)
+ (call_indirect $t0 (type $i32_i64_f32_f64_=>_i32)
(i32.const 13)
(i64.const 37)
(f32.const 1.2999999523162842)
@@ -3685,7 +3685,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(f32.const 1.2999999523162842)
(f64.const 3.7)
)
- (return_call_indirect $0 (type $i32_i64_f32_f64_=>_i32)
+ (return_call_indirect $t0 (type $i32_i64_f32_f64_=>_i32)
(i32.const 13)
(i64.const 37)
(f32.const 1.2999999523162842)
@@ -4389,8 +4389,8 @@ sizeof Literal: 24
(memory $0 1 256)
(data (i32.const 10) "hello, world")
(data (global.get $a-global) "segment data 2")
- (table $0 1 funcref)
- (elem (i32.const 0) $fn0 $fn1 $fn2)
+ (table $t0 1 funcref)
+ (elem $e0 (i32.const 0) $fn0 $fn1 $fn2)
(global $a-global i32 (i32.const 125))
(global $a-global2 i32 (i32.const 2))
(global $a-global3 i32 (i32.const 3))
diff --git a/test/binaryen.js/reloc.js b/test/binaryen.js/reloc.js
index bb011916d..2b7cc9f90 100644
--- a/test/binaryen.js/reloc.js
+++ b/test/binaryen.js/reloc.js
@@ -15,7 +15,7 @@ module.setMemory(1, -1, null, [
var func = module.addFunction("func", binaryen.none, binaryen.none, [], module.nop());
module.addGlobalImport("table_base", "env", "table_base", binaryen.i32, false);
-module.setFunctionTable(1, -1, [ "func", "func" ], module.global.get("table_base", binaryen.i32));
-
+module.addTable("0", 1, -1);
+module.addActiveElementSegment("0", "0", [ "func", "func" ], module.global.get("table_base", binaryen.i32));
assert(module.validate());
console.log(module.emitText());
diff --git a/test/binaryen.js/reloc.js.txt b/test/binaryen.js/reloc.js.txt
index 729f29b9d..262ba3d0c 100644
--- a/test/binaryen.js/reloc.js.txt
+++ b/test/binaryen.js/reloc.js.txt
@@ -5,7 +5,7 @@
(memory $0 1)
(data (global.get $memory_base) "data data")
(table $0 1 funcref)
- (elem (global.get $table_base) $func $func)
+ (elem $0 (global.get $table_base) $func $func)
(func $func
(nop)
)