Skip to content

Commit fd8e78a

Browse files
dcodeIOkripken
authored andcommitted
Fix yet another BinaryenAddGlobal tracing issue (#1283)
Now also includes a test.
1 parent 29963c3 commit fd8e78a

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/binaryen-c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* na
841841

842842
BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name, BinaryenType type, int8_t mutable_, BinaryenExpressionRef init) {
843843
if (tracing) {
844-
std::cout << " BinaryenAddGlobal(the_module, \"" << name << "\", " << type << ", " << mutable_ << ", expressions[" << expressions[init] << "]);\n";
844+
std::cout << " BinaryenAddGlobal(the_module, \"" << name << "\", " << type << ", " << int(mutable_) << ", expressions[" << expressions[init] << "]);\n";
845845
}
846846

847847
auto* wasm = (Module*)module;

test/example/c-api-kitchen-sink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ void test_core() {
234234
// Create the function
235235
BinaryenType localTypes[] = { BinaryenInt32() };
236236
BinaryenFunctionRef sinker = BinaryenAddFunction(module, "kitchen()sinker", iiIfF, localTypes, 1, body);
237+
238+
// Globals
239+
240+
BinaryenAddGlobal(module, "a-global", BinaryenInt32(), 0, makeInt32(module, 7));
241+
BinaryenAddGlobal(module, "a-mutable-global", BinaryenFloat32(), 1, makeFloat32(module, 7.5));
237242

238243
// Imports
239244

test/example/c-api-kitchen-sink.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ BinaryenFloat64: 4
1212
(type $v (func))
1313
(type $3 (func))
1414
(import "module" "base" (func $an-imported (param i32 f64) (result f32)))
15+
(global $a-global i32 (i32.const 7))
16+
(global $a-mutable-global (mut f32) (f32.const 7.5))
1517
(table 1 1 anyfunc)
1618
(elem (i32.const 0) "$kitchen()sinker")
1719
(memory $0 1 256)
@@ -1386,6 +1388,10 @@ int main() {
13861388
BinaryenType varTypes[] = { 1 };
13871389
functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[0], varTypes, 1, expressions[251]);
13881390
}
1391+
expressions[252] = BinaryenConst(the_module, BinaryenLiteralInt32(7));
1392+
BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[252]);
1393+
expressions[253] = BinaryenConst(the_module, BinaryenLiteralFloat32(7.5));
1394+
BinaryenAddGlobal(the_module, "a-mutable-global", 3, 1, expressions[253]);
13891395
{
13901396
BinaryenType paramTypes[] = { 1, 4 };
13911397
functionTypes[1] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2);
@@ -1396,22 +1402,22 @@ int main() {
13961402
BinaryenFunctionRef funcs[] = { functions[0] };
13971403
BinaryenSetFunctionTable(the_module, funcs, 1);
13981404
}
1399-
expressions[252] = BinaryenConst(the_module, BinaryenLiteralInt32(10));
1405+
expressions[254] = BinaryenConst(the_module, BinaryenLiteralInt32(10));
14001406
{
14011407
const char segment0[] = { 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100 };
14021408
const char* segments[] = { segment0 };
1403-
BinaryenExpressionRef segmentOffsets[] = { expressions[252] };
1409+
BinaryenExpressionRef segmentOffsets[] = { expressions[254] };
14041410
BinaryenIndex segmentSizes[] = { 12 };
14051411
BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentOffsets, segmentSizes, 1);
14061412
}
14071413
{
14081414
BinaryenType paramTypes[] = { 0 };
14091415
functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0);
14101416
}
1411-
expressions[253] = BinaryenNop(the_module);
1417+
expressions[255] = BinaryenNop(the_module);
14121418
{
14131419
BinaryenType varTypes[] = { 0 };
1414-
functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[253]);
1420+
functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[255]);
14151421
}
14161422
BinaryenSetStart(the_module, functions[1]);
14171423
{
@@ -1427,6 +1433,8 @@ int main() {
14271433
(type $v (func))
14281434
(type $3 (func))
14291435
(import "module" "base" (func $an-imported (param i32 f64) (result f32)))
1436+
(global $a-global i32 (i32.const 7))
1437+
(global $a-mutable-global (mut f32) (f32.const 7.5))
14301438
(table 1 1 anyfunc)
14311439
(elem (i32.const 0) "$kitchen()sinker")
14321440
(memory $0 1 256)

test/example/c-api-kitchen-sink.txt.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
(type $v (func))
88
(type $3 (func))
99
(import "module" "base" (func $an-imported (param i32 f64) (result f32)))
10+
(global $a-global i32 (i32.const 7))
11+
(global $a-mutable-global (mut f32) (f32.const 7.5))
1012
(table 1 1 anyfunc)
1113
(elem (i32.const 0) "$kitchen()sinker")
1214
(memory $0 1 256)

0 commit comments

Comments
 (0)