|
Lines 242-249
static void runWASMTests()
a/Source/JavaScriptCore/testWASM.cpp_sec1
|
| 242 |
{ |
242 |
{ |
| 243 |
{ |
243 |
{ |
| 244 |
// Generated from: |
244 |
// Generated from: |
|
|
245 |
// (module |
| 246 |
// (memory 1) |
| 247 |
// (func (export "i32_load8_s") (param $i i32) (param $ptr i32) (result i32) |
| 248 |
// (i32.store (get_local $ptr) (get_local $i)) |
| 249 |
// (return (i32.load (get_local $ptr))) |
| 250 |
// ) |
| 251 |
// ) |
| 252 |
Vector<uint8_t> vector = { |
| 253 |
0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, |
| 254 |
0x02, 0x02, 0x01, 0x01, 0x02, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, |
| 255 |
0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0b, 0x69, 0x33, |
| 256 |
0x32, 0x5f, 0x6c, 0x6f, 0x61, 0x64, 0x38, 0x5f, 0x73, 0x00, 0x00, 0x0a, 0x95, 0x80, 0x80, 0x80, |
| 257 |
0x00, 0x01, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x01, 0x14, 0x00, 0x34, 0x03, 0x00, 0x14, |
| 258 |
0x01, 0x2b, 0x03, 0x00, 0x09, 0x0f |
| 259 |
}; |
| 260 |
|
| 261 |
Plan plan(*vm, vector); |
| 262 |
if (plan.result.size() != 1 || !plan.result[0]) { |
| 263 |
dataLogLn("Module failed to compile correctly."); |
| 264 |
CRASH(); |
| 265 |
} |
| 266 |
|
| 267 |
// Test this doesn't crash. |
| 268 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(0), box(10) }), 0); |
| 269 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(100), box(2) }), 100); |
| 270 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(1), box(100) }), 1); |
| 271 |
} |
| 272 |
|
| 273 |
{ |
| 274 |
// Generated from: |
| 275 |
// (module |
| 276 |
// (memory 1) |
| 277 |
// (func (export "i32_load8_s") (param $i i32) (param $ptr i32) (result i32) |
| 278 |
// (i32.store (get_local $ptr) (get_local $i)) |
| 279 |
// (return (i32.load (get_local $ptr))) |
| 280 |
// ) |
| 281 |
// ) |
| 282 |
Vector<uint8_t> vector = { |
| 283 |
0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, |
| 284 |
0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, |
| 285 |
0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0b, 0x69, 0x33, |
| 286 |
0x32, 0x5f, 0x6c, 0x6f, 0x61, 0x64, 0x38, 0x5f, 0x73, 0x00, 0x00, 0x0a, 0x95, 0x80, 0x80, 0x80, |
| 287 |
0x00, 0x01, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x01, 0x14, 0x00, 0x33, 0x02, 0x00, 0x14, |
| 288 |
0x01, 0x2a, 0x02, 0x00, 0x09, 0x0f |
| 289 |
}; |
| 290 |
|
| 291 |
Plan plan(*vm, vector); |
| 292 |
if (plan.result.size() != 1 || !plan.result[0]) { |
| 293 |
dataLogLn("Module failed to compile correctly."); |
| 294 |
CRASH(); |
| 295 |
} |
| 296 |
|
| 297 |
// Test this doesn't crash. |
| 298 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(0), box(10) }), 0); |
| 299 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(100), box(2) }), 100); |
| 300 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(1), box(100) }), 1); |
| 301 |
} |
| 302 |
|
| 303 |
{ |
| 304 |
// Generated from: |
| 305 |
// (module |
| 306 |
// (memory 1) |
| 307 |
// (func (export "write_array") (param $x i32) (param $p i32) (param $length i32) (local $i i32) |
| 308 |
// (set_local $i (i32.const 0)) |
| 309 |
// (block |
| 310 |
// (loop |
| 311 |
// (br_if 1 (i32.ge_u (get_local $i) (get_local $length))) |
| 312 |
// (i32.store (i32.add (get_local $p) (i32.mul (get_local $i) (i32.const 4))) (get_local $x)) |
| 313 |
// (set_local $i (i32.add (i32.const 1) (get_local $i))) |
| 314 |
// (br 0) |
| 315 |
// ) |
| 316 |
// ) |
| 317 |
// (return) |
| 318 |
// ) |
| 319 |
// ) |
| 320 |
Vector<uint8_t> vector = { |
| 321 |
0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, |
| 322 |
0x03, 0x01, 0x01, 0x01, 0x00, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, |
| 323 |
0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0b, 0x77, 0x72, |
| 324 |
0x69, 0x74, 0x65, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x00, 0x00, 0x0a, 0xb2, 0x80, 0x80, 0x80, |
| 325 |
0x00, 0x01, 0xac, 0x80, 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x15, 0x03, 0x01, 0x00, |
| 326 |
0x02, 0x00, 0x14, 0x03, 0x14, 0x02, 0x56, 0x07, 0x01, 0x14, 0x01, 0x14, 0x03, 0x10, 0x04, 0x42, |
| 327 |
0x40, 0x14, 0x00, 0x33, 0x02, 0x00, 0x10, 0x01, 0x14, 0x03, 0x40, 0x15, 0x03, 0x06, 0x00, 0x0f, |
| 328 |
0x0f, 0x09, 0x0f |
| 329 |
}; |
| 330 |
|
| 331 |
Plan plan(*vm, vector); |
| 332 |
if (plan.result.size() != 1 || !plan.result[0]) { |
| 333 |
dataLogLn("Module failed to compile correctly."); |
| 334 |
CRASH(); |
| 335 |
} |
| 336 |
ASSERT(plan.memory->size()); |
| 337 |
|
| 338 |
// Test this doesn't crash. |
| 339 |
unsigned length = 5; |
| 340 |
unsigned offset = sizeof(uint32_t); |
| 341 |
uint32_t* memory = static_cast<uint32_t*>(plan.memory->memory()); |
| 342 |
invoke<void>(*plan.result[0], { box(100), box(offset), box(length) }); |
| 343 |
offset /= sizeof(uint32_t); |
| 344 |
CHECK_EQ(memory[offset - 1], 0u); |
| 345 |
CHECK_EQ(memory[offset + length], 0u); |
| 346 |
for (unsigned i = 0; i < length; ++i) |
| 347 |
CHECK_EQ(memory[i + offset], 100u); |
| 348 |
|
| 349 |
length = 10; |
| 350 |
offset = 5 * sizeof(uint32_t); |
| 351 |
invoke<void>(*plan.result[0], { box(5), box(offset), box(length) }); |
| 352 |
offset /= sizeof(uint32_t); |
| 353 |
CHECK_EQ(memory[offset - 1], 100u); |
| 354 |
CHECK_EQ(memory[offset + length], 0u); |
| 355 |
for (unsigned i = 0; i < length; ++i) |
| 356 |
CHECK_EQ(memory[i + offset], 5u); |
| 357 |
} |
| 358 |
|
| 359 |
{ |
| 360 |
// Generated from: |
| 361 |
// (module |
| 362 |
// (memory 1) |
| 363 |
// (func (export "write_array") (param $x i32) (param $p i32) (param $length i32) (local $i i32) |
| 364 |
// (set_local $i (i32.const 0)) |
| 365 |
// (block |
| 366 |
// (loop |
| 367 |
// (br_if 1 (i32.ge_u (get_local $i) (get_local $length))) |
| 368 |
// (i32.store8 (i32.add (get_local $p) (get_local $i)) (get_local $x)) |
| 369 |
// (set_local $i (i32.add (i32.const 1) (get_local $i))) |
| 370 |
// (br 0) |
| 371 |
// ) |
| 372 |
// ) |
| 373 |
// (return) |
| 374 |
// ) |
| 375 |
// ) |
| 376 |
Vector<uint8_t> vector = { |
| 377 |
0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, |
| 378 |
0x03, 0x01, 0x01, 0x01, 0x00, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, |
| 379 |
0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0b, 0x77, 0x72, |
| 380 |
0x69, 0x74, 0x65, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x00, 0x00, 0x0a, 0xaf, 0x80, 0x80, 0x80, |
| 381 |
0x00, 0x01, 0xa9, 0x80, 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x15, 0x03, 0x01, 0x00, |
| 382 |
0x02, 0x00, 0x14, 0x03, 0x14, 0x02, 0x56, 0x07, 0x01, 0x14, 0x01, 0x14, 0x03, 0x40, 0x14, 0x00, |
| 383 |
0x2e, 0x00, 0x00, 0x10, 0x01, 0x14, 0x03, 0x40, 0x15, 0x03, 0x06, 0x00, 0x0f, 0x0f, 0x09, 0x0f |
| 384 |
}; |
| 385 |
|
| 386 |
Plan plan(*vm, vector); |
| 387 |
if (plan.result.size() != 1 || !plan.result[0]) { |
| 388 |
dataLogLn("Module failed to compile correctly."); |
| 389 |
CRASH(); |
| 390 |
} |
| 391 |
ASSERT(plan.memory->size()); |
| 392 |
|
| 393 |
// Test this doesn't crash. |
| 394 |
unsigned length = 5; |
| 395 |
unsigned offset = 1; |
| 396 |
uint8_t* memory = static_cast<uint8_t*>(plan.memory->memory()); |
| 397 |
invoke<void>(*plan.result[0], { box(100), box(offset), box(length) }); |
| 398 |
CHECK_EQ(memory[offset - 1], 0u); |
| 399 |
CHECK_EQ(memory[offset + length], 0u); |
| 400 |
for (unsigned i = 0; i < length; ++i) |
| 401 |
CHECK_EQ(memory[i + offset], 100u); |
| 402 |
|
| 403 |
length = 10; |
| 404 |
offset = 5; |
| 405 |
invoke<void>(*plan.result[0], { box(5), box(offset), box(length) }); |
| 406 |
CHECK_EQ(memory[offset - 1], 100u); |
| 407 |
CHECK_EQ(memory[offset + length], 0u); |
| 408 |
for (unsigned i = 0; i < length; ++i) |
| 409 |
CHECK_EQ(memory[i + offset], 5u); |
| 410 |
} |
| 411 |
|
| 412 |
{ |
| 413 |
// Generated from: |
| 414 |
// (module |
| 415 |
// (memory 1) |
| 416 |
// (func (export "i32_load8_s") (param $i i32) (param $ptr i32) (result i32) |
| 417 |
// (i32.store8 (get_local $ptr) (get_local $i)) |
| 418 |
// (return (i32.load8_s (get_local $ptr))) |
| 419 |
// ) |
| 420 |
// ) |
| 421 |
Vector<uint8_t> vector = { |
| 422 |
0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, |
| 423 |
0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, |
| 424 |
0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0b, 0x69, 0x33, |
| 425 |
0x32, 0x5f, 0x6c, 0x6f, 0x61, 0x64, 0x38, 0x5f, 0x73, 0x00, 0x00, 0x0a, 0x95, 0x80, 0x80, 0x80, |
| 426 |
0x00, 0x01, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x01, 0x14, 0x00, 0x2e, 0x00, 0x00, 0x14, |
| 427 |
0x01, 0x20, 0x00, 0x00, 0x09, 0x0f |
| 428 |
}; |
| 429 |
|
| 430 |
Plan plan(*vm, vector); |
| 431 |
if (plan.result.size() != 1 || !plan.result[0]) { |
| 432 |
dataLogLn("Module failed to compile correctly."); |
| 433 |
CRASH(); |
| 434 |
} |
| 435 |
ASSERT(plan.memory->size()); |
| 436 |
|
| 437 |
// Test this doesn't crash. |
| 438 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(0), box(10) }), 0); |
| 439 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(100), box(2) }), 100); |
| 440 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(1), box(100) }), 1); |
| 441 |
} |
| 442 |
|
| 443 |
{ |
| 444 |
// Generated from: |
| 445 |
// (module |
| 446 |
// (memory 1) |
| 447 |
// (func (export "i32_load8_s") (param $i i32) (result i32) |
| 448 |
// (i32.store8 (i32.const 8) (get_local $i)) |
| 449 |
// (return (i32.load8_s (i32.const 8))) |
| 450 |
// ) |
| 451 |
// ) |
| 452 |
Vector<uint8_t> vector = { |
| 453 |
0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x86, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, |
| 454 |
0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, 0x80, |
| 455 |
0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0b, 0x69, 0x33, 0x32, |
| 456 |
0x5f, 0x6c, 0x6f, 0x61, 0x64, 0x38, 0x5f, 0x73, 0x00, 0x00, 0x0a, 0x95, 0x80, 0x80, 0x80, 0x00, |
| 457 |
0x01, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x08, 0x14, 0x00, 0x2e, 0x00, 0x00, 0x10, 0x08, |
| 458 |
0x20, 0x00, 0x00, 0x09, 0x0f |
| 459 |
}; |
| 460 |
|
| 461 |
Plan plan(*vm, vector); |
| 462 |
if (plan.result.size() != 1 || !plan.result[0]) { |
| 463 |
dataLogLn("Module failed to compile correctly."); |
| 464 |
CRASH(); |
| 465 |
} |
| 466 |
|
| 467 |
// Test this doesn't crash. |
| 468 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(0) }), 0); |
| 469 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(100) }), 100); |
| 470 |
CHECK_EQ(invoke<int>(*plan.result[0], { box(1) }), 1); |
| 471 |
} |
| 472 |
|
| 473 |
{ |
| 474 |
// Generated from: |
| 245 |
// (module |
475 |
// (module |
| 246 |
// (func (export "dumb-eq") (param $x i32) (param $y i32) (result i32) |
476 |
// (func "dumb-eq" (param $x i32) (param $y i32) (result i32) |
| 247 |
// (if (i32.eq (get_local $x) (get_local $y)) |
477 |
// (if (i32.eq (get_local $x) (get_local $y)) |
| 248 |
// (then (br 0)) |
478 |
// (then (br 0)) |
| 249 |
// (else (return (i32.const 1)))) |
479 |
// (else (return (i32.const 1)))) |