diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-07 12:49:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-07 12:49:51 -0700 |
commit | e74dcc425dfb95bbf0bb296fa0d6c4494355b6e1 (patch) | |
tree | 79fdef328a97cc41bde7181c6b7124b27bd36373 /test | |
parent | 9455a8749e1bb2c4788c37495b9cd319f046f6ff (diff) | |
parent | 4215d5f76f151fe2c4609db7f6041c4354851af3 (diff) | |
download | binaryen-e74dcc425dfb95bbf0bb296fa0d6c4494355b6e1.tar.gz binaryen-e74dcc425dfb95bbf0bb296fa0d6c4494355b6e1.tar.bz2 binaryen-e74dcc425dfb95bbf0bb296fa0d6c4494355b6e1.zip |
Merge pull request #622 from WebAssembly/duffs-device-test
Add a relooper test for duff's device, and c api improvements
Diffstat (limited to 'test')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 13 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 93 |
2 files changed, 106 insertions, 0 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index ace95177a..6fb095d20 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -395,6 +395,19 @@ void test_relooper() { BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0, module); BinaryenFunctionRef sinker = BinaryenAddFunction(module, "switch", v, localTypes, 1, body); } + { // duff's device + RelooperRef relooper = RelooperCreate(); + RelooperBlockRef block0 = RelooperAddBlock(relooper, makeInt32(module, 0)); + RelooperBlockRef block1 = RelooperAddBlock(relooper, makeInt32(module, 1)); + RelooperBlockRef block2 = RelooperAddBlock(relooper, makeInt32(module, 2)); + RelooperAddBranch(block0, block1, makeInt32(module, 10), NULL); + RelooperAddBranch(block0, block2, NULL, NULL); + RelooperAddBranch(block1, block2, NULL, NULL); + RelooperAddBranch(block2, block1, NULL, NULL); + BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 3, module); // use $3 as the helper var + BinaryenType localTypes[] = { BinaryenInt32(), BinaryenInt32(), BinaryenInt64(), BinaryenInt32(), BinaryenFloat32(), BinaryenFloat64(), BinaryenInt32() }; + BinaryenFunctionRef sinker = BinaryenAddFunction(module, "duffs-device", v, localTypes, sizeof(localTypes)/sizeof(BinaryenType), body); + } BinaryenFunctionTypeRef i = BinaryenAddFunctionType(module, "i", BinaryenInt32(), NULL, 0); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index d4eb5e337..7076622c5 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -667,6 +667,67 @@ raw: ) ) ) + (func $duffs-device (type $v) + (local $0 i32) + (local $1 i32) + (local $2 i64) + (local $3 i32) + (local $4 f32) + (local $5 f64) + (local $6 i32) + (block + (i32.const 0) + (if + (i32.const 10) + (set_local $3 + (i32.const 2) + ) + (set_local $3 + (i32.const 3) + ) + ) + ) + (loop $shape$1$break $shape$1$continue + (block $shape$2$break + (if + (i32.eq + (get_local $3) + (i32.const 2) + ) + (block + (set_local $3 + (i32.const 0) + ) + (i32.const 1) + (block + (set_local $3 + (i32.const 3) + ) + (br $shape$1$continue) + ) + ) + (if + (i32.eq + (get_local $3) + (i32.const 3) + ) + (block + (set_local $3 + (i32.const 0) + ) + (i32.const 2) + (block + (set_local $3 + (i32.const 2) + ) + (br $shape$1$continue) + ) + ) + ) + ) + ) + ) + ) (func $return (type $i) (result i32) (local $0 i32) (block $the-list @@ -685,6 +746,38 @@ optimized: (func $just-one-block (type $v) (nop) ) + (func $duffs-device (type $v) + (local $0 i32) + (set_local $0 + (i32.const 2) + ) + (loop $shape$1$break $shape$1$continue + (if + (i32.eq + (get_local $0) + (i32.const 2) + ) + (block + (set_local $0 + (i32.const 3) + ) + (br $shape$1$continue) + ) + (if + (i32.eq + (get_local $0) + (i32.const 3) + ) + (block + (set_local $0 + (i32.const 2) + ) + (br $shape$1$continue) + ) + ) + ) + ) + ) (func $return (type $i) (result i32) (i32.const 1337) ) |