Bug 1274618 - Fixes wasmBinaryToText for call expressions. r?sunfish
MozReview-Commit-ID: IpCg12xyOnr
--- a/js/src/asmjs/WasmBinaryToAST.cpp
+++ b/js/src/asmjs/WasmBinaryToAST.cpp
@@ -227,21 +227,22 @@ AstDecodeCall(AstDecodeContext& c)
AstExprVector args(c.lifo);
if (!AstDecodeCallArgs(c, arity, *sig, &args))
return false;
if (!AstDecodeCallReturn(c, *sig))
return false;
+ uint32_t argsLength = args.length();
AstCall* call = new(c.lifo) AstCall(Expr::Call, funcRef, Move(args));
if (!call)
return false;
- c.iter().setResult(AstDecodeStackItem(call, args.length()));
+ c.iter().setResult(AstDecodeStackItem(call, argsLength));
return true;
}
static bool
AstDecodeCallIndirect(AstDecodeContext& c)
{
uint32_t sigIndex;
uint32_t arity;
@@ -263,21 +264,22 @@ AstDecodeCallIndirect(AstDecodeContext&
AstDecodeStackItem index;
if (!c.iter().readCallIndirectCallee(&index))
return false;
if (!AstDecodeCallReturn(c, *sig))
return false;
+ uint32_t argsLength = args.length();
AstCallIndirect* call = new(c.lifo) AstCallIndirect(sigRef, index.expr, Move(args));
if (!call)
return false;
- c.iter().setResult(AstDecodeStackItem(call, 1 + args.length()));
+ c.iter().setResult(AstDecodeStackItem(call, 1 + argsLength));
return true;
}
static bool
AstDecodeCallImport(AstDecodeContext& c)
{
uint32_t importIndex;
uint32_t arity;
@@ -295,21 +297,22 @@ AstDecodeCallImport(AstDecodeContext& c)
AstExprVector args(c.lifo);
if (!AstDecodeCallArgs(c, arity, *sig, &args))
return false;
if (!AstDecodeCallReturn(c, *sig))
return false;
+ uint32_t argsLength = args.length();
AstCall* call = new(c.lifo) AstCall(Expr::CallImport, funcRef, Move(args));
if (!call)
return false;
- c.iter().setResult(AstDecodeStackItem(call, args.length()));
+ c.iter().setResult(AstDecodeStackItem(call, argsLength));
return true;
}
static bool
AstDecodeBrTable(AstDecodeContext& c)
{
uint32_t tableLength;
ExprType type;
--- a/js/src/asmjs/WasmBinaryToText.cpp
+++ b/js/src/asmjs/WasmBinaryToText.cpp
@@ -293,16 +293,20 @@ RenderCallIndirect(WasmRenderContext& c,
if (!RenderExpr(c, *call.index()))
return false;
if (!c.buffer.append(" "))
return false;
if (!RenderCallArgs(c, call.args()))
return false;
+
+ if (!c.buffer.append(")"))
+ return false;
+
return true;
}
static bool
RenderConst(WasmRenderContext& c, AstConst& cst)
{
if (!c.buffer.append('('))
return false;
@@ -1040,20 +1044,20 @@ RenderTypeSection(WasmRenderContext& c,
for (uint32_t sigIndex = 0; sigIndex < numSigs; sigIndex++) {
const AstSig* sig = sigs[sigIndex];
if (!RenderIndent(c))
return false;
if (!c.buffer.append("(type"))
return false;
if (!sig->name().empty()) {
- if (!c.buffer.append(" "))
- return false;
- if (!RenderName(c, sig->name()))
- return false;
+ if (!c.buffer.append(" "))
+ return false;
+ if (!RenderName(c, sig->name()))
+ return false;
}
if (!c.buffer.append(" (func"))
return false;
if (!RenderSignature(c, *sig))
return false;
if (!c.buffer.append("))\n"))
return false;
}
@@ -1063,32 +1067,37 @@ RenderTypeSection(WasmRenderContext& c,
static bool
RenderTableSection(WasmRenderContext& c, AstTable* maybeTable, const AstModule::FuncVector& funcs)
{
if (!maybeTable)
return true;
uint32_t numTableElems = maybeTable->elems().length();
- if (!c.buffer.append("(table "))
+ if (!RenderIndent(c))
+ return false;
+
+ if (!c.buffer.append("(table"))
return false;
for (uint32_t i = 0; i < numTableElems; i++) {
+ if (!c.buffer.append(" "))
+ return false;
AstRef& elem = maybeTable->elems()[i];
AstFunc* func = funcs[elem.index()];
if (func->name().empty()) {
if (!RenderInt32(c, elem.index()))
return false;
} else {
if (!RenderName(c, func->name()))
return false;
}
}
- if (!c.buffer.append(")"))
+ if (!c.buffer.append(")\n"))
return false;
return true;
}
static bool
RenderImport(WasmRenderContext& c, AstImport& import, const AstModule::SigVector& sigs)
{
--- a/js/src/jit-test/tests/wasm/totext1.js
+++ b/js/src/jit-test/tests/wasm/totext1.js
@@ -145,8 +145,26 @@ runTest(`
(func $itrunc_u_f64 (param $x f64) (result i32) (i32.trunc_u/f64 (get_local $x)))
(func $fconvert_s_i32 (param $x i32) (result f32) (f32.convert_s/i32 (get_local $x)))
(func $dconvert_s_i32 (param $x i32) (result f64) (f64.convert_s/i32 (get_local $x)))
(func $fconvert_u_i32 (param $x i32) (result f32) (f32.convert_u/i32 (get_local $x)))
(func $dconvert_u_i32 (param $x i32) (result f64) (f64.convert_u/i32 (get_local $x)))
(func $dpromote_f32 (param $x f32) (result f64) (f64.promote/f32 (get_local $x)))
(func $fdemote_f64 (param $x f64) (result f32) (f32.demote/f64 (get_local $x)))
(memory 0))`);
+
+// function calls
+runTest(`
+(module
+ (type $type1 (func (param i32) (result i32)))
+ (import $import1 "mod" "test" (param f32) (result f32))
+ (table $func1 $func2)
+ (func $func1 (param i32) (param f32) (nop))
+ (func $func2 (param i32) (result i32) (get_local 0))
+ (func $test
+ (call $func1
+ (call_indirect $type1 (i32.const 1) (i32.const 2))
+ (call_import $import1 (f32.const 1.0))
+ )
+ )
+ (export "test" $test)
+ (memory 1)
+)`);