| OLD | NEW |
| 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/wasm/asm-types.h" | 5 #include "src/wasm/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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 Function(Type::Int)(Type::Int)) | 218 Function(Type::Int)(Type::Int)) |
| 219 ->Name(), | 219 ->Name(), |
| 220 StrEq("(double, float) -> int /\\ (int) -> int")); | 220 StrEq("(double, float) -> int /\\ (int) -> int")); |
| 221 | 221 |
| 222 EXPECT_THAT(Type::FroundType(zone())->Name(), StrEq("fround")); | 222 EXPECT_THAT(Type::FroundType(zone())->Name(), StrEq("fround")); |
| 223 | 223 |
| 224 EXPECT_THAT(Type::MinMaxType(zone(), Type::Signed(), Type::Int())->Name(), | 224 EXPECT_THAT(Type::MinMaxType(zone(), Type::Signed(), Type::Int())->Name(), |
| 225 StrEq("(int, int...) -> signed")); | 225 StrEq("(int, int...) -> signed")); |
| 226 EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(), | 226 EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(), |
| 227 StrEq("(floatish, floatish...) -> float")); | 227 StrEq("(floatish, floatish...) -> float")); |
| 228 EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::Double())->Name(), | 228 EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::DoubleQ())->Name(), |
| 229 StrEq("(double, double...) -> double")); | 229 StrEq("(double?, double?...) -> double")); |
| 230 |
| 231 EXPECT_THAT(Type::FFIType(zone())->Name(), StrEq("Function")); |
| 232 |
| 233 auto* ft = |
| 234 Type::FunctionTableType(zone(), 15, Function(Type::Double)(Type::Int)); |
| 235 EXPECT_THAT(ft->Name(), StrEq("(int) -> double[15]")); |
| 230 } | 236 } |
| 231 | 237 |
| 232 TEST_F(AsmTypeTest, IsExactly) { | 238 TEST_F(AsmTypeTest, IsExactly) { |
| 233 Type* test_types[] = { | 239 Type* test_types[] = { |
| 234 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 240 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 235 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 241 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 236 #undef CREATE | 242 #undef CREATE |
| 237 Function(Type::Int)(Type::Double), | 243 Function(Type::Int)(Type::Double), |
| 238 Function(Type::Int)(Type::DoubleQ), | 244 Function(Type::Int)(Type::DoubleQ), |
| 239 Overload(Function(Type::Int)(Type::Double)), | 245 Overload(Function(Type::Int)(Type::Double)), |
| 240 Function(Type::Int)(Type::Int, Type::Int), | 246 Function(Type::Int)(Type::Int, Type::Int), |
| 241 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 247 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 242 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 248 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 249 Type::FFIType(zone()), |
| 250 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 243 }; | 251 }; |
| 244 | 252 |
| 245 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 253 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 246 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { | 254 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { |
| 247 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj])) | 255 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj])) |
| 248 << test_types[ii]->Name() | 256 << test_types[ii]->Name() |
| 249 << ((ii == jj) ? " is not exactly " : " is exactly ") | 257 << ((ii == jj) ? " is not exactly " : " is exactly ") |
| 250 << test_types[jj]->Name(); | 258 << test_types[jj]->Name(); |
| 251 } | 259 } |
| 252 } | 260 } |
| 253 } | 261 } |
| 254 | 262 |
| 255 TEST_F(AsmTypeTest, IsA) { | 263 TEST_F(AsmTypeTest, IsA) { |
| 256 Type* test_types[] = { | 264 Type* test_types[] = { |
| 257 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 265 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 258 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 266 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 259 #undef CREATE | 267 #undef CREATE |
| 260 Function(Type::Int)(Type::Double), | 268 Function(Type::Int)(Type::Double), |
| 261 Function(Type::Int)(Type::DoubleQ), | 269 Function(Type::Int)(Type::DoubleQ), |
| 262 Overload(Function(Type::Int)(Type::Double)), | 270 Overload(Function(Type::Int)(Type::Double)), |
| 263 Function(Type::Int)(Type::Int, Type::Int), | 271 Function(Type::Int)(Type::Int, Type::Int), |
| 264 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 272 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 265 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 273 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 274 Type::FFIType(zone()), |
| 275 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 266 }; | 276 }; |
| 267 | 277 |
| 268 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 278 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 269 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { | 279 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { |
| 270 const bool Expected = | 280 const bool Expected = |
| 271 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0; | 281 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0; |
| 272 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj])) | 282 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj])) |
| 273 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ") | 283 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ") |
| 274 << test_types[jj]->Name(); | 284 << test_types[jj]->Name(); |
| 275 } | 285 } |
| 276 } | 286 } |
| 277 } | 287 } |
| 278 | 288 |
| 279 TEST_F(AsmTypeTest, ValidateCall) { | 289 TEST_F(AsmTypeTest, ValidateCall) { |
| 280 auto* min_max_int = Type::MinMaxType(zone(), Type::Signed(), Type::Int()); | 290 auto* min_max_int = Type::MinMaxType(zone(), Type::Signed(), Type::Int()); |
| 281 auto* i2s = Function(Type::Signed)(Type::Int); | 291 auto* i2s = Function(Type::Signed)(Type::Int); |
| 282 auto* ii2s = Function(Type::Signed)(Type::Int, Type::Int); | 292 auto* ii2s = Function(Type::Signed)(Type::Int, Type::Int); |
| 283 auto* iii2s = Function(Type::Signed)(Type::Int, Type::Int, Type::Int); | 293 auto* iii2s = Function(Type::Signed)(Type::Int, Type::Int, Type::Int); |
| 284 auto* iiii2s = | 294 auto* iiii2s = |
| 285 Function(Type::Signed)(Type::Int, Type::Int, Type::Int, Type::Int); | 295 Function(Type::Signed)(Type::Int, Type::Int, Type::Int, Type::Int); |
| 286 | 296 |
| 287 EXPECT_EQ(Type::Signed(), | 297 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( |
| 288 min_max_int->AsCallableType()->ValidateCall(min_max_int)); | 298 min_max_int->AsFunctionType()->ReturnType(), |
| 289 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall(ii2s)); | 299 min_max_int->AsFunctionType()->Arguments())); |
| 290 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall(iii2s)); | 300 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( |
| 291 EXPECT_EQ(Type::Signed(), | 301 ii2s->AsFunctionType()->ReturnType(), |
| 292 min_max_int->AsCallableType()->ValidateCall(iiii2s)); | 302 ii2s->AsFunctionType()->Arguments())); |
| 293 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall(i2s)); | 303 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( |
| 304 iii2s->AsFunctionType()->ReturnType(), |
| 305 iii2s->AsFunctionType()->Arguments())); |
| 306 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall( |
| 307 iiii2s->AsFunctionType()->ReturnType(), |
| 308 iiii2s->AsFunctionType()->Arguments())); |
| 309 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall( |
| 310 i2s->AsFunctionType()->ReturnType(), |
| 311 i2s->AsFunctionType()->Arguments())); |
| 294 | 312 |
| 295 auto* min_max_double = | 313 auto* min_max_double = |
| 296 Type::MinMaxType(zone(), Type::Double(), Type::Double()); | 314 Type::MinMaxType(zone(), Type::Double(), Type::Double()); |
| 297 auto* d2d = Function(Type::Double)(Type::Double); | 315 auto* d2d = Function(Type::Double)(Type::Double); |
| 298 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double); | 316 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double); |
| 299 auto* ddd2d = | 317 auto* ddd2d = |
| 300 Function(Type::Double)(Type::Double, Type::Double, Type::Double); | 318 Function(Type::Double)(Type::Double, Type::Double, Type::Double); |
| 301 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double, | 319 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double, |
| 302 Type::Double, Type::Double); | 320 Type::Double, Type::Double); |
| 303 EXPECT_EQ(Type::Double(), | 321 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( |
| 304 min_max_double->AsCallableType()->ValidateCall(min_max_double)); | 322 min_max_double->AsFunctionType()->ReturnType(), |
| 305 EXPECT_EQ(Type::Double(), | 323 min_max_double->AsFunctionType()->Arguments())); |
| 306 min_max_double->AsCallableType()->ValidateCall(dd2d)); | 324 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( |
| 307 EXPECT_EQ(Type::Double(), | 325 dd2d->AsFunctionType()->ReturnType(), |
| 308 min_max_double->AsCallableType()->ValidateCall(ddd2d)); | 326 dd2d->AsFunctionType()->Arguments())); |
| 309 EXPECT_EQ(Type::Double(), | 327 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( |
| 310 min_max_double->AsCallableType()->ValidateCall(dddd2d)); | 328 ddd2d->AsFunctionType()->ReturnType(), |
| 311 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall(d2d)); | 329 ddd2d->AsFunctionType()->Arguments())); |
| 330 EXPECT_EQ(Type::Double(), min_max_double->AsCallableType()->ValidateCall( |
| 331 dddd2d->AsFunctionType()->ReturnType(), |
| 332 dddd2d->AsFunctionType()->Arguments())); |
| 333 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall( |
| 334 d2d->AsFunctionType()->ReturnType(), |
| 335 d2d->AsFunctionType()->Arguments())); |
| 312 | 336 |
| 313 auto* min_max = Overload(min_max_int, min_max_double); | 337 auto* min_max = Overload(min_max_int, min_max_double); |
| 314 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(min_max)); | 338 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall( |
| 315 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(i2s)); | 339 i2s->AsFunctionType()->ReturnType(), |
| 316 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(d2d)); | 340 i2s->AsFunctionType()->Arguments())); |
| 317 EXPECT_EQ(Type::Signed(), | 341 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall( |
| 318 min_max->AsCallableType()->ValidateCall(min_max_int)); | 342 d2d->AsFunctionType()->ReturnType(), |
| 319 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(ii2s)); | 343 d2d->AsFunctionType()->Arguments())); |
| 320 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(iii2s)); | 344 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( |
| 321 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(iiii2s)); | 345 min_max_int->AsFunctionType()->ReturnType(), |
| 322 EXPECT_EQ(Type::Double(), | 346 min_max_int->AsFunctionType()->Arguments())); |
| 323 min_max->AsCallableType()->ValidateCall(min_max_double)); | 347 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( |
| 324 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dd2d)); | 348 ii2s->AsFunctionType()->ReturnType(), |
| 325 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(ddd2d)); | 349 ii2s->AsFunctionType()->Arguments())); |
| 326 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dddd2d)); | 350 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( |
| 351 iii2s->AsFunctionType()->ReturnType(), |
| 352 iii2s->AsFunctionType()->Arguments())); |
| 353 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall( |
| 354 iiii2s->AsFunctionType()->ReturnType(), |
| 355 iiii2s->AsFunctionType()->Arguments())); |
| 356 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall( |
| 357 min_max_double->AsFunctionType()->ReturnType(), |
| 358 min_max_double->AsFunctionType()->Arguments())); |
| 359 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall( |
| 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())); |
| 327 | 368 |
| 328 auto* fround = Type::FroundType(zone()); | 369 auto* fround = Type::FroundType(zone()); |
| 329 | 370 |
| 330 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 371 ZoneVector<AsmType*> arg(zone()); |
| 331 Function(Type::Float)(Type::Floatish))); | 372 arg.push_back(Type::Floatish()); |
| 332 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 373 EXPECT_EQ(Type::Float(), |
| 333 Function(Type::Float)(Type::FloatQ))); | 374 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 334 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 375 arg.clear(); |
| 335 Function(Type::Float)(Type::Float))); | 376 arg.push_back(Type::FloatQ()); |
| 336 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 377 EXPECT_EQ(Type::Float(), |
| 337 Function(Type::Float)(Type::DoubleQ))); | 378 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 338 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 379 arg.clear(); |
| 339 Function(Type::Float)(Type::Double))); | 380 arg.push_back(Type::Float()); |
| 340 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 381 EXPECT_EQ(Type::Float(), |
| 341 Function(Type::Float)(Type::Signed))); | 382 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 342 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 383 arg.clear(); |
| 343 Function(Type::Float)(Type::Unsigned))); | 384 arg.push_back(Type::DoubleQ()); |
| 344 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 385 EXPECT_EQ(Type::Float(), |
| 345 Function(Type::Float)(Type::FixNum))); | 386 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 387 arg.clear(); |
| 388 arg.push_back(Type::Double()); |
| 389 EXPECT_EQ(Type::Float(), |
| 390 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 391 arg.clear(); |
| 392 arg.push_back(Type::Signed()); |
| 393 EXPECT_EQ(Type::Float(), |
| 394 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 395 arg.clear(); |
| 396 arg.push_back(Type::Unsigned()); |
| 397 EXPECT_EQ(Type::Float(), |
| 398 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 399 arg.clear(); |
| 400 arg.push_back(Type::FixNum()); |
| 401 EXPECT_EQ(Type::Float(), |
| 402 fround->AsCallableType()->ValidateCall(Type::Float(), arg)); |
| 346 | 403 |
| 347 auto* idf2v = Function(Type::Void)(Type::Int, Type::Double, Type::Float); | 404 auto* idf2v = Function(Type::Void)(Type::Int, Type::Double, Type::Float); |
| 348 auto* i2d = Function(Type::Double)(Type::Int); | 405 auto* i2d = Function(Type::Double)(Type::Int); |
| 349 auto* i2f = Function(Type::Float)(Type::Int); | 406 auto* i2f = Function(Type::Float)(Type::Int); |
| 350 auto* fi2d = Function(Type::Double)(Type::Float, Type::Int); | 407 auto* fi2d = Function(Type::Double)(Type::Float, Type::Int); |
| 351 auto* idif2i = | 408 auto* idif2i = |
| 352 Function(Type::Int)(Type::Int, Type::Double, Type::Int, Type::Float); | 409 Function(Type::Int)(Type::Int, Type::Double, Type::Int, Type::Float); |
| 353 auto* overload = Overload(idf2v, i2f, /*i2d missing, */ fi2d, idif2i); | 410 auto* overload = Overload(idf2v, i2f, /*i2d missing, */ fi2d, idif2i); |
| 354 EXPECT_EQ(Type::Void(), overload->AsCallableType()->ValidateCall(idf2v)); | 411 EXPECT_EQ(Type::Void(), overload->AsCallableType()->ValidateCall( |
| 355 EXPECT_EQ(Type::Float(), overload->AsCallableType()->ValidateCall(i2f)); | 412 idf2v->AsFunctionType()->ReturnType(), |
| 356 EXPECT_EQ(Type::Double(), overload->AsCallableType()->ValidateCall(fi2d)); | 413 idf2v->AsFunctionType()->Arguments())); |
| 357 EXPECT_EQ(Type::Int(), overload->AsCallableType()->ValidateCall(idif2i)); | 414 EXPECT_EQ(Type::Float(), overload->AsCallableType()->ValidateCall( |
| 358 EXPECT_EQ(Type::None(), overload->AsCallableType()->ValidateCall(i2d)); | 415 i2f->AsFunctionType()->ReturnType(), |
| 359 EXPECT_EQ(Type::None(), i2f->AsCallableType()->ValidateCall(i2d)); | 416 i2f->AsFunctionType()->Arguments())); |
| 417 EXPECT_EQ(Type::Double(), overload->AsCallableType()->ValidateCall( |
| 418 fi2d->AsFunctionType()->ReturnType(), |
| 419 fi2d->AsFunctionType()->Arguments())); |
| 420 EXPECT_EQ(Type::Int(), overload->AsCallableType()->ValidateCall( |
| 421 idif2i->AsFunctionType()->ReturnType(), |
| 422 idif2i->AsFunctionType()->Arguments())); |
| 423 EXPECT_EQ(Type::None(), overload->AsCallableType()->ValidateCall( |
| 424 i2d->AsFunctionType()->ReturnType(), |
| 425 i2d->AsFunctionType()->Arguments())); |
| 426 EXPECT_EQ(Type::None(), i2f->AsCallableType()->ValidateCall( |
| 427 i2d->AsFunctionType()->ReturnType(), |
| 428 i2d->AsFunctionType()->Arguments())); |
| 429 |
| 430 auto* ffi = Type::FFIType(zone()); |
| 431 AsmType* (*kReturnTypes[])() = { |
| 432 Type::Void, Type::Double, Type::Signed, |
| 433 }; |
| 434 AsmType* (*kParameterTypes[])() = { |
| 435 Type::Double, Type::Signed, Type::FixNum, |
| 436 }; |
| 437 for (size_t ii = 0; ii < arraysize(kReturnTypes); ++ii) { |
| 438 for (size_t jj = 0; jj < arraysize(kParameterTypes); ++jj) { |
| 439 auto* f = Function(kReturnTypes[ii])(kParameterTypes[jj]); |
| 440 EXPECT_EQ(kReturnTypes[ii](), ffi->AsCallableType()->ValidateCall( |
| 441 f->AsFunctionType()->ReturnType(), |
| 442 f->AsFunctionType()->Arguments())) |
| 443 << kReturnTypes[ii]()->Name(); |
| 444 |
| 445 // Call with non-parameter type type should fail. |
| 446 f = Function(kReturnTypes[ii])(kParameterTypes[jj], Type::Int); |
| 447 EXPECT_EQ(Type::None(), ffi->AsCallableType()->ValidateCall( |
| 448 f->AsFunctionType()->ReturnType(), |
| 449 f->AsFunctionType()->Arguments())) |
| 450 << kReturnTypes[ii]()->Name(); |
| 451 } |
| 452 } |
| 453 |
| 454 auto* ft0 = Type::FunctionTableType(zone(), 10, fi2d); |
| 455 EXPECT_EQ(Type::Double(), ft0->AsCallableType()->ValidateCall( |
| 456 fi2d->AsFunctionType()->ReturnType(), |
| 457 fi2d->AsFunctionType()->Arguments())); |
| 458 EXPECT_EQ(Type::None(), ft0->AsCallableType()->ValidateCall( |
| 459 i2d->AsFunctionType()->ReturnType(), |
| 460 i2d->AsFunctionType()->Arguments())); |
| 461 } |
| 462 |
| 463 TEST_F(AsmTypeTest, ToReturnType) { |
| 464 std::unordered_map<AsmType*, AsmType*> kToReturnType = { |
| 465 {Type::Signed(), Type::Signed()}, {Type::FixNum(), Type::Signed()}, |
| 466 {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()}, |
| 467 {Type::Void(), Type::Void()}, |
| 468 }; |
| 469 |
| 470 Type* test_types[] = { |
| 471 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 472 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 473 #undef CREATE |
| 474 Function(Type::Int)(Type::Double), |
| 475 Function(Type::Int)(Type::DoubleQ), |
| 476 Overload(Function(Type::Int)(Type::Double)), |
| 477 Function(Type::Int)(Type::Int, Type::Int), |
| 478 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 479 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 480 Type::FFIType(zone()), |
| 481 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 482 }; |
| 483 |
| 484 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 485 auto* return_type = Type::None(); |
| 486 auto to_return_type_iter = kToReturnType.find(test_types[ii]); |
| 487 if (to_return_type_iter != kToReturnType.end()) { |
| 488 return_type = to_return_type_iter->second; |
| 489 } |
| 490 EXPECT_EQ(return_type, test_types[ii]->ToReturnType()) |
| 491 << return_type->Name() << " != " << test_types[ii]->ToReturnType(); |
| 492 } |
| 360 } | 493 } |
| 361 | 494 |
| 362 TEST_F(AsmTypeTest, IsReturnType) { | 495 TEST_F(AsmTypeTest, IsReturnType) { |
| 363 Type* test_types[] = { | 496 Type* test_types[] = { |
| 364 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 497 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 365 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 498 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 366 #undef CREATE | 499 #undef CREATE |
| 367 Function(Type::Int)(Type::Double), | 500 Function(Type::Int)(Type::Double), |
| 368 Function(Type::Int)(Type::DoubleQ), | 501 Function(Type::Int)(Type::DoubleQ), |
| 369 Overload(Function(Type::Int)(Type::Double)), | 502 Overload(Function(Type::Int)(Type::Double)), |
| 370 Function(Type::Int)(Type::Int, Type::Int), | 503 Function(Type::Int)(Type::Int, Type::Int), |
| 371 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 504 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 372 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 505 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 506 Type::FFIType(zone()), |
| 507 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 373 }; | 508 }; |
| 374 | 509 |
| 375 std::unordered_set<Type*> return_types{ | 510 std::unordered_set<Type*> return_types{ |
| 376 Type::Double(), Type::Signed(), Type::Float(), Type::Void(), | 511 Type::Double(), Type::Signed(), Type::Float(), Type::Void(), |
| 377 }; | 512 }; |
| 378 | 513 |
| 379 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 514 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 380 const bool IsReturnType = return_types.count(test_types[ii]); | 515 const bool IsReturnType = return_types.count(test_types[ii]); |
| 381 EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType()) | 516 EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType()) |
| 382 << test_types[ii]->Name() | 517 << test_types[ii]->Name() |
| 383 << (IsReturnType ? " is not a return type" : " is a return type"); | 518 << (IsReturnType ? " is not a return type" : " is a return type"); |
| 384 } | 519 } |
| 385 } | 520 } |
| 386 | 521 |
| 522 TEST_F(AsmTypeTest, ToParameterType) { |
| 523 std::unordered_map<AsmType*, AsmType*> kToParameterType = { |
| 524 {Type::Int(), Type::Int()}, {Type::Signed(), Type::Int()}, |
| 525 {Type::Unsigned(), Type::Int()}, {Type::FixNum(), Type::Int()}, |
| 526 {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()}, |
| 527 }; |
| 528 |
| 529 Type* test_types[] = { |
| 530 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 531 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 532 #undef CREATE |
| 533 Function(Type::Int)(Type::Double), |
| 534 Function(Type::Int)(Type::DoubleQ), |
| 535 Overload(Function(Type::Int)(Type::Double)), |
| 536 Function(Type::Int)(Type::Int, Type::Int), |
| 537 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 538 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 539 Type::FFIType(zone()), |
| 540 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 541 }; |
| 542 |
| 543 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 544 auto* parameter_type = Type::None(); |
| 545 auto to_parameter_type_iter = kToParameterType.find(test_types[ii]); |
| 546 if (to_parameter_type_iter != kToParameterType.end()) { |
| 547 parameter_type = to_parameter_type_iter->second; |
| 548 } |
| 549 EXPECT_EQ(parameter_type, test_types[ii]->ToParameterType()) |
| 550 << parameter_type->Name() |
| 551 << " != " << test_types[ii]->ToParameterType(); |
| 552 } |
| 553 } |
| 554 |
| 387 TEST_F(AsmTypeTest, IsParameterType) { | 555 TEST_F(AsmTypeTest, IsParameterType) { |
| 388 Type* test_types[] = { | 556 Type* test_types[] = { |
| 389 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 557 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 390 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 558 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 391 #undef CREATE | 559 #undef CREATE |
| 392 Function(Type::Int)(Type::Double), | 560 Function(Type::Int)(Type::Double), |
| 393 Function(Type::Int)(Type::DoubleQ), | 561 Function(Type::Int)(Type::DoubleQ), |
| 394 Overload(Function(Type::Int)(Type::Double)), | 562 Overload(Function(Type::Int)(Type::Double)), |
| 395 Function(Type::Int)(Type::Int, Type::Int), | 563 Function(Type::Int)(Type::Int, Type::Int), |
| 396 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 564 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 397 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 565 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 566 Type::FFIType(zone()), |
| 567 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 398 }; | 568 }; |
| 399 | 569 |
| 400 std::unordered_set<Type*> parameter_types{ | 570 std::unordered_set<Type*> parameter_types{ |
| 401 Type::Double(), Type::Int(), Type::Float(), | 571 Type::Double(), Type::Int(), Type::Float(), |
| 402 }; | 572 }; |
| 403 | 573 |
| 404 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 574 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 405 const bool IsParameterType = parameter_types.count(test_types[ii]); | 575 const bool IsParameterType = parameter_types.count(test_types[ii]); |
| 406 EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType()) | 576 EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType()) |
| 407 << test_types[ii]->Name() | 577 << test_types[ii]->Name() |
| 408 << (IsParameterType ? " is not a parameter type" | 578 << (IsParameterType ? " is not a parameter type" |
| 409 : " is a parameter type"); | 579 : " is a parameter type"); |
| 410 } | 580 } |
| 411 } | 581 } |
| 412 | 582 |
| 413 TEST_F(AsmTypeTest, IsComparableType) { | 583 TEST_F(AsmTypeTest, IsComparableType) { |
| 414 Type* test_types[] = { | 584 Type* test_types[] = { |
| 415 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 585 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 416 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 586 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 417 #undef CREATE | 587 #undef CREATE |
| 418 Function(Type::Int)(Type::Double), | 588 Function(Type::Int)(Type::Double), |
| 419 Function(Type::Int)(Type::DoubleQ), | 589 Function(Type::Int)(Type::DoubleQ), |
| 420 Overload(Function(Type::Int)(Type::Double)), | 590 Overload(Function(Type::Int)(Type::Double)), |
| 421 Function(Type::Int)(Type::Int, Type::Int), | 591 Function(Type::Int)(Type::Int, Type::Int), |
| 422 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 592 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 423 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 593 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 594 Type::FFIType(zone()), |
| 595 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 424 }; | 596 }; |
| 425 | 597 |
| 426 std::unordered_set<Type*> comparable_types{ | 598 std::unordered_set<Type*> comparable_types{ |
| 427 Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(), | 599 Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(), |
| 428 }; | 600 }; |
| 429 | 601 |
| 430 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 602 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 431 const bool IsComparableType = comparable_types.count(test_types[ii]); | 603 const bool IsComparableType = comparable_types.count(test_types[ii]); |
| 432 EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType()) | 604 EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType()) |
| 433 << test_types[ii]->Name() | 605 << test_types[ii]->Name() |
| 434 << (IsComparableType ? " is not a comparable type" | 606 << (IsComparableType ? " is not a comparable type" |
| 435 : " is a comparable type"); | 607 : " is a comparable type"); |
| 436 } | 608 } |
| 437 } | 609 } |
| 438 | 610 |
| 439 TEST_F(AsmTypeTest, ElementSizeInBytes) { | 611 TEST_F(AsmTypeTest, ElementSizeInBytes) { |
| 440 Type* test_types[] = { | 612 Type* test_types[] = { |
| 441 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 613 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 442 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 614 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 443 #undef CREATE | 615 #undef CREATE |
| 444 Function(Type::Int)(Type::Double), | 616 Function(Type::Int)(Type::Double), |
| 445 Function(Type::Int)(Type::DoubleQ), | 617 Function(Type::Int)(Type::DoubleQ), |
| 446 Overload(Function(Type::Int)(Type::Double)), | 618 Overload(Function(Type::Int)(Type::Double)), |
| 447 Function(Type::Int)(Type::Int, Type::Int), | 619 Function(Type::Int)(Type::Int, Type::Int), |
| 448 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 620 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 449 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 621 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 622 Type::FFIType(zone()), |
| 623 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 450 }; | 624 }; |
| 451 | 625 |
| 452 auto ElementSizeInBytesForType = [](Type* type) -> int32_t { | 626 auto ElementSizeInBytesForType = [](Type* type) -> int32_t { |
| 453 if (type == Type::Int8Array() || type == Type::Uint8Array()) { | 627 if (type == Type::Int8Array() || type == Type::Uint8Array()) { |
| 454 return 1; | 628 return 1; |
| 455 } | 629 } |
| 456 if (type == Type::Int16Array() || type == Type::Uint16Array()) { | 630 if (type == Type::Int16Array() || type == Type::Uint16Array()) { |
| 457 return 2; | 631 return 2; |
| 458 } | 632 } |
| 459 if (type == Type::Int32Array() || type == Type::Uint32Array() || | 633 if (type == Type::Int32Array() || type == Type::Uint32Array() || |
| (...skipping 16 matching lines...) Expand all Loading... |
| 476 Type* test_types[] = { | 650 Type* test_types[] = { |
| 477 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 651 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 478 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 652 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 479 #undef CREATE | 653 #undef CREATE |
| 480 Function(Type::Int)(Type::Double), | 654 Function(Type::Int)(Type::Double), |
| 481 Function(Type::Int)(Type::DoubleQ), | 655 Function(Type::Int)(Type::DoubleQ), |
| 482 Overload(Function(Type::Int)(Type::Double)), | 656 Overload(Function(Type::Int)(Type::Double)), |
| 483 Function(Type::Int)(Type::Int, Type::Int), | 657 Function(Type::Int)(Type::Int, Type::Int), |
| 484 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 658 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 485 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 659 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 660 Type::FFIType(zone()), |
| 661 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 486 }; | 662 }; |
| 487 | 663 |
| 488 auto LoadTypeForType = [](Type* type) -> Type* { | 664 auto LoadTypeForType = [](Type* type) -> Type* { |
| 489 if (type == Type::Int8Array() || type == Type::Uint8Array() || | 665 if (type == Type::Int8Array() || type == Type::Uint8Array() || |
| 490 type == Type::Int16Array() || type == Type::Uint16Array() || | 666 type == Type::Int16Array() || type == Type::Uint16Array() || |
| 491 type == Type::Int32Array() || type == Type::Uint32Array()) { | 667 type == Type::Int32Array() || type == Type::Uint32Array()) { |
| 492 return Type::Intish(); | 668 return Type::Intish(); |
| 493 } | 669 } |
| 494 | 670 |
| 495 if (type == Type::Float32Array()) { | 671 if (type == Type::Float32Array()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 512 Type* test_types[] = { | 688 Type* test_types[] = { |
| 513 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 689 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
| 514 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 690 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
| 515 #undef CREATE | 691 #undef CREATE |
| 516 Function(Type::Int)(Type::Double), | 692 Function(Type::Int)(Type::Double), |
| 517 Function(Type::Int)(Type::DoubleQ), | 693 Function(Type::Int)(Type::DoubleQ), |
| 518 Overload(Function(Type::Int)(Type::Double)), | 694 Overload(Function(Type::Int)(Type::Double)), |
| 519 Function(Type::Int)(Type::Int, Type::Int), | 695 Function(Type::Int)(Type::Int, Type::Int), |
| 520 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), | 696 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
| 521 Function(Type::Int)(Type::Float), Type::FroundType(zone()), | 697 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
| 698 Type::FFIType(zone()), |
| 699 Type::FunctionTableType(zone(), 10, Function(Type::Void)()), |
| 522 }; | 700 }; |
| 523 | 701 |
| 524 auto StoreTypeForType = [](Type* type) -> Type* { | 702 auto StoreTypeForType = [](Type* type) -> Type* { |
| 525 if (type == Type::Int8Array() || type == Type::Uint8Array() || | 703 if (type == Type::Int8Array() || type == Type::Uint8Array() || |
| 526 type == Type::Int16Array() || type == Type::Uint16Array() || | 704 type == Type::Int16Array() || type == Type::Uint16Array() || |
| 527 type == Type::Int32Array() || type == Type::Uint32Array()) { | 705 type == Type::Int32Array() || type == Type::Uint32Array()) { |
| 528 return Type::Intish(); | 706 return Type::Intish(); |
| 529 } | 707 } |
| 530 | 708 |
| 531 if (type == Type::Float32Array()) { | 709 if (type == Type::Float32Array()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 542 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 720 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
| 543 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType()) | 721 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType()) |
| 544 << test_types[ii]->Name(); | 722 << test_types[ii]->Name(); |
| 545 } | 723 } |
| 546 } | 724 } |
| 547 | 725 |
| 548 } // namespace | 726 } // namespace |
| 549 } // namespace wasm | 727 } // namespace wasm |
| 550 } // namespace internal | 728 } // namespace internal |
| 551 } // namespace v8 | 729 } // namespace v8 |
| OLD | NEW |