Skip to content

Commit 69336c8

Browse files
committed
Specifying type=-1 on BinaryenBlock falls back to the old behavior
1 parent ab952d0 commit 69336c8

11 files changed

+86
-80
lines changed

bin/binaryen.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/binaryen-c.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ BinaryenType BinaryenInt32(void) { return i32; }
9494
BinaryenType BinaryenInt64(void) { return i64; }
9595
BinaryenType BinaryenFloat32(void) { return f32; }
9696
BinaryenType BinaryenFloat64(void) { return f64; }
97+
BinaryenType BinaryenAuto(void) { return -1; }
9798

9899
// Modules
99100

@@ -144,7 +145,7 @@ BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const
144145

145146
if (tracing) {
146147
std::cout << " {\n";
147-
std::cout << " BinaryenIndex paramTypes[] = { ";
148+
std::cout << " BinaryenType paramTypes[] = { ";
148149
for (BinaryenIndex i = 0; i < numParams; i++) {
149150
if (i > 0) std::cout << ", ";
150151
std::cout << paramTypes[i];
@@ -305,8 +306,8 @@ BinaryenExpressionRef BinaryenBlock(BinaryenModuleRef module, const char* name,
305306
for (BinaryenIndex i = 0; i < numChildren; i++) {
306307
ret->list.push_back((Expression*)children[i]);
307308
}
308-
if (type) ret->type = WasmType(type);
309-
ret->finalize();
309+
if (type != -1) ret->finalize(WasmType(type));
310+
else ret->finalize();
310311

311312
if (tracing) {
312313
std::cout << " {\n";
@@ -1076,6 +1077,7 @@ void BinaryenSetAPITracing(int on) {
10761077
// ===== Emscripten support =====
10771078
//
10781079

1080+
// TODO: remove this function once https://github.com/kripken/emscripten/pull/5261 lands
10791081
#ifdef EMSCRIPTEN
10801082
int __cxa_thread_atexit(void(*)(char*), char*, char*)
10811083
{

src/binaryen-c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ typedef uint32_t BinaryenIndex;
6464
// Core types (call to get the value of each; you can cache them, they
6565
// never change)
6666

67-
typedef uint32_t BinaryenType;
67+
typedef int32_t BinaryenType;
6868

6969
BinaryenType BinaryenNone(void);
7070
BinaryenType BinaryenInt32(void);
7171
BinaryenType BinaryenInt64(void);
7272
BinaryenType BinaryenFloat32(void);
7373
BinaryenType BinaryenFloat64(void);
74+
BinaryenType BinaryenAuto(void);
7475

7576
// Modules
7677
//

src/js/binaryen.js-post.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
Module['i64'] = Module['_BinaryenInt64']();
2828
Module['f32'] = Module['_BinaryenFloat32']();
2929
Module['f64'] = Module['_BinaryenFloat64']();
30+
Module['auto'] = Module['_BinaryenAuto']();
3031

3132
Module['ClzInt32'] = Module['_BinaryenClzInt32']();
3233
Module['CtzInt32'] = Module['_BinaryenCtzInt32']();
@@ -174,7 +175,8 @@
174175
this['block'] = function(name, children, type) {
175176
return preserveStack(function() {
176177
return Module['_BinaryenBlock'](module, name ? strToStack(name) : 0,
177-
i32sToStack(children), children.length, type);
178+
i32sToStack(children), children.length,
179+
typeof type !== 'undefined' ? type : Module['auto']);
178180
});
179181
};
180182
this['if'] = function(condition, ifTrue, ifFalse) {

src/wasm-js.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE call_from_js(const char *target) {
562562
else abort();
563563
}
564564

565+
// TODO: remove this function once https://github.com/kripken/emscripten/pull/5261 lands
565566
extern "C" int __cxa_thread_atexit(void(*)(char*), char*, char*)
566567
{
567568
return 0;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void test_core() {
182182
makeBinary(module, BinaryenGtFloat64(), 4),
183183
makeBinary(module, BinaryenGeFloat32(), 3),
184184
// All the rest
185-
BinaryenBlock(module, NULL, NULL, 0, 0), // block with no name and no type
185+
BinaryenBlock(module, NULL, NULL, 0, -1), // block with no name and no type
186186
BinaryenIf(module, temp1, temp2, temp3),
187187
BinaryenIf(module, temp4, temp5, NULL),
188188
BinaryenLoop(module, "in", makeInt32(module, 0)),
@@ -224,11 +224,11 @@ void test_core() {
224224
BinaryenExpressionPrint(valueList[3]); // test printing a standalone expression
225225

226226
// Make the main body of the function. and one block with a return value, one without
227-
BinaryenExpressionRef value = BinaryenBlock(module, "the-value", valueList, sizeof(valueList) / sizeof(BinaryenExpressionRef), 0);
227+
BinaryenExpressionRef value = BinaryenBlock(module, "the-value", valueList, sizeof(valueList) / sizeof(BinaryenExpressionRef), -1);
228228
BinaryenExpressionRef droppedValue = BinaryenDrop(module, value);
229-
BinaryenExpressionRef nothing = BinaryenBlock(module, "the-nothing", &droppedValue, 1, 0);
229+
BinaryenExpressionRef nothing = BinaryenBlock(module, "the-nothing", &droppedValue, 1, -1);
230230
BinaryenExpressionRef bodyList[] = { nothing, makeInt32(module, 42) };
231-
BinaryenExpressionRef body = BinaryenBlock(module, "the-body", bodyList, 2, 0);
231+
BinaryenExpressionRef body = BinaryenBlock(module, "the-body", bodyList, 2, -1);
232232

233233
// Create the function
234234
BinaryenType localTypes[] = { BinaryenInt32() };
@@ -460,7 +460,7 @@ void test_relooper() {
460460
{ // return in a block
461461
RelooperRef relooper = RelooperCreate();
462462
BinaryenExpressionRef listList[] = { makeCallCheck(module, 42), BinaryenReturn(module, makeInt32(module, 1337)) };
463-
BinaryenExpressionRef list = BinaryenBlock(module, "the-list", listList, 2, 0);
463+
BinaryenExpressionRef list = BinaryenBlock(module, "the-list", listList, 2, -1);
464464
RelooperBlockRef block = RelooperAddBlock(relooper, list);
465465
BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block, 0, module);
466466
BinaryenFunctionRef sinker = BinaryenAddFunction(module, "return", i, localTypes, 1, body);

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ int main() {
10911091
expressions[11] = BinaryenConst(the_module, BinaryenLiteralFloat32(1.3));
10921092
expressions[12] = BinaryenConst(the_module, BinaryenLiteralFloat64(3.7));
10931093
{
1094-
BinaryenIndex paramTypes[] = { 1, 2, 3, 4 };
1094+
BinaryenType paramTypes[] = { 1, 2, 3, 4 };
10951095
functionTypes[0] = BinaryenAddFunctionType(the_module, "iiIfF", 1, paramTypes, 4);
10961096
}
10971097
expressions[13] = BinaryenConst(the_module, BinaryenLiteralInt32(1));
@@ -1280,7 +1280,7 @@ int main() {
12801280
expressions[196] = BinaryenBinary(the_module, 62, expressions[195], expressions[194]);
12811281
{
12821282
BinaryenExpressionRef children[] = { 0 };
1283-
expressions[197] = BinaryenBlock(the_module, NULL, children, 0, 0);
1283+
expressions[197] = BinaryenBlock(the_module, NULL, children, 0, -1);
12841284
}
12851285
expressions[198] = BinaryenIf(the_module, expressions[13], expressions[14], expressions[15]);
12861286
expressions[199] = BinaryenIf(the_module, expressions[16], expressions[17], expressions[0]);
@@ -1348,24 +1348,24 @@ int main() {
13481348
)
13491349
{
13501350
BinaryenExpressionRef children[] = { expressions[30], expressions[32], expressions[34], expressions[36], expressions[38], expressions[40], expressions[42], expressions[44], expressions[46], expressions[48], expressions[50], expressions[52], expressions[54], expressions[56], expressions[58], expressions[60], expressions[62], expressions[64], expressions[66], expressions[68], expressions[70], expressions[72], expressions[74], expressions[76], expressions[78], expressions[80], expressions[82], expressions[84], expressions[86], expressions[88], expressions[90], expressions[92], expressions[94], expressions[96], expressions[98], expressions[100], expressions[103], expressions[106], expressions[109], expressions[112], expressions[115], expressions[118], expressions[121], expressions[124], expressions[127], expressions[130], expressions[133], expressions[136], expressions[139], expressions[142], expressions[145], expressions[148], expressions[151], expressions[154], expressions[157], expressions[160], expressions[163], expressions[166], expressions[169], expressions[172], expressions[175], expressions[178], expressions[181], expressions[184], expressions[187], expressions[190], expressions[193], expressions[196], expressions[197], expressions[198], expressions[199], expressions[201], expressions[203], expressions[204], expressions[206], expressions[208], expressions[209], expressions[210], expressions[212], expressions[214], expressions[217], expressions[220], expressions[222], expressions[224], expressions[227], expressions[229], expressions[231], expressions[233], expressions[235], expressions[236], expressions[237], expressions[238], expressions[240], expressions[241], expressions[242] };
1351-
expressions[243] = BinaryenBlock(the_module, "the-value", children, 95, 0);
1351+
expressions[243] = BinaryenBlock(the_module, "the-value", children, 95, -1);
13521352
}
13531353
expressions[244] = BinaryenDrop(the_module, expressions[243]);
13541354
{
13551355
BinaryenExpressionRef children[] = { expressions[244] };
1356-
expressions[245] = BinaryenBlock(the_module, "the-nothing", children, 1, 0);
1356+
expressions[245] = BinaryenBlock(the_module, "the-nothing", children, 1, -1);
13571357
}
13581358
expressions[246] = BinaryenConst(the_module, BinaryenLiteralInt32(42));
13591359
{
13601360
BinaryenExpressionRef children[] = { expressions[245], expressions[246] };
1361-
expressions[247] = BinaryenBlock(the_module, "the-body", children, 2, 0);
1361+
expressions[247] = BinaryenBlock(the_module, "the-body", children, 2, -1);
13621362
}
13631363
{
13641364
BinaryenType varTypes[] = { 1 };
13651365
functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[0], varTypes, 1, expressions[247]);
13661366
}
13671367
{
1368-
BinaryenIndex paramTypes[] = { 1, 4 };
1368+
BinaryenType paramTypes[] = { 1, 4 };
13691369
functionTypes[1] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2);
13701370
}
13711371
BinaryenAddImport(the_module, "an-imported", "module", "base", functionTypes[1]);
@@ -1383,7 +1383,7 @@ int main() {
13831383
BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentOffsets, segmentSizes, 1);
13841384
}
13851385
{
1386-
BinaryenIndex paramTypes[] = { 0 };
1386+
BinaryenType paramTypes[] = { 0 };
13871387
functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0);
13881388
}
13891389
expressions[249] = BinaryenNop(the_module);
@@ -1393,7 +1393,7 @@ int main() {
13931393
}
13941394
BinaryenSetStart(the_module, functions[1]);
13951395
{
1396-
BinaryenIndex paramTypes[] = { 0 };
1396+
BinaryenType paramTypes[] = { 0 };
13971397
functionTypes[3] = BinaryenAddFunctionType(the_module, NULL, 0, paramTypes, 0);
13981398
}
13991399
BinaryenModuleAutoDrop(the_module);
@@ -1937,11 +1937,11 @@ int main() {
19371937
the_module = BinaryenModuleCreate();
19381938
expressions[size_t(NULL)] = BinaryenExpressionRef(NULL);
19391939
{
1940-
BinaryenIndex paramTypes[] = { 0 };
1940+
BinaryenType paramTypes[] = { 0 };
19411941
functionTypes[0] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0);
19421942
}
19431943
{
1944-
BinaryenIndex paramTypes[] = { 1 };
1944+
BinaryenType paramTypes[] = { 1 };
19451945
functionTypes[1] = BinaryenAddFunctionType(the_module, "vi", 0, paramTypes, 1);
19461946
}
19471947
BinaryenAddImport(the_module, "check", "module", "check", functionTypes[1]);
@@ -2367,7 +2367,7 @@ int main() {
23672367
functions[13] = BinaryenAddFunction(the_module, "duffs-device", functionTypes[0], varTypes, 7, expressions[135]);
23682368
}
23692369
{
2370-
BinaryenIndex paramTypes[] = { 0 };
2370+
BinaryenType paramTypes[] = { 0 };
23712371
functionTypes[2] = BinaryenAddFunctionType(the_module, "i", 1, paramTypes, 0);
23722372
}
23732373
the_relooper = RelooperCreate();
@@ -2380,7 +2380,7 @@ int main() {
23802380
expressions[139] = BinaryenReturn(the_module, expressions[138]);
23812381
{
23822382
BinaryenExpressionRef children[] = { expressions[137], expressions[139] };
2383-
expressions[140] = BinaryenBlock(the_module, "the-list", children, 2, 0);
2383+
expressions[140] = BinaryenBlock(the_module, "the-list", children, 2, -1);
23842384
}
23852385
relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[140]);
23862386
expressions[141] = RelooperRenderAndDispose(the_relooper, relooperBlocks[0], 0, the_module);

0 commit comments

Comments
 (0)