Skip to content

Commit 20f1932

Browse files
committed
WASM: Fix emit_const() implementation
1 parent d7fdffe commit 20f1932

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/libasr/codegen/asr_to_wasm.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,20 +663,23 @@ class ASRToWASMVisitor : public ASR::BaseVisitor<ASRToWASMVisitor> {
663663
template <typename T>
664664
void emit_const(Vec<uint8_t> &m_code, wasm::type typ, T init_val) {
665665
using namespace wasm;
666-
wasm::emit_b8(m_code, m_al, typ);
667666
switch (typ)
668667
{
669668
case i32:
670-
wasm::emit_i32(m_code, m_al, init_val);
669+
wasm::emit_b8(m_code, m_al, 0x41); // emit instruction
670+
wasm::emit_i32(m_code, m_al, init_val); // emit val
671671
break;
672672
case i64:
673-
wasm::emit_i64(m_code, m_al, init_val);
673+
wasm::emit_b8(m_code, m_al, 0x42); // emit instruction
674+
wasm::emit_i64(m_code, m_al, init_val); // emit val
674675
break;
675676
case f32:
676-
wasm::emit_f32(m_code, m_al, init_val);
677+
wasm::emit_b8(m_code, m_al, 0x43); // emit instruction
678+
wasm::emit_f32(m_code, m_al, init_val); // emit val
677679
break;
678680
case f64:
679-
wasm::emit_f64(m_code, m_al, init_val);
681+
wasm::emit_b8(m_code, m_al, 0x44); // emit instruction
682+
wasm::emit_f64(m_code, m_al, init_val); // emit val
680683
break;
681684
default:
682685
throw CodeGenError("emit_global_const: Unsupported type");

0 commit comments

Comments
 (0)