summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
Diffstat (limited to 'test/example')
-rw-r--r--test/example/c-api-kitchen-sink.c18
-rw-r--r--test/example/c-api-kitchen-sink.txt36
2 files changed, 52 insertions, 2 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index feffc9d4c..fa245c102 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -377,6 +377,20 @@ void test_relooper() {
BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0, module);
BinaryenFunctionRef sinker = BinaryenAddFunction(module, "nontrivial-loop-plus-phi-to-head", v, localTypes, 1, body);
}
+ { // switch
+ RelooperRef relooper = RelooperCreate();
+ RelooperBlockRef block0 = RelooperAddBlockWithSwitch(relooper, makeInt32(module, 0), makeInt32(module, -99));
+ RelooperBlockRef block1 = RelooperAddBlock(relooper, makeInt32(module, 1));
+ RelooperBlockRef block2 = RelooperAddBlock(relooper, makeInt32(module, 2));
+ RelooperBlockRef block3 = RelooperAddBlock(relooper, makeInt32(module, 3));
+ BinaryenIndex to_block1[] = { 2, 5 };
+ RelooperAddBranchForSwitch(block0, block1, to_block1, 2, NULL);
+ BinaryenIndex to_block2[] = { 4 };
+ RelooperAddBranchForSwitch(block0, block2, to_block2, 1, makeInt32(module, 55));
+ RelooperAddBranchForSwitch(block0, block3, NULL, 0, NULL);
+ BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0, module);
+ BinaryenFunctionRef sinker = BinaryenAddFunction(module, "switch", v, localTypes, 1, body);
+ }
BinaryenFunctionTypeRef i = BinaryenAddFunctionType(module, "i", BinaryenInt32(), NULL, 0);
@@ -389,11 +403,11 @@ void test_relooper() {
BinaryenFunctionRef sinker = BinaryenAddFunction(module, "return", i, localTypes, 1, body);
}
- assert(BinaryenModuleValidate(module));
-
printf("raw:\n");
BinaryenModulePrint(module);
+ assert(BinaryenModuleValidate(module));
+
BinaryenModuleOptimize(module);
assert(BinaryenModuleValidate(module));
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 6776fe2a5..9e2e62aad 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -631,6 +631,42 @@ raw:
)
)
)
+ (func $switch (type $v)
+ (local $0 i32)
+ (i32.const 0)
+ (block $shape$1$break
+ (block $switch$1$leave
+ (block $switch$1$default
+ (block $switch$1$case$3
+ (block $switch$1$case$2
+ (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default
+ (i32.const -99)
+ )
+ )
+ (block
+ (block
+ (i32.const 1)
+ )
+ )
+ (br $switch$1$leave)
+ )
+ (block
+ (i32.const 55)
+ (block
+ (i32.const 2)
+ )
+ )
+ (br $switch$1$leave)
+ )
+ (block
+ (block
+ (i32.const 3)
+ )
+ )
+ (br $switch$1$leave)
+ )
+ )
+ )
(func $return (type $i) (result i32)
(local $0 i32)
(block $the-list