2016-03-07 10:01:24 +00:00
|
|
|
// Copyright 2016 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: --expose-wasm
|
|
|
|
|
|
|
|
load('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
var debug = true;
|
2016-03-07 10:12:52 +00:00
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
function instantiate(buffer, ffi) {
|
2017-11-18 23:20:09 +00:00
|
|
|
return new WebAssembly.Instance(new WebAssembly.Module(buffer), ffi);
|
2016-10-26 16:58:40 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 10:01:24 +00:00
|
|
|
(function BasicTest() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("BasicTest");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addMemory(1, 2, false);
|
|
|
|
builder.addFunction("foo", kSig_i_v)
|
2017-01-09 13:57:26 +00:00
|
|
|
.addBody([kExprI32Const, 11])
|
2016-03-07 10:01:24 +00:00
|
|
|
.exportAs("blarg");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
|
|
|
var instance = instantiate(buffer);
|
2016-03-07 10:01:24 +00:00
|
|
|
assertEquals(11, instance.exports.blarg());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function ImportTest() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("ImportTest");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2016-12-21 13:43:00 +00:00
|
|
|
var index = builder.addImport("", "print", makeSig_v_x(kWasmI32));
|
2016-10-26 16:58:40 +00:00
|
|
|
builder.addFunction("foo", kSig_v_v)
|
2017-01-09 13:57:26 +00:00
|
|
|
.addBody([kExprI32Const, 13, kExprCallFunction, index])
|
2016-03-07 10:01:24 +00:00
|
|
|
.exportAs("main");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
2016-12-20 15:32:56 +00:00
|
|
|
var instance = instantiate(buffer, {"": {print: print}});
|
2016-03-07 10:01:24 +00:00
|
|
|
print("should print 13! ");
|
|
|
|
instance.exports.main();
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function LocalsTest() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("LocalsTest");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction(undefined, kSig_i_i)
|
2016-03-07 10:01:24 +00:00
|
|
|
.addLocals({i32_count: 1})
|
2016-09-27 20:46:10 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
|
2016-03-07 10:01:24 +00:00
|
|
|
.exportAs("main");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
|
|
|
var instance = instantiate(buffer);
|
2016-03-07 10:01:24 +00:00
|
|
|
assertEquals(19, instance.exports.main(19));
|
|
|
|
assertEquals(27777, instance.exports.main(27777));
|
|
|
|
})();
|
|
|
|
|
2016-03-07 21:04:07 +00:00
|
|
|
(function LocalsTest2() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("LocalsTest2");
|
2016-03-07 21:04:07 +00:00
|
|
|
// TODO(titzer): i64 only works on 64-bit platforms.
|
|
|
|
var types = [
|
2016-12-21 13:43:00 +00:00
|
|
|
{locals: {i32_count: 1}, type: kWasmI32},
|
|
|
|
// {locals: {i64_count: 1}, type: kWasmI64},
|
|
|
|
{locals: {f32_count: 1}, type: kWasmF32},
|
|
|
|
{locals: {f64_count: 1}, type: kWasmF64},
|
2016-03-07 21:04:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
for (p of types) {
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction(undefined, makeSig_r_x(p.type, p.type))
|
2016-03-07 21:04:07 +00:00
|
|
|
.addLocals(p.locals)
|
2016-09-27 20:46:10 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
|
2016-03-07 21:04:07 +00:00
|
|
|
.exportAs("main");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
|
|
|
var instance = instantiate(buffer);
|
2016-03-07 21:04:07 +00:00
|
|
|
assertEquals(19, instance.exports.main(19));
|
|
|
|
assertEquals(27777, instance.exports.main(27777));
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2016-03-07 10:01:24 +00:00
|
|
|
(function CallTest() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("CallTest");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction("add", kSig_i_ii)
|
2016-04-29 09:15:26 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
|
2016-10-26 16:58:40 +00:00
|
|
|
builder.addFunction("main", kSig_i_ii)
|
2016-09-27 20:46:10 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
|
2016-03-07 10:01:24 +00:00
|
|
|
.exportAs("main");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var instance = builder.instantiate();
|
2016-03-07 10:01:24 +00:00
|
|
|
assertEquals(44, instance.exports.main(11, 33));
|
|
|
|
assertEquals(7777, instance.exports.main(2222, 5555));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function IndirectCallTest() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("IndirectCallTest");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction("add", kSig_i_ii)
|
2016-04-29 09:15:26 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
|
2016-10-26 16:58:40 +00:00
|
|
|
builder.addFunction("main", kSig_i_iii)
|
2016-04-29 09:15:26 +00:00
|
|
|
.addBody([kExprGetLocal,
|
2016-10-26 16:56:05 +00:00
|
|
|
1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0, kTableZero])
|
2016-03-07 10:01:24 +00:00
|
|
|
.exportAs("main");
|
2016-10-26 16:58:40 +00:00
|
|
|
builder.appendToTable([0]);
|
2016-03-07 10:01:24 +00:00
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var instance = builder.instantiate();
|
2016-03-07 10:01:24 +00:00
|
|
|
assertEquals(44, instance.exports.main(0, 11, 33));
|
|
|
|
assertEquals(7777, instance.exports.main(0, 2222, 5555));
|
|
|
|
assertThrows(function() { instance.exports.main(1, 1, 1); });
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function DataSegmentTest() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("DataSegmentTest");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addMemory(1, 1, false);
|
|
|
|
builder.addFunction("load", kSig_i_i)
|
2016-04-29 09:15:26 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
|
2016-03-07 10:01:24 +00:00
|
|
|
.exportAs("load");
|
2016-10-26 16:58:40 +00:00
|
|
|
builder.addDataSegment(0, [9, 9, 9, 9]);
|
2016-03-07 10:01:24 +00:00
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
|
|
|
var instance = instantiate(buffer);
|
2016-03-07 10:01:24 +00:00
|
|
|
assertEquals(151587081, instance.exports.load(0));
|
|
|
|
})();
|
2016-03-07 21:09:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
(function BasicTestWithUint8Array() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("BasicTestWithUint8Array");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addMemory(1, 2, false);
|
|
|
|
builder.addFunction("foo", kSig_i_v)
|
2017-01-09 13:57:26 +00:00
|
|
|
.addBody([kExprI32Const, 17])
|
2016-03-07 21:09:22 +00:00
|
|
|
.exportAs("blarg");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
2016-03-07 21:09:22 +00:00
|
|
|
var array = new Uint8Array(buffer);
|
2016-10-26 16:58:40 +00:00
|
|
|
var instance = instantiate(array);
|
2016-03-07 21:09:22 +00:00
|
|
|
assertEquals(17, instance.exports.blarg());
|
|
|
|
|
|
|
|
var kPad = 5;
|
|
|
|
var buffer2 = new ArrayBuffer(kPad + buffer.byteLength + kPad);
|
|
|
|
var whole = new Uint8Array(buffer2);
|
|
|
|
for (var i = 0; i < whole.byteLength; i++) {
|
|
|
|
whole[i] = 0xff;
|
|
|
|
}
|
|
|
|
var array2 = new Uint8Array(buffer2, kPad, buffer.byteLength);
|
|
|
|
for (var i = 0; i < array2.byteLength; i++) {
|
|
|
|
array2[i] = array[i];
|
|
|
|
}
|
2016-10-26 16:58:40 +00:00
|
|
|
var instance = instantiate(array2);
|
2016-03-07 21:09:22 +00:00
|
|
|
assertEquals(17, instance.exports.blarg());
|
|
|
|
})();
|
2016-03-08 19:55:36 +00:00
|
|
|
|
|
|
|
(function ImportTestTwoLevel() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
print("ImportTestTwoLevel");
|
2016-10-26 16:58:40 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2016-12-21 13:43:00 +00:00
|
|
|
var index = builder.addImport("mod", "print", makeSig_v_x(kWasmI32));
|
2016-10-26 16:58:40 +00:00
|
|
|
builder.addFunction("foo", kSig_v_v)
|
2017-01-09 13:57:26 +00:00
|
|
|
.addBody([kExprI32Const, 19, kExprCallFunction, index])
|
2016-03-08 19:55:36 +00:00
|
|
|
.exportAs("main");
|
|
|
|
|
2016-10-26 16:58:40 +00:00
|
|
|
var buffer = builder.toBuffer(debug);
|
|
|
|
var instance = instantiate(buffer, {mod: {print: print}});
|
2016-03-08 19:55:36 +00:00
|
|
|
print("should print 19! ");
|
|
|
|
instance.exports.main();
|
|
|
|
})();
|