v8/test/mjsunit/wasm/compilation-hints-interpreter.js
Clemens Backes 421fd3929d [wasm] Rename {Get,Set,Tee}Local to Local{Get,Set,Tee}
This brings our constants back in line with the changed spec text. We
already use kExprTableGet and kExprTableSet, but for locals and globals
we still use the old wording.

This renaming is mostly mechanical.

PS1 was created using:
ag -l 'kExpr(Get|Set|Tee)Local' src test | \
  xargs -L1 sed -E 's/kExpr(Get|Set|Tee)Local\b/kExprLocal\1/g' -i

PS2 contains manual fixes.

R=mstarzinger@chromium.org

Bug: v8:9810
Change-Id: I1617f1b2a100685a3bf56218e76845a9481959c5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1847354
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64161}
2019-10-08 14:14:40 +00:00

114 lines
5.0 KiB
JavaScript

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
// Flags: --experimental-wasm-compilation-hints --wasm-lazy-validation
load('test/mjsunit/wasm/wasm-module-builder.js');
(function testInterpreterCallsLazyFunctionInOtherInstance() {
print(arguments.callee.name);
let builder0 = new WasmModuleBuilder();
builder0.addFunction("getX", kSig_i_v)
.addBody([kExprI32Const, 42])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierBaseline,
kCompilationHintTierBaseline)
.exportFunc();
let builder1 = new WasmModuleBuilder();
builder1.addImport("otherModule", "getX", kSig_i_v);
builder1.addFunction("plusX", kSig_i_i)
.addBody([kExprCallFunction, 0,
kExprLocalGet, 0,
kExprI32Add])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierInterpreter,
kCompilationHintTierInterpreter)
.exportFunc();
let instance0 = builder0.instantiate();
let instance1 = builder1.instantiate(
{otherModule: {getX: instance0.exports.getX}});
assertEquals(46, instance1.exports.plusX(4));
})();
(function testInterpreterCallsLazyBadFunctionInOtherInstance() {
print(arguments.callee.name);
let builder0 = new WasmModuleBuilder();
builder0.addFunction("getX", kSig_i_v)
.addBody([kExprI64Const, 42])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierBaseline,
kCompilationHintTierBaseline)
.exportFunc();
let builder1 = new WasmModuleBuilder();
builder1.addImport("otherModule", "getX", kSig_i_v);
builder1.addFunction("plusX", kSig_i_i)
.addBody([kExprCallFunction, 0,
kExprLocalGet, 0,
kExprI32Add])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierInterpreter,
kCompilationHintTierInterpreter)
.exportFunc();
let instance0 = builder0.instantiate();
let instance1 = builder1.instantiate(
{otherModule: {getX: instance0.exports.getX}});
assertThrows(() => instance1.exports.plusX(4),
WebAssembly.CompileError,
"Compiling function #0:\"getX\" failed: type error in " +
"merge[0] (expected i32, got i64) @+57");
})();
(function testInterpreterCallsLazyFunctionThroughIndirection() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig_i_ii = builder.addType(kSig_i_ii);
let add = builder.addFunction('add', sig_i_ii)
.addBody([kExprLocalGet, 0,
kExprLocalGet, 1,
kExprI32Add])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierInterpreter,
kCompilationHintTierInterpreter);
builder.appendToTable([add.index]);
builder.addFunction('main', kSig_i_iii)
.addBody([// Call indirect #0 with args <#1, #2>.
kExprLocalGet, 1,
kExprLocalGet, 2,
kExprLocalGet, 0,
kExprCallIndirect, sig_i_ii, kTableZero])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierInterpreter,
kCompilationHintTierInterpreter)
.exportFunc();
assertEquals(99, builder.instantiate().exports.main(0, 22, 77));
})();
(function testInterpreterCallsLazyBadFunctionThroughIndirection() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig_i_ii = builder.addType(kSig_i_ii);
let add = builder.addFunction('add', sig_i_ii)
.addBody([kExprLocalGet, 0,
kExprLocalGet, 1,
kExprI64Add])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierInterpreter,
kCompilationHintTierInterpreter);
builder.appendToTable([add.index]);
builder.addFunction('main', kSig_i_iii)
.addBody([// Call indirect #0 with args <#1, #2>.
kExprLocalGet, 1,
kExprLocalGet, 2,
kExprLocalGet, 0,
kExprCallIndirect, sig_i_ii, kTableZero])
.setCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierInterpreter,
kCompilationHintTierInterpreter)
.exportFunc();
assertThrows(() => builder.instantiate().exports.main(0, 22, 77),
WebAssembly.CompileError,
"Compiling function #0:\"add\" failed: i64.add[1] expected " +
"type i64, found local.get of type i32 @+83");
})();