Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --expose-wasm | |
| 6 // Flags: --wasm-jit-prototype | |
| 7 | |
| 8 load("test/mjsunit/wasm/wasm-constants.js"); | |
| 9 load("test/mjsunit/wasm/wasm-module-builder.js"); | |
| 10 | |
| 11 var module = (function () { | |
|
titzer
2016/07/14 08:59:44
There should be additional cctests for this functi
ritesht
2016/07/14 18:10:00
Acknowledged.
| |
| 12 var builder = new WasmModuleBuilder(); | |
| 13 | |
| 14 var kSig_i_iiiii = | |
| 15 makeSig([kAstI32, kAstI32, kAstI32, kAstI32, kAstI32], [kAstI32]); | |
| 16 | |
| 17 var sig_index2 = builder.addType(kSig_i_ii); | |
| 18 var sig_index5 = builder.addType(kSig_i_iiiii); | |
| 19 | |
| 20 builder.addMemory(1, 1, true); | |
| 21 var wasm_bytes_sub = [ | |
| 22 0, | |
| 23 kExprGetLocal, 0, | |
| 24 kExprGetLocal, 1, | |
| 25 kExprI32Sub | |
| 26 ]; | |
| 27 builder.addDataSegment(0, wasm_bytes_sub, false); | |
| 28 | |
| 29 var wasm_bytes_mul = [ | |
| 30 0, | |
| 31 kExprGetLocal, 0, | |
| 32 kExprGetLocal, 1, | |
| 33 kExprI32Mul | |
| 34 ]; | |
| 35 builder.addDataSegment(6, wasm_bytes_mul, false); | |
| 36 | |
| 37 builder.addPadFunctionTable(10); | |
| 38 builder.addImport("add", sig_index2); | |
| 39 builder.addFunction("add", sig_index2) | |
| 40 .addBody([ | |
| 41 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 | |
| 42 ]); | |
| 43 builder.addFunction("main", sig_index5) | |
| 44 .addBody([ | |
| 45 kExprGetLocal, 0, | |
| 46 kExprGetLocal, 1, | |
| 47 kExprGetLocal, 2, | |
| 48 kExprJITSingleFunction, sig_index2, | |
| 49 kExprGetLocal, 2, | |
| 50 kExprGetLocal, 3, | |
| 51 kExprGetLocal, 4, | |
| 52 kExprCallIndirect, kArity2, sig_index2 | |
| 53 ]) | |
| 54 .exportFunc() | |
| 55 builder.appendToTable([0, 1]); | |
| 56 | |
| 57 return builder.instantiate({add: function(a, b) { return a + b | 0; }}); | |
| 58 })(); | |
| 59 | |
| 60 // Check that the module exists | |
| 61 assertFalse(module === undefined); | |
| 62 assertFalse(module === null); | |
| 63 assertFalse(module === 0); | |
| 64 assertEquals("object", typeof module.exports); | |
| 65 assertEquals("function", typeof module.exports.main); | |
| 66 | |
| 67 // Check that the bytes referred to lie in the bounds of the memory buffer | |
| 68 assertTraps(kTrapMemOutOfBounds, "module.exports.main(0, 100000, 3, 55, 99)"); | |
| 69 assertTraps(kTrapMemOutOfBounds, "module.exports.main(65536, 1, 3, 55, 99)"); | |
| 70 | |
| 71 // Check that the index lies in the bounds of the table size | |
| 72 assertTraps(kTrapInvalidIndex, "module.exports.main(0, 6, 10, 55, 99)"); | |
| 73 assertTraps(kTrapInvalidIndex, "module.exports.main(0, 6, -1, 55, 99)"); | |
| 74 | |
| 75 // args: base offset, size of func_bytes, index, param1, param2 | |
| 76 assertEquals(-444, module.exports.main(0, 6, 3, 555, 999)); // JIT sub function | |
| 77 assertEquals(13, module.exports.main(0, 6, 9, 45, 32)); // JIT sub function | |
| 78 assertEquals(187, module.exports.main(6, 6, 6, 17, 11)); // JIT mul function | |
| 79 assertEquals(30525, module.exports.main(6, 6, 9, 555, 55)); // JIT mul function | |
| OLD | NEW |