diff options
Diffstat (limited to 'test/example')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 65 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 2 |
2 files changed, 43 insertions, 24 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 6d56ccf44..67f7e0642 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -1225,33 +1225,32 @@ void test_color_status() { } void test_for_each() { - uint32_t i; + BinaryenIndex i; BinaryenModuleRef module = BinaryenModuleCreate(); + BinaryenFunctionRef fns[3] = {}; + fns[0] = BinaryenAddFunction(module, + "fn0", + BinaryenTypeNone(), + BinaryenTypeNone(), + NULL, + 0, + BinaryenNop(module)); + fns[1] = BinaryenAddFunction(module, + "fn1", + BinaryenTypeNone(), + BinaryenTypeNone(), + NULL, + 0, + BinaryenNop(module)); + fns[2] = BinaryenAddFunction(module, + "fn2", + BinaryenTypeNone(), + BinaryenTypeNone(), + NULL, + 0, + BinaryenNop(module)); { - BinaryenFunctionRef fns[3] = {0}; - fns[0] = BinaryenAddFunction(module, - "fn0", - BinaryenTypeNone(), - BinaryenTypeNone(), - NULL, - 0, - BinaryenNop(module)); - fns[1] = BinaryenAddFunction(module, - "fn1", - BinaryenTypeNone(), - BinaryenTypeNone(), - NULL, - 0, - BinaryenNop(module)); - fns[2] = BinaryenAddFunction(module, - "fn2", - BinaryenTypeNone(), - BinaryenTypeNone(), - NULL, - 0, - BinaryenNop(module)); - for (i = 0; i < BinaryenGetNumFunctions(module) ; i++) { assert(BinaryenGetFunctionByIndex(module, i) == fns[i]); } @@ -1285,6 +1284,24 @@ void test_for_each() { assert(0 == strcmp(segments[i], out)); } } + { + const char* funcNames[] = { + BinaryenFunctionGetName(fns[0]), + BinaryenFunctionGetName(fns[1]), + BinaryenFunctionGetName(fns[2]) + }; + BinaryenExpressionRef constExprRef = BinaryenConst(module, BinaryenLiteralInt32(0)); + BinaryenSetFunctionTable(module, 1, 1, funcNames, 3, constExprRef); + assert(0 == BinaryenIsFunctionTableImported(module)); + assert(1 == BinaryenGetNumFunctionTableSegments(module)); + assert(constExprRef == BinaryenGetFunctionTableSegmentOffset(module, 0)); + assert(3 == BinaryenGetFunctionTableSegmentLength(module, 0)); + for (i = 0; i != BinaryenGetFunctionTableSegmentLength(module, 0); ++i) + { + const char * str = BinaryenGetFunctionTableSegmentData(module, 0, i); + assert(0 == strcmp(funcNames[i], str)); + } + } BinaryenModulePrint(module); BinaryenModuleDispose(module); } diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index b64aeefc7..1d3ee1dc2 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -6749,6 +6749,8 @@ validation: 0 (memory $0 1 256) (data (i32.const 10) "hello, world") (data (global.get $a-global) "segment data 2") + (table $0 1 1 funcref) + (elem (i32.const 0) $fn0 $fn1 $fn2) (global $a-global i32 (i32.const 125)) (export "export0" (func $fn0)) (export "export1" (func $fn1)) |