diff --git a/src/libasr/codegen/asr_to_wasm.cpp b/src/libasr/codegen/asr_to_wasm.cpp index 28816d0cd7..3b8cba4619 100644 --- a/src/libasr/codegen/asr_to_wasm.cpp +++ b/src/libasr/codegen/asr_to_wasm.cpp @@ -107,7 +107,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { bool is_prototype_only; bool is_local_vars_only; ASR::Function_t* main_func; - WASMAssembler wa; + WASMAssembler m_wa; std::vector local_vars; uint32_t avail_mem_loc; @@ -128,7 +128,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { public: ASRToWASMVisitor(Allocator &al, diag::Diagnostics &diagnostics) - : m_al(al), diag(diagnostics), wa(al) { + : m_al(al), diag(diagnostics), m_wa(al) { is_prototype_only = false; is_local_vars_only = false; main_func = nullptr; @@ -146,9 +146,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { void import_function(IMPORT_FUNC fn, std::vector param_types, std::vector result_types) { - int func_idx = wa.emit_func_type(param_types, result_types); + int func_idx = m_wa.emit_func_type(param_types, result_types); m_import_func_idx_map[fn] = func_idx; - wa.emit_import_fn( "wasi_snapshot_preview1", import_fn_to_str(fn), func_idx); + m_wa.emit_import_fn( "wasi_snapshot_preview1", import_fn_to_str(fn), func_idx); } void import_function(ASR::Function_t* fn) { @@ -158,7 +158,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (ASRUtils::is_intrinsic_function2(fn)) return; emit_function_prototype(*fn); - wa.emit_import_fn("js", fn->m_name, + m_wa.emit_import_fn("js", fn->m_name, m_func_name_idx_map[get_hash((ASR::asr_t*) fn)]->index); } @@ -190,326 +190,326 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { void emit_print_int() { using namespace wasm; - wa.define_func({i64}, {}, {i64, i64, i64, i64}, "print_i64", [&](){ + m_wa.define_func({i64}, {}, {i64, i64, i64, i64}, "print_i64", [&](){ // locals 0 is given parameter // locals 1 is digits_cnt // locals 2 is divisor (in powers of 10) // locals 3 is loop counter (counts upto digits_cnt (which is decreasing)) // locals 4 is extra copy of given parameter - wa.emit_if_else([&](){ - wa.emit_local_get(0); - wa.emit_i64_const(0); - wa.emit_i64_eq(); + m_wa.emit_if_else([&](){ + m_wa.emit_local_get(0); + m_wa.emit_i64_const(0); + m_wa.emit_i64_eq(); }, [&](){ emit_call_fd_write(1, "0", 1, 0); - wa.emit_return(); + m_wa.emit_return(); }, [&](){}); - wa.emit_if_else([&](){ - wa.emit_local_get(0); - wa.emit_i64_const(0); - wa.emit_i64_lt_s(); + m_wa.emit_if_else([&](){ + m_wa.emit_local_get(0); + m_wa.emit_i64_const(0); + m_wa.emit_i64_lt_s(); }, [&](){ emit_call_fd_write(1, "-", 1, 0); - wa.emit_local_get(0); - wa.emit_i64_const(-1); - wa.emit_i64_mul(); - wa.emit_local_set(0); + m_wa.emit_local_get(0); + m_wa.emit_i64_const(-1); + m_wa.emit_i64_mul(); + m_wa.emit_local_set(0); }, [&](){}); - wa.emit_local_get(0); - wa.emit_local_set(4); - wa.emit_i64_const(0); - wa.emit_local_set(1); + m_wa.emit_local_get(0); + m_wa.emit_local_set(4); + m_wa.emit_i64_const(0); + m_wa.emit_local_set(1); - wa.emit_loop([&](){ - wa.emit_local_get(0); - wa.emit_i64_const(0); - wa.emit_i64_gt_s(); + m_wa.emit_loop([&](){ + m_wa.emit_local_get(0); + m_wa.emit_i64_const(0); + m_wa.emit_i64_gt_s(); }, [&](){ - wa.emit_local_get(1); - wa.emit_i64_const(1); - wa.emit_i64_add(); - wa.emit_local_set(1); - wa.emit_local_get(0); - wa.emit_i64_const(10); - wa.emit_i64_div_s(); - wa.emit_local_set(0); + m_wa.emit_local_get(1); + m_wa.emit_i64_const(1); + m_wa.emit_i64_add(); + m_wa.emit_local_set(1); + m_wa.emit_local_get(0); + m_wa.emit_i64_const(10); + m_wa.emit_i64_div_s(); + m_wa.emit_local_set(0); }); - wa.emit_loop([&](){ - wa.emit_local_get(1); - wa.emit_i64_const(0); - wa.emit_i64_gt_s(); + m_wa.emit_loop([&](){ + m_wa.emit_local_get(1); + m_wa.emit_i64_const(0); + m_wa.emit_i64_gt_s(); }, [&](){ - wa.emit_local_get(1); - wa.emit_i64_const(1); - wa.emit_i64_sub(); - wa.emit_local_set(1); - - wa.emit_i64_const(1); - wa.emit_local_set(2); - wa.emit_i64_const(0); - wa.emit_local_set(3); - - wa.emit_loop([&](){ - wa.emit_local_get(3); - wa.emit_local_get(1); - wa.emit_i64_lt_s(); + m_wa.emit_local_get(1); + m_wa.emit_i64_const(1); + m_wa.emit_i64_sub(); + m_wa.emit_local_set(1); + + m_wa.emit_i64_const(1); + m_wa.emit_local_set(2); + m_wa.emit_i64_const(0); + m_wa.emit_local_set(3); + + m_wa.emit_loop([&](){ + m_wa.emit_local_get(3); + m_wa.emit_local_get(1); + m_wa.emit_i64_lt_s(); }, [&](){ - wa.emit_local_get(3); - wa.emit_i64_const(1); - wa.emit_i64_add(); - wa.emit_local_set(3); - wa.emit_local_get(2); - wa.emit_i64_const(10); - wa.emit_i64_mul(); - wa.emit_local_set(2); + m_wa.emit_local_get(3); + m_wa.emit_i64_const(1); + m_wa.emit_i64_add(); + m_wa.emit_local_set(3); + m_wa.emit_local_get(2); + m_wa.emit_i64_const(10); + m_wa.emit_i64_mul(); + m_wa.emit_local_set(2); }); - wa.emit_local_get(4); - wa.emit_local_get(2); - wa.emit_i64_div_s(); - wa.emit_i64_const(10); - wa.emit_i64_rem_s(); + m_wa.emit_local_get(4); + m_wa.emit_local_get(2); + m_wa.emit_i64_div_s(); + m_wa.emit_i64_const(10); + m_wa.emit_i64_rem_s(); /* The digit is on stack */ - wa.emit_i64_const(12 /* 4 + 4 + 4 (iov vec + str size)*/); - wa.emit_i64_mul(); - wa.emit_i64_const(digits_mem_loc); - wa.emit_i64_add(); - wa.emit_local_set(0); // temporary save + m_wa.emit_i64_const(12 /* 4 + 4 + 4 (iov vec + str size)*/); + m_wa.emit_i64_mul(); + m_wa.emit_i64_const(digits_mem_loc); + m_wa.emit_i64_add(); + m_wa.emit_local_set(0); // temporary save { - wa.emit_i32_const(1); // file type: 1 for stdout - wa.emit_local_get(0); // use stored digit - wa.emit_i32_wrap_i64(); - wa.emit_i32_const(1); // size of iov vector - wa.emit_i32_const(0); // mem_loction to return no. of bytes written + m_wa.emit_i32_const(1); // file type: 1 for stdout + m_wa.emit_local_get(0); // use stored digit + m_wa.emit_i32_wrap_i64(); + m_wa.emit_i32_const(1); // size of iov vector + m_wa.emit_i32_const(0); // mem_loction to return no. of bytes written // call WASI fd_write - wa.emit_call(m_import_func_idx_map[fd_write]); - wa.emit_drop(); + m_wa.emit_call(m_import_func_idx_map[fd_write]); + m_wa.emit_drop(); } }); - wa.emit_return(); + m_wa.emit_return(); }); } void emit_print_float() { using namespace wasm; - wa.define_func({f64}, {}, {i64, i64, i64}, "print_f64", [&](){ - wa.emit_if_else([&](){ - wa.emit_local_get(0); - wa.emit_f64_const(0); - wa.emit_f64_lt(); + m_wa.define_func({f64}, {}, {i64, i64, i64}, "print_f64", [&](){ + m_wa.emit_if_else([&](){ + m_wa.emit_local_get(0); + m_wa.emit_f64_const(0); + m_wa.emit_f64_lt(); }, [&](){ emit_call_fd_write(1, "-", 1, 0); - wa.emit_local_get(0); - wa.emit_f64_const(-1); - wa.emit_f64_mul(); - wa.emit_local_set(0); + m_wa.emit_local_get(0); + m_wa.emit_f64_const(-1); + m_wa.emit_f64_mul(); + m_wa.emit_local_set(0); }, [&](){}); - wa.emit_local_get(0); - wa.emit_i64_trunc_f64_s(); - wa.emit_call(m_rt_func_used_idx[print_i64]); + m_wa.emit_local_get(0); + m_wa.emit_i64_trunc_f64_s(); + m_wa.emit_call(m_rt_func_used_idx[print_i64]); emit_call_fd_write(1, ".", 1, 0); - wa.emit_local_get(0); - wa.emit_local_get(0); - wa.emit_i64_trunc_f64_s(); - wa.emit_f64_convert_i64_s(); - wa.emit_f64_sub(); - wa.emit_f64_const(1e8); - wa.emit_f64_mul(); - wa.emit_i64_trunc_f64_s(); - wa.emit_local_set(2); /* save the current fractional part value */ - wa.emit_local_get(2); - wa.emit_local_set(3); /* save the another copy */ - - wa.emit_i64_const(0); - wa.emit_local_set(1); // digits_cnt - - wa.emit_loop([&](){ - wa.emit_local_get(2); - wa.emit_i64_const(0); - wa.emit_i64_gt_s(); + m_wa.emit_local_get(0); + m_wa.emit_local_get(0); + m_wa.emit_i64_trunc_f64_s(); + m_wa.emit_f64_convert_i64_s(); + m_wa.emit_f64_sub(); + m_wa.emit_f64_const(1e8); + m_wa.emit_f64_mul(); + m_wa.emit_i64_trunc_f64_s(); + m_wa.emit_local_set(2); /* save the current fractional part value */ + m_wa.emit_local_get(2); + m_wa.emit_local_set(3); /* save the another copy */ + + m_wa.emit_i64_const(0); + m_wa.emit_local_set(1); // digits_cnt + + m_wa.emit_loop([&](){ + m_wa.emit_local_get(2); + m_wa.emit_i64_const(0); + m_wa.emit_i64_gt_s(); }, [&](){ - wa.emit_local_get(1); - wa.emit_i64_const(1); - wa.emit_i64_add(); - wa.emit_local_set(1); - - wa.emit_local_get(2); - wa.emit_f64_convert_i64_s(); - wa.emit_i64_const(10); - wa.emit_f64_convert_i64_s(); - wa.emit_f64_div(); - wa.emit_i64_trunc_f64_s(); - wa.emit_local_set(2); + m_wa.emit_local_get(1); + m_wa.emit_i64_const(1); + m_wa.emit_i64_add(); + m_wa.emit_local_set(1); + + m_wa.emit_local_get(2); + m_wa.emit_f64_convert_i64_s(); + m_wa.emit_i64_const(10); + m_wa.emit_f64_convert_i64_s(); + m_wa.emit_f64_div(); + m_wa.emit_i64_trunc_f64_s(); + m_wa.emit_local_set(2); }); - wa.emit_loop([&](){ - wa.emit_local_get(1); - wa.emit_i64_const(8); - wa.emit_i64_lt_s(); + m_wa.emit_loop([&](){ + m_wa.emit_local_get(1); + m_wa.emit_i64_const(8); + m_wa.emit_i64_lt_s(); }, [&](){ - wa.emit_local_get(1); - wa.emit_i64_const(1); - wa.emit_i64_add(); - wa.emit_local_set(1); + m_wa.emit_local_get(1); + m_wa.emit_i64_const(1); + m_wa.emit_i64_add(); + m_wa.emit_local_set(1); emit_call_fd_write(1, "0", 1, 0); }); - wa.emit_local_get(3); - wa.emit_call(m_rt_func_used_idx[print_i64]); - wa.emit_return(); + m_wa.emit_local_get(3); + m_wa.emit_call(m_rt_func_used_idx[print_i64]); + m_wa.emit_return(); }); } void emit_complex_add_32() { using namespace wasm; - wa.define_func({f32, f32, f32, f32}, {f32, f32}, {}, "add_c32", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(2); - wa.emit_f32_add(); - - wa.emit_local_get(1); - wa.emit_local_get(3); - wa.emit_f32_add(); - wa.emit_return(); + m_wa.define_func({f32, f32, f32, f32}, {f32, f32}, {}, "add_c32", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(2); + m_wa.emit_f32_add(); + + m_wa.emit_local_get(1); + m_wa.emit_local_get(3); + m_wa.emit_f32_add(); + m_wa.emit_return(); }); } void emit_complex_add_64() { using namespace wasm; - wa.define_func({f64, f64, f64, f64}, {f64, f64}, {}, "add_c64", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(2); - wa.emit_f64_add(); - - wa.emit_local_get(1); - wa.emit_local_get(3); - wa.emit_f64_add(); - wa.emit_return(); + m_wa.define_func({f64, f64, f64, f64}, {f64, f64}, {}, "add_c64", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(2); + m_wa.emit_f64_add(); + + m_wa.emit_local_get(1); + m_wa.emit_local_get(3); + m_wa.emit_f64_add(); + m_wa.emit_return(); }); } void emit_complex_sub_32() { using namespace wasm; - wa.define_func({f32, f32, f32, f32}, {f32, f32}, {}, "sub_c32", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(2); - wa.emit_f32_sub(); - - wa.emit_local_get(1); - wa.emit_local_get(3); - wa.emit_f32_sub(); - wa.emit_return(); + m_wa.define_func({f32, f32, f32, f32}, {f32, f32}, {}, "sub_c32", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(2); + m_wa.emit_f32_sub(); + + m_wa.emit_local_get(1); + m_wa.emit_local_get(3); + m_wa.emit_f32_sub(); + m_wa.emit_return(); }); } void emit_complex_sub_64() { using namespace wasm; - wa.define_func({f64, f64, f64, f64}, {f64, f64}, {}, "sub_c64", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(2); - wa.emit_f64_sub(); - - wa.emit_local_get(1); - wa.emit_local_get(3); - wa.emit_f64_sub(); - wa.emit_return(); + m_wa.define_func({f64, f64, f64, f64}, {f64, f64}, {}, "sub_c64", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(2); + m_wa.emit_f64_sub(); + + m_wa.emit_local_get(1); + m_wa.emit_local_get(3); + m_wa.emit_f64_sub(); + m_wa.emit_return(); }); } void emit_complex_mul_32() { using namespace wasm; - wa.define_func({f32, f32, f32, f32}, {f32, f32}, {}, "mul_c32", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(2); - wa.emit_f32_mul(); + m_wa.define_func({f32, f32, f32, f32}, {f32, f32}, {}, "mul_c32", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(2); + m_wa.emit_f32_mul(); - wa.emit_local_get(1); - wa.emit_local_get(3); - wa.emit_f32_mul(); + m_wa.emit_local_get(1); + m_wa.emit_local_get(3); + m_wa.emit_f32_mul(); - wa.emit_f32_sub(); + m_wa.emit_f32_sub(); - wa.emit_local_get(0); - wa.emit_local_get(3); - wa.emit_f32_mul(); + m_wa.emit_local_get(0); + m_wa.emit_local_get(3); + m_wa.emit_f32_mul(); - wa.emit_local_get(1); - wa.emit_local_get(2); - wa.emit_f32_mul(); + m_wa.emit_local_get(1); + m_wa.emit_local_get(2); + m_wa.emit_f32_mul(); - wa.emit_f32_add(); - wa.emit_return(); + m_wa.emit_f32_add(); + m_wa.emit_return(); }); } void emit_complex_mul_64() { using namespace wasm; - wa.define_func({f64, f64, f64, f64}, {f64, f64}, {}, "mul_c64", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(2); - wa.emit_f64_mul(); + m_wa.define_func({f64, f64, f64, f64}, {f64, f64}, {}, "mul_c64", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(2); + m_wa.emit_f64_mul(); - wa.emit_local_get(1); - wa.emit_local_get(3); - wa.emit_f64_mul(); + m_wa.emit_local_get(1); + m_wa.emit_local_get(3); + m_wa.emit_f64_mul(); - wa.emit_f64_sub(); + m_wa.emit_f64_sub(); - wa.emit_local_get(0); - wa.emit_local_get(3); - wa.emit_f64_mul(); + m_wa.emit_local_get(0); + m_wa.emit_local_get(3); + m_wa.emit_f64_mul(); - wa.emit_local_get(1); - wa.emit_local_get(2); - wa.emit_f64_mul(); + m_wa.emit_local_get(1); + m_wa.emit_local_get(2); + m_wa.emit_f64_mul(); - wa.emit_f64_add(); - wa.emit_return(); + m_wa.emit_f64_add(); + m_wa.emit_return(); }); } void emit_complex_abs_32() { using namespace wasm; - wa.define_func({f32, f32}, {f32}, {}, "abs_c32", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(0); - wa.emit_f32_mul(); - - wa.emit_local_get(1); - wa.emit_local_get(1); - wa.emit_f32_mul(); - - wa.emit_f32_add(); - wa.emit_f32_sqrt(); - wa.emit_return(); + m_wa.define_func({f32, f32}, {f32}, {}, "abs_c32", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(0); + m_wa.emit_f32_mul(); + + m_wa.emit_local_get(1); + m_wa.emit_local_get(1); + m_wa.emit_f32_mul(); + + m_wa.emit_f32_add(); + m_wa.emit_f32_sqrt(); + m_wa.emit_return(); }); } void emit_complex_abs_64() { using namespace wasm; - wa.define_func({f64, f64}, {f64}, {}, "abs_c64", [&](){ - wa.emit_local_get(0); - wa.emit_local_get(0); - wa.emit_f64_mul(); - - wa.emit_local_get(1); - wa.emit_local_get(1); - wa.emit_f64_mul(); - - wa.emit_f64_add(); - wa.emit_f64_sqrt(); - wa.emit_return(); + m_wa.define_func({f64, f64}, {f64}, {}, "abs_c64", [&](){ + m_wa.emit_local_get(0); + m_wa.emit_local_get(0); + m_wa.emit_f64_mul(); + + m_wa.emit_local_get(1); + m_wa.emit_local_get(1); + m_wa.emit_f64_mul(); + + m_wa.emit_f64_add(); + m_wa.emit_f64_sqrt(); + m_wa.emit_return(); }); } @@ -529,8 +529,8 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { init_val = ASR::down_cast(v->m_value)->m_n; } switch (kind) { - case 4: global_var_idx = wa.declare_global_var(i32, init_val); break; - case 8: global_var_idx = wa.declare_global_var(i64, init_val); break; + case 4: global_var_idx = m_wa.declare_global_var(i32, init_val); break; + case 8: global_var_idx = m_wa.declare_global_var(i64, init_val); break; default: throw CodeGenError("Declare Global: Unsupported Integer kind"); } break; @@ -541,8 +541,8 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { init_val = ASR::down_cast(v->m_value)->m_r; } switch (kind) { - case 4: global_var_idx = wa.declare_global_var(f32, init_val); break; - case 8: global_var_idx = wa.declare_global_var(f64, init_val); break; + case 4: global_var_idx = m_wa.declare_global_var(f32, init_val); break; + case 8: global_var_idx = m_wa.declare_global_var(f64, init_val); break; default: throw CodeGenError("Declare Global: Unsupported Real kind"); } break; @@ -553,7 +553,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { init_val = ASR::down_cast(v->m_value)->m_value; } switch (kind) { - case 4: global_var_idx = wa.declare_global_var(i32, init_val); break; + case 4: global_var_idx = m_wa.declare_global_var(i32, init_val); break; default: throw CodeGenError("Declare Global: Unsupported Logical kind"); } break; @@ -566,7 +566,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { emit_string(init_val); switch (kind) { case 1: - global_var_idx = wa.declare_global_var(i32, m_string_to_iov_loc_map[init_val]); + global_var_idx = m_wa.declare_global_var(i32, m_string_to_iov_loc_map[init_val]); break; default: throw CodeGenError("Declare Global: Unsupported Character kind"); } @@ -575,7 +575,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { default: { diag.codegen_warning_label("Declare Global: Type " + ASRUtils::type_to_str(v->m_type) + " not yet supported", {v->base.base.loc}, ""); - global_var_idx = wa.declare_global_var(i32, 0); + global_var_idx = m_wa.declare_global_var(i32, 0); } } LCOMPILERS_ASSERT(global_var_idx >= 0); @@ -613,14 +613,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { emit_imports(x.m_global_scope); - wa.emit_declare_mem(min_no_pages, max_no_pages); - wa.emit_export_mem("memory", 0 /* mem_idx */); + m_wa.emit_declare_mem(min_no_pages, max_no_pages); + m_wa.emit_export_mem("memory", 0 /* mem_idx */); - m_compiler_globals[cur_mem_loc] = wa.declare_global_var(wasm::var_type::i32, 0); - m_compiler_globals[tmp_reg_i32] = wa.declare_global_var(wasm::var_type::i32, 0); - m_compiler_globals[tmp_reg_i64] = wa.declare_global_var(wasm::var_type::i64, 0); - m_compiler_globals[tmp_reg_f32] = wa.declare_global_var(wasm::var_type::f32, 0); - m_compiler_globals[tmp_reg_f64] = wa.declare_global_var(wasm::var_type::f64, 0); + m_compiler_globals[cur_mem_loc] = m_wa.declare_global_var(wasm::var_type::i32, 0); + m_compiler_globals[tmp_reg_i32] = m_wa.declare_global_var(wasm::var_type::i32, 0); + m_compiler_globals[tmp_reg_i64] = m_wa.declare_global_var(wasm::var_type::i64, 0); + m_compiler_globals[tmp_reg_f32] = m_wa.declare_global_var(wasm::var_type::f32, 0); + m_compiler_globals[tmp_reg_f64] = m_wa.declare_global_var(wasm::var_type::f64, 0); emit_string(" "); emit_string("\n"); @@ -652,7 +652,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { declare_symbols(x); is_prototype_only = false; - rt_funcs_seq_order = wa.get_no_of_types(); + rt_funcs_seq_order = m_wa.get_no_of_types(); } declare_symbols(x); @@ -856,17 +856,17 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { uint64_t hash = get_hash((ASR::asr_t *)v); if (m_var_idx_map.find(hash) != m_var_idx_map.end()) { uint32_t var_idx = m_var_idx_map[hash]; - wa.emit_local_get(var_idx); + m_wa.emit_local_get(var_idx); if (ASRUtils::is_complex(*v->m_type)) { // get the imaginary part - wa.emit_local_get(var_idx + 1u); + m_wa.emit_local_get(var_idx + 1u); } } else if (m_global_var_idx_map.find(hash) != m_global_var_idx_map.end()) { uint32_t var_idx = m_global_var_idx_map[hash]; - wa.emit_global_get(var_idx); + m_wa.emit_global_get(var_idx); if (ASRUtils::is_complex(*v->m_type)) { // get the imaginary part - wa.emit_global_get(var_idx + 1u); + m_wa.emit_global_get(var_idx + 1u); } } else { throw CodeGenError("Variable " + std::string(v->m_name) + " not declared"); @@ -879,16 +879,16 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { uint32_t var_idx = m_var_idx_map[hash]; if (ASRUtils::is_complex(*v->m_type)) { // set the imaginary part - wa.emit_local_set(var_idx + 1u); + m_wa.emit_local_set(var_idx + 1u); } - wa.emit_local_set(var_idx); + m_wa.emit_local_set(var_idx); } else if (m_global_var_idx_map.find(hash) != m_global_var_idx_map.end()) { uint32_t var_idx = m_global_var_idx_map[hash]; if (ASRUtils::is_complex(*v->m_type)) { // set the imaginary part - wa.emit_global_set(var_idx + 1u); + m_wa.emit_global_set(var_idx + 1u); } - wa.emit_global_set(var_idx); + m_wa.emit_global_set(var_idx); } else { throw CodeGenError("Variable " + std::string(v->m_name) + " not declared"); } @@ -916,7 +916,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { total_array_size *= dim; } - wa.emit_i32_const(avail_mem_loc); + m_wa.emit_i32_const(avail_mem_loc); emit_var_set(v); avail_mem_loc += kind * total_array_size; } @@ -961,7 +961,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } } - s->index = wa.emit_func_type(params, results); + s->index = m_wa.emit_func_type(params, results); m_func_name_idx_map[get_hash((ASR::asr_t *)&x)] = s; } @@ -990,14 +990,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { is_local_vars_only = false; } - wa.emit_func_body(cur_sym_info->index, x.m_name, local_vars, [&](){ + m_wa.emit_func_body(cur_sym_info->index, x.m_name, local_vars, [&](){ initialize_local_vars(x.m_symtab); for (size_t i = 0; i < x.n_body; i++) { this->visit_stmt(*x.m_body[i]); } if (strcmp(x.m_name, "_start") == 0) { - wa.emit_i32_const(0 /* zero exit code */); - wa.emit_call(m_import_func_idx_map[proc_exit]); + m_wa.emit_i32_const(0 /* zero exit code */); + m_wa.emit_call(m_import_func_idx_map[proc_exit]); } if (x.n_body == 0 || !ASR::is_a(*x.m_body[x.n_body - 1])) { handle_return(); @@ -1072,10 +1072,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Integer: { switch (kind) { case 4: - wa.emit_i32_store(wasm::mem_align::b8, 0); + m_wa.emit_i32_store(wasm::mem_align::b8, 0); break; case 8: - wa.emit_i64_store(wasm::mem_align::b8, 0); + m_wa.emit_i64_store(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1086,10 +1086,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Real: { switch (kind) { case 4: - wa.emit_f32_store(wasm::mem_align::b8, 0); + m_wa.emit_f32_store(wasm::mem_align::b8, 0); break; case 8: - wa.emit_f64_store(wasm::mem_align::b8, 0); + m_wa.emit_f64_store(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1100,7 +1100,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Logical: { switch (kind) { case 4: - wa.emit_i32_store(wasm::mem_align::b8, 0); + m_wa.emit_i32_store(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1111,10 +1111,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Character: { switch (kind) { case 4: - wa.emit_i32_store(wasm::mem_align::b8, 0); + m_wa.emit_i32_store(wasm::mem_align::b8, 0); break; case 8: - wa.emit_i64_store(wasm::mem_align::b8, 0); + m_wa.emit_i64_store(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1138,10 +1138,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Integer: { switch (kind) { case 4: - wa.emit_i32_load(wasm::mem_align::b8, 0); + m_wa.emit_i32_load(wasm::mem_align::b8, 0); break; case 8: - wa.emit_i64_load(wasm::mem_align::b8, 0); + m_wa.emit_i64_load(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1152,10 +1152,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Real: { switch (kind) { case 4: - wa.emit_f32_load(wasm::mem_align::b8, 0); + m_wa.emit_f32_load(wasm::mem_align::b8, 0); break; case 8: - wa.emit_f64_load(wasm::mem_align::b8, 0); + m_wa.emit_f64_load(wasm::mem_align::b8, 0); break; default: throw CodeGenError("MemoryLoad: Unsupported Real kind"); @@ -1165,7 +1165,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Logical: { switch (kind) { case 4: - wa.emit_i32_load(wasm::mem_align::b8, 0); + m_wa.emit_i32_load(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1176,10 +1176,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { case ASR::ttypeType::Character: { switch (kind) { case 4: - wa.emit_i32_load(wasm::mem_align::b8, 0); + m_wa.emit_i32_load(wasm::mem_align::b8, 0); break; case 8: - wa.emit_i64_load(wasm::mem_align::b8, 0); + m_wa.emit_i64_load(wasm::mem_align::b8, 0); break; default: throw CodeGenError( @@ -1222,19 +1222,19 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (i->m_kind == 4) { switch (x.m_op) { case ASR::binopType::Add: { - wa.emit_i32_add(); + m_wa.emit_i32_add(); break; }; case ASR::binopType::Sub: { - wa.emit_i32_sub(); + m_wa.emit_i32_sub(); break; }; case ASR::binopType::Mul: { - wa.emit_i32_mul(); + m_wa.emit_i32_mul(); break; }; case ASR::binopType::Div: { - wa.emit_i32_div_s(); + m_wa.emit_i32_div_s(); break; }; case ASR::binopType::Pow: { @@ -1244,9 +1244,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::down_cast(val); if (c->m_n == 2) { // drop the last stack item in the wasm stack - wa.emit_drop(); + m_wa.emit_drop(); this->visit_expr(*x.m_left); - wa.emit_i32_mul(); + m_wa.emit_i32_mul(); } else { throw CodeGenError( "IntegerBinop kind 4: only x**2 implemented so " @@ -1260,23 +1260,23 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { break; }; case ASR::binopType::BitAnd: { - wa.emit_i32_and(); + m_wa.emit_i32_and(); break; }; case ASR::binopType::BitOr: { - wa.emit_i32_or(); + m_wa.emit_i32_or(); break; }; case ASR::binopType::BitXor: { - wa.emit_i32_xor(); + m_wa.emit_i32_xor(); break; }; case ASR::binopType::BitLShift: { - wa.emit_i32_shl(); + m_wa.emit_i32_shl(); break; }; case ASR::binopType::BitRShift: { - wa.emit_i32_shr_s(); + m_wa.emit_i32_shr_s(); break; }; default: { @@ -1287,19 +1287,19 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } else if (i->m_kind == 8) { switch (x.m_op) { case ASR::binopType::Add: { - wa.emit_i64_add(); + m_wa.emit_i64_add(); break; }; case ASR::binopType::Sub: { - wa.emit_i64_sub(); + m_wa.emit_i64_sub(); break; }; case ASR::binopType::Mul: { - wa.emit_i64_mul(); + m_wa.emit_i64_mul(); break; }; case ASR::binopType::Div: { - wa.emit_i64_div_s(); + m_wa.emit_i64_div_s(); break; }; case ASR::binopType::Pow: { @@ -1309,9 +1309,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::down_cast(val); if (c->m_n == 2) { // drop the last stack item in the wasm stack - wa.emit_drop(); + m_wa.emit_drop(); this->visit_expr(*x.m_left); - wa.emit_i64_mul(); + m_wa.emit_i64_mul(); } else { throw CodeGenError( "IntegerBinop kind 8: only x**2 implemented so " @@ -1325,23 +1325,23 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { break; }; case ASR::binopType::BitAnd: { - wa.emit_i64_and(); + m_wa.emit_i64_and(); break; }; case ASR::binopType::BitOr: { - wa.emit_i64_or(); + m_wa.emit_i64_or(); break; }; case ASR::binopType::BitXor: { - wa.emit_i64_xor(); + m_wa.emit_i64_xor(); break; }; case ASR::binopType::BitLShift: { - wa.emit_i64_shl(); + m_wa.emit_i64_shl(); break; }; case ASR::binopType::BitRShift: { - wa.emit_i64_shr_s(); + m_wa.emit_i64_shr_s(); break; }; default: { @@ -1364,12 +1364,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { // there is no direct bit-invert inst in wasm, // so xor-ing with -1 (sequence of 32/64 1s) if(i->m_kind == 4){ - wa.emit_i32_const(-1); - wa.emit_i32_xor(); + m_wa.emit_i32_const(-1); + m_wa.emit_i32_xor(); } else if(i->m_kind == 8){ - wa.emit_i64_const(-1LL); - wa.emit_i64_xor(); + m_wa.emit_i64_const(-1LL); + m_wa.emit_i64_xor(); } else{ throw CodeGenError("IntegerBitNot: Only kind 4 and 8 supported"); @@ -1387,19 +1387,19 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (f->m_kind == 4) { switch (x.m_op) { case ASR::binopType::Add: { - wa.emit_f32_add(); + m_wa.emit_f32_add(); break; }; case ASR::binopType::Sub: { - wa.emit_f32_sub(); + m_wa.emit_f32_sub(); break; }; case ASR::binopType::Mul: { - wa.emit_f32_mul(); + m_wa.emit_f32_mul(); break; }; case ASR::binopType::Div: { - wa.emit_f32_div(); + m_wa.emit_f32_div(); break; }; case ASR::binopType::Pow: { @@ -1409,9 +1409,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::down_cast(val); if (c->m_r == 2.0) { // drop the last stack item in the wasm stack - wa.emit_drop(); + m_wa.emit_drop(); this->visit_expr(*x.m_left); - wa.emit_f32_mul(); + m_wa.emit_f32_mul(); } else { throw CodeGenError( "RealBinop: only x**2 implemented so far for " @@ -1432,19 +1432,19 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } else if (f->m_kind == 8) { switch (x.m_op) { case ASR::binopType::Add: { - wa.emit_f64_add(); + m_wa.emit_f64_add(); break; }; case ASR::binopType::Sub: { - wa.emit_f64_sub(); + m_wa.emit_f64_sub(); break; }; case ASR::binopType::Mul: { - wa.emit_f64_mul(); + m_wa.emit_f64_mul(); break; }; case ASR::binopType::Div: { - wa.emit_f64_div(); + m_wa.emit_f64_div(); break; }; case ASR::binopType::Pow: { @@ -1454,9 +1454,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::down_cast(val); if (c->m_r == 2.0) { // drop the last stack item in the wasm stack - wa.emit_drop(); + m_wa.emit_drop(); this->visit_expr(*x.m_left); - wa.emit_f64_mul(); + m_wa.emit_f64_mul(); } else { throw CodeGenError( "RealBinop: only x**2 implemented so far for " @@ -1493,12 +1493,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (m_rt_func_used_idx[add_c32] == -1) { m_rt_func_used_idx[add_c32] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[add_c32]); + m_wa.emit_call(m_rt_func_used_idx[add_c32]); } else { if (m_rt_func_used_idx[add_c64] == -1) { m_rt_func_used_idx[add_c64] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[add_c64]); + m_wa.emit_call(m_rt_func_used_idx[add_c64]); } break; }; @@ -1507,12 +1507,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (m_rt_func_used_idx[sub_c32] == -1) { m_rt_func_used_idx[sub_c32] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[sub_c32]); + m_wa.emit_call(m_rt_func_used_idx[sub_c32]); } else { if (m_rt_func_used_idx[sub_c64] == -1) { m_rt_func_used_idx[sub_c64] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[sub_c64]); + m_wa.emit_call(m_rt_func_used_idx[sub_c64]); } break; }; @@ -1521,12 +1521,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (m_rt_func_used_idx[mul_c32] == -1) { m_rt_func_used_idx[mul_c32] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[mul_c32]); + m_wa.emit_call(m_rt_func_used_idx[mul_c32]); } else { if (m_rt_func_used_idx[mul_c64] == -1) { m_rt_func_used_idx[mul_c64] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[mul_c64]); + m_wa.emit_call(m_rt_func_used_idx[mul_c64]); } break; }; @@ -1545,13 +1545,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::Integer_t *i = ASR::down_cast(x.m_type); // there seems no direct unary-minus inst in wasm, so subtracting from 0 if (i->m_kind == 4) { - wa.emit_i32_const(0); + m_wa.emit_i32_const(0); this->visit_expr(*x.m_arg); - wa.emit_i32_sub(); + m_wa.emit_i32_sub(); } else if (i->m_kind == 8) { - wa.emit_i64_const(0LL); + m_wa.emit_i64_const(0LL); this->visit_expr(*x.m_arg); - wa.emit_i64_sub(); + m_wa.emit_i64_sub(); } else { throw CodeGenError( "IntegerUnaryMinus: Only kind 4 and 8 supported"); @@ -1566,10 +1566,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::Real_t *f = ASR::down_cast(x.m_type); if (f->m_kind == 4) { this->visit_expr(*x.m_arg); - wa.emit_f32_neg(); + m_wa.emit_f32_neg(); } else if (f->m_kind == 8) { this->visit_expr(*x.m_arg); - wa.emit_f64_neg(); + m_wa.emit_f64_neg(); } else { throw CodeGenError("RealUnaryMinus: Only kind 4 and 8 supported"); } @@ -1583,16 +1583,16 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::Complex_t *f = ASR::down_cast(x.m_type); if (f->m_kind == 4) { this->visit_expr(*x.m_arg); - wa.emit_f32_neg(); - wa.emit_global_set(m_compiler_globals[tmp_reg_f32]); - wa.emit_f32_neg(); - wa.emit_global_get(m_compiler_globals[tmp_reg_f32]); + m_wa.emit_f32_neg(); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f32]); + m_wa.emit_f32_neg(); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f32]); } else if (f->m_kind == 8) { this->visit_expr(*x.m_arg); - wa.emit_f64_neg(); - wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); - wa.emit_f64_neg(); - wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_f64_neg(); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_f64_neg(); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); } else { throw CodeGenError("ComplexUnaryMinus: Only kind 4 and 8 supported"); } @@ -1629,27 +1629,27 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (a_kind == 4) { switch (x.m_op) { case (ASR::cmpopType::Eq): { - wa.emit_i32_eq(); + m_wa.emit_i32_eq(); break; } case (ASR::cmpopType::Gt): { - wa.emit_i32_gt_s(); + m_wa.emit_i32_gt_s(); break; } case (ASR::cmpopType::GtE): { - wa.emit_i32_ge_s(); + m_wa.emit_i32_ge_s(); break; } case (ASR::cmpopType::Lt): { - wa.emit_i32_lt_s(); + m_wa.emit_i32_lt_s(); break; } case (ASR::cmpopType::LtE): { - wa.emit_i32_le_s(); + m_wa.emit_i32_le_s(); break; } case (ASR::cmpopType::NotEq): { - wa.emit_i32_ne(); + m_wa.emit_i32_ne(); break; } default: @@ -1660,27 +1660,27 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } else if (a_kind == 8) { switch (x.m_op) { case (ASR::cmpopType::Eq): { - wa.emit_i64_eq(); + m_wa.emit_i64_eq(); break; } case (ASR::cmpopType::Gt): { - wa.emit_i64_gt_s(); + m_wa.emit_i64_gt_s(); break; } case (ASR::cmpopType::GtE): { - wa.emit_i64_ge_s(); + m_wa.emit_i64_ge_s(); break; } case (ASR::cmpopType::Lt): { - wa.emit_i64_lt_s(); + m_wa.emit_i64_lt_s(); break; } case (ASR::cmpopType::LtE): { - wa.emit_i64_le_s(); + m_wa.emit_i64_le_s(); break; } case (ASR::cmpopType::NotEq): { - wa.emit_i64_ne(); + m_wa.emit_i64_ne(); break; } default: @@ -1705,27 +1705,27 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (a_kind == 4) { switch (x.m_op) { case (ASR::cmpopType::Eq): { - wa.emit_f32_eq(); + m_wa.emit_f32_eq(); break; } case (ASR::cmpopType::Gt): { - wa.emit_f32_gt(); + m_wa.emit_f32_gt(); break; } case (ASR::cmpopType::GtE): { - wa.emit_f32_ge(); + m_wa.emit_f32_ge(); break; } case (ASR::cmpopType::Lt): { - wa.emit_f32_lt(); + m_wa.emit_f32_lt(); break; } case (ASR::cmpopType::LtE): { - wa.emit_f32_le(); + m_wa.emit_f32_le(); break; } case (ASR::cmpopType::NotEq): { - wa.emit_f32_ne(); + m_wa.emit_f32_ne(); break; } default: @@ -1735,27 +1735,27 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } else if (a_kind == 8) { switch (x.m_op) { case (ASR::cmpopType::Eq): { - wa.emit_f64_eq(); + m_wa.emit_f64_eq(); break; } case (ASR::cmpopType::Gt): { - wa.emit_f64_gt(); + m_wa.emit_f64_gt(); break; } case (ASR::cmpopType::GtE): { - wa.emit_f64_ge(); + m_wa.emit_f64_ge(); break; } case (ASR::cmpopType::Lt): { - wa.emit_f64_lt(); + m_wa.emit_f64_lt(); break; } case (ASR::cmpopType::LtE): { - wa.emit_f64_le(); + m_wa.emit_f64_le(); break; } case (ASR::cmpopType::NotEq): { - wa.emit_f64_ne(); + m_wa.emit_f64_ne(); break; } default: @@ -1798,23 +1798,23 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (a_kind == 4) { switch (x.m_op) { case (ASR::logicalbinopType::And): { - wa.emit_i32_and(); + m_wa.emit_i32_and(); break; } case (ASR::logicalbinopType::Or): { - wa.emit_i32_or(); + m_wa.emit_i32_or(); break; } case ASR::logicalbinopType::Xor: { - wa.emit_i32_xor(); + m_wa.emit_i32_xor(); break; } case (ASR::logicalbinopType::NEqv): { - wa.emit_i32_xor(); + m_wa.emit_i32_xor(); break; } case (ASR::logicalbinopType::Eqv): { - wa.emit_i32_eq(); + m_wa.emit_i32_eq(); break; } default: @@ -1834,9 +1834,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { this->visit_expr(*x.m_arg); int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); if (a_kind == 4) { - wa.emit_i32_eqz(); + m_wa.emit_i32_eqz(); } else if (a_kind == 8) { - wa.emit_i64_eqz(); + m_wa.emit_i64_eqz(); } else { throw CodeGenError("LogicalNot: kind 4 and 8 supported only"); } @@ -1882,12 +1882,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASR::dimension_t *m_dims; ASRUtils::extract_dimensions_from_ttype(ttype, m_dims); - wa.emit_i32_const(0); + m_wa.emit_i32_const(0); for (uint32_t i = 0; i < x.n_args; i++) { if (x.m_args[i].m_right) { this->visit_expr(*x.m_args[i].m_right); this->visit_expr(*m_dims[i].m_start); - wa.emit_i32_sub(); + m_wa.emit_i32_sub(); size_t jmin, jmax; if (x.m_storage_format == ASR::arraystorageType::ColMajor) { @@ -1902,18 +1902,18 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { for (size_t j = jmin; j < jmax; j++) { this->visit_expr(*m_dims[j].m_length); - wa.emit_i32_mul(); + m_wa.emit_i32_mul(); } - wa.emit_i32_add(); + m_wa.emit_i32_add(); } else { diag.codegen_warning_label("/* FIXME right index */", {x.base.base.loc}, ""); } } - wa.emit_i32_const(kind); - wa.emit_i32_mul(); - wa.emit_i32_add(); + m_wa.emit_i32_const(kind); + m_wa.emit_i32_mul(); + m_wa.emit_i32_add(); } void visit_ArrayItem(const ASR::ArrayItem_t &x) { @@ -1948,13 +1948,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { this->visit_expr(*(m_dims[0].m_length)); for (int i = 1; i < n_dims; i++) { this->visit_expr(*m_dims[i].m_length); - wa.emit_i32_mul(); + m_wa.emit_i32_mul(); } } int kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); if (kind == 8) { - wa.emit_i64_extend_i32_s(); + m_wa.emit_i64_extend_i32_s(); } } @@ -1966,7 +1966,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { emit_var_get(return_var); } } - wa.emit_return(); + m_wa.emit_return(); } void visit_Return(const ASR::Return_t & /* x */) { handle_return(); } @@ -1976,11 +1976,11 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { int a_kind = ((ASR::Integer_t *)(&(x.m_type->base)))->m_kind; switch (a_kind) { case 4: { - wa.emit_i32_const(val); + m_wa.emit_i32_const(val); break; } case 8: { - wa.emit_i64_const(val); + m_wa.emit_i64_const(val); break; } default: { @@ -1995,11 +1995,11 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { int a_kind = ((ASR::Real_t *)(&(x.m_type->base)))->m_kind; switch (a_kind) { case 4: { - wa.emit_f32_const(val); + m_wa.emit_f32_const(val); break; } case 8: { - wa.emit_f64_const(val); + m_wa.emit_f64_const(val); break; } default: { @@ -2014,7 +2014,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { int a_kind = ((ASR::Logical_t *)(&(x.m_type->base)))->m_kind; switch (a_kind) { case 4: { - wa.emit_i32_const(val); + m_wa.emit_i32_const(val); break; } default: { @@ -2036,13 +2036,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); switch( a_kind ) { case 4: { - wa.emit_f32_const(x.m_re); - wa.emit_f32_const(x.m_im); + m_wa.emit_f32_const(x.m_re); + m_wa.emit_f32_const(x.m_im); break; } case 8: { - wa.emit_f64_const(x.m_re); - wa.emit_f64_const(x.m_im); + m_wa.emit_f64_const(x.m_re); + m_wa.emit_f64_const(x.m_im); break; } default: { @@ -2081,17 +2081,17 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { uint32_t string_loc = avail_mem_loc + 8U /* IOV_SIZE */; std::string iov = convert_int_to_bytes_string(string_loc) + convert_int_to_bytes_string(str.length()); - wa.emit_data_str(avail_mem_loc, iov); + m_wa.emit_data_str(avail_mem_loc, iov); avail_mem_loc += iov.length(); align_str_by_4_bytes(str); - wa.emit_data_str(avail_mem_loc, str); + m_wa.emit_data_str(avail_mem_loc, str); avail_mem_loc += str.length(); } void visit_StringConstant(const ASR::StringConstant_t &x) { emit_string(x.m_s); - wa.emit_i32_const(m_string_to_iov_loc_map[x.m_s]); + m_wa.emit_i32_const(m_string_to_iov_loc_map[x.m_s]); } void visit_ArrayConstant(const ASR::ArrayConstant_t &x) { @@ -2100,14 +2100,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { uint32_t cur_mem_loc = avail_mem_loc; for (size_t i = 0; i < x.n_args; i++) { // emit memory location to store array element - wa.emit_i32_const(avail_mem_loc); + m_wa.emit_i32_const(avail_mem_loc); this->visit_expr(*x.m_args[i]); int element_size_in_bytes = emit_memory_store(x.m_args[i]); avail_mem_loc += element_size_in_bytes; } // leave array location in memory on the stack - wa.emit_i32_const(cur_mem_loc); + m_wa.emit_i32_const(cur_mem_loc); } void visit_FunctionCall(const ASR::FunctionCall_t &x) { @@ -2125,17 +2125,17 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { uint64_t hash = get_hash((ASR::asr_t *)fn); if (m_func_name_idx_map.find(hash) != m_func_name_idx_map.end()) { - wa.emit_call(m_func_name_idx_map[hash]->index); + m_wa.emit_call(m_func_name_idx_map[hash]->index); } else { if (strcmp(fn->m_name, "c_caimag") == 0) { LCOMPILERS_ASSERT(x.n_args == 1); - wa.emit_global_set(m_compiler_globals[tmp_reg_f32]); - wa.emit_drop(); - wa.emit_global_get(m_compiler_globals[tmp_reg_f32]); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f32]); + m_wa.emit_drop(); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f32]); } else if (strcmp(fn->m_name, "c_zaimag") == 0) { - wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); - wa.emit_drop(); - wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_drop(); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); } else { throw CodeGenError("FunctionCall: Function " + std::string(fn->m_name) + " not found"); } @@ -2188,7 +2188,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { " not yet supported"); } } - wa.emit_global_set(m_compiler_globals[global_var]); + m_wa.emit_global_set(m_compiler_globals[global_var]); } void temp_value_get(ASR::expr_t* expr) { @@ -2237,7 +2237,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { " not yet supported"); } } - wa.emit_global_get(m_compiler_globals[global_var]); + m_wa.emit_global_get(m_compiler_globals[global_var]); } void visit_SubroutineCall(const ASR::SubroutineCall_t &x) { @@ -2264,7 +2264,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { uint64_t hash = get_hash((ASR::asr_t *)s); if (m_func_name_idx_map.find(hash) != m_func_name_idx_map.end()) { - wa.emit_call(m_func_name_idx_map[hash]->index); + m_wa.emit_call(m_func_name_idx_map[hash]->index); } else { throw CodeGenError("SubroutineCall: Function " + std::string(s->m_name) + " not found"); } @@ -2307,13 +2307,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 4) { - wa.emit_f32_convert_i32_s(); + m_wa.emit_f32_convert_i32_s(); } else if (arg_kind == 8 && dest_kind == 8) { - wa.emit_f64_convert_i64_s(); + m_wa.emit_f64_convert_i64_s(); } else if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_convert_i32_s(); + m_wa.emit_f64_convert_i32_s(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f32_convert_i64_s(); + m_wa.emit_f32_convert_i64_s(); } else { std::string msg = "Conversion from " + std::to_string(arg_kind) + " to " + @@ -2329,13 +2329,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 4) { - wa.emit_i32_trunc_f32_s(); + m_wa.emit_i32_trunc_f32_s(); } else if (arg_kind == 8 && dest_kind == 8) { - wa.emit_i64_trunc_f64_s(); + m_wa.emit_i64_trunc_f64_s(); } else if (arg_kind == 4 && dest_kind == 8) { - wa.emit_i64_trunc_f32_s(); + m_wa.emit_i64_trunc_f32_s(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_i32_trunc_f64_s(); + m_wa.emit_i32_trunc_f64_s(); } else { std::string msg = "Conversion from " + std::to_string(arg_kind) + " to " + @@ -2352,9 +2352,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (arg_kind == dest_kind) { } else if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_promote_f32(); + m_wa.emit_f64_promote_f32(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f32_demote_f64(); + m_wa.emit_f32_demote_f64(); } else { std::string msg = "RealToComplex: Conversion from " + std::to_string(arg_kind) + " to " + @@ -2365,10 +2365,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { switch(dest_kind) { case 4: - wa.emit_f32_const(0.0); + m_wa.emit_f32_const(0.0); break; case 8: - wa.emit_f64_const(0.0); + m_wa.emit_f64_const(0.0); break; default: throw CodeGenError("RealToComplex: Only 32 and 64 bits real kinds are supported."); @@ -2380,13 +2380,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 4) { - wa.emit_f32_convert_i32_s(); + m_wa.emit_f32_convert_i32_s(); } else if (arg_kind == 8 && dest_kind == 8) { - wa.emit_f64_convert_i64_s(); + m_wa.emit_f64_convert_i64_s(); } else if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_convert_i32_s(); + m_wa.emit_f64_convert_i32_s(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f32_convert_i64_s(); + m_wa.emit_f32_convert_i64_s(); } else { std::string msg = "IntegerToComplex: Conversion from " + std::to_string(arg_kind) + " to " + @@ -2398,10 +2398,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { switch(dest_kind) { case 4: - wa.emit_f32_const(0.0); + m_wa.emit_f32_const(0.0); break; case 8: - wa.emit_f64_const(0.0); + m_wa.emit_f64_const(0.0); break; default: throw CodeGenError("RealToComplex: Only 32 and 64 bits real kinds are supported."); @@ -2413,12 +2413,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 4) { - wa.emit_i32_eqz(); - wa.emit_i32_eqz(); + m_wa.emit_i32_eqz(); + m_wa.emit_i32_eqz(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_i64_eqz(); - wa.emit_i64_eqz(); - wa.emit_i32_wrap_i64(); + m_wa.emit_i64_eqz(); + m_wa.emit_i64_eqz(); + m_wa.emit_i32_wrap_i64(); } else { std::string msg = "Conversion from kinds " + std::to_string(arg_kind) + " to " + @@ -2434,14 +2434,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 4) { - wa.emit_f32_const(0.0); - wa.emit_f32_eq(); - wa.emit_i32_eqz(); + m_wa.emit_f32_const(0.0); + m_wa.emit_f32_eq(); + m_wa.emit_i32_eqz(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f64_const(0.0); - wa.emit_f64_eq(); - wa.emit_i64_eqz(); - wa.emit_i32_wrap_i64(); + m_wa.emit_f64_const(0.0); + m_wa.emit_f64_eq(); + m_wa.emit_i64_eqz(); + m_wa.emit_i32_wrap_i64(); } else { std::string msg = "Conversion from kinds " + std::to_string(arg_kind) + " to " + @@ -2464,16 +2464,16 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { if (m_rt_func_used_idx[abs_c32] == -1) { m_rt_func_used_idx[abs_c32] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[abs_c32]); - wa.emit_f32_const(0.0); - wa.emit_f32_gt(); + m_wa.emit_call(m_rt_func_used_idx[abs_c32]); + m_wa.emit_f32_const(0.0); + m_wa.emit_f32_gt(); } else if (arg_kind == 8) { if (m_rt_func_used_idx[abs_c64] == -1) { m_rt_func_used_idx[abs_c64] = rt_funcs_seq_order++; } - wa.emit_call(m_rt_func_used_idx[abs_c64]); - wa.emit_f64_const(0.0); - wa.emit_f64_gt(); + m_wa.emit_call(m_rt_func_used_idx[abs_c64]); + m_wa.emit_f64_const(0.0); + m_wa.emit_f64_gt(); } else { std::string msg = "ComplexToLogical: Conversion from kinds " + std::to_string(arg_kind) + " to " + @@ -2488,7 +2488,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 8) { - wa.emit_i64_extend_i32_s(); + m_wa.emit_i64_extend_i32_s(); } else if (arg_kind == 4 && dest_kind == 4) { } else { std::string msg = "Conversion from kinds " + @@ -2505,9 +2505,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0) { if (arg_kind == 4 && dest_kind == 4) { - wa.emit_f32_convert_i32_s(); + m_wa.emit_f32_convert_i32_s(); } else if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_convert_i32_s(); + m_wa.emit_f64_convert_i32_s(); } else { std::string msg = "Conversion from kinds " + std::to_string(arg_kind) + " to " + @@ -2523,9 +2523,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0 && arg_kind != dest_kind) { if (arg_kind == 4 && dest_kind == 8) { - wa.emit_i64_extend_i32_s(); + m_wa.emit_i64_extend_i32_s(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_i32_wrap_i64(); + m_wa.emit_i32_wrap_i64(); } else { std::string msg = "Conversion from " + std::to_string(arg_kind) + " to " + @@ -2541,9 +2541,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0 && arg_kind != dest_kind) { if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_promote_f32(); + m_wa.emit_f64_promote_f32(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f32_demote_f64(); + m_wa.emit_f32_demote_f64(); } else { std::string msg = "Conversion from " + std::to_string(arg_kind) + " to " + @@ -2559,15 +2559,15 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0 && arg_kind != dest_kind) { if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_promote_f32(); - wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); - wa.emit_f64_promote_f32(); - wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_f64_promote_f32(); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_f64_promote_f32(); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f32_demote_f64(); - wa.emit_global_set(m_compiler_globals[tmp_reg_f32]); - wa.emit_f32_demote_f64(); - wa.emit_global_get(m_compiler_globals[tmp_reg_f32]); + m_wa.emit_f32_demote_f64(); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f32]); + m_wa.emit_f32_demote_f64(); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f32]); } else { std::string msg = "ComplexToComplex: Conversion from " + std::to_string(arg_kind) + " to " + @@ -2579,14 +2579,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { break; } case (ASR::cast_kindType::ComplexToReal): { - wa.emit_drop(); // drop imag part + m_wa.emit_drop(); // drop imag part int arg_kind = -1, dest_kind = -1; extract_kinds(x, arg_kind, dest_kind); if (arg_kind > 0 && dest_kind > 0 && arg_kind != dest_kind) { if (arg_kind == 4 && dest_kind == 8) { - wa.emit_f64_promote_f32(); + m_wa.emit_f64_promote_f32(); } else if (arg_kind == 8 && dest_kind == 4) { - wa.emit_f32_demote_f64(); + m_wa.emit_f32_demote_f64(); } else { std::string msg = "ComplexToReal: Conversion from " + std::to_string(arg_kind) + " to " + @@ -2604,28 +2604,28 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { void visit_ComplexRe(const ASR::ComplexRe_t &x) { this->visit_expr(*x.m_arg); - wa.emit_drop(); + m_wa.emit_drop(); } void visit_ComplexIm(const ASR::ComplexIm_t &x) { this->visit_expr(*x.m_arg); int a_kind = ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(x.m_arg)); - wa.emit_global_set((a_kind == 4) ? m_compiler_globals[tmp_reg_f32] + m_wa.emit_global_set((a_kind == 4) ? m_compiler_globals[tmp_reg_f32] : m_compiler_globals[tmp_reg_f64]); - wa.emit_drop(); - wa.emit_global_get((a_kind == 4) ? m_compiler_globals[tmp_reg_f32] + m_wa.emit_drop(); + m_wa.emit_global_get((a_kind == 4) ? m_compiler_globals[tmp_reg_f32] : m_compiler_globals[tmp_reg_f64]); } void emit_call_fd_write(int filetype, const std::string &str, int iov_vec_len, int return_val_mem_loc) { - wa.emit_i32_const(filetype); // file type: 1 for stdout - wa.emit_i32_const(m_string_to_iov_loc_map[str]); // iov location - wa.emit_i32_const(iov_vec_len); // size of iov vector - wa.emit_i32_const(return_val_mem_loc); // mem_loction to return no. of bytes written + m_wa.emit_i32_const(filetype); // file type: 1 for stdout + m_wa.emit_i32_const(m_string_to_iov_loc_map[str]); // iov location + m_wa.emit_i32_const(iov_vec_len); // size of iov vector + m_wa.emit_i32_const(return_val_mem_loc); // mem_loction to return no. of bytes written // call WASI fd_write - wa.emit_call(m_import_func_idx_map[fd_write]); - wa.emit_drop(); + m_wa.emit_call(m_import_func_idx_map[fd_write]); + m_wa.emit_drop(); } template @@ -2633,14 +2633,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { for (size_t i = 0; i < x.n_values; i++) { if (i > 0) { if (x.m_separator) { - wa.emit_i32_const(1); // file type: 1 for stdout + m_wa.emit_i32_const(1); // file type: 1 for stdout this->visit_expr(*x.m_separator); // iov location - wa.emit_i32_const(1); // size of iov vector - wa.emit_i32_const(0); // mem_loction to return no. of bytes written + m_wa.emit_i32_const(1); // size of iov vector + m_wa.emit_i32_const(0); // mem_loction to return no. of bytes written // call WASI fd_write - wa.emit_call(m_import_func_idx_map[fd_write]); - wa.emit_drop(); + m_wa.emit_call(m_import_func_idx_map[fd_write]); + m_wa.emit_drop(); } else { emit_call_fd_write(1, " ", 1, 0); } @@ -2656,12 +2656,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { this->visit_expr(*x.m_values[i]); switch (a_kind) { case 4: { - wa.emit_i64_extend_i32_s(); - wa.emit_call(m_rt_func_used_idx[print_i64]); + m_wa.emit_i64_extend_i32_s(); + m_wa.emit_call(m_rt_func_used_idx[print_i64]); break; } case 8: { - wa.emit_call(m_rt_func_used_idx[print_i64]); + m_wa.emit_call(m_rt_func_used_idx[print_i64]); break; } default: { @@ -2680,12 +2680,12 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { this->visit_expr(*x.m_values[i]); switch (a_kind) { case 4: { - wa.emit_f64_promote_f32(); - wa.emit_call(m_rt_func_used_idx[print_f64]); + m_wa.emit_f64_promote_f32(); + m_wa.emit_call(m_rt_func_used_idx[print_f64]); break; } case 8: { - wa.emit_call(m_rt_func_used_idx[print_f64]); + m_wa.emit_call(m_rt_func_used_idx[print_f64]); break; } default: { @@ -2695,14 +2695,14 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } } } else if (t->type == ASR::ttypeType::Character) { - wa.emit_i32_const(1); // file type: 1 for stdout + m_wa.emit_i32_const(1); // file type: 1 for stdout this->visit_expr(*x.m_values[i]); // iov location - wa.emit_i32_const(1); // size of iov vector - wa.emit_i32_const(0); // mem_loction to return no. of bytes written + m_wa.emit_i32_const(1); // size of iov vector + m_wa.emit_i32_const(0); // mem_loction to return no. of bytes written // call WASI fd_write - wa.emit_call(m_import_func_idx_map[fd_write]); - wa.emit_drop(); + m_wa.emit_call(m_import_func_idx_map[fd_write]); + m_wa.emit_drop(); } else if (t->type == ASR::ttypeType::Complex) { if (m_rt_func_used_idx[print_i64] == -1) { m_rt_func_used_idx[print_i64] = rt_funcs_seq_order++; @@ -2713,30 +2713,30 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { emit_call_fd_write(1, "(", 1, 0); this->visit_expr(*x.m_values[i]); if (a_kind == 4) { - wa.emit_f64_promote_f32(); - wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); - wa.emit_f64_promote_f32(); + m_wa.emit_f64_promote_f32(); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_f64_promote_f32(); } else { - wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_global_set(m_compiler_globals[tmp_reg_f64]); } - wa.emit_call(m_rt_func_used_idx[print_f64]); + m_wa.emit_call(m_rt_func_used_idx[print_f64]); emit_call_fd_write(1, ",", 1, 0); - wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); - wa.emit_call(m_rt_func_used_idx[print_f64]); + m_wa.emit_global_get(m_compiler_globals[tmp_reg_f64]); + m_wa.emit_call(m_rt_func_used_idx[print_f64]); emit_call_fd_write(1, ")", 1, 0); } } // print "\n" newline character if (x.m_end) { - wa.emit_i32_const(1); // file type: 1 for stdout + m_wa.emit_i32_const(1); // file type: 1 for stdout this->visit_expr(*x.m_end); // iov location - wa.emit_i32_const(1); // size of iov vector - wa.emit_i32_const(0); // mem_loction to return no. of bytes written + m_wa.emit_i32_const(1); // size of iov vector + m_wa.emit_i32_const(0); // mem_loction to return no. of bytes written // call WASI fd_write - wa.emit_call(m_import_func_idx_map[fd_write]); - wa.emit_drop(); + m_wa.emit_call(m_import_func_idx_map[fd_write]); + m_wa.emit_drop(); } else { emit_call_fd_write(1, "\n", 1, 0); } @@ -2795,8 +2795,8 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { void wasm_exit() { // exit_code would be on stack, so set this exit code using // proc_exit(). this exit code would be read by JavaScript glue code - wa.emit_call(m_import_func_idx_map[proc_exit]); - wa.emit_unreachable(); // raise trap/exception + m_wa.emit_call(m_import_func_idx_map[proc_exit]); + m_wa.emit_unreachable(); // raise trap/exception } void visit_ArrayBound(const ASR::ArrayBound_t& x) { @@ -2820,13 +2820,13 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } else { this->visit_expr(*m_dims[dimDir->m_n - 1].m_start); this->visit_expr(*m_dims[dimDir->m_n - 1].m_length); - wa.emit_i32_add(); - wa.emit_i32_const(1); - wa.emit_i32_sub(); + m_wa.emit_i32_add(); + m_wa.emit_i32_const(1); + m_wa.emit_i32_sub(); } } else { if (x.m_bound == ASR::arrayboundType::LBound) { - wa.emit_i32_const(1); + m_wa.emit_i32_const(1); } else { // emit the whole array size if (!m_dims[0].m_length) { @@ -2836,7 +2836,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { this->visit_expr(*(m_dims[0].m_length)); for (int i = 1; i < n_dims; i++) { this->visit_expr(*m_dims[i].m_length); - wa.emit_i32_mul(); + m_wa.emit_i32_mul(); } } } @@ -2848,19 +2848,19 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { ASRUtils::expr_type(x.m_code)->type == ASR::ttypeType::Integer) { this->visit_expr(*x.m_code); } else { - wa.emit_i32_const(0); // zero exit code + m_wa.emit_i32_const(0); // zero exit code } wasm_exit(); } void visit_ErrorStop(const ASR::ErrorStop_t & /* x */) { print_msg("ERROR STOP"); - wa.emit_i32_const(1); // non-zero exit code + m_wa.emit_i32_const(1); // non-zero exit code wasm_exit(); } void visit_If(const ASR::If_t &x) { - wa.emit_if_else([&](){ this->visit_expr(*x.m_test); }, [&](){ + m_wa.emit_if_else([&](){ this->visit_expr(*x.m_test); }, [&](){ for (size_t i = 0; i < x.n_body; i++) { this->visit_stmt(*x.m_body[i]); } @@ -2872,7 +2872,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } void visit_WhileLoop(const ASR::WhileLoop_t &x) { - wa.emit_loop([&](){ this->visit_expr(*x.m_test); }, [&](){ + m_wa.emit_loop([&](){ this->visit_expr(*x.m_test); }, [&](){ for (size_t i = 0; i < x.n_body; i++) { this->visit_stmt(*x.m_body[i]); } @@ -2880,15 +2880,15 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } void visit_Exit(const ASR::Exit_t & /* x */) { - wa.emit_br(wa.nest_lvl - wa.cur_loop_nest_lvl - 2U); // branch to end of if + m_wa.emit_br(m_wa.nest_lvl - m_wa.cur_loop_nest_lvl - 2U); // branch to end of if } void visit_Cycle(const ASR::Cycle_t & /* x */) { - wa.emit_br(wa.nest_lvl - wa.cur_loop_nest_lvl - 1U); // branch to start of loop + m_wa.emit_br(m_wa.nest_lvl - m_wa.cur_loop_nest_lvl - 1U); // branch to start of loop } void visit_Assert(const ASR::Assert_t &x) { - wa.emit_if_else([&](){ + m_wa.emit_if_else([&](){ this->visit_expr(*x.m_test); }, [&](){}, [&](){ if (x.m_msg) { @@ -2898,7 +2898,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } else { print_msg("AssertionError"); } - wa.emit_i32_const(1); // non-zero exit code + m_wa.emit_i32_const(1); // non-zero exit code wasm_exit(); }); } @@ -2929,7 +2929,7 @@ Result> asr_to_wasm_bytes_stream(ASR::TranslationUnit_t &asr, return Error(); } - return v.wa.get_wasm(); + return v.m_wa.get_wasm(); } Result asr_to_wasm(ASR::TranslationUnit_t &asr, Allocator &al,