diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-02 10:05:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-02 10:05:23 -0700 |
commit | ef93042503a61e5a051536ba7f02b41fffcd69bc (patch) | |
tree | 82d5e221f6654e181c6c4ac3a9a870f5680852c9 /test | |
parent | 44290db4fc014c8e032fb61f95ca9805d2ce57bc (diff) | |
download | binaryen-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')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 18 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 36 |
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 |