summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/example/c-api-hello-world.c15
-rw-r--r--test/example/c-api-kitchen-sink.c22
2 files changed, 18 insertions, 19 deletions
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);