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 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_CALL(6, jsfunc, 0x3F, 0); | 145 EXPECT_CALL(6, jsfunc, 0x3F, 0); |
146 } | 146 } |
147 | 147 |
148 TEST(Run_CallJS_Add_jswrapped) { | 148 TEST(Run_CallJS_Add_jswrapped) { |
149 CcTest::InitializeVM(); | 149 CcTest::InitializeVM(); |
150 TestSignatures sigs; | 150 TestSignatures sigs; |
151 TestingModule module; | 151 TestingModule module; |
152 WasmFunctionCompiler t(sigs.i_i(), &module); | 152 WasmFunctionCompiler t(sigs.i_i(), &module); |
153 uint32_t js_index = | 153 uint32_t js_index = |
154 module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })"); | 154 module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })"); |
155 BUILD(t, WASM_CALL_FUNCTION1(js_index, WASM_GET_LOCAL(0))); | 155 BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); |
156 | 156 |
157 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd()); | 157 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd()); |
158 | 158 |
159 EXPECT_CALL(101, jsfunc, 2, -8); | 159 EXPECT_CALL(101, jsfunc, 2, -8); |
160 EXPECT_CALL(199, jsfunc, 100, -1); | 160 EXPECT_CALL(199, jsfunc, 100, -1); |
161 EXPECT_CALL(-666666801, jsfunc, -666666900, -1); | 161 EXPECT_CALL(-666666801, jsfunc, -666666900, -1); |
162 } | 162 } |
163 | 163 |
164 void RunJSSelectTest(int which) { | 164 void RunJSSelectTest(int which) { |
165 const int kMaxParams = 8; | 165 const int kMaxParams = 8; |
166 PredictableInputValues inputs(0x100); | 166 PredictableInputValues inputs(0x100); |
167 LocalType type = kAstF64; | 167 LocalType type = kAstF64; |
168 LocalType types[kMaxParams + 1] = {type, type, type, type, type, | 168 LocalType types[kMaxParams + 1] = {type, type, type, type, type, |
169 type, type, type, type}; | 169 type, type, type, type}; |
170 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { | 170 for (int num_params = which + 1; num_params < kMaxParams; num_params++) { |
171 HandleScope scope(CcTest::InitIsolateOnce()); | 171 HandleScope scope(CcTest::InitIsolateOnce()); |
172 FunctionSig sig(1, num_params, types); | 172 FunctionSig sig(1, num_params, types); |
173 | 173 |
174 TestingModule module; | 174 TestingModule module; |
175 uint32_t js_index = AddJSSelector(&module, &sig, which); | 175 uint32_t js_index = AddJSSelector(&module, &sig, which); |
176 WasmFunctionCompiler t(&sig, &module); | 176 WasmFunctionCompiler t(&sig, &module); |
177 | 177 |
178 { | 178 { |
179 std::vector<byte> code; | 179 std::vector<byte> code; |
180 | 180 |
181 for (int i = 0; i < num_params; i++) { | 181 for (int i = 0; i < num_params; i++) { |
182 ADD_CODE(code, WASM_F64(inputs.arg_d(i))); | 182 ADD_CODE(code, WASM_F64(inputs.arg_d(i))); |
183 } | 183 } |
184 | 184 |
185 ADD_CODE(code, kExprCallFunction, static_cast<byte>(num_params), | 185 ADD_CODE(code, kExprCallFunction, static_cast<byte>(js_index)); |
186 static_cast<byte>(js_index)); | |
187 | 186 |
188 size_t end = code.size(); | 187 size_t end = code.size(); |
189 code.push_back(0); | 188 code.push_back(0); |
190 t.Build(&code[0], &code[end]); | 189 t.Build(&code[0], &code[end]); |
191 } | 190 } |
192 | 191 |
193 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd()); | 192 Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd()); |
194 double expected = inputs.arg_d(which); | 193 double expected = inputs.arg_d(which); |
195 EXPECT_CALL(expected, jsfunc, 0.0, 0.0); | 194 EXPECT_CALL(expected, jsfunc, 0.0, 0.0); |
196 } | 195 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 type, type, type, type, type}; | 412 type, type, type, type, type}; |
414 FunctionSig sig(1, num_params, types); | 413 FunctionSig sig(1, num_params, types); |
415 | 414 |
416 // Build the calling code. | 415 // Build the calling code. |
417 std::vector<byte> code; | 416 std::vector<byte> code; |
418 | 417 |
419 for (int i = 0; i < num_params; i++) { | 418 for (int i = 0; i < num_params; i++) { |
420 ADD_CODE(code, WASM_GET_LOCAL(i)); | 419 ADD_CODE(code, WASM_GET_LOCAL(i)); |
421 } | 420 } |
422 | 421 |
423 ADD_CODE(code, kExprCallFunction, static_cast<byte>(num_params), 0); | 422 ADD_CODE(code, kExprCallFunction, 0); |
424 | 423 |
425 size_t end = code.size(); | 424 size_t end = code.size(); |
426 code.push_back(0); | 425 code.push_back(0); |
427 | 426 |
428 // Call different select JS functions. | 427 // Call different select JS functions. |
429 for (int which = 0; which < num_params; which++) { | 428 for (int which = 0; which < num_params; which++) { |
430 HandleScope scope(isolate); | 429 HandleScope scope(isolate); |
431 TestingModule module; | 430 TestingModule module; |
432 uint32_t js_index = AddJSSelector(&module, &sig, which); | 431 uint32_t js_index = AddJSSelector(&module, &sig, which); |
433 CHECK_EQ(0, js_index); | 432 CHECK_EQ(0, js_index); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 RunJSSelectAlignTest(9, 9); | 508 RunJSSelectAlignTest(9, 9); |
510 } | 509 } |
511 | 510 |
512 TEST(Run_JSSelectAlign_10) { | 511 TEST(Run_JSSelectAlign_10) { |
513 CcTest::InitializeVM(); | 512 CcTest::InitializeVM(); |
514 RunJSSelectAlignTest(10, 7); | 513 RunJSSelectAlignTest(10, 7); |
515 RunJSSelectAlignTest(10, 8); | 514 RunJSSelectAlignTest(10, 8); |
516 RunJSSelectAlignTest(10, 9); | 515 RunJSSelectAlignTest(10, 9); |
517 RunJSSelectAlignTest(10, 10); | 516 RunJSSelectAlignTest(10, 10); |
518 } | 517 } |
OLD | NEW |