Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: test/unittests/wasm/asm-types-unittest.cc

Issue 2148073002: V8. ASM-2-WASM. Fixes technical debt in asm-types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/asmjs/asm-types.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 "src/asmjs/asm-types.h" 5 #include "src/asmjs/asm-types.h"
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "src/base/macros.h" 10 #include "src/base/macros.h"
(...skipping 15 matching lines...) Expand all
26 AsmTypeTest() 26 AsmTypeTest()
27 : parents_({ 27 : parents_({
28 {Type::Uint8Array(), {Type::Heap()}}, 28 {Type::Uint8Array(), {Type::Heap()}},
29 {Type::Int8Array(), {Type::Heap()}}, 29 {Type::Int8Array(), {Type::Heap()}},
30 {Type::Uint16Array(), {Type::Heap()}}, 30 {Type::Uint16Array(), {Type::Heap()}},
31 {Type::Int16Array(), {Type::Heap()}}, 31 {Type::Int16Array(), {Type::Heap()}},
32 {Type::Uint32Array(), {Type::Heap()}}, 32 {Type::Uint32Array(), {Type::Heap()}},
33 {Type::Int32Array(), {Type::Heap()}}, 33 {Type::Int32Array(), {Type::Heap()}},
34 {Type::Float32Array(), {Type::Heap()}}, 34 {Type::Float32Array(), {Type::Heap()}},
35 {Type::Float64Array(), {Type::Heap()}}, 35 {Type::Float64Array(), {Type::Heap()}},
36 {Type::FloatishDoubleQ(), {Type::Floatish(), Type::DoubleQ()}}, 36 {Type::Float(),
37 {Type::FloatQDoubleQ(), 37 {Type::FloatishDoubleQ(), Type::FloatQDoubleQ(), Type::FloatQ(),
38 {Type::FloatQ(), Type::Floatish(), Type::DoubleQ()}}, 38 Type::Floatish()}},
39 {Type::Float(), {Type::FloatQ(), Type::Floatish()}}, 39 {Type::Floatish(), {Type::FloatishDoubleQ()}},
40 {Type::FloatQ(), {Type::Floatish()}}, 40 {Type::FloatQ(),
41 {Type::FloatishDoubleQ(), Type::FloatQDoubleQ(),
42 Type::Floatish()}},
41 {Type::FixNum(), 43 {Type::FixNum(),
42 {Type::Signed(), Type::Extern(), Type::Unsigned(), Type::Int(), 44 {Type::Signed(), Type::Extern(), Type::Unsigned(), Type::Int(),
43 Type::Intish()}}, 45 Type::Intish()}},
44 {Type::Unsigned(), {Type::Int(), Type::Intish()}}, 46 {Type::Unsigned(), {Type::Int(), Type::Intish()}},
45 {Type::Signed(), {Type::Extern(), Type::Int(), Type::Intish()}}, 47 {Type::Signed(), {Type::Extern(), Type::Int(), Type::Intish()}},
46 {Type::Int(), {Type::Intish()}}, 48 {Type::Int(), {Type::Intish()}},
47 {Type::Double(), {Type::DoubleQ(), Type::Extern()}}, 49 {Type::DoubleQ(), {Type::FloatishDoubleQ(), Type::FloatQDoubleQ()}},
50 {Type::Double(),
51 {Type::FloatishDoubleQ(), Type::FloatQDoubleQ(), Type::DoubleQ(),
52 Type::Extern()}},
48 }) {} 53 }) {}
49 54
50 protected: 55 protected:
51 std::unordered_set<Type*> ParentsOf(Type* derived) const { 56 std::unordered_set<Type*> ParentsOf(Type* derived) const {
52 const auto parents_iter = parents_.find(derived); 57 const auto parents_iter = parents_.find(derived);
53 if (parents_iter == parents_.end()) { 58 if (parents_iter == parents_.end()) {
54 return std::unordered_set<Type*>(); 59 return std::unordered_set<Type*>();
55 } 60 }
56 return parents_iter->second; 61 return parents_iter->second;
57 } 62 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 StrEq("(int, int...) -> signed")); 230 StrEq("(int, int...) -> signed"));
226 EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(), 231 EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(),
227 StrEq("(floatish, floatish...) -> float")); 232 StrEq("(floatish, floatish...) -> float"));
228 EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::DoubleQ())->Name(), 233 EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::DoubleQ())->Name(),
229 StrEq("(double?, double?...) -> double")); 234 StrEq("(double?, double?...) -> double"));
230 235
231 EXPECT_THAT(Type::FFIType(zone())->Name(), StrEq("Function")); 236 EXPECT_THAT(Type::FFIType(zone())->Name(), StrEq("Function"));
232 237
233 auto* ft = 238 auto* ft =
234 Type::FunctionTableType(zone(), 15, Function(Type::Double)(Type::Int)); 239 Type::FunctionTableType(zone(), 15, Function(Type::Double)(Type::Int));
235 EXPECT_THAT(ft->Name(), StrEq("(int) -> double[15]")); 240 EXPECT_THAT(ft->Name(), StrEq("((int) -> double)[15]"));
236 } 241 }
237 242
238 TEST_F(AsmTypeTest, IsExactly) { 243 TEST_F(AsmTypeTest, IsExactly) {
239 Type* test_types[] = { 244 Type* test_types[] = {
240 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 245 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
241 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 246 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
242 #undef CREATE 247 #undef CREATE
243 Function(Type::Int)(Type::Double), 248 Function(Type::Int)(Type::Double),
244 Function(Type::Int)(Type::DoubleQ), 249 Function(Type::Int)(Type::DoubleQ),
245 Overload(Function(Type::Int)(Type::Double)), 250 Overload(Function(Type::Int)(Type::Double)),
246 Function(Type::Int)(Type::Int, Type::Int), 251 Function(Type::Int)(Type::Int, Type::Int),
247 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), 252 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
248 Function(Type::Int)(Type::Float), Type::FroundType(zone()), 253 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
249 Type::FFIType(zone()), 254 Type::FFIType(zone()),
250 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), 255 Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
251 }; 256 };
252 257
253 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 258 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
254 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { 259 for (size_t jj = 0; jj < arraysize(test_types); ++jj) {
255 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj])) 260 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj]))
256 << test_types[ii]->Name() 261 << test_types[ii]->Name()
257 << ((ii == jj) ? " is not exactly " : " is exactly ") 262 << ((ii == jj) ? " is not exactly " : " is exactly ")
258 << test_types[jj]->Name(); 263 << test_types[jj]->Name();
259 } 264 }
260 } 265 }
261 } 266 }
262 267
268 bool FunctionsWithSameSignature(AsmType* a, AsmType* b) {
269 if (auto* func_a = a->AsFunctionType()) {
John 2016/07/13 22:54:36 Brad, I'm OOO right now, so can you please send a
270 if (auto* func_b = b->AsFunctionType()) {
271 return a->IsA(b);
272 }
273 }
274 return false;
275 }
276
263 TEST_F(AsmTypeTest, IsA) { 277 TEST_F(AsmTypeTest, IsA) {
264 Type* test_types[] = { 278 Type* test_types[] = {
265 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 279 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
266 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 280 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
267 #undef CREATE 281 #undef CREATE
268 Function(Type::Int)(Type::Double), 282 Function(Type::Int)(Type::Double),
283 Function(Type::Int)(Type::Int, Type::Int),
269 Function(Type::Int)(Type::DoubleQ), 284 Function(Type::Int)(Type::DoubleQ),
270 Overload(Function(Type::Int)(Type::Double)), 285 Overload(Function(Type::Int)(Type::Double)),
271 Function(Type::Int)(Type::Int, Type::Int), 286 Function(Type::Int)(Type::Int, Type::Int),
272 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), 287 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
273 Function(Type::Int)(Type::Float), Type::FroundType(zone()), 288 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
274 Type::FFIType(zone()), 289 Type::FFIType(zone()),
275 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), 290 Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
276 }; 291 };
277 292
278 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 293 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
279 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { 294 for (size_t jj = 0; jj < arraysize(test_types); ++jj) {
280 const bool Expected = 295 const bool Expected =
281 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0; 296 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0 ||
297 FunctionsWithSameSignature(test_types[ii], test_types[jj]);
282 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj])) 298 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj]))
283 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ") 299 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ")
284 << test_types[jj]->Name(); 300 << test_types[jj]->Name();
285 } 301 }
286 } 302 }
303
304 EXPECT_TRUE(Function(Type::Int)(Type::Int, Type::Int)
305 ->IsA(Function(Type::Int)(Type::Int, Type::Int)));
306
307 EXPECT_FALSE(Function(Type::Int)(Type::Int, Type::Int)
308 ->IsA(Function(Type::Double)(Type::Int, Type::Int)));
309 EXPECT_FALSE(Function(Type::Int)(Type::Int, Type::Int)
310 ->IsA(Function(Type::Int)(Type::Double, Type::Int)));
287 } 311 }
288 312
289 TEST_F(AsmTypeTest, ValidateCall) { 313 TEST_F(AsmTypeTest, CanBeInvokedWith) {
290 auto* min_max_int = Type::MinMaxType(zone(), Type::Signed(), Type::Int()); 314 auto* min_max_int = Type::MinMaxType(zone(), Type::Signed(), Type::Int());
291 auto* i2s = Function(Type::Signed)(Type::Int); 315 auto* i2s = Function(Type::Signed)(Type::Int);
292 auto* ii2s = Function(Type::Signed)(Type::Int, Type::Int); 316 auto* ii2s = Function(Type::Signed)(Type::Int, Type::Int);
293 auto* iii2s = Function(Type::Signed)(Type::Int, Type::Int, Type::Int); 317 auto* iii2s = Function(Type::Signed)(Type::Int, Type::Int, Type::Int);
294 auto* iiii2s = 318 auto* iiii2s =
295 Function(Type::Signed)(Type::Int, Type::Int, Type::Int, Type::Int); 319 Function(Type::Signed)(Type::Int, Type::Int, Type::Int, Type::Int);
296 320
297 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( 321 EXPECT_TRUE(min_max_int->AsCallableType()->CanBeInvokedWith(
298 min_max_int->AsFunctionType()->ReturnType(), 322 ii2s->AsFunctionType()->ReturnType(),
299 min_max_int->AsFunctionType()->Arguments())); 323 ii2s->AsFunctionType()->Arguments()));
300 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( 324 EXPECT_TRUE(min_max_int->AsCallableType()->CanBeInvokedWith(
301 ii2s->AsFunctionType()->ReturnType(), 325 iii2s->AsFunctionType()->ReturnType(),
302 ii2s->AsFunctionType()->Arguments())); 326 iii2s->AsFunctionType()->Arguments()));
303 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( 327 EXPECT_TRUE(min_max_int->AsCallableType()->CanBeInvokedWith(
304 iii2s->AsFunctionType()->ReturnType(), 328 iiii2s->AsFunctionType()->ReturnType(),
305 iii2s->AsFunctionType()->Arguments())); 329 iiii2s->AsFunctionType()->Arguments()));
306 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( 330 EXPECT_FALSE(min_max_int->AsCallableType()->CanBeInvokedWith(
307 iiii2s->AsFunctionType()->ReturnType(), 331 i2s->AsFunctionType()->ReturnType(), i2s->AsFunctionType()->Arguments()));
308 iiii2s->AsFunctionType()->Arguments()));
309 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall(
310 i2s->AsFunctionType()->ReturnType(),
311 i2s->AsFunctionType()->Arguments()));
312 332
313 auto* min_max_double = 333 auto* min_max_double =
314 Type::MinMaxType(zone(), Type::Double(), Type::Double()); 334 Type::MinMaxType(zone(), Type::Double(), Type::Double());
315 auto* d2d = Function(Type::Double)(Type::Double); 335 auto* d2d = Function(Type::Double)(Type::Double);
316 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double); 336 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double);
317 auto* ddd2d = 337 auto* ddd2d =
318 Function(Type::Double)(Type::Double, Type::Double, Type::Double); 338 Function(Type::Double)(Type::Double, Type::Double, Type::Double);
319 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double, 339 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double,
320 Type::Double, Type::Double); 340 Type::Double, Type::Double);
321 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( 341 EXPECT_TRUE(min_max_double->AsCallableType()->CanBeInvokedWith(
322 min_max_double->AsFunctionType()->ReturnType(), 342 dd2d->AsFunctionType()->ReturnType(),
323 min_max_double->AsFunctionType()->Arguments())); 343 dd2d->AsFunctionType()->Arguments()));
324 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( 344 EXPECT_TRUE(min_max_double->AsCallableType()->CanBeInvokedWith(
325 dd2d->AsFunctionType()->ReturnType(), 345 ddd2d->AsFunctionType()->ReturnType(),
326 dd2d->AsFunctionType()->Arguments())); 346 ddd2d->AsFunctionType()->Arguments()));
327 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( 347 EXPECT_TRUE(min_max_double->AsCallableType()->CanBeInvokedWith(
328 ddd2d->AsFunctionType()->ReturnType(), 348 dddd2d->AsFunctionType()->ReturnType(),
329 ddd2d->AsFunctionType()->Arguments())); 349 dddd2d->AsFunctionType()->Arguments()));
330 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( 350 EXPECT_FALSE(min_max_double->AsCallableType()->CanBeInvokedWith(
331 dddd2d->AsFunctionType()->ReturnType(), 351 d2d->AsFunctionType()->ReturnType(), d2d->AsFunctionType()->Arguments()));
332 dddd2d->AsFunctionType()->Arguments()));
333 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall(
334 d2d->AsFunctionType()->ReturnType(),
335 d2d->AsFunctionType()->Arguments()));
336 352
337 auto* min_max = Overload(min_max_int, min_max_double); 353 auto* min_max = Overload(min_max_int, min_max_double);
338 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall( 354 EXPECT_FALSE(min_max->AsCallableType()->CanBeInvokedWith(
339 i2s->AsFunctionType()->ReturnType(), 355 i2s->AsFunctionType()->ReturnType(), i2s->AsFunctionType()->Arguments()));
340 i2s->AsFunctionType()->Arguments())); 356 EXPECT_FALSE(min_max->AsCallableType()->CanBeInvokedWith(
341 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall( 357 d2d->AsFunctionType()->ReturnType(), d2d->AsFunctionType()->Arguments()));
342 d2d->AsFunctionType()->ReturnType(), 358 EXPECT_TRUE(min_max->AsCallableType()->CanBeInvokedWith(
343 d2d->AsFunctionType()->Arguments())); 359 ii2s->AsFunctionType()->ReturnType(),
344 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( 360 ii2s->AsFunctionType()->Arguments()));
345 min_max_int->AsFunctionType()->ReturnType(), 361 EXPECT_TRUE(min_max->AsCallableType()->CanBeInvokedWith(
346 min_max_int->AsFunctionType()->Arguments())); 362 iii2s->AsFunctionType()->ReturnType(),
347 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( 363 iii2s->AsFunctionType()->Arguments()));
348 ii2s->AsFunctionType()->ReturnType(), 364 EXPECT_TRUE(min_max->AsCallableType()->CanBeInvokedWith(
349 ii2s->AsFunctionType()->Arguments())); 365 iiii2s->AsFunctionType()->ReturnType(),
350 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( 366 iiii2s->AsFunctionType()->Arguments()));
351 iii2s->AsFunctionType()->ReturnType(), 367 EXPECT_TRUE(min_max->AsCallableType()->CanBeInvokedWith(
352 iii2s->AsFunctionType()->Arguments())); 368 dd2d->AsFunctionType()->ReturnType(),
353 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( 369 dd2d->AsFunctionType()->Arguments()));
354 iiii2s->AsFunctionType()->ReturnType(), 370 EXPECT_TRUE(min_max->AsCallableType()->CanBeInvokedWith(
355 iiii2s->AsFunctionType()->Arguments())); 371 ddd2d->AsFunctionType()->ReturnType(),
356 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall( 372 ddd2d->AsFunctionType()->Arguments()));
357 min_max_double->AsFunctionType()->ReturnType(), 373 EXPECT_TRUE(min_max->AsCallableType()->CanBeInvokedWith(
358 min_max_double->AsFunctionType()->Arguments())); 374 dddd2d->AsFunctionType()->ReturnType(),
359 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall( 375 dddd2d->AsFunctionType()->Arguments()));
360 dd2d->AsFunctionType()->ReturnType(),
361 dd2d->AsFunctionType()->Arguments()));
362 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(
363 ddd2d->AsFunctionType()->ReturnType(),
364 ddd2d->AsFunctionType()->Arguments()));
365 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(
366 dddd2d->AsFunctionType()->ReturnType(),
367 dddd2d->AsFunctionType()->Arguments()));
368 376
369 auto* fround = Type::FroundType(zone()); 377 auto* fround = Type::FroundType(zone());
370 378
371 ZoneVector<AsmType*> arg(zone()); 379 ZoneVector<AsmType*> arg(zone());
372 arg.push_back(Type::Floatish()); 380 arg.push_back(Type::Floatish());
373 EXPECT_EQ(Type::Float(), 381 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
374 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
375 arg.clear(); 382 arg.clear();
376 arg.push_back(Type::FloatQ()); 383 arg.push_back(Type::FloatQ());
377 EXPECT_EQ(Type::Float(), 384 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
378 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
379 arg.clear(); 385 arg.clear();
380 arg.push_back(Type::Float()); 386 arg.push_back(Type::Float());
381 EXPECT_EQ(Type::Float(), 387 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
382 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
383 arg.clear(); 388 arg.clear();
384 arg.push_back(Type::DoubleQ()); 389 arg.push_back(Type::DoubleQ());
385 EXPECT_EQ(Type::Float(), 390 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
386 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
387 arg.clear(); 391 arg.clear();
388 arg.push_back(Type::Double()); 392 arg.push_back(Type::Double());
389 EXPECT_EQ(Type::Float(), 393 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
390 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
391 arg.clear(); 394 arg.clear();
392 arg.push_back(Type::Signed()); 395 arg.push_back(Type::Signed());
393 EXPECT_EQ(Type::Float(), 396 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
394 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
395 arg.clear(); 397 arg.clear();
396 arg.push_back(Type::Unsigned()); 398 arg.push_back(Type::Unsigned());
397 EXPECT_EQ(Type::Float(), 399 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
398 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
399 arg.clear(); 400 arg.clear();
400 arg.push_back(Type::FixNum()); 401 arg.push_back(Type::FixNum());
401 EXPECT_EQ(Type::Float(), 402 EXPECT_TRUE(fround->AsCallableType()->CanBeInvokedWith(Type::Float(), arg));
402 fround->AsCallableType()->ValidateCall(Type::Float(), arg));
403 403
404 auto* idf2v = Function(Type::Void)(Type::Int, Type::Double, Type::Float); 404 auto* idf2v = Function(Type::Void)(Type::Int, Type::Double, Type::Float);
405 auto* i2d = Function(Type::Double)(Type::Int); 405 auto* i2d = Function(Type::Double)(Type::Int);
406 auto* i2f = Function(Type::Float)(Type::Int); 406 auto* i2f = Function(Type::Float)(Type::Int);
407 auto* fi2d = Function(Type::Double)(Type::Float, Type::Int); 407 auto* fi2d = Function(Type::Double)(Type::Float, Type::Int);
408 auto* idif2i = 408 auto* idif2i =
409 Function(Type::Int)(Type::Int, Type::Double, Type::Int, Type::Float); 409 Function(Type::Int)(Type::Int, Type::Double, Type::Int, Type::Float);
410 auto* overload = Overload(idf2v, i2f, /*i2d missing, */ fi2d, idif2i); 410 auto* overload = Overload(idf2v, i2f, /*i2d missing, */ fi2d, idif2i);
411 EXPECT_EQ(Type::Void(), overload->AsCallableType()->ValidateCall( 411 EXPECT_TRUE(overload->AsCallableType()->CanBeInvokedWith(
412 idf2v->AsFunctionType()->ReturnType(), 412 idf2v->AsFunctionType()->ReturnType(),
413 idf2v->AsFunctionType()->Arguments())); 413 idf2v->AsFunctionType()->Arguments()));
414 EXPECT_EQ(Type::Float(), overload->AsCallableType()->ValidateCall( 414 EXPECT_TRUE(overload->AsCallableType()->CanBeInvokedWith(
415 i2f->AsFunctionType()->ReturnType(), 415 i2f->AsFunctionType()->ReturnType(), i2f->AsFunctionType()->Arguments()));
416 i2f->AsFunctionType()->Arguments())); 416 EXPECT_TRUE(overload->AsCallableType()->CanBeInvokedWith(
417 EXPECT_EQ(Type::Double(), overload->AsCallableType()->ValidateCall( 417 fi2d->AsFunctionType()->ReturnType(),
418 fi2d->AsFunctionType()->ReturnType(), 418 fi2d->AsFunctionType()->Arguments()));
419 fi2d->AsFunctionType()->Arguments())); 419 EXPECT_TRUE(overload->AsCallableType()->CanBeInvokedWith(
420 EXPECT_EQ(Type::Int(), overload->AsCallableType()->ValidateCall( 420 idif2i->AsFunctionType()->ReturnType(),
421 idif2i->AsFunctionType()->ReturnType(), 421 idif2i->AsFunctionType()->Arguments()));
422 idif2i->AsFunctionType()->Arguments())); 422 EXPECT_FALSE(overload->AsCallableType()->CanBeInvokedWith(
423 EXPECT_EQ(Type::None(), overload->AsCallableType()->ValidateCall( 423 i2d->AsFunctionType()->ReturnType(), i2d->AsFunctionType()->Arguments()));
424 i2d->AsFunctionType()->ReturnType(), 424 EXPECT_FALSE(i2f->AsCallableType()->CanBeInvokedWith(
425 i2d->AsFunctionType()->Arguments())); 425 i2d->AsFunctionType()->ReturnType(), i2d->AsFunctionType()->Arguments()));
426 EXPECT_EQ(Type::None(), i2f->AsCallableType()->ValidateCall(
427 i2d->AsFunctionType()->ReturnType(),
428 i2d->AsFunctionType()->Arguments()));
429 426
430 auto* ffi = Type::FFIType(zone()); 427 auto* ffi = Type::FFIType(zone());
431 AsmType* (*kReturnTypes[])() = { 428 AsmType* (*kReturnTypes[])() = {
432 Type::Void, Type::Double, Type::Signed, 429 Type::Void, Type::Double, Type::Signed,
433 }; 430 };
434 AsmType* (*kParameterTypes[])() = { 431 AsmType* (*kParameterTypes[])() = {
435 Type::Double, Type::Signed, Type::FixNum, 432 Type::Double, Type::Signed, Type::FixNum,
436 }; 433 };
437 for (size_t ii = 0; ii < arraysize(kReturnTypes); ++ii) { 434 for (size_t ii = 0; ii < arraysize(kReturnTypes); ++ii) {
438 for (size_t jj = 0; jj < arraysize(kParameterTypes); ++jj) { 435 for (size_t jj = 0; jj < arraysize(kParameterTypes); ++jj) {
439 auto* f = Function(kReturnTypes[ii])(kParameterTypes[jj]); 436 auto* f = Function(kReturnTypes[ii])(kParameterTypes[jj]);
440 EXPECT_EQ(kReturnTypes[ii](), ffi->AsCallableType()->ValidateCall( 437 EXPECT_TRUE(ffi->AsCallableType()->CanBeInvokedWith(
441 f->AsFunctionType()->ReturnType(), 438 f->AsFunctionType()->ReturnType(), f->AsFunctionType()->Arguments()))
442 f->AsFunctionType()->Arguments()))
443 << kReturnTypes[ii]()->Name(); 439 << kReturnTypes[ii]()->Name();
444 440
445 // Call with non-parameter type type should fail. 441 // Call with non-parameter type type should fail.
446 f = Function(kReturnTypes[ii])(kParameterTypes[jj], Type::Int); 442 f = Function(kReturnTypes[ii])(kParameterTypes[jj], Type::Int);
447 EXPECT_EQ(Type::None(), ffi->AsCallableType()->ValidateCall( 443 EXPECT_FALSE(ffi->AsCallableType()->CanBeInvokedWith(
448 f->AsFunctionType()->ReturnType(), 444 f->AsFunctionType()->ReturnType(), f->AsFunctionType()->Arguments()))
449 f->AsFunctionType()->Arguments()))
450 << kReturnTypes[ii]()->Name(); 445 << kReturnTypes[ii]()->Name();
451 } 446 }
452 } 447 }
453 448
454 auto* ft0 = Type::FunctionTableType(zone(), 10, fi2d); 449 auto* ft0 = Type::FunctionTableType(zone(), 10, fi2d);
455 EXPECT_EQ(Type::Double(), ft0->AsCallableType()->ValidateCall( 450 EXPECT_TRUE(ft0->AsCallableType()->CanBeInvokedWith(
456 fi2d->AsFunctionType()->ReturnType(), 451 fi2d->AsFunctionType()->ReturnType(),
457 fi2d->AsFunctionType()->Arguments())); 452 fi2d->AsFunctionType()->Arguments()));
458 EXPECT_EQ(Type::None(), ft0->AsCallableType()->ValidateCall( 453 EXPECT_FALSE(ft0->AsCallableType()->CanBeInvokedWith(
459 i2d->AsFunctionType()->ReturnType(), 454 i2d->AsFunctionType()->ReturnType(), i2d->AsFunctionType()->Arguments()));
460 i2d->AsFunctionType()->Arguments()));
461 } 455 }
462 456
463 TEST_F(AsmTypeTest, ToReturnType) { 457 TEST_F(AsmTypeTest, ToReturnType) {
464 std::unordered_map<AsmType*, AsmType*> kToReturnType = { 458 std::unordered_map<AsmType*, AsmType*> kToReturnType = {
465 {Type::Signed(), Type::Signed()}, {Type::FixNum(), Type::Signed()}, 459 {Type::Signed(), Type::Signed()}, {Type::FixNum(), Type::Signed()},
466 {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()}, 460 {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
467 {Type::Void(), Type::Void()}, 461 {Type::Void(), Type::Void()},
468 }; 462 };
469 463
470 Type* test_types[] = { 464 Type* test_types[] = {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 714 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
721 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType()) 715 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType())
722 << test_types[ii]->Name(); 716 << test_types[ii]->Name();
723 } 717 }
724 } 718 }
725 719
726 } // namespace 720 } // namespace
727 } // namespace wasm 721 } // namespace wasm
728 } // namespace internal 722 } // namespace internal
729 } // namespace v8 723 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698