summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-15 17:26:54 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-03-15 17:26:54 -0700
commita0156dbc900c642dd9f1b8f44ab13c06ff2e8fb9 (patch)
tree361ccaaafc58b632e22927a34b729763b06bb333 /src
parentc68e1ebb0c63f427400230cd71e46dd7629b735f (diff)
downloadbinaryen-a0156dbc900c642dd9f1b8f44ab13c06ff2e8fb9.tar.gz
binaryen-a0156dbc900c642dd9f1b8f44ab13c06ff2e8fb9.tar.bz2
binaryen-a0156dbc900c642dd9f1b8f44ab13c06ff2e8fb9.zip
add explicit memory export support
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h1
-rw-r--r--src/passes/Print.cpp6
-rw-r--r--src/s2wasm.h1
-rw-r--r--src/wasm-s-parser.h10
-rw-r--r--src/wasm.h1
5 files changed, 19 insertions, 0 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index aa59faa2d..c4f73b57a 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -721,6 +721,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
wasm.addExport(export_);
}
+ wasm.memory.exportName = MEMORY;
}
Function* Asm2WasmBuilder::processFunction(Ref ast) {
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 2a940359f..e3663e164 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -483,6 +483,12 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
}
o << ((curr->memory.segments.size() > 0 && !minify) ? "\n " : "") << ")";
o << maybeNewLine;
+ if (curr->memory.exportName.is()) {
+ doIndent(o, indent);
+ printOpening(o, "export ");
+ printText(o, curr->memory.exportName.str) << " memory)";
+ o << maybeNewLine;
+ }
if (curr->start.is()) {
doIndent(o, indent);
printOpening(o, "start") << " " << curr->start << ")";
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 2744bafc9..eeff5ba04 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -1187,6 +1187,7 @@ class S2WasmBuilder {
// of initial and max
wasm.memory.initial = ((initialMemory + Memory::kPageSize - 1) & Memory::kPageMask) /
Memory::kPageSize;
+ wasm.memory.exportName = MEMORY;
// XXX For now, export all functions marked .globl.
for (Name name : globls) {
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index db57dda9f..feb09f333 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -1011,7 +1011,11 @@ private:
return ret;
}
+ bool hasMemory = false;
+
void parseMemory(Element& s) {
+ hasMemory = true;
+
wasm.memory.initial = atoi(s[1]->c_str());
if (s.size() == 2) return;
size_t i = 2;
@@ -1063,6 +1067,12 @@ private:
}
void parseExport(Element& s) {
+ if (!s[2]->dollared() && !std::isdigit(s[2]->str()[0])) {
+ assert(s[2]->str() == MEMORY);
+ if (!hasMemory) onError();
+ wasm.memory.exportName = s[1]->str();
+ return;
+ }
auto ex = allocator.alloc<Export>();
ex->name = s[1]->str();
ex->value = s[2]->str();
diff --git a/src/wasm.h b/src/wasm.h
index b52803799..50aeef94b 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1100,6 +1100,7 @@ public:
size_t initial, max; // sizes are in pages
std::vector<Segment> segments;
+ Name exportName;
Memory() : initial(0), max((uint32_t)-1) {}
};