summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-07-18 15:24:17 -0700
committerGitHub <noreply@github.com>2019-07-18 15:24:17 -0700
commite4ae8848b484110207c9a77d0c089aac3db482bb (patch)
tree28747370ff112ef6b1d09cfd035e66a732f42e77 /src
parent6cc61b89bc3a22fb2dc42999d27af52124197baf (diff)
downloadbinaryen-e4ae8848b484110207c9a77d0c089aac3db482bb.tar.gz
binaryen-e4ae8848b484110207c9a77d0c089aac3db482bb.tar.bz2
binaryen-e4ae8848b484110207c9a77d0c089aac3db482bb.zip
Generalize EM_JS parsing code. (#2233)
The key thing is that there is a single constant, which may or may not be saved/loaded from a local, and may or may not get an added global if in relocatable code. Fixes emscripten-core/emscripten#8993
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp33
1 files changed, 6 insertions, 27 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index df5da949e..a3433bf9f 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -741,35 +741,14 @@ struct EmJsWalker : public PostWalker<EmJsWalker> {
return;
}
auto funcName = std::string(curr->name.stripPrefix(EM_JS_PREFIX.str));
- auto addrConst = curr->body->dynCast<Const>();
- if (addrConst == nullptr) {
- auto block = curr->body->dynCast<Block>();
- Expression* value = nullptr;
- if (block && block->list.size() > 0) {
- value = block->list[0];
- // first item may be a set of a local that we get later
- auto* set = value->dynCast<LocalSet>();
- if (set) {
- value = block->list[1];
- }
- // look into a return value
- if (auto* ret = value->dynCast<Return>()) {
- value = ret->value;
- }
- // if it's a get of that set, use that value
- if (auto* get = value->dynCast<LocalGet>()) {
- if (set && get->index == set->index) {
- value = set->value;
- }
- }
- }
- if (value) {
- addrConst = value->dynCast<Const>();
- }
- }
- if (addrConst == nullptr) {
+ // An EM_JS has a single const in the body. Typically it is just returned,
+ // but in unoptimized code it might be stored to a local and loaded from
+ // there, and in relocatable code it might get added to __memory_base etc.
+ FindAll<Const> consts(curr->body);
+ if (consts.list.size() != 1) {
Fatal() << "Unexpected generated __em_js__ function body: " << curr->name;
}
+ auto* addrConst = consts.list[0];
auto code = codeForConstAddr(wasm, segmentOffsets, addrConst);
codeByName[funcName] = code;
}