diff options
author | Alon Zakai <azakai@google.com> | 2020-11-11 16:33:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 16:33:25 -0800 |
commit | 24bd9b984fc71c38d3d24c5f03fa81a15d591322 (patch) | |
tree | 849aade0d2f759c93961e04cd7e994eceb16bb90 /test | |
parent | f0d6b089960e089bcc5c1794003585ebbd91d33a (diff) | |
download | binaryen-24bd9b984fc71c38d3d24c5f03fa81a15d591322.tar.gz binaryen-24bd9b984fc71c38d3d24c5f03fa81a15d591322.tar.bz2 binaryen-24bd9b984fc71c38d3d24c5f03fa81a15d591322.zip |
Fix BinaryenFunctionOptimize. (#3339)
We mistakenly tried to run all passes there, but should run only
the function ones.
Fixes #3333
Diffstat (limited to 'test')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 26 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 17 |
2 files changed, 43 insertions, 0 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index a8aa05c4a..8a2f22e8d 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -1365,6 +1365,31 @@ void test_for_each() { BinaryenModuleDispose(module); } +void test_func_opt() { + BinaryenModuleRef module = BinaryenModuleCreate(); + BinaryenType ii_[2] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; + BinaryenType ii = BinaryenTypeCreate(ii_, 2); + BinaryenExpressionRef x = BinaryenConst(module, BinaryenLiteralInt32(1)), + y = BinaryenConst(module, BinaryenLiteralInt32(3)); + BinaryenExpressionRef add = BinaryenBinary(module, BinaryenAddInt32(), x, y); + BinaryenFunctionRef adder = BinaryenAddFunction( + module, "adder", BinaryenTypeNone(), BinaryenTypeInt32(), NULL, 0, add); + + puts("module with a function to optimize:"); + BinaryenModulePrint(module); + + assert(BinaryenModuleValidate(module)); + + BinaryenFunctionOptimize(adder, module); + + assert(BinaryenModuleValidate(module)); + + puts("optimized:"); + BinaryenModulePrint(module); + + BinaryenModuleDispose(module); +} + int main() { test_types(); test_features(); @@ -1376,6 +1401,7 @@ int main() { test_nonvalid(); test_color_status(); test_for_each(); + test_func_opt(); return 0; } diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 0e85ac18a..723d81999 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -2450,3 +2450,20 @@ validation: 0 (nop) ) ) +module with a function to optimize: +(module + (type $none_=>_i32 (func (result i32))) + (func $adder (result i32) + (i32.add + (i32.const 1) + (i32.const 3) + ) + ) +) +optimized: +(module + (type $none_=>_i32 (func (result i32))) + (func $adder (result i32) + (i32.const 4) + ) +) |