Skip to content

Commit

Permalink
wat-writer.cc: resolve missing type index in call_indirect (WebAssemb…
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw authored Aug 1, 2023
1 parent 00083b5 commit 3d1d29f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/wat-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,11 @@ Result WatWriter::ExprVisitorDelegate::OnCallIndirectExpr(
writer_->WritePutsSpace(Opcode::CallIndirect_Opcode.GetName());
writer_->WriteVarUnlessZero(expr->table, NextChar::Space);
writer_->WriteOpenSpace("type");
writer_->WriteVar(expr->decl.type_var, NextChar::Newline);
const auto type_var =
expr->decl.has_func_type
? expr->decl.type_var
: Var{writer_->module.GetFuncTypeIndex(expr->decl), expr->loc};
writer_->WriteVar(type_var, NextChar::Newline);
writer_->WriteCloseNewline();
return Result::Ok;
}
Expand Down Expand Up @@ -911,7 +915,11 @@ Result WatWriter::ExprVisitorDelegate::OnReturnCallIndirectExpr(
ReturnCallIndirectExpr* expr) {
writer_->WritePutsSpace(Opcode::ReturnCallIndirect_Opcode.GetName());
writer_->WriteOpenSpace("type");
writer_->WriteVar(expr->decl.type_var, NextChar::Space);
const auto type_var =
expr->decl.has_func_type
? expr->decl.type_var
: Var{writer_->module.GetFuncTypeIndex(expr->decl), expr->loc};
writer_->WriteVar(type_var, NextChar::Space);
writer_->WriteCloseNewline();
return Result::Ok;
}
Expand Down
24 changes: 24 additions & 0 deletions test/desugar/call_indirect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;;; TOOL: wat-desugar
(table 0 funcref)
(func
i32.const 0
i32.const 0
i32.const 0
i32.const 0
call_indirect (type 0)
call_indirect
call_indirect (param i32))
(;; STDOUT ;;;
(module
(table (;0;) 0 funcref)
(func (;0;)
i32.const 0
i32.const 0
i32.const 0
i32.const 0
call_indirect (type 0)
call_indirect (type 0)
call_indirect (type 1))
(type (;0;) (func))
(type (;1;) (func (param i32))))
;;; STDOUT ;;)

0 comments on commit 3d1d29f

Please sign in to comment.