summaryrefslogtreecommitdiff
path: root/src/asm2wasm.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r--src/asm2wasm.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 5bdb2a9bf..377b6b20b 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -954,9 +954,15 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
void visitCallIndirect(CallIndirect* curr) {
// we already call into target = something + offset, where offset is a callImport with the name of the table. replace that with the table offset
auto add = curr->target->cast<Binary>();
- auto offset = add->right->cast<CallImport>();
- auto tableName = offset->target;
- add->right = parent->builder.makeConst(Literal((int32_t)parent->functionTableStarts[tableName]));
+ if (add->right->is<CallImport>()) {
+ auto offset = add->right->cast<CallImport>();
+ auto tableName = offset->target;
+ add->right = parent->builder.makeConst(Literal((int32_t)parent->functionTableStarts[tableName]));
+ } else {
+ auto offset = add->left->cast<CallImport>();
+ auto tableName = offset->target;
+ add->left = parent->builder.makeConst(Literal((int32_t)parent->functionTableStarts[tableName]));
+ }
}
};