diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-20 13:16:51 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-20 13:16:51 -0700 |
commit | 2aa7ba43b59782243cd4960df43c7936292c41f4 (patch) | |
tree | db6dc29064740d274f116755f02d05e6904b30d0 /src | |
parent | 48a0da1be94a8cabb36dc84d0bc6203c20c22b15 (diff) | |
download | binaryen-2aa7ba43b59782243cd4960df43c7936292c41f4.tar.gz binaryen-2aa7ba43b59782243cd4960df43c7936292c41f4.tar.bz2 binaryen-2aa7ba43b59782243cd4960df43c7936292c41f4.zip |
memory parsing fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-s-parser.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 6d9f4aec2..9ed38e8da 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -388,6 +388,7 @@ private: if (id == FUNC) parseFunction(curr, true /* preParseImport */); else if (id == GLOBAL) parseGlobal(curr, true /* preParseImport */); else if (id == TABLE) parseTable(curr, true /* preParseImport */); + else if (id == MEMORY) parseMemory(curr, true /* preParseImport */); else throw ParseException("fancy import we don't support yet", curr.line, curr.col); } } @@ -1432,12 +1433,14 @@ private: bool hasMemory = false; - void parseMemory(Element& s) { + void parseMemory(Element& s, bool preParseImport = false) { + if (hasMemory) throw ParseException("too many memories"); hasMemory = true; Index i = 1; if (s[i]->dollared()) { wasm.memory.name = s[i++]->str(); } + Name importModule, importBase; if (s[i]->isList()) { auto& inner = *s[i]; if (inner[0]->str() == EXPORT) { @@ -1448,6 +1451,10 @@ private: if (wasm.checkExport(ex->name)) throw ParseException("duplicate export", s.line, s.col); wasm.addExport(ex.release()); i++; + } else if (inner[0]->str() == IMPORT) { + importModule = inner[1]->str(); + importBase = inner[2]->str(); + i++; } else { assert(inner.size() > 0 ? inner[0]->str() != IMPORT : true); // (memory (data ..)) format @@ -1555,6 +1562,7 @@ private: im->kind = Import::Function; } else if ((*s[3])[0]->str() == MEMORY) { im->kind = Import::Memory; + if (hasMemory) throw ParseException("too many memories"); hasMemory = true; } else if ((*s[3])[0]->str() == TABLE) { im->kind = Import::Table; @@ -1650,11 +1658,12 @@ private: if (j < inner.size() - 1) { wasm.table.max = atoi(inner[j++]->c_str()); } + // ends with the table element type } else if (im->kind == Import::Memory) { - if (j < inner.size() - 1) { + if (j < inner.size()) { wasm.memory.initial = atoi(inner[j++]->c_str()); } - if (j < inner.size() - 1) { + if (j < inner.size()) { wasm.memory.max = atoi(inner[j++]->c_str()); } } |