Bug 1274618 - Fixes wasmBinaryToText for call expressions. r=sunfish

MozReview-Commit-ID: IpCg12xyOnr

--HG--
extra : transplant_source : %D51%0F%BD%3A%8F%84%26%EB%AD%1B%92%2C%DDt%FC%E0%12%CD%26
This commit is contained in:
Yury Delendik 2016-05-23 15:02:44 -05:00
parent 3ceac99520
commit 14ec6d03a8
3 changed files with 39 additions and 9 deletions

View File

@ -232,11 +232,12 @@ AstDecodeCall(AstDecodeContext& c)
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;
}
@ -268,11 +269,12 @@ AstDecodeCallIndirect(AstDecodeContext& c)
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;
}
@ -300,11 +302,12 @@ AstDecodeCallImport(AstDecodeContext& c)
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;
}

View File

@ -298,6 +298,10 @@ RenderCallIndirect(WasmRenderContext& c, AstCallIndirect& call)
return false;
if (!RenderCallArgs(c, call.args()))
return false;
if (!c.buffer.append(")"))
return false;
return true;
}
@ -1045,10 +1049,10 @@ RenderTypeSection(WasmRenderContext& c, const AstModule::SigVector& sigs)
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;
@ -1068,10 +1072,15 @@ RenderTableSection(WasmRenderContext& c, AstTable* maybeTable, const AstModule::
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()) {
@ -1083,7 +1092,7 @@ RenderTableSection(WasmRenderContext& c, AstTable* maybeTable, const AstModule::
}
}
if (!c.buffer.append(")"))
if (!c.buffer.append(")\n"))
return false;
return true;

View File

@ -150,3 +150,21 @@ runTest(`
(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)
)`);