summaryrefslogtreecommitdiff
path: root/src/tools/wasm-ctor-eval.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/wasm-ctor-eval.cpp')
-rw-r--r--src/tools/wasm-ctor-eval.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index 9e3915073..f39d8a34e 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -231,23 +231,27 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
// we assume the table is not modified (hmm)
// look through the segments, try to find the function
- for (auto& segment : table->segments) {
+ for (auto& segment : wasm->elementSegments) {
+ if (segment->table != tableName) {
+ continue;
+ }
+
Index start;
// look for the index in this segment. if it has a constant offset, we
// look in the proper range. if it instead gets a global, we rely on the
// fact that when not dynamically linking then the table is loaded at
// offset 0.
- if (auto* c = segment.offset->dynCast<Const>()) {
+ if (auto* c = segment->offset->dynCast<Const>()) {
start = c->value.getInteger();
- } else if (segment.offset->is<GlobalGet>()) {
+ } else if (segment->offset->is<GlobalGet>()) {
start = 0;
} else {
// wasm spec only allows const and global.get there
WASM_UNREACHABLE("invalid expr type");
}
- auto end = start + segment.data.size();
+ auto end = start + segment->data.size();
if (start <= index && index < end) {
- auto name = segment.data[index - start];
+ auto name = segment->data[index - start];
// if this is one of our functions, we can call it; if it was imported,
// fail
auto* func = wasm->getFunction(name);