Changeset 209934 in webkit
- Timestamp:
- Dec 16, 2016 1:36:40 PM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r209929 r209934 1 2016-12-16 Keith Miller <keith_miller@apple.com> 2 3 Add missing cases to parseUnreachableExpression and cleanup FunctionParser 4 https://bugs.webkit.org/show_bug.cgi?id=165966 5 6 Reviewed by Saam Barati. 7 8 This patch adds a number of missing cases to the Wasm FunctionParser's unreachable 9 code decoder. It also, removes unneeded OpType namespaces where they were not 10 needed and has the unary / binary macros cover all the cases rather than 11 just the simple cases. 12 13 * wasm/WasmFunctionParser.h: 14 1 15 2016-12-16 Mark Lam <mark.lam@apple.com> 2 16 -
trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h
r209923 r209934 137 137 } 138 138 139 if (op == OpType::End && !m_controlStack.size()) {139 if (op == End && !m_controlStack.size()) { 140 140 if (m_unreachableBlocks) 141 141 return { }; … … 202 202 switch (op) { 203 203 #define CREATE_CASE(name, id, b3op, inc) case OpType::name: return binaryCase<OpType::name>(); 204 FOR_EACH_WASM_ SIMPLE_BINARY_OP(CREATE_CASE)204 FOR_EACH_WASM_BINARY_OP(CREATE_CASE) 205 205 #undef CREATE_CASE 206 206 207 case OpType::F32ConvertUI64: return unaryCase<OpType::F32ConvertUI64>();208 case OpType::F64ConvertUI64: return unaryCase<OpType::F64ConvertUI64>();209 case OpType::F32Nearest: return unaryCase<OpType::F32Nearest>();210 case OpType::F64Nearest: return unaryCase<OpType::F64Nearest>();211 case OpType::F32Trunc: return unaryCase<OpType::F32Trunc>();212 case OpType::F64Trunc: return unaryCase<OpType::F64Trunc>();213 case OpType::I32Ctz: return unaryCase<OpType::I32Ctz>();214 case OpType::I64Ctz: return unaryCase<OpType::I64Ctz>();215 case OpType::I32Popcnt: return unaryCase<OpType::I32Popcnt>();216 case OpType::I64Popcnt: return unaryCase<OpType::I64Popcnt>();217 case OpType::I32TruncSF32: return unaryCase<OpType::I32TruncSF32>();218 case OpType::I32TruncUF32: return unaryCase<OpType::I32TruncUF32>();219 case OpType::I32TruncSF64: return unaryCase<OpType::I32TruncSF64>();220 case OpType::I32TruncUF64: return unaryCase<OpType::I32TruncUF64>();221 case OpType::I64TruncSF32: return unaryCase<OpType::I64TruncSF32>();222 case OpType::I64TruncUF32: return unaryCase<OpType::I64TruncUF32>();223 case OpType::I64TruncSF64: return unaryCase<OpType::I64TruncSF64>();224 case OpType::I64TruncUF64: return unaryCase<OpType::I64TruncUF64>();225 207 #define CREATE_CASE(name, id, b3op, inc) case OpType::name: return unaryCase<OpType::name>(); 226 FOR_EACH_WASM_ SIMPLE_UNARY_OP(CREATE_CASE)208 FOR_EACH_WASM_UNARY_OP(CREATE_CASE) 227 209 #undef CREATE_CASE 228 210 229 case OpType::Select: {211 case Select: { 230 212 ExpressionType condition; 231 213 ExpressionType zero; … … 271 253 #undef CREATE_CASE 272 254 273 case OpType::F32Const: {255 case F32Const: { 274 256 uint32_t constant; 275 257 WASM_PARSER_FAIL_IF(!parseUInt32(constant), "can't parse 32-bit floating-point constant"); … … 278 260 } 279 261 280 case OpType::I32Const: {262 case I32Const: { 281 263 int32_t constant; 282 264 WASM_PARSER_FAIL_IF(!parseVarInt32(constant), "can't parse 32-bit constant"); … … 285 267 } 286 268 287 case OpType::F64Const: {269 case F64Const: { 288 270 uint64_t constant; 289 271 WASM_PARSER_FAIL_IF(!parseUInt64(constant), "can't parse 64-bit floating-point constant"); … … 292 274 } 293 275 294 case OpType::I64Const: {276 case I64Const: { 295 277 int64_t constant; 296 278 WASM_PARSER_FAIL_IF(!parseVarInt64(constant), "can't parse 64-bit constant"); … … 299 281 } 300 282 301 case OpType::GetLocal: {283 case GetLocal: { 302 284 uint32_t index; 303 285 ExpressionType result; … … 308 290 } 309 291 310 case OpType::SetLocal: {292 case SetLocal: { 311 293 uint32_t index; 312 294 ExpressionType value; … … 317 299 } 318 300 319 case OpType::TeeLocal: {301 case TeeLocal: { 320 302 uint32_t index; 321 303 WASM_PARSER_FAIL_IF(!parseVarUInt32(index), "can't get index for tee_local"); … … 325 307 } 326 308 327 case OpType::GetGlobal: {309 case GetGlobal: { 328 310 uint32_t index; 329 311 ExpressionType result; … … 334 316 } 335 317 336 case OpType::SetGlobal: {318 case SetGlobal: { 337 319 uint32_t index; 338 320 ExpressionType value; … … 343 325 } 344 326 345 case OpType::Call: {327 case Call: { 346 328 uint32_t functionIndex; 347 329 WASM_PARSER_FAIL_IF(!parseVarUInt32(functionIndex), "can't parse call's function index"); … … 367 349 } 368 350 369 case OpType::CallIndirect: {351 case CallIndirect: { 370 352 uint32_t signatureIndex; 371 353 uint8_t reserved; … … 396 378 } 397 379 398 case OpType::Block: {380 case Block: { 399 381 Type inlineSignature; 400 382 WASM_PARSER_FAIL_IF(!parseResultType(inlineSignature), "can't get block's inline signature"); … … 404 386 } 405 387 406 case OpType::Loop: {388 case Loop: { 407 389 Type inlineSignature; 408 390 WASM_PARSER_FAIL_IF(!parseResultType(inlineSignature), "can't get loop's inline signature"); … … 412 394 } 413 395 414 case OpType::If: {396 case If: { 415 397 Type inlineSignature; 416 398 ExpressionType condition; … … 424 406 } 425 407 426 case OpType::Else: {408 case Else: { 427 409 WASM_PARSER_FAIL_IF(m_controlStack.isEmpty(), "can't use else block at the top-level of a function"); 428 410 WASM_TRY_ADD_TO_CONTEXT(addElse(m_controlStack.last().controlData, m_expressionStack)); … … 431 413 } 432 414 433 case OpType::Br:434 case OpType::BrIf: {415 case Br: 416 case BrIf: { 435 417 uint32_t target; 436 418 ExpressionType condition = Context::emptyExpression; 437 419 WASM_PARSER_FAIL_IF(!parseVarUInt32(target), "can't get br / br_if's target"); 438 420 WASM_PARSER_FAIL_IF(target >= m_controlStack.size(), "br / br_if's target ", target, " exceeds control stack size ", m_controlStack.size()); 439 if (op == OpType::BrIf)421 if (op == BrIf) 440 422 WASM_TRY_POP_EXPRESSION_STACK_INTO(condition, "br / br_if condition"); 441 423 else … … 448 430 } 449 431 450 case OpType::BrTable: {432 case BrTable: { 451 433 uint32_t numberOfTargets; 452 434 ExpressionType condition; … … 473 455 } 474 456 475 case OpType::Return: {457 case Return: { 476 458 return addReturn(); 477 459 } 478 460 479 case OpType::End: {461 case End: { 480 462 ControlEntry data = m_controlStack.takeLast(); 481 463 // FIXME: This is a little weird in that it will modify the expressionStack for the result of the block. … … 487 469 } 488 470 489 case OpType::Unreachable: {471 case Unreachable: { 490 472 WASM_TRY_ADD_TO_CONTEXT(addUnreachable()); 491 473 m_unreachableBlocks = 1; … … 493 475 } 494 476 495 case OpType::Drop: {477 case Drop: { 496 478 WASM_PARSER_FAIL_IF(!m_expressionStack.size(), "can't drop on empty stack"); 497 479 m_expressionStack.takeLast(); … … 499 481 } 500 482 501 case OpType::Nop: {502 return { }; 503 } 504 505 case OpType::GrowMemory:483 case Nop: { 484 return { }; 485 } 486 487 case GrowMemory: 506 488 return fail("not yet implemented: grow_memory"); // FIXME: Not yet implemented. 507 489 508 case OpType::CurrentMemory:490 case CurrentMemory: 509 491 return fail("not yet implemented: current_memory"); // FIXME: Not yet implemented. 510 492 … … 514 496 } 515 497 498 // FIXME: We should try to use the same decoder function for both unreachable and reachable code. https://bugs.webkit.org/show_bug.cgi?id=165965 516 499 template<typename Context> 517 500 auto FunctionParser<Context>::parseUnreachableExpression(OpType op) -> PartialResult 518 501 { 519 502 ASSERT(m_unreachableBlocks); 503 #define CREATE_CASE(name, id, b3op, inc) case OpType::name: 520 504 switch (op) { 521 case OpType::Else: {505 case Else: { 522 506 if (m_unreachableBlocks > 1) 523 507 return { }; … … 530 514 } 531 515 532 case OpType::End: {516 case End: { 533 517 if (m_unreachableBlocks == 1) { 534 518 ControlEntry data = m_controlStack.takeLast(); … … 540 524 } 541 525 542 case OpType::Loop:543 case OpType::If:544 case OpType::Block: {526 case Loop: 527 case If: 528 case Block: { 545 529 m_unreachableBlocks++; 546 return { }; 547 } 530 int8_t unused; 531 WASM_PARSER_FAIL_IF(!parseInt7(unused), "can't get inline type for ", op, " in unreachable context"); 532 return { }; 533 } 534 535 case BrTable: { 536 uint32_t numberOfTargets; 537 uint32_t unused; 538 WASM_PARSER_FAIL_IF(!parseVarUInt32(numberOfTargets), "can't get the number of targets for br_table in unreachable context"); 539 WASM_PARSER_FAIL_IF(numberOfTargets == std::numeric_limits<uint32_t>::max(), "br_table's number of targets is too big ", numberOfTargets); 540 541 for (uint32_t i = 0; i < numberOfTargets; ++i) 542 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get ", i, "th target for br_table in unreachable context"); 543 544 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get default target for br_table in unreachable context"); 545 return { }; 546 } 547 548 548 549 549 // two immediate cases 550 case OpType::Br: 551 case OpType::BrIf: { 550 FOR_EACH_WASM_MEMORY_LOAD_OP(CREATE_CASE) 551 FOR_EACH_WASM_MEMORY_STORE_OP(CREATE_CASE) 552 case Br: 553 case BrIf: 554 case CallIndirect: { 552 555 uint32_t unused; 553 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get br / br_ifin unreachable context");554 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get br / br_ifin unreachable context");556 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get first immediate for ", op, " in unreachable context"); 557 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get second immediate for ", op, " in unreachable context"); 555 558 return { }; 556 559 } 557 560 558 561 // one immediate cases 559 case OpType::F32Const: 560 case OpType::I32Const: 561 case OpType::F64Const: 562 case OpType::I64Const: 563 case OpType::SetLocal: 564 case OpType::GetLocal: { 562 case F32Const: 563 case I32Const: 564 case F64Const: 565 case I64Const: 566 case SetLocal: 567 case GetLocal: 568 case TeeLocal: 569 case GetGlobal: 570 case SetGlobal: 571 case Call: { 565 572 uint32_t unused; 566 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get const / local in unreachable context"); 567 return { }; 568 } 569 570 default: 571 break; 572 } 573 return { }; 573 WASM_PARSER_FAIL_IF(!parseVarUInt32(unused), "can't get immediate for ", op, " in unreachable context"); 574 return { }; 575 } 576 577 // no immediate cases 578 FOR_EACH_WASM_BINARY_OP(CREATE_CASE) 579 FOR_EACH_WASM_UNARY_OP(CREATE_CASE) 580 case Unreachable: 581 case Nop: 582 case Return: 583 case Select: 584 case Drop: 585 case GrowMemory: 586 case CurrentMemory: { 587 return { }; 588 } 589 } 590 #undef CREATE_CASE 591 RELEASE_ASSERT_NOT_REACHED(); 574 592 } 575 593
Note: See TracChangeset
for help on using the changeset viewer.