diff options
-rw-r--r-- | src/binaryen-c.cpp | 4 | ||||
-rw-r--r-- | src/binaryen-c.h | 2 | ||||
-rw-r--r-- | test/example/c-api-hello-world.c | 15 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 22 |
4 files changed, 21 insertions, 22 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 4e5ad22f1..1cdddfdc8 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -3623,8 +3623,8 @@ uint32_t BinaryenGetNumMemorySegments(BinaryenModuleRef module) { auto* wasm = (Module*)module; return wasm->memory.segments.size(); } -int64_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module, - BinaryenIndex id) { +uint32_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module, + BinaryenIndex id) { if (tracing) { std::cout << " BinaryenGetMemorySegmentByteOffset(the_module, " << id << ");\n"; diff --git a/src/binaryen-c.h b/src/binaryen-c.h index dd5acf325..67eda040a 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -1190,7 +1190,7 @@ BINARYEN_API void BinaryenSetMemory(BinaryenModuleRef module, // Memory segments. Query utilities. BINARYEN_API uint32_t BinaryenGetNumMemorySegments(BinaryenModuleRef module); -BINARYEN_API int64_t +BINARYEN_API uint32_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module, BinaryenIndex id); BINARYEN_API size_t BinaryenGetMemorySegmentByteLength(BinaryenModuleRef module, BinaryenIndex id); diff --git a/test/example/c-api-hello-world.c b/test/example/c-api-hello-world.c index 066799de6..3b412f67f 100644 --- a/test/example/c-api-hello-world.c +++ b/test/example/c-api-hello-world.c @@ -1,14 +1,16 @@ #include <binaryen-c.h> -// "hello world" type example: create a function that adds two i32s and returns the result +// "hello world" type example: create a function that adds two i32s and returns +// the result int main() { BinaryenModuleRef module = BinaryenModuleCreate(); // Create a function type for i32 (i32, i32) - BinaryenType params[2] = { BinaryenTypeInt32(), BinaryenTypeInt32() }; - BinaryenFunctionTypeRef iii = BinaryenAddFunctionType(module, "iii", BinaryenTypeInt32(), params, 2); + BinaryenType params[2] = {BinaryenTypeInt32(), BinaryenTypeInt32()}; + BinaryenFunctionTypeRef iii = + BinaryenAddFunctionType(module, "iii", BinaryenTypeInt32(), params, 2); // Get the 0 and 1 arguments, and add them BinaryenExpressionRef x = BinaryenLocalGet(module, 0, BinaryenTypeInt32()), @@ -17,8 +19,10 @@ int main() { // Create the add function // Note: no additional local variables - // Note: no basic blocks here, we are an AST. The function body is just an expression node. - BinaryenFunctionRef adder = BinaryenAddFunction(module, "adder", iii, NULL, 0, add); + // Note: no basic blocks here, we are an AST. The function body is just an + // expression node. + BinaryenFunctionRef adder = + BinaryenAddFunction(module, "adder", iii, NULL, 0, add); // Print it out BinaryenModulePrint(module); @@ -28,4 +32,3 @@ int main() { return 0; } - diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index f7bc12b8d..f5fe5dc50 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -1033,28 +1033,24 @@ void test_for_each() { assert(BinaryenGetExportByIndex(module, i) == exps[i]); } - BinaryenAddGlobal(module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, 125)); - const char* segments[] = { "hello, world", "segment data 2" }; + const uint32_t expected_offsets[] = { 10, 125 }; int8_t segmentPassive[] = { 0, 0 }; + BinaryenIndex segmentSizes[] = { 12, 14 }; + BinaryenExpressionRef segmentOffsets[] = { - BinaryenConst(module, BinaryenLiteralInt32(10)), + BinaryenConst(module, BinaryenLiteralInt32(expected_offsets[0])), BinaryenGlobalGet(module, "a-global", BinaryenTypeInt32()) }; - BinaryenIndex segmentSizes[] = { 12, 14 }; BinaryenSetMemory(module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 0); + BinaryenAddGlobal(module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, expected_offsets[1])); for (i = 0; i < BinaryenGetNumMemorySegments(module) ; i++) { - char out[15] = {0}; - assert(BinaryenGetMemorySegmentByteOffset(module, i) == (0==i?10:125)); + char out[15] = {}; + assert(BinaryenGetMemorySegmentByteOffset(module, i) == expected_offsets[i]); assert(BinaryenGetMemorySegmentByteLength(module, i) == segmentSizes[i]); - BinaryenCopyMemorySegmentData(module, i, &out[0]); - if (0 == i) { - assert(0 == strcmp("hello, world", &out[0])); - } - else { - assert(0 == strcmp("segment data 2", &out[0])); - } + BinaryenCopyMemorySegmentData(module, i, out); + assert(0 == strcmp(segments[i], out)); } } BinaryenModulePrint(module); |