computation ::= ('ENTRY')? name (param_list_to_shape)? instruction_list
| 568 | |
| 569 | // computation ::= ('ENTRY')? name (param_list_to_shape)? instruction_list |
| 570 | bool HloParserImpl::ParseComputation(HloComputation** entry_computation) { |
| 571 | LocTy maybe_entry_loc = lexer_.GetLoc(); |
| 572 | const bool is_entry_computation = EatIfPresent(TokKind::kw_ENTRY); |
| 573 | |
| 574 | std::string name; |
| 575 | LocTy name_loc = lexer_.GetLoc(); |
| 576 | if (!ParseName(&name)) { |
| 577 | return false; |
| 578 | } |
| 579 | |
| 580 | LocTy shape_loc = nullptr; |
| 581 | Shape shape; |
| 582 | if (CanBeParamListToShape() && !ParseParamListToShape(&shape, &shape_loc)) { |
| 583 | return false; |
| 584 | } |
| 585 | |
| 586 | HloComputation* computation = nullptr; |
| 587 | if (!ParseInstructionList(&computation, name)) { |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | // If param_list_to_shape was present, check compatibility. |
| 592 | if (shape_loc != nullptr && |
| 593 | !ShapeUtil::Compatible(computation->root_instruction()->shape(), shape)) { |
| 594 | return Error( |
| 595 | shape_loc, |
| 596 | StrCat( |
| 597 | "Shape of computation ", name, ", ", ShapeUtil::HumanString(shape), |
| 598 | ", is not compatible with that of its root instruction ", |
| 599 | computation->root_instruction()->name(), ", ", |
| 600 | ShapeUtil::HumanString(computation->root_instruction()->shape()))); |
| 601 | } |
| 602 | |
| 603 | if (is_entry_computation) { |
| 604 | if (*entry_computation != nullptr) { |
| 605 | return Error(maybe_entry_loc, "expects only one ENTRY"); |
| 606 | } |
| 607 | *entry_computation = computation; |
| 608 | } |
| 609 | |
| 610 | return AddComputation(name, computation, name_loc); |
| 611 | } |
| 612 | |
| 613 | // instruction_list ::= '{' instruction_list1 '}' |
| 614 | // instruction_list1 ::= (instruction)+ |
nothing calls this directly
no test coverage detected