instruction_list ::= '{' instruction_list1 '}' instruction_list1 ::= (instruction)+
| 613 | // instruction_list ::= '{' instruction_list1 '}' |
| 614 | // instruction_list1 ::= (instruction)+ |
| 615 | bool HloParserImpl::ParseInstructionList(HloComputation** computation, |
| 616 | const std::string& computation_name) { |
| 617 | Scope scope(&scoped_name_tables_); |
| 618 | HloComputation::Builder builder(computation_name); |
| 619 | if (!ParseToken(TokKind::kLbrace, |
| 620 | "expects '{' at the beginning of instruction list.")) { |
| 621 | return false; |
| 622 | } |
| 623 | std::string root_name; |
| 624 | do { |
| 625 | if (!ParseInstruction(&builder, &root_name)) { |
| 626 | return false; |
| 627 | } |
| 628 | } while (lexer_.GetKind() != TokKind::kRbrace); |
| 629 | if (!ParseToken(TokKind::kRbrace, |
| 630 | "expects '}' at the end of instruction list.")) { |
| 631 | return false; |
| 632 | } |
| 633 | HloInstruction* root = nullptr; |
| 634 | if (!root_name.empty()) { |
| 635 | std::pair<HloInstruction*, LocTy>* root_node = |
| 636 | tensorflow::gtl::FindOrNull(current_name_table(), root_name); |
| 637 | |
| 638 | // This means some instruction was marked as ROOT but we didn't find it in |
| 639 | // the pool, which should not happen. |
| 640 | if (root_node == nullptr) { |
| 641 | // LOG(FATAL) crashes the program by calling abort(). |
| 642 | LOG(FATAL) << "instruction " << root_name |
| 643 | << " was marked as ROOT but the parser has not seen it before"; |
| 644 | } |
| 645 | root = root_node->first; |
| 646 | } |
| 647 | |
| 648 | // Now root can be either an existing instruction or a nullptr. If it's a |
| 649 | // nullptr, the implementation of Builder will set the last instruction as |
| 650 | // the root instruction. |
| 651 | computations_.emplace_back(builder.Build(root)); |
| 652 | *computation = computations_.back().get(); |
| 653 | return true; |
| 654 | } |
| 655 | |
| 656 | // instruction ::= ('ROOT')? name '=' shape opcode operands (attribute)* |
| 657 | bool HloParserImpl::ParseInstruction(HloComputation::Builder* builder, |
nothing calls this directly
no test coverage detected