summaryrefslogtreecommitdiff
path: root/src/wasm-s-parser.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-08-18 18:03:05 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-09-07 09:55:02 -0700
commit9660c200eff60c10266a85aae0637b495c4cba39 (patch)
tree386e74bb16cca4c7d20939ab4786806a32e3b1b5 /src/wasm-s-parser.h
parenta10ca64dc04bdba4fbf4a468604c0c88f62a4a8d (diff)
downloadbinaryen-9660c200eff60c10266a85aae0637b495c4cba39.tar.gz
binaryen-9660c200eff60c10266a85aae0637b495c4cba39.tar.bz2
binaryen-9660c200eff60c10266a85aae0637b495c4cba39.zip
get_global and set_global use a Name instead of an Index, to be more consistent with refering to other global objects; e.g. this avoids ordering issues with imported vs non-imported globals
Diffstat (limited to 'src/wasm-s-parser.h')
-rw-r--r--src/wasm-s-parser.h22
1 files changed, 5 insertions, 17 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 50d566baf..60cc21e26 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -945,30 +945,18 @@ private:
return ret;
}
- Index getGlobalIndex(Element& s) {
- if (s.dollared()) {
- auto name = s.str();
- for (Index i = 0; i < wasm.globals.size(); i++) {
- if (wasm.globals[i]->name == name) return i;
- }
- throw ParseException("bad global name", s.line, s.col);
- }
- // this is a numeric index
- Index ret = atoi(s.c_str());
- if (!wasm.checkGlobal(ret)) throw ParseException("bad global index", s.line, s.col);
- return ret;
- }
-
Expression* makeGetGlobal(Element& s) {
auto ret = allocator.alloc<GetGlobal>();
- ret->index = getGlobalIndex(*s[1]);
- ret->type = wasm.getGlobal(ret->index)->type;
+ ret->name = s[1]->str();
+ auto* global = wasm.checkGlobal(ret->name);
+ if (!global) throw ParseException("bad get_global name", s.line, s.col);
+ ret->type = global->type;
return ret;
}
Expression* makeSetGlobal(Element& s) {
auto ret = allocator.alloc<SetGlobal>();
- ret->index = getGlobalIndex(*s[1]);
+ ret->name = s[1]->str();
ret->value = parseExpression(s[2]);
return ret;
}