OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 function testCallFFI(func, check) { | 10 function testCallFFI(func, check) { |
11 var builder = new WasmModuleBuilder(); | 11 var builder = new WasmModuleBuilder(); |
12 | 12 |
13 var sig_index = builder.addSignature([kAstI32, kAstF64, kAstF64]); | 13 var sig_index = builder.addSignature([kAstI32, kAstF64, kAstF64]); |
14 builder.addImport("func", sig_index); | 14 builder.addImport("func", sig_index); |
15 builder.addFunction("main", sig_index) | 15 builder.addFunction("main", sig_index) |
16 .addBody([ | 16 .addBody([ |
17 kExprCallImport, 0, // -- | 17 kExprGetLocal, 0, // -- |
18 kExprGetLocal, 0, // -- | 18 kExprGetLocal, 1, // -- |
19 kExprGetLocal, 1]) // -- | 19 kExprCallImport, kArity2, 0 // -- |
| 20 ]) // -- |
20 .exportFunc(); | 21 .exportFunc(); |
21 | 22 |
22 var main = builder.instantiate({func: func}).exports.main; | 23 var main = builder.instantiate({func: func}).exports.main; |
23 | 24 |
24 for (var i = 0; i < 100000; i += 10003) { | 25 for (var i = 0; i < 100000; i += 10003) { |
25 var a = 22.5 + i, b = 10.5 + i; | 26 var a = 22.5 + i, b = 10.5 + i; |
26 var r = main(a, b); | 27 var r = main(a, b); |
27 check(r, a, b); | 28 check(r, a, b); |
28 } | 29 } |
29 } | 30 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 passed_b = b; | 181 passed_b = b; |
181 args_a = arguments[0]; | 182 args_a = arguments[0]; |
182 args_b = arguments[1]; | 183 args_b = arguments[1]; |
183 }}; | 184 }}; |
184 | 185 |
185 var builder = new WasmModuleBuilder(); | 186 var builder = new WasmModuleBuilder(); |
186 | 187 |
187 builder.addImport("func", [kAstStmt, type, type]); | 188 builder.addImport("func", [kAstStmt, type, type]); |
188 builder.addFunction("main", [kAstI32, type, type]) | 189 builder.addFunction("main", [kAstI32, type, type]) |
189 .addBody([ | 190 .addBody([ |
190 kExprBlock, 2, // -- | 191 kExprGetLocal, 0, // -- |
191 kExprCallImport, 0, // -- | 192 kExprGetLocal, 1, // -- |
192 kExprGetLocal, 0, // -- | 193 kExprCallImport, kArity2, 0, // -- |
193 kExprGetLocal, 1, // -- | 194 kExprI8Const, 99 // -- |
194 kExprI8Const, 99]) // -- | 195 ]) // -- |
195 .exportFunc() | 196 .exportFunc() |
196 | 197 |
197 var main = builder.instantiate(ffi).exports.main; | 198 var main = builder.instantiate(ffi).exports.main; |
198 | 199 |
199 print("testCallBinopVoid", type); | 200 print("testCallBinopVoid", type); |
200 | 201 |
201 for (var i = 0; i < 100000; i += 10003.1) { | 202 for (var i = 0; i < 100000; i += 10003.1) { |
202 var a = 22.5 + i, b = 10.5 + i; | 203 var a = 22.5 + i, b = 10.5 + i; |
203 var r = main(a, b); | 204 var r = main(a, b); |
204 assertEquals(99, r); | 205 assertEquals(99, r); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 238 |
238 | 239 |
239 | 240 |
240 function testCallPrint() { | 241 function testCallPrint() { |
241 var builder = new WasmModuleBuilder(); | 242 var builder = new WasmModuleBuilder(); |
242 | 243 |
243 builder.addImport("print", [kAstStmt, kAstI32]); | 244 builder.addImport("print", [kAstStmt, kAstI32]); |
244 builder.addImport("print", [kAstStmt, kAstF64]); | 245 builder.addImport("print", [kAstStmt, kAstF64]); |
245 builder.addFunction("main", [kAstStmt, kAstF64]) | 246 builder.addFunction("main", [kAstStmt, kAstF64]) |
246 .addBody([ | 247 .addBody([ |
247 kExprBlock, 2, // -- | 248 kExprI8Const, 97, // -- |
248 kExprCallImport, 0, // -- | 249 kExprCallImport, kArity1, 0, // -- |
249 kExprI8Const, 97, // -- | 250 kExprGetLocal, 0, // -- |
250 kExprCallImport, 1, // -- | 251 kExprCallImport, kArity1, 1 // -- |
251 kExprGetLocal, 0]) // -- | 252 ]) // -- |
252 .exportFunc() | 253 .exportFunc() |
253 | 254 |
254 var main = builder.instantiate({print: print}).exports.main; | 255 var main = builder.instantiate({print: print}).exports.main; |
255 for (var i = -9; i < 900; i += 6.125) main(i); | 256 for (var i = -9; i < 900; i += 6.125) main(i); |
256 } | 257 } |
257 | 258 |
258 testCallPrint(); | 259 testCallPrint(); |
259 testCallPrint(); | 260 testCallPrint(); |
OLD | NEW |