Bug 1359612 - Baldr: make ToABIFunctionType work on any function signature (r=bbouvier)

MozReview-Commit-ID: IzzCpt6wwPr

--HG--
extra : rebase_source : f5d5e72647e2cdcecefca671d4bc57120aa80500
This commit is contained in:
Luke Wagner 2017-04-26 09:52:11 -05:00
Родитель 0cfcb2a325
Коммит 77a486b3b3
3 изменённых файлов: 37 добавлений и 8 удалений

Просмотреть файл

@ -0,0 +1,9 @@
load(libdir + 'asm.js');
asmLink(asmCompile('stdlib', 'foreign', USE_ASM + `
var ff = foreign.ff;
function f() {
ff(+1);
}
return f
`), this, { ff: Math.log1p });

Просмотреть файл

@ -0,0 +1,15 @@
var code = wasmTextToBinary(`(module
(import $one "" "builtin")
(import $two "" "builtin" (param i32))
(import $three "" "builtin" (result i32))
(import $four "" "builtin" (result f32) (param f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32))
(func (export "run")
(call $one)
(call $two (i32.const 0))
(drop (call $three))
(drop (call $four (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0) (f32.const 0)))
)
)`);
var m = new WebAssembly.Module(code);
var i = new WebAssembly.Instance(m, {'':{builtin:Math.sin}});
i.exports.run();

Просмотреть файл

@ -904,8 +904,8 @@ wasm::SymbolicAddressTarget(SymbolicAddress sym)
return thunks.codeBase + thunks.codeRanges[codeRangeIndex].begin(); return thunks.codeBase + thunks.codeRanges[codeRangeIndex].begin();
} }
static ABIFunctionType static Maybe<ABIFunctionType>
ToABIFunctionType(const Sig& sig) ToBuiltinABIFunctionType(const Sig& sig)
{ {
const ValTypeVector& args = sig.args(); const ValTypeVector& args = sig.args();
ExprType ret = sig.ret(); ExprType ret = sig.ret();
@ -914,18 +914,21 @@ ToABIFunctionType(const Sig& sig)
switch (ret) { switch (ret) {
case ExprType::F32: abiType = ArgType_Float32 << RetType_Shift; break; case ExprType::F32: abiType = ArgType_Float32 << RetType_Shift; break;
case ExprType::F64: abiType = ArgType_Double << RetType_Shift; break; case ExprType::F64: abiType = ArgType_Double << RetType_Shift; break;
default: MOZ_CRASH("unhandled ret type"); default: return Nothing();
} }
if ((args.length() + 1) > (sizeof(uint32_t) * 8 / ArgType_Shift))
return Nothing();
for (size_t i = 0; i < args.length(); i++) { for (size_t i = 0; i < args.length(); i++) {
switch (args[i]) { switch (args[i]) {
case ValType::F32: abiType |= (ArgType_Float32 << (ArgType_Shift * (i + 1))); break; case ValType::F32: abiType |= (ArgType_Float32 << (ArgType_Shift * (i + 1))); break;
case ValType::F64: abiType |= (ArgType_Double << (ArgType_Shift * (i + 1))); break; case ValType::F64: abiType |= (ArgType_Double << (ArgType_Shift * (i + 1))); break;
default: MOZ_CRASH("unhandled arg type"); default: return Nothing();
} }
} }
return ABIFunctionType(abiType); return Some(ABIFunctionType(abiType));
} }
void* void*
@ -936,9 +939,11 @@ wasm::MaybeGetBuiltinThunk(HandleFunction f, const Sig& sig, JSContext* cx)
if (!f->isNative() || !f->jitInfo() || f->jitInfo()->type() != JSJitInfo::InlinableNative) if (!f->isNative() || !f->jitInfo() || f->jitInfo()->type() != JSJitInfo::InlinableNative)
return nullptr; return nullptr;
InlinableNative native = f->jitInfo()->inlinableNative; Maybe<ABIFunctionType> abiType = ToBuiltinABIFunctionType(sig);
ABIFunctionType abiType = ToABIFunctionType(sig); if (!abiType)
TypedNative typedNative(native, abiType); return nullptr;
TypedNative typedNative(f->jitInfo()->inlinableNative, *abiType);
const BuiltinThunks& thunks = *builtinThunks; const BuiltinThunks& thunks = *builtinThunks;
auto p = thunks.typedNativeToCodeRange.readonlyThreadsafeLookup(typedNative); auto p = thunks.typedNativeToCodeRange.readonlyThreadsafeLookup(typedNative);