diff options
-rw-r--r-- | src/binaryen-c.cpp | 2 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 5 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 16 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt.txt | 2 |
4 files changed, 20 insertions, 5 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 08136d059..9883aef71 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -841,7 +841,7 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* na BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name, BinaryenType type, int8_t mutable_, BinaryenExpressionRef init) { if (tracing) { - std::cout << " BinaryenAddGlobal(the_module, \"" << name << "\", " << type << ", " << mutable_ << ", expressions[" << expressions[init] << "]);\n"; + std::cout << " BinaryenAddGlobal(the_module, \"" << name << "\", " << type << ", " << int(mutable_) << ", expressions[" << expressions[init] << "]);\n"; } auto* wasm = (Module*)module; diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 0802d96cd..3b711d28a 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -234,6 +234,11 @@ void test_core() { // Create the function BinaryenType localTypes[] = { BinaryenInt32() }; BinaryenFunctionRef sinker = BinaryenAddFunction(module, "kitchen()sinker", iiIfF, localTypes, 1, body); + + // Globals + + BinaryenAddGlobal(module, "a-global", BinaryenInt32(), 0, makeInt32(module, 7)); + BinaryenAddGlobal(module, "a-mutable-global", BinaryenFloat32(), 1, makeFloat32(module, 7.5)); // Imports diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index d08a204a9..21c26791c 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -12,6 +12,8 @@ BinaryenFloat64: 4 (type $v (func)) (type $3 (func)) (import "module" "base" (func $an-imported (param i32 f64) (result f32))) + (global $a-global i32 (i32.const 7)) + (global $a-mutable-global (mut f32) (f32.const 7.5)) (table 1 1 anyfunc) (elem (i32.const 0) "$kitchen()sinker") (memory $0 1 256) @@ -1386,6 +1388,10 @@ int main() { BinaryenType varTypes[] = { 1 }; functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[0], varTypes, 1, expressions[251]); } + expressions[252] = BinaryenConst(the_module, BinaryenLiteralInt32(7)); + BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[252]); + expressions[253] = BinaryenConst(the_module, BinaryenLiteralFloat32(7.5)); + BinaryenAddGlobal(the_module, "a-mutable-global", 3, 1, expressions[253]); { BinaryenType paramTypes[] = { 1, 4 }; functionTypes[1] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2); @@ -1396,11 +1402,11 @@ int main() { BinaryenFunctionRef funcs[] = { functions[0] }; BinaryenSetFunctionTable(the_module, funcs, 1); } - expressions[252] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); + expressions[254] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); { const char segment0[] = { 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100 }; const char* segments[] = { segment0 }; - BinaryenExpressionRef segmentOffsets[] = { expressions[252] }; + BinaryenExpressionRef segmentOffsets[] = { expressions[254] }; BinaryenIndex segmentSizes[] = { 12 }; BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentOffsets, segmentSizes, 1); } @@ -1408,10 +1414,10 @@ int main() { BinaryenType paramTypes[] = { 0 }; functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } - expressions[253] = BinaryenNop(the_module); + expressions[255] = BinaryenNop(the_module); { BinaryenType varTypes[] = { 0 }; - functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[253]); + functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[255]); } BinaryenSetStart(the_module, functions[1]); { @@ -1427,6 +1433,8 @@ int main() { (type $v (func)) (type $3 (func)) (import "module" "base" (func $an-imported (param i32 f64) (result f32))) + (global $a-global i32 (i32.const 7)) + (global $a-mutable-global (mut f32) (f32.const 7.5)) (table 1 1 anyfunc) (elem (i32.const 0) "$kitchen()sinker") (memory $0 1 256) diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index 4f35a746f..a14138166 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -7,6 +7,8 @@ (type $v (func)) (type $3 (func)) (import "module" "base" (func $an-imported (param i32 f64) (result f32))) + (global $a-global i32 (i32.const 7)) + (global $a-mutable-global (mut f32) (f32.const 7.5)) (table 1 1 anyfunc) (elem (i32.const 0) "$kitchen()sinker") (memory $0 1 256) |