Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions src/wasm/wasm-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man a Const-finder? That's way nicer :D

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;
}
Expand Down