summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorericvergnaud <eric.vergnaud@wanadoo.fr>2024-02-01 19:48:06 +0100
committerGitHub <noreply@github.com>2024-02-01 10:48:06 -0800
commit2b3a2e8c341395e4cb0f76db6ad4f31fb17720cc (patch)
treecca37d0a307f56b351611fb11e604d347c0ba301 /test
parent6c70fcdf246ba5619c75b56e2ffddd8256dfd857 (diff)
downloadbinaryen-2b3a2e8c341395e4cb0f76db6ad4f31fb17720cc.tar.gz
binaryen-2b3a2e8c341395e4cb0f76db6ad4f31fb17720cc.tar.bz2
binaryen-2b3a2e8c341395e4cb0f76db6ad4f31fb17720cc.zip
C API: Use segment names (#6254)
Move from segment indexes to names. This is a breaking change to make the API more capable and consistent. An effort has been made to reduce the burden on C API users where possible (specifically, you can avoid providing names and let Binaryen make them for you, which will basically be numbers that match the indexes from before). Fixes #6247
Diffstat (limited to 'test')
-rw-r--r--test/binaryen.js/kitchen-sink.js12
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt22
-rw-r--r--test/binaryen.js/reloc.js1
-rw-r--r--test/binaryen.js/reloc.js.txt2
-rw-r--r--test/example/c-api-kitchen-sink.c29
-rw-r--r--test/example/c-api-relooper-unreachable-if.cpp20
-rw-r--r--test/example/c-api-unused-mem.cpp20
-rw-r--r--test/example/relooper-fuzz.c3
-rw-r--r--test/example/relooper-fuzz1.c3
-rw-r--r--test/example/relooper-fuzz2.c3
-rw-r--r--test/example/relooper-merge1.c3
-rw-r--r--test/example/relooper-merge2.c3
-rw-r--r--test/example/relooper-merge3.c3
-rw-r--r--test/example/relooper-merge4.c3
-rw-r--r--test/example/relooper-merge5.c3
-rw-r--r--test/example/relooper-merge6.c3
16 files changed, 81 insertions, 52 deletions
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index 235d09f3e..52975f8bc 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -196,11 +196,13 @@ function test_core() {
// Memory
module.setMemory(1, 256, "mem", [
{
+ name: "x0",
passive: false,
offset: module.i32.const(10),
data: "hello, world".split('').map(function(x) { return x.charCodeAt(0) })
},
{
+ name: "y1",
passive: true,
offset: null,
data: "I am passive".split('').map(function(x) { return x.charCodeAt(0) })
@@ -555,8 +557,8 @@ function test_core() {
module.i8x16.shuffle(module.v128.const(v128_bytes), module.v128.const(v128_bytes), v128_bytes),
module.v128.bitselect(module.v128.const(v128_bytes), module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
// Bulk memory
- module.memory.init("0", makeInt32(1024), makeInt32(0), makeInt32(12)),
- module.data.drop("0"),
+ module.memory.init("x0", makeInt32(1024), makeInt32(0), makeInt32(12)),
+ module.data.drop("x0"),
module.memory.copy(makeInt32(2048), makeInt32(1024), makeInt32(12)),
module.memory.fill(makeInt32(0), makeInt32(42), makeInt32(1024)),
// All the rest
@@ -1090,6 +1092,7 @@ function test_for_each() {
}
var expected_offsets = [10, 125, null];
+ var expected_names = ["x0", "y1", "z2"];
var expected_data = ["hello, world", "segment data 2", "hello, passive"];
var expected_passive = [false, false, true];
@@ -1105,23 +1108,26 @@ function test_for_each() {
module.setMemory(1, 256, "mem", [
{
+ name: expected_names[0],
passive: expected_passive[0],
offset: module.i32.const(expected_offsets[0]),
data: expected_data[0].split('').map(function(x) { return x.charCodeAt(0) })
},
{
+ name: expected_names[1],
passive: expected_passive[1],
offset: module.global.get("a-global"),
data: expected_data[1].split('').map(function(x) { return x.charCodeAt(0) })
},
{
+ name: expected_names[2],
passive: expected_passive[2],
offset: expected_offsets[2],
data: expected_data[2].split('').map(function(x) { return x.charCodeAt(0) })
}
], false);
for (i = 0; i < module.getNumMemorySegments(); i++) {
- var segment = module.getMemorySegmentInfoByIndex(i);
+ var segment = module.getMemorySegmentInfo(expected_names[i]);
assert(expected_offsets[i] === segment.offset);
var data8 = new Uint8Array(segment.data);
var str = String.fromCharCode.apply(null, data8);
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index b5a9b713e..2c54f1142 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -140,8 +140,8 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(import "module" "base" (tag $a-tag-imp (param i32)))
(global $a-global i32 (i32.const 1))
(memory $0 1 256 shared)
- (data $0 (i32.const 10) "hello, world")
- (data $1 "I am passive")
+ (data $x0 (i32.const 10) "hello, world")
+ (data $y1 "I am passive")
(table $t0 1 funcref)
(elem $e0 (i32.const 0) $"kitchen()sinker")
(tag $a-tag (param i32))
@@ -1914,12 +1914,12 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
- (memory.init $0
+ (memory.init $x0
(i32.const 1024)
(i32.const 0)
(i32.const 12)
)
- (data.drop $0)
+ (data.drop $x0)
(memory.copy
(i32.const 2048)
(i32.const 1024)
@@ -2250,8 +2250,8 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(import "module" "base" (tag $a-tag-imp (param i32)))
(global $a-global i32 (i32.const 1))
(memory $0 1 256 shared)
- (data $0 (i32.const 10) "hello, world")
- (data $1 "I am passive")
+ (data $x0 (i32.const 10) "hello, world")
+ (data $y1 "I am passive")
(table $t0 1 funcref)
(elem $e0 (i32.const 0) $"kitchen()sinker")
(tag $a-tag (param i32))
@@ -4024,12 +4024,12 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
- (memory.init $0
+ (memory.init $x0
(i32.const 1024)
(i32.const 0)
(i32.const 12)
)
- (data.drop $0)
+ (data.drop $x0)
(memory.copy
(i32.const 2048)
(i32.const 1024)
@@ -4922,9 +4922,9 @@ sizeof Literal: 24
(global $a-global2 i32 (i32.const 2))
(global $a-global3 i32 (i32.const 3))
(memory $0 1 256)
- (data $0 (i32.const 10) "hello, world")
- (data $1 (global.get $a-global) "segment data 2")
- (data $2 "hello, passive")
+ (data $x0 (i32.const 10) "hello, world")
+ (data $y1 (global.get $a-global) "segment data 2")
+ (data $z2 "hello, passive")
(table $t0 1 funcref)
(elem $e0 (i32.const 0) $fn0 $fn1 $fn2)
(export "export0" (func $fn0))
diff --git a/test/binaryen.js/reloc.js b/test/binaryen.js/reloc.js
index 0235ea413..cd63fb5a4 100644
--- a/test/binaryen.js/reloc.js
+++ b/test/binaryen.js/reloc.js
@@ -5,6 +5,7 @@ var module = new binaryen.Module();
module.addGlobalImport("memory_base", "env", "memory_base", binaryen.i32, false);
module.setMemory(1, -1, null, [
{
+ name: "x0",
offset: module.global.get("memory_base", binaryen.i32),
data: "data data".split('').map(function(x) { return x.charCodeAt(0) })
}
diff --git a/test/binaryen.js/reloc.js.txt b/test/binaryen.js/reloc.js.txt
index 0aa075841..b98bc4bef 100644
--- a/test/binaryen.js/reloc.js.txt
+++ b/test/binaryen.js/reloc.js.txt
@@ -3,7 +3,7 @@
(import "env" "memory_base" (global $memory_base i32))
(import "env" "table_base" (global $table_base i32))
(memory $0 1)
- (data $0 (global.get $memory_base) "data data")
+ (data $x0 (global.get $memory_base) "data data")
(table $0 1 funcref)
(elem $0 (global.get $table_base) $func $func)
(func $func
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index edf8d61f7..d5681097c 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -530,8 +530,9 @@ void test_core() {
// Memory. Add it before creating any memory-using instructions.
- const char* segments[] = {"hello, world", "I am passive"};
- bool segmentPassive[] = {false, true};
+ const char* segmentNames[] = {"0", "1"};
+ const char* segmentDatas[] = {"hello, world", "I am passive"};
+ bool segmentPassives[] = {false, true};
BinaryenExpressionRef segmentOffsets[] = {
BinaryenConst(module, BinaryenLiteralInt32(10)), NULL};
BinaryenIndex segmentSizes[] = {12, 12};
@@ -539,8 +540,9 @@ void test_core() {
1,
256,
"mem",
- segments,
- segmentPassive,
+ segmentNames,
+ segmentDatas,
+ segmentPassives,
segmentOffsets,
segmentSizes,
2,
@@ -2085,9 +2087,10 @@ void test_for_each() {
assert(BinaryenGetExportByIndex(module, i) == exps[i]);
}
- const char* segments[] = {"hello, world", "segment data 2"};
+ const char* segmentNames[] = {"0", "1"};
+ const char* segmentDatas[] = {"hello, world", "segment data 2"};
const uint32_t expected_offsets[] = {10, 125};
- bool segmentPassive[] = {false, false};
+ bool segmentPassives[] = {false, false};
BinaryenIndex segmentSizes[] = {12, 14};
BinaryenExpressionRef segmentOffsets[] = {
@@ -2097,8 +2100,9 @@ void test_for_each() {
1,
256,
"mem",
- segments,
- segmentPassive,
+ segmentNames,
+ segmentDatas,
+ segmentPassives,
segmentOffsets,
segmentSizes,
2,
@@ -2113,11 +2117,12 @@ void test_for_each() {
for (i = 0; i < BinaryenGetNumMemorySegments(module); i++) {
char out[15] = {};
- assert(BinaryenGetMemorySegmentByteOffset(module, i) ==
+ assert(BinaryenGetMemorySegmentByteOffset(module, segmentNames[i]) ==
expected_offsets[i]);
- assert(BinaryenGetMemorySegmentByteLength(module, i) == segmentSizes[i]);
- BinaryenCopyMemorySegmentData(module, i, out);
- assert(0 == strcmp(segments[i], out));
+ assert(BinaryenGetMemorySegmentByteLength(module, segmentNames[i]) ==
+ segmentSizes[i]);
+ BinaryenCopyMemorySegmentData(module, segmentNames[i], out);
+ assert(0 == strcmp(segmentDatas[i], out));
}
}
{
diff --git a/test/example/c-api-relooper-unreachable-if.cpp b/test/example/c-api-relooper-unreachable-if.cpp
index 1c5708835..96c6c1149 100644
--- a/test/example/c-api-relooper-unreachable-if.cpp
+++ b/test/example/c-api-relooper-unreachable-if.cpp
@@ -15,16 +15,18 @@ int main() {
expressions[size_t(NULL)] = BinaryenExpressionRef(NULL);
BinaryenModuleAutoDrop(the_module);
{
- const char* segments[] = {0};
- bool segmentPassive[] = {false};
+ const char* segmentNames[] = {"0"};
+ const char* segmentDatas[] = {0};
+ bool segmentPassives[] = {false};
BinaryenExpressionRef segmentOffsets[] = {0};
BinaryenIndex segmentSizes[] = {0};
BinaryenSetMemory(the_module,
256,
256,
"memory",
- segments,
- segmentPassive,
+ segmentNames,
+ segmentDatas,
+ segmentPassives,
segmentOffsets,
segmentSizes,
0,
@@ -585,16 +587,18 @@ int main() {
}
BinaryenAddFunctionExport(the_module, "main", "main");
{
- const char* segments[] = {0};
+ const char* segmentNames[] = {"0"};
+ const char* segmentDatas[] = {0};
BinaryenExpressionRef segmentOffsets[] = {0};
- bool segmentPassive[] = {false};
+ bool segmentPassives[] = {false};
BinaryenIndex segmentSizes[] = {0};
BinaryenSetMemory(the_module,
1,
1,
NULL,
- segments,
- segmentPassive,
+ segmentNames,
+ segmentDatas,
+ segmentPassives,
segmentOffsets,
segmentSizes,
0,
diff --git a/test/example/c-api-unused-mem.cpp b/test/example/c-api-unused-mem.cpp
index a0970a8ca..750f3b703 100644
--- a/test/example/c-api-unused-mem.cpp
+++ b/test/example/c-api-unused-mem.cpp
@@ -16,16 +16,18 @@ int main() {
expressions[size_t(NULL)] = BinaryenExpressionRef(NULL);
BinaryenModuleAutoDrop(the_module);
{
- const char* segments[] = {0};
- bool segmentPassive[] = {false};
+ const char* segmentNames[] = {"0"};
+ const char* segmentDatas[] = {0};
+ bool segmentPassives[] = {false};
BinaryenExpressionRef segmentOffsets[] = {0};
BinaryenIndex segmentSizes[] = {0};
BinaryenSetMemory(the_module,
256,
256,
"memory",
- segments,
- segmentPassive,
+ segmentNames,
+ segmentDatas,
+ segmentPassives,
segmentOffsets,
segmentSizes,
0,
@@ -81,16 +83,18 @@ int main() {
}
BinaryenAddFunctionExport(the_module, "main", "main");
{
- const char* segments[] = {0};
- bool segmentPassive[] = {false};
+ const char* segmentNames[] = {"0"};
+ const char* segmentDatas[] = {0};
+ bool segmentPassives[] = {false};
BinaryenExpressionRef segmentOffsets[] = {0};
BinaryenIndex segmentSizes[] = {0};
BinaryenSetMemory(the_module,
1024,
1024,
NULL,
- segments,
- segmentPassive,
+ segmentNames,
+ segmentDatas,
+ segmentPassives,
segmentOffsets,
segmentSizes,
0,
diff --git a/test/example/relooper-fuzz.c b/test/example/relooper-fuzz.c
index a648e61b4..afa8e7ec1 100644
--- a/test/example/relooper-fuzz.c
+++ b/test/example/relooper-fuzz.c
@@ -369,7 +369,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
assert(BinaryenModuleValidate(module));
diff --git a/test/example/relooper-fuzz1.c b/test/example/relooper-fuzz1.c
index a524922d7..a2594407a 100644
--- a/test/example/relooper-fuzz1.c
+++ b/test/example/relooper-fuzz1.c
@@ -366,7 +366,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
assert(BinaryenModuleValidate(module));
diff --git a/test/example/relooper-fuzz2.c b/test/example/relooper-fuzz2.c
index 8d129b77b..9ccba34d7 100644
--- a/test/example/relooper-fuzz2.c
+++ b/test/example/relooper-fuzz2.c
@@ -690,7 +690,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)
diff --git a/test/example/relooper-merge1.c b/test/example/relooper-merge1.c
index 4086de438..d571696f8 100644
--- a/test/example/relooper-merge1.c
+++ b/test/example/relooper-merge1.c
@@ -232,7 +232,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)
diff --git a/test/example/relooper-merge2.c b/test/example/relooper-merge2.c
index d85f9d71c..c70ef5601 100644
--- a/test/example/relooper-merge2.c
+++ b/test/example/relooper-merge2.c
@@ -247,7 +247,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)
diff --git a/test/example/relooper-merge3.c b/test/example/relooper-merge3.c
index 9347e0fde..933739254 100644
--- a/test/example/relooper-merge3.c
+++ b/test/example/relooper-merge3.c
@@ -231,7 +231,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)
diff --git a/test/example/relooper-merge4.c b/test/example/relooper-merge4.c
index b4373454d..6fc36be36 100644
--- a/test/example/relooper-merge4.c
+++ b/test/example/relooper-merge4.c
@@ -231,7 +231,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)
diff --git a/test/example/relooper-merge5.c b/test/example/relooper-merge5.c
index 79ee6abc8..7e4fbee0f 100644
--- a/test/example/relooper-merge5.c
+++ b/test/example/relooper-merge5.c
@@ -231,7 +231,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)
diff --git a/test/example/relooper-merge6.c b/test/example/relooper-merge6.c
index 774dd934c..93043ef32 100644
--- a/test/example/relooper-merge6.c
+++ b/test/example/relooper-merge6.c
@@ -234,7 +234,8 @@ int main() {
BinaryenTypeNone());
// memory
- BinaryenSetMemory(module, 1, 1, "mem", NULL, NULL, NULL, NULL, 0, 0, 0, "0");
+ BinaryenSetMemory(
+ module, 1, 1, "mem", NULL, NULL, NULL, NULL, NULL, 0, 0, 0, "0");
// optionally, optimize
if (0)