summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-09-20 13:45:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-09-20 13:45:16 -0700
commit947cd3f224623f2d1e76f3c6cc30487ea8fd79ef (patch)
tree084235cae91bc812f2bd31c58c75a5c9fccb7a2d /src
parent2aa7ba43b59782243cd4960df43c7936292c41f4 (diff)
downloadbinaryen-947cd3f224623f2d1e76f3c6cc30487ea8fd79ef.tar.gz
binaryen-947cd3f224623f2d1e76f3c6cc30487ea8fd79ef.tar.bz2
binaryen-947cd3f224623f2d1e76f3c6cc30487ea8fd79ef.zip
memory and table printing fixes
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 06a8758c5..363147b98 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -540,8 +540,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
printText(o, curr->base.str) << ' ';
switch (curr->kind) {
case Export::Function: if (curr->functionType) visitFunctionType(curr->functionType, &curr->name); break;
- case Export::Table: o << "(table " << curr->name << ")"; break;
- case Export::Memory: o << "(memory " << curr->name << ")"; break;
+ case Export::Table: printTableHeader(&currModule->table); break;
+ case Export::Memory: printMemoryHeader(&currModule->memory); break;
case Export::Global: o << "(global " << curr->name << ' ' << printWasmType(curr->globalType) << ")"; break;
default: WASM_UNREACHABLE();
}
@@ -606,11 +606,26 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
decIndent();
}
- void visitTable(Table *curr) {
+ void printTableHeader(Table* curr) {
printOpening(o, "table") << ' ';
o << curr->initial;
if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max;
- o << " anyfunc)\n";
+ o << " anyfunc)";
+ }
+ void visitTable(Table *curr) {
+ // if table wasn't imported, declare it
+ bool found = false;
+ for (auto& import : currModule->imports) {
+ if (import->kind == Import::Table) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ doIndent(o, indent);
+ printTableHeader(curr);
+ o << '\n';
+ }
doIndent(o, indent);
for (auto& segment : curr->segments) {
printOpening(o, "elem ", true);
@@ -622,11 +637,26 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
o << ')';
}
}
- void visitMemory(Memory* curr) {
+ void printMemoryHeader(Memory* curr) {
printOpening(o, "memory") << ' ';
o << curr->initial;
if (curr->max && curr->max != Memory::kMaxSize) o << ' ' << curr->max;
- o << ")\n";
+ o << ")";
+ }
+ void visitMemory(Memory* curr) {
+ // if memory wasn't imported, declare it
+ bool found = false;
+ for (auto& import : currModule->imports) {
+ if (import->kind == Import::Memory) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ doIndent(o, indent);
+ printMemoryHeader(curr);
+ o << '\n';
+ }
for (auto segment : curr->segments) {
doIndent(o, indent);
printOpening(o, "data ", true);
@@ -659,7 +689,6 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
currModule = curr;
printOpening(o, "module", true);
incIndent();
- doIndent(o, indent);
visitMemory(&curr->memory);
if (curr->start.is()) {
doIndent(o, indent);
@@ -689,7 +718,6 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
o << maybeNewLine;
}
if (curr->table.segments.size() > 0 || curr->table.initial > 0 || curr->table.max != Table::kMaxSize) {
- doIndent(o, indent);
visitTable(&curr->table);
o << maybeNewLine;
}