| 501 | } |
| 502 | |
| 503 | int Compiler::AddSuffixRecursive(int root, int id) { |
| 504 | DCHECK(inst_[root].opcode() == kInstAlt || |
| 505 | inst_[root].opcode() == kInstByteRange); |
| 506 | |
| 507 | Frag f = FindByteRange(root, id); |
| 508 | if (IsNoMatch(f)) { |
| 509 | int alt = AllocInst(1); |
| 510 | if (alt < 0) |
| 511 | return 0; |
| 512 | inst_[alt].InitAlt(root, id); |
| 513 | return alt; |
| 514 | } |
| 515 | |
| 516 | int br; |
| 517 | if (f.end.head == 0) |
| 518 | br = root; |
| 519 | else if (f.end.head&1) |
| 520 | br = inst_[f.begin].out1(); |
| 521 | else |
| 522 | br = inst_[f.begin].out(); |
| 523 | |
| 524 | if (IsCachedRuneByteSuffix(br)) { |
| 525 | // We can't fiddle with cached suffixes, so make a clone of the head. |
| 526 | int byterange = AllocInst(1); |
| 527 | if (byterange < 0) |
| 528 | return 0; |
| 529 | inst_[byterange].InitByteRange(inst_[br].lo(), inst_[br].hi(), |
| 530 | inst_[br].foldcase(), inst_[br].out()); |
| 531 | |
| 532 | // Ensure that the parent points to the clone, not to the original. |
| 533 | // Note that this could leave the head unreachable except via the cache. |
| 534 | br = byterange; |
| 535 | if (f.end.head == 0) |
| 536 | root = br; |
| 537 | else if (f.end.head&1) |
| 538 | inst_[f.begin].out1_ = br; |
| 539 | else |
| 540 | inst_[f.begin].set_out(br); |
| 541 | } |
| 542 | |
| 543 | int out = inst_[id].out(); |
| 544 | if (!IsCachedRuneByteSuffix(id)) { |
| 545 | // The head should be the instruction most recently allocated, so free it |
| 546 | // instead of leaving it unreachable. |
| 547 | DCHECK_EQ(id, ninst_-1); |
| 548 | inst_[id].out_opcode_ = 0; |
| 549 | inst_[id].out1_ = 0; |
| 550 | ninst_--; |
| 551 | } |
| 552 | |
| 553 | out = AddSuffixRecursive(inst_[br].out(), out); |
| 554 | if (out == 0) |
| 555 | return 0; |
| 556 | |
| 557 | inst_[br].set_out(out); |
| 558 | return root; |
| 559 | } |
| 560 | |