Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ export_function "_BinaryenMemoryInitId"
export_function "_BinaryenDataDropId"
export_function "_BinaryenMemoryCopyId"
export_function "_BinaryenMemoryFillId"
export_function "_BinaryenPushId"
export_function "_BinaryenPopId"

# External kinds
export_function "_BinaryenExternalFunction"
Expand Down Expand Up @@ -576,6 +578,8 @@ export_function "_BinaryenMemoryInit"
export_function "_BinaryenDataDrop"
export_function "_BinaryenMemoryCopy"
export_function "_BinaryenMemoryFill"
export_function "_BinaryenPush"
export_function "_BinaryenPop"

# 'Expression' operations
export_function "_BinaryenExpressionGetId"
Expand Down Expand Up @@ -752,6 +756,9 @@ export_function "_BinaryenMemoryFillGetDest"
export_function "_BinaryenMemoryFillGetValue"
export_function "_BinaryenMemoryFillGetSize"

# 'Push' expression operations
export_function "_BinaryenPushGetValue"

# 'Module' operations
export_function "_BinaryenModuleCreate"
export_function "_BinaryenModuleDispose"
Expand Down
2 changes: 2 additions & 0 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
("i64.pop", "makePop(i64)"),
("f32.pop", "makePop(f32)"),
("f64.pop", "makePop(f64)"),
("v128.pop", "makePop(v128)"),
("exnref.pop", "makePop(exnref)"),
("i32.load", "makeLoad(s, i32, /*isAtomic=*/false)"),
("i64.load", "makeLoad(s, i64, /*isAtomic=*/false)"),
("f32.load", "makeLoad(s, f32, /*isAtomic=*/false)"),
Expand Down
27 changes: 27 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ BinaryenExpressionId BinaryenMemoryCopyId(void) {
BinaryenExpressionId BinaryenMemoryFillId(void) {
return Expression::Id::MemoryFillId;
}
BinaryenExpressionId BinaryenPushId(void) { return Expression::Id::PushId; }
BinaryenExpressionId BinaryenPopId(void) { return Expression::Id::PopId; }

// External kinds

Expand Down Expand Up @@ -1573,6 +1575,21 @@ BinaryenExpressionRef BinaryenMemoryFill(BinaryenModuleRef module,
}
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenPush(BinaryenModuleRef module,
BinaryenExpressionRef value) {
auto* ret = Builder(*(Module*)module).makePush((Expression*)value);
if (tracing) {
traceExpression(ret, "BinaryenPush", value);
}
return static_cast<Expression*>(ret);
}
BinaryenExpressionRef BinaryenPop(BinaryenModuleRef module, BinaryenType type) {
auto* ret = Builder(*(Module*)module).makePop(Type(type));
if (tracing) {
traceExpression(ret, "BinaryenPop", type);
}
return static_cast<Expression*>(ret);
}

// Expression utility

Expand Down Expand Up @@ -2704,6 +2721,16 @@ BinaryenExpressionRef BinaryenMemoryFillGetSize(BinaryenExpressionRef expr) {
assert(expression->is<MemoryFill>());
return static_cast<MemoryFill*>(expression)->size;
}
BinaryenExpressionRef BinaryenPushGetValue(BinaryenExpressionRef expr) {
if (tracing) {
std::cout << " BinaryenPushGetValue(expressions[" << expressions[expr]
<< "]);\n";
}

auto* expression = (Expression*)expr;
assert(expression->is<Push>());
return static_cast<Push*>(expression)->value;
}

// Functions

Expand Down
7 changes: 7 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ BinaryenExpressionId BinaryenMemoryInitId(void);
BinaryenExpressionId BinaryenDataDropId(void);
BinaryenExpressionId BinaryenMemoryCopyId(void);
BinaryenExpressionId BinaryenMemoryFillId(void);
BinaryenExpressionId BinaryenPushId(void);
BinaryenExpressionId BinaryenPopId(void);

// External kinds (call to get the value of each; you can cache them)

Expand Down Expand Up @@ -699,6 +701,9 @@ BinaryenExpressionRef BinaryenMemoryFill(BinaryenModuleRef module,
BinaryenExpressionRef dest,
BinaryenExpressionRef value,
BinaryenExpressionRef size);
BinaryenExpressionRef BinaryenPush(BinaryenModuleRef module,
BinaryenExpressionRef value);
BinaryenExpressionRef BinaryenPop(BinaryenModuleRef module, BinaryenType type);

BinaryenExpressionId BinaryenExpressionGetId(BinaryenExpressionRef expr);
BinaryenType BinaryenExpressionGetType(BinaryenExpressionRef expr);
Expand Down Expand Up @@ -850,6 +855,8 @@ BinaryenExpressionRef BinaryenMemoryFillGetDest(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenMemoryFillGetValue(BinaryenExpressionRef expr);
BinaryenExpressionRef BinaryenMemoryFillGetSize(BinaryenExpressionRef expr);

BinaryenExpressionRef BinaryenPushGetValue(BinaryenExpressionRef expr);

// Functions

typedef void* BinaryenFunctionRef;
Expand Down
17 changes: 14 additions & 3 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'e':
if (strcmp(op, "else") == 0) { return makeThenOrElse(s); }
goto parse_error;
case 'e': {
switch (op[1]) {
case 'l':
if (strcmp(op, "else") == 0) { return makeThenOrElse(s); }
goto parse_error;
case 'x':
if (strcmp(op, "exnref.pop") == 0) { return makePop(exnref); }
goto parse_error;
default: goto parse_error;
}
}
case 'f': {
switch (op[1]) {
case '3': {
Expand Down Expand Up @@ -2278,6 +2286,9 @@ switch (op[0]) {
case 'o':
if (strcmp(op, "v128.or") == 0) { return makeBinary(s, BinaryOp::OrVec128); }
goto parse_error;
case 'p':
if (strcmp(op, "v128.pop") == 0) { return makePop(v128); }
goto parse_error;
case 's':
if (strcmp(op, "v128.store") == 0) { return makeStore(s, v128, /*isAtomic=*/false); }
goto parse_error;
Expand Down
32 changes: 32 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Module['MemoryInitId'] = Module['_BinaryenMemoryInitId']();
Module['DataDropId'] = Module['_BinaryenDataDropId']();
Module['MemoryCopyId'] = Module['_BinaryenMemoryCopyId']();
Module['MemoryFillId'] = Module['_BinaryenMemoryFillId']();
Module['PushId'] = Module['_BinaryenPushId']();
Module['PopId'] = Module['_BinaryenPopId']();

// External kinds
Module['ExternalFunction'] = Module['_BinaryenExternalFunction']();
Expand Down Expand Up @@ -761,6 +763,9 @@ function wrapModule(module, self) {
'wait': function(ptr, expected, timeout) {
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i32']);
},
'pop': function() {
return Module['_BinaryenPop'](module, Module['i32']);
}
};

self['i64'] = {
Expand Down Expand Up @@ -1062,6 +1067,9 @@ function wrapModule(module, self) {
'wait': function(ptr, expected, timeout) {
return Module['_BinaryenAtomicWait'](module, ptr, expected, timeout, Module['i64']);
},
'pop': function() {
return Module['_BinaryenPop'](module, Module['i64']);
}
};

self['f32'] = {
Expand Down Expand Up @@ -1167,6 +1175,9 @@ function wrapModule(module, self) {
'ge': function(left, right) {
return Module['_BinaryenBinary'](module, Module['GeFloat32'], left, right);
},
'pop': function() {
return Module['_BinaryenPop'](module, Module['f32']);
}
};

self['f64'] = {
Expand Down Expand Up @@ -1272,6 +1283,9 @@ function wrapModule(module, self) {
'ge': function(left, right) {
return Module['_BinaryenBinary'](module, Module['GeFloat64'], left, right);
},
'pop': function() {
return Module['_BinaryenPop'](module, Module['f64']);
}
};

self['v128'] = {
Expand Down Expand Up @@ -1302,6 +1316,9 @@ function wrapModule(module, self) {
},
'bitselect': function(left, right, cond) {
return Module['_BinaryenSIMDBitselect'](module, left, right, cond);
},
'pop': function() {
return Module['_BinaryenPop'](module, Module['v128']);
}
};

Expand Down Expand Up @@ -1724,6 +1741,12 @@ function wrapModule(module, self) {
},
};

self['exnref'] = {
'pop': function() {
return Module['_BinaryenPop'](module, Module['exnref']);
}
};

self['select'] = function(condition, ifTrue, ifFalse) {
return Module['_BinaryenSelect'](module, condition, ifTrue, ifFalse);
};
Expand All @@ -1748,6 +1771,9 @@ function wrapModule(module, self) {
self['notify'] = function(ptr, notifyCount) {
return Module['_BinaryenAtomicNotify'](module, ptr, notifyCount);
};
self['push'] = function(value) {
return Module['_BinaryenPush'](module, value);
};

// 'Module' operations
self['addFunctionType'] = function(name, result, paramTypes) {
Expand Down Expand Up @@ -2225,6 +2251,7 @@ Module['getExpressionInfo'] = function(expr) {
};
case Module['NopId']:
case Module['UnreachableId']:
case Module['PopId']:
return {
'id': id,
'type': type
Expand Down Expand Up @@ -2349,6 +2376,11 @@ Module['getExpressionInfo'] = function(expr) {
'value': Module['_BinaryenMemoryFillGetValue'](expr),
'size': Module['_BinaryenMemoryFillGetSize'](expr)
};
case Module['PushId']:
return {
'id': id,
'value': Module['_BinaryenPushGetValue'](expr)
};

default:
throw Error('unexpected id: ' + id);
Expand Down
9 changes: 9 additions & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function test_ids() {
console.log("DataDropId: " + Binaryen.DataDropId);
console.log("MemoryCopyId: " + Binaryen.MemoryCopyId);
console.log("MemoryFillId: " + Binaryen.MemoryFillId);
console.log("PushId: " + Binaryen.PushId);
console.log("PopId: " + Binaryen.PopId);
}

function test_core() {
Expand Down Expand Up @@ -399,6 +401,13 @@ function test_core() {
// Tail Call
module.returnCall("kitchen()sinker", [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], Binaryen.i32),
module.returnCallIndirect(makeInt32(2449), [ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ], "iiIfF"),
// Push and pop
module.push(module.i32.pop()),
module.push(module.i64.pop()),
module.push(module.f32.pop()),
module.push(module.f64.pop()),
module.push(module.v128.pop()),
module.push(module.exnref.pop()),
// TODO: Host
module.nop(),
module.unreachable(),
Expand Down
Loading