diff options
author | Sam Clegg <sbc@chromium.org> | 2018-11-30 08:45:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-30 08:45:29 -0800 |
commit | f16a7605b8226502062c6ca24323d431669c90ec (patch) | |
tree | 325a9184c5b1c562fd27bc89ad1a35b951cd34f9 /src/wasm/wasm-s-parser.cpp | |
parent | 955a9a9440f26438ba50e35ebe57a86a5111d4a1 (diff) | |
download | binaryen-f16a7605b8226502062c6ca24323d431669c90ec.tar.gz binaryen-f16a7605b8226502062c6ca24323d431669c90ec.tar.bz2 binaryen-f16a7605b8226502062c6ca24323d431669c90ec.zip |
Add support for a mutable globals as a Feature (#1785)
This picks up from #1644 and indeed borrows the test case from there.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 34022b72b..42dd9df0d 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1487,19 +1487,21 @@ void SExpressionWasmBuilder::parseImport(Element& s) { wasm.addFunction(func.release()); } else if (kind == ExternalKind::Global) { Type type; + bool mutable_ = false; if (inner[j]->isStr()) { type = stringToType(inner[j]->str()); } else { auto& inner2 = *inner[j]; if (inner2[0]->str() != MUT) throw ParseException("expected mut"); type = stringToType(inner2[1]->str()); - throw ParseException("cannot import a mutable global", s.line, s.col); + mutable_ = true; } auto global = make_unique<Global>(); global->name = name; global->module = module; global->base = base; global->type = type; + global->mutable_ = mutable_; wasm.addGlobal(global.release()); } else if (kind == ExternalKind::Table) { wasm.table.module = module; @@ -1571,12 +1573,12 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) { if (importModule.is()) { // this is an import, actually if (!preParseImport) throw ParseException("!preParseImport in global"); - if (mutable_) throw ParseException("cannot import a mutable global", s.line, s.col); auto im = make_unique<Global>(); im->name = global->name; im->module = importModule; im->base = importBase; im->type = type; + im->mutable_ = mutable_; if (wasm.getGlobalOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col); wasm.addGlobal(im.release()); return; |