From 24bd9b984fc71c38d3d24c5f03fa81a15d591322 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 11 Nov 2020 16:33:25 -0800 Subject: Fix BinaryenFunctionOptimize. (#3339) We mistakenly tried to run all passes there, but should run only the function ones. Fixes #3333 --- test/example/c-api-kitchen-sink.c | 26 ++++++++++++++++++++++++++ test/example/c-api-kitchen-sink.txt | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'test') 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) + ) +) -- cgit v1.2.3