summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-04 15:40:33 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-04 15:40:33 -0800
commit2bb4b33e296f999d45b95b2252dfaa11e2ea61b5 (patch)
tree0d3c678fbb726d001633819d0604af47e90819c6 /src
parent98719470da218f2cbe2a256e478f56520a29f4dc (diff)
downloadbinaryen-2bb4b33e296f999d45b95b2252dfaa11e2ea61b5.tar.gz
binaryen-2bb4b33e296f999d45b95b2252dfaa11e2ea61b5.tar.bz2
binaryen-2bb4b33e296f999d45b95b2252dfaa11e2ea61b5.zip
memory
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm-main.cpp2
-rw-r--r--src/wasm-js.cpp2
-rw-r--r--src/wasm-s-parser.h14
-rw-r--r--src/wasm.h23
4 files changed, 34 insertions, 7 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp
index 1a338831c..7c4d93052 100644
--- a/src/asm2wasm-main.cpp
+++ b/src/asm2wasm-main.cpp
@@ -52,7 +52,7 @@ int main(int argc, char **argv) {
if (debug) std::cerr << "wasming...\n";
Module wasm;
- wasm.memorySize = 16*1024*1024; // we would normally receive this from the compiler
+ wasm.memory.initial = wasm.memory.max = 16*1024*1024; // we would normally receive this from the compiler
Asm2WasmBuilder asm2wasm(wasm);
asm2wasm.processAsm(asmjs);
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index 7eda4d10a..6a3e05725 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -51,7 +51,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm(char *input) {
Ref asmjs = builder.parseToplevel(input);
module = new Module();
- module->memorySize = 16*1024*1024; // TODO: receive this from emscripten
+ module->memory.initial = module->memory.max = 16*1024*1024; // TODO: receive this from emscripten
if (debug) std::cerr << "wasming...\n";
asm2wasm = new Asm2WasmBuilder(*module);
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index fbcf9fcbc..415936c0b 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -20,6 +20,7 @@ IString MODULE("module"),
PARAM("param"),
RESULT("result"),
MEMORY("memory"),
+ SEGMENT("segment"),
EXPORT("export"),
IMPORT("import"),
TABLE("table"),
@@ -611,7 +612,18 @@ private:
}
void parseMemory(Element& s) {
- wasm.memorySize = atoi(s[1]->c_str());
+ wasm.memory.initial = atoi(s[1]->c_str());
+ if (s.size() == 2) return;
+ size_t i = 2;
+ if (s[i]->isStr()) {
+ wasm.memory.max = atoi(s[i]->c_str());
+ i++;
+ }
+ while (i < s.size()) {
+ Element& curr = *s[i];
+ assert(curr[0]->str() == SEGMENT);
+
+ }
}
void parseExport(Element& s) {
diff --git a/src/wasm.h b/src/wasm.h
index 6655a167e..8b2f9ad94 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -798,6 +798,19 @@ public:
}
};
+class Memory {
+public:
+ struct Segment {
+ size_t offset;
+ const char* data;
+ };
+
+ size_t initial, max;
+ std::vector<Segment> segments;
+
+ Memory() : initial(0), max(0) {}
+};
+
class Module {
public:
// wasm contents
@@ -806,18 +819,20 @@ public:
std::vector<Export> exports;
Table table;
std::vector<Function*> functions;
- size_t memorySize;
+ Memory memory;
- Module() : memorySize(0) {}
+ Module() {}
friend std::ostream& operator<<(std::ostream &o, Module module) {
unsigned indent = 0;
printOpening(o, "module", true);
incIndent(o, indent);
doIndent(o, indent);
- if (module.memorySize) {
- printOpening(o, "memory") << " " << module.memorySize << " " << module.memorySize << ")\n";
+ printOpening(o, "memory") << " " << module.memory.initial << " " << module.memory.max;
+ for (auto segment : module.memory.segments) {
+ o << " (segment " << segment.offset << " \"" << segment.data << "\")";
}
+ o << ")\n";
for (auto& curr : module.functionTypes) {
doIndent(o, indent);
curr.second->print(o, indent, true);