Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // | |
| 3 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 5 | 4 |
| 5 // Flags: --wasm-jit-prototype | |
|
Mircea Trofin
2016/07/12 02:49:13
why flip these switches?
ritesht
2016/07/13 23:58:45
This basically enables the flag to gate the experi
Mircea Trofin
2016/07/14 00:16:15
Sorry, I meant, why is wasm-jit-prototype on top n
ritesht
2016/07/14 00:18:38
Ok. Fixed.
| |
| 6 // Flags: --expose-wasm | 6 // Flags: --expose-wasm |
| 7 // Flags: --wasm-jit-prototype | |
| 8 | 7 |
| 9 load("test/mjsunit/wasm/wasm-constants.js"); | 8 load("test/mjsunit/wasm/wasm-constants.js"); |
| 10 load("test/mjsunit/wasm/wasm-module-builder.js"); | 9 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 11 | 10 |
| 12 var module = (function () { | 11 var module = (function () { |
| 13 var builder = new WasmModuleBuilder(); | 12 var builder = new WasmModuleBuilder(); |
| 14 | 13 |
| 14 var kSig_i_iiiii = makeSig([kAstI32, kAstI32, kAstI32, kAstI32, kAstI32], [kAs tI32]); | |
|
John
2016/07/13 19:56:59
this line is too long.
ritesht
2016/07/13 23:58:45
Done.
| |
| 15 var sig_index = builder.addType(kSig_i_ii); | 15 var sig_index = builder.addType(kSig_i_ii); |
| 16 builder.addPadFunctionTable(512); | 16 |
| 17 builder.addMemory(1, 1, true); | |
| 18 var wasm_bytes_sub = [ | |
| 19 1, 2, kAstI32, | |
| 20 kExprGetLocal, 0, | |
| 21 kExprGetLocal, 1, | |
| 22 kExprI32Sub | |
| 23 ]; | |
| 24 builder.addDataSegment(0, wasm_bytes_sub, false); | |
| 25 | |
| 26 var wasm_bytes_mul = [ | |
| 27 1, 2, kAstI32, | |
| 28 kExprGetLocal, 0, | |
| 29 kExprGetLocal, 1, | |
| 30 kExprI32Mul | |
| 31 ]; | |
| 32 builder.addDataSegment(8, wasm_bytes_mul, false); | |
| 33 | |
| 34 builder.addPadFunctionTable(10); | |
| 17 builder.addImport("add", sig_index); | 35 builder.addImport("add", sig_index); |
| 18 builder.addFunction("add", sig_index) | 36 builder.addFunction("add", sig_index) |
| 19 .addBody([ | 37 .addBody([ |
| 20 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 | 38 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 |
| 21 ]); | 39 ]); |
| 22 builder.addFunction("sub", sig_index) | 40 builder.addFunction("main", kSig_i_iiiii) |
| 23 .addBody([ | |
| 24 kExprGetLocal, 0, // -- | |
| 25 kExprGetLocal, 1, // -- | |
| 26 kExprI32Sub, // -- | |
| 27 ]); | |
| 28 builder.addFunction("main", kSig_i_iii) | |
| 29 .addBody([ | 41 .addBody([ |
| 30 kExprGetLocal, 0, | 42 kExprGetLocal, 0, |
| 31 kExprGetLocal, 1, | 43 kExprGetLocal, 1, |
| 32 kExprGetLocal, 2, | 44 kExprGetLocal, 2, |
| 45 kExprJITSingleFunction, sig_index, | |
| 46 kExprGetLocal, 2, | |
| 47 kExprGetLocal, 3, | |
| 48 kExprGetLocal, 4, | |
| 33 kExprCallIndirect, kArity2, sig_index | 49 kExprCallIndirect, kArity2, sig_index |
| 34 ]) | 50 ]) |
| 35 .exportFunc() | 51 .exportFunc() |
| 36 builder.appendToTable([0, 1, 2]); | 52 builder.appendToTable([0, 1]); |
| 37 | 53 |
| 38 return builder.instantiate({add: function(a, b) { return a + b | 0; }}); | 54 return builder.instantiate({add: function(a, b) { return a + b | 0; }}); |
| 39 })(); | 55 })(); |
| 40 | 56 |
| 41 // Check the module exists. | 57 // Check that the module exists |
| 42 assertFalse(module === undefined); | 58 assertFalse(module === undefined); |
| 43 assertFalse(module === null); | 59 assertFalse(module === null); |
| 44 assertFalse(module === 0); | 60 assertFalse(module === 0); |
| 45 assertEquals("object", typeof module.exports); | 61 assertEquals("object", typeof module.exports); |
| 46 assertEquals("function", typeof module.exports.main); | 62 assertEquals("function", typeof module.exports.main); |
| 47 | 63 |
| 48 assertEquals(5, module.exports.main(1, 12, 7)); | 64 // args: base offset, size of func_bytes, index, param1, param2 |
| 49 assertEquals(19, module.exports.main(0, 12, 7)); | 65 assertEquals(13, module.exports.main(0, 8, 3, 45, 32)); // JIT sub function |
| 50 | 66 assertEquals(187, module.exports.main(8, 8, 6, 17, 11)); // JIT sub function |
| 51 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); | |
| 52 assertTraps(kTrapFuncSigMismatch, "module.exports.main(4, 12, 33)"); | |
| 53 assertTraps(kTrapFuncSigMismatch, "module.exports.main(511, 12, 33)"); | |
| 54 assertTraps(kTrapFuncInvalid, "module.exports.main(512, 12, 33)"); | |
| 55 assertTraps(kTrapFuncInvalid, "module.exports.main(1025, 12, 33)"); | |
| 56 assertTraps(kTrapFuncInvalid, "module.exports.main(-1, 12, 33)"); | |
| OLD | NEW |