summaryrefslogtreecommitdiff
path: root/test/example/c-api-kitchen-sink.c
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-07-02 10:05:23 -0700
committerGitHub <noreply@github.com>2016-07-02 10:05:23 -0700
commitef93042503a61e5a051536ba7f02b41fffcd69bc (patch)
tree82d5e221f6654e181c6c4ac3a9a870f5680852c9 /test/example/c-api-kitchen-sink.c
parent44290db4fc014c8e032fb61f95ca9805d2ce57bc (diff)
downloadbinaryen-ef93042503a61e5a051536ba7f02b41fffcd69bc.tar.gz
binaryen-ef93042503a61e5a051536ba7f02b41fffcd69bc.tar.bz2
binaryen-ef93042503a61e5a051536ba7f02b41fffcd69bc.zip
Relooper switch support (#617)
* support switches in relooper and c api * update relooper fuzzer for switches
Diffstat (limited to 'test/example/c-api-kitchen-sink.c')
-rw-r--r--test/example/c-api-kitchen-sink.c18
1 files changed, 16 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));