diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 39 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 23 | ||||
-rw-r--r-- | src/wasm.h | 14 |
3 files changed, 53 insertions, 23 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index d25b64886..43ddc954c 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -546,19 +546,21 @@ struct PrintSExpression : public Visitor<PrintSExpression> { } void visitExport(Export *curr) { printOpening(o, "export "); - printText(o, curr->name.str) << ' '; + printText(o, curr->name.str) << " ("; switch (curr->kind) { - case Export::Function: printName(curr->value); break; - case Export::Table: o << "table"; break; - case Export::Memory: o << "memory"; break; - case Export::Global: o << "global "; printName(curr->value); break; + case Export::Function: o << "func"; break; + case Export::Table: o << "table"; break; + case Export::Memory: o << "memory"; break; + case Export::Global: o << "global"; break; default: WASM_UNREACHABLE(); } - o << ')'; + o << ' '; + printName(curr->value) << "))"; } void visitGlobal(Global *curr) { printOpening(o, "global "); - printName(curr->name) << ' ' << printWasmType(curr->type) << ' '; + printName(curr->name) << ' '; + o << printWasmType(curr->type) << ' '; visit(curr->init); o << ')'; } @@ -598,7 +600,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> { decIndent(); } void visitTable(Table *curr) { - printOpening(o, "table") << ' ' << curr->initial; + printOpening(o, "table") << ' '; + o << curr->initial; if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max; o << " anyfunc)\n"; doIndent(o, indent); @@ -612,15 +615,12 @@ struct PrintSExpression : public Visitor<PrintSExpression> { o << ')'; } } - void visitModule(Module *curr) { - currModule = curr; - printOpening(o, "module", true); - incIndent(); - doIndent(o, indent); - printOpening(o, "memory") << ' ' << curr->memory.initial; - if (curr->memory.max && curr->memory.max != Memory::kMaxSize) o << ' ' << curr->memory.max; + void visitMemory(Memory* curr) { + printOpening(o, "memory") << ' '; + o << curr->initial; + if (curr->max && curr->max != Memory::kMaxSize) o << ' ' << curr->max; o << ")\n"; - for (auto segment : curr->memory.segments) { + for (auto segment : curr->segments) { doIndent(o, indent); printOpening(o, "data ", true); visit(segment.offset); @@ -647,6 +647,13 @@ struct PrintSExpression : public Visitor<PrintSExpression> { } o << "\")\n"; } + } + void visitModule(Module *curr) { + currModule = curr; + printOpening(o, "module", true); + incIndent(); + doIndent(o, indent); + visitMemory(&curr->memory); if (curr->start.is()) { doIndent(o, indent); printOpening(o, "start") << ' ' << curr->start << ')'; diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 3ac900213..c328f3e29 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1402,8 +1402,26 @@ private: void parseExport(Element& s) { std::unique_ptr<Export> ex = make_unique<Export>(); - if (!s[2]->dollared() && !std::isdigit(s[2]->str()[0])) { - ex->name = s[1]->str(); + ex->name = s[1]->str(); + if (s[2]->isList()) { + auto& inner = *s[2]; + if (inner[0]->str() == FUNC) { + ex->value = inner[1]->str(); + ex->kind = Export::Function; + } else if (inner[0]->str() == MEMORY) { + if (!hasMemory) throw ParseException("memory exported but no memory"); + ex->value = Name::fromInt(0); + ex->kind = Export::Memory; + } else if (inner[0]->str() == TABLE) { + ex->value = Name::fromInt(0); + ex->kind = Export::Table; + } else if (inner[0]->str() == GLOBAL) { + ex->value = inner[1]->str(); + ex->kind = Export::Table; + } else { + WASM_UNREACHABLE(); + } + } else if (!s[2]->dollared() && !std::isdigit(s[2]->str()[0])) { if (s[2]->str() == MEMORY) { if (!hasMemory) throw ParseException("memory exported but no memory"); ex->value = Name::fromInt(0); @@ -1419,7 +1437,6 @@ private: } } else { // function - ex->name = s[1]->str(); ex->value = s[2]->str(); ex->kind = Export::Function; } diff --git a/src/wasm.h b/src/wasm.h index 1cf00cc36..d6bdfe91f 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1454,7 +1454,7 @@ public: Global = 3, }; - Name name; // exported name + Name name; // exported name - note that this is the key, as the internal name is non-unique (can have multiple exports for an internal, also over kinds) Name value; // internal name Kind kind; }; @@ -1474,10 +1474,13 @@ public: } }; + Name name; Address initial, max; std::vector<Segment> segments; - Table() : initial(0), max(kMaxSize) {} + Table() : initial(0), max(kMaxSize) { + name = Name::fromInt(0); + } }; class Memory { @@ -1499,10 +1502,13 @@ public: } }; + Name name; Address initial, max; // sizes are in pages std::vector<Segment> segments; - Memory() : initial(0), max(kMaxSize) {} + Memory() : initial(0), max(kMaxSize) { + name = Name::fromInt(0); + } }; class Global { @@ -1531,7 +1537,7 @@ private: // TODO: add a build option where Names are just indices, and then these methods are not needed std::map<Name, FunctionType*> functionTypesMap; std::map<Name, Import*> importsMap; - std::map<Name, Export*> exportsMap; + std::map<Name, Export*> exportsMap; // exports map is by the *exported* name, which is unique std::map<Name, Function*> functionsMap; std::map<Name, Global*> globalsMap; |