Skip to content

Update Pop text format to handle tuples #3116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 11, 2020
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
12 changes: 2 additions & 10 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@
("data.drop", "makeDataDrop(s)"),
("memory.copy", "makeMemoryCopy(s)"),
("memory.fill", "makeMemoryFill(s)"),
("i32.pop", "makePop(Type::i32)"),
("i64.pop", "makePop(Type::i64)"),
("f32.pop", "makePop(Type::f32)"),
("f64.pop", "makePop(Type::f64)"),
("v128.pop", "makePop(Type::v128)"),
("funcref.pop", "makePop(Type::funcref)"),
("externref.pop", "makePop(Type::externref)"),
("exnref.pop", "makePop(Type::exnref)"),
("anyref.pop", "makePop(Type::anyref)"),
("i32.load", "makeLoad(s, Type::i32, /*isAtomic=*/false)"),
("i64.load", "makeLoad(s, Type::i64, /*isAtomic=*/false)"),
("f32.load", "makeLoad(s, Type::f32, /*isAtomic=*/false)"),
Expand Down Expand Up @@ -503,7 +494,8 @@
("br_on_exn", "makeBrOnExn(s)"),
# Multivalue pseudoinstructions
("tuple.make", "makeTupleMake(s)"),
("tuple.extract", "makeTupleExtract(s)")
("tuple.extract", "makeTupleExtract(s)"),
("pop", "makePop(s)")
]


Expand Down
94 changes: 20 additions & 74 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@ char op[27] = {'\0'};
strncpy(op, s[0]->c_str(), 26);
switch (op[0]) {
case 'a': {
switch (op[1]) {
switch (op[7]) {
case 'f':
if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); }
goto parse_error;
case 'n':
if (strcmp(op, "anyref.pop") == 0) { return makePop(Type::anyref); }
if (strcmp(op, "atomic.notify") == 0) { return makeAtomicNotify(s); }
goto parse_error;
case 't': {
switch (op[7]) {
case 'f':
if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); }
goto parse_error;
case 'n':
if (strcmp(op, "atomic.notify") == 0) { return makeAtomicNotify(s); }
goto parse_error;
default: goto parse_error;
}
}
default: goto parse_error;
}
}
Expand Down Expand Up @@ -78,25 +70,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'e': {
switch (op[1]) {
case 'l':
if (strcmp(op, "else") == 0) { return makeThenOrElse(s); }
goto parse_error;
case 'x': {
switch (op[2]) {
case 'n':
if (strcmp(op, "exnref.pop") == 0) { return makePop(Type::exnref); }
goto parse_error;
case 't':
if (strcmp(op, "externref.pop") == 0) { return makePop(Type::externref); }
goto parse_error;
default: goto parse_error;
}
}
default: goto parse_error;
}
}
case 'e':
if (strcmp(op, "else") == 0) { return makeThenOrElse(s); }
goto parse_error;
case 'f': {
switch (op[1]) {
case '3': {
Expand Down Expand Up @@ -235,9 +211,6 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'p':
if (strcmp(op, "f32.pop") == 0) { return makePop(Type::f32); }
goto parse_error;
case 'r':
if (strcmp(op, "f32.reinterpret_i32") == 0) { return makeUnary(s, UnaryOp::ReinterpretInt32); }
goto parse_error;
Expand Down Expand Up @@ -536,17 +509,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'p': {
switch (op[5]) {
case 'o':
if (strcmp(op, "f64.pop") == 0) { return makePop(Type::f64); }
goto parse_error;
case 'r':
if (strcmp(op, "f64.promote_f32") == 0) { return makeUnary(s, UnaryOp::PromoteFloat32); }
goto parse_error;
default: goto parse_error;
}
}
case 'p':
if (strcmp(op, "f64.promote_f32") == 0) { return makeUnary(s, UnaryOp::PromoteFloat32); }
goto parse_error;
case 'r':
if (strcmp(op, "f64.reinterpret_i64") == 0) { return makeUnary(s, UnaryOp::ReinterpretInt64); }
goto parse_error;
Expand Down Expand Up @@ -717,9 +682,6 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'u':
if (strcmp(op, "funcref.pop") == 0) { return makePop(Type::funcref); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down Expand Up @@ -1306,17 +1268,9 @@ switch (op[0]) {
case 'o':
if (strcmp(op, "i32.or") == 0) { return makeBinary(s, BinaryOp::OrInt32); }
goto parse_error;
case 'p': {
switch (op[7]) {
case '\0':
if (strcmp(op, "i32.pop") == 0) { return makePop(Type::i32); }
goto parse_error;
case 'c':
if (strcmp(op, "i32.popcnt") == 0) { return makeUnary(s, UnaryOp::PopcntInt32); }
goto parse_error;
default: goto parse_error;
}
}
case 'p':
if (strcmp(op, "i32.popcnt") == 0) { return makeUnary(s, UnaryOp::PopcntInt32); }
goto parse_error;
case 'r': {
switch (op[5]) {
case 'e': {
Expand Down Expand Up @@ -2056,17 +2010,9 @@ switch (op[0]) {
case 'o':
if (strcmp(op, "i64.or") == 0) { return makeBinary(s, BinaryOp::OrInt64); }
goto parse_error;
case 'p': {
switch (op[7]) {
case '\0':
if (strcmp(op, "i64.pop") == 0) { return makePop(Type::i64); }
goto parse_error;
case 'c':
if (strcmp(op, "i64.popcnt") == 0) { return makeUnary(s, UnaryOp::PopcntInt64); }
goto parse_error;
default: goto parse_error;
}
}
case 'p':
if (strcmp(op, "i64.popcnt") == 0) { return makeUnary(s, UnaryOp::PopcntInt64); }
goto parse_error;
case 'r': {
switch (op[5]) {
case 'e': {
Expand Down Expand Up @@ -2571,6 +2517,9 @@ switch (op[0]) {
case 'n':
if (strcmp(op, "nop") == 0) { return makeNop(); }
goto parse_error;
case 'p':
if (strcmp(op, "pop") == 0) { return makePop(s); }
goto parse_error;
case 'r': {
switch (op[2]) {
case 'f': {
Expand Down Expand Up @@ -2696,9 +2645,6 @@ 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(Type::v128); }
goto parse_error;
case 's':
if (strcmp(op, "v128.store") == 0) { return makeStore(s, Type::v128, /*isAtomic=*/false); }
goto parse_error;
Expand Down
7 changes: 5 additions & 2 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,8 +1469,11 @@ struct PrintExpressionContents
void visitNop(Nop* curr) { printMinor(o, "nop"); }
void visitUnreachable(Unreachable* curr) { printMinor(o, "unreachable"); }
void visitPop(Pop* curr) {
prepareColor(o) << curr->type;
o << ".pop";
prepareColor(o) << "pop";
for (auto type : curr->type) {
assert(type.isBasic() && "TODO: print and parse compound types");
o << " " << type;
}
restoreNormalColor(o);
}
void visitTupleMake(TupleMake* curr) { printMedium(o, "tuple.make"); }
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-s-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class SExpressionWasmBuilder {
Expression* makeMemoryCopy(Element& s);
Expression* makeMemoryFill(Element& s);
Expression* makePush(Element& s);
Expression* makePop(Type type);
Expression* makePop(Element& s);
Expression* makeIf(Element& s);
Expression* makeMaybeBlock(Element& s, size_t i, Type type);
Expression* makeLoop(Element& s);
Expand Down
8 changes: 6 additions & 2 deletions src/wasm/wasm-s-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,9 +1620,13 @@ Expression* SExpressionWasmBuilder::makeMemoryFill(Element& s) {
return ret;
}

Expression* SExpressionWasmBuilder::makePop(Type type) {
Expression* SExpressionWasmBuilder::makePop(Element& s) {
auto ret = allocator.alloc<Pop>();
ret->type = type;
std::vector<Type> types;
for (size_t i = 1; i < s.size(); ++i) {
types.push_back(stringToType(s[i]->str()));
}
ret->type = Type(types);
ret->finalize();
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion test/binaryen.js/exception-handling.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
(catch
(local.set $0
(exnref.pop)
(pop exnref)
)
(drop
(block $l (result i32)
Expand Down
36 changes: 18 additions & 18 deletions test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
)
(catch
(local.set $5
(exnref.pop)
(pop exnref)
)
(drop
(block $try-block (result i32)
Expand Down Expand Up @@ -1896,28 +1896,28 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
)
)
(drop
(i32.pop)
(pop i32)
)
(drop
(i64.pop)
(pop i64)
)
(drop
(f32.pop)
(pop f32)
)
(drop
(f64.pop)
(pop f64)
)
(drop
(v128.pop)
(pop v128)
)
(drop
(externref.pop)
(pop externref)
)
(drop
(funcref.pop)
(pop funcref)
)
(drop
(exnref.pop)
(pop exnref)
)
(nop)
(unreachable)
Expand Down Expand Up @@ -3684,7 +3684,7 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
)
(catch
(local.set $5
(exnref.pop)
(pop exnref)
)
(drop
(block $try-block (result i32)
Expand Down Expand Up @@ -3736,28 +3736,28 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
)
)
(drop
(i32.pop)
(pop i32)
)
(drop
(i64.pop)
(pop i64)
)
(drop
(f32.pop)
(pop f32)
)
(drop
(f64.pop)
(pop f64)
)
(drop
(v128.pop)
(pop v128)
)
(drop
(externref.pop)
(pop externref)
)
(drop
(funcref.pop)
(pop funcref)
)
(drop
(exnref.pop)
(pop exnref)
)
(nop)
(unreachable)
Expand Down
8 changes: 6 additions & 2 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,11 @@ void test_core() {
BinaryenRefIsNull(module, externrefExpr),
BinaryenRefIsNull(module, funcrefExpr),
BinaryenRefIsNull(module, exnrefExpr),
BinaryenSelect(
module, temp10, BinaryenRefNull(module, BinaryenTypeFuncref()), BinaryenRefFunc(module, "kitchen()sinker"), BinaryenTypeFuncref()),
BinaryenSelect(module,
temp10,
BinaryenRefNull(module, BinaryenTypeFuncref()),
BinaryenRefFunc(module, "kitchen()sinker"),
BinaryenTypeFuncref()),
// Exception handling
BinaryenTry(module, tryBody, catchBody),
// Atomics
Expand Down Expand Up @@ -752,6 +755,7 @@ void test_core() {
BinaryenPop(module, BinaryenTypeFuncref()),
BinaryenPop(module, BinaryenTypeExternref()),
BinaryenPop(module, BinaryenTypeExnref()),
BinaryenPop(module, iIfF),

// TODO: Host
BinaryenNop(module),
Expand Down
19 changes: 11 additions & 8 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ BinaryenFeatureAll: 2047
)
(catch
(local.set $5
(exnref.pop)
(pop exnref)
)
(drop
(block $try-block (result i32)
Expand Down Expand Up @@ -1834,25 +1834,28 @@ BinaryenFeatureAll: 2047
)
)
(drop
(i32.pop)
(pop i32)
)
(drop
(i64.pop)
(pop i64)
)
(drop
(f32.pop)
(pop f32)
)
(drop
(f64.pop)
(pop f64)
)
(drop
(funcref.pop)
(pop funcref)
)
(drop
(externref.pop)
(pop externref)
)
(drop
(exnref.pop)
(pop exnref)
)
(drop
(pop i32 i64 f32 f64)
)
(nop)
(unreachable)
Expand Down
Loading