Parses a textual representation of a [`Function`] into a [`GenericFunction`]. The text format is the same as the one generated by [`DisplayFunction`]. [`DisplayFunction`]: crate::debug_utils::DisplayFunction [`Function`]: crate::function::Function
(input: &str)
| 384 | /// [`DisplayFunction`]: crate::debug_utils::DisplayFunction |
| 385 | /// [`Function`]: crate::function::Function |
| 386 | pub fn parse(input: &str) -> Result<Self> { |
| 387 | let parse_result = FunctionParser::parse(Rule::function, input)?; |
| 388 | |
| 389 | let mut blocks = PrimaryMap::new(); |
| 390 | let mut insts = PrimaryMap::new(); |
| 391 | let mut values = PrimaryMap::new(); |
| 392 | let mut value_groups = PrimaryMap::new(); |
| 393 | let mut entry_points = vec![]; |
| 394 | |
| 395 | for pair in parse_result { |
| 396 | match pair.as_rule() { |
| 397 | Rule::value_declaration => { |
| 398 | parse_value_declaration(pair, &mut values, &mut value_groups)?; |
| 399 | } |
| 400 | Rule::block_label => { |
| 401 | parse_block_label(pair, &mut entry_points, &mut blocks, &mut insts)?; |
| 402 | } |
| 403 | Rule::instruction => { |
| 404 | parse_instruction(pair, &mut blocks, &mut insts, &mut value_groups)?; |
| 405 | } |
| 406 | Rule::EOI => {} |
| 407 | _ => unreachable!(), |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | let mut func = Self { |
| 412 | entry_points, |
| 413 | blocks, |
| 414 | insts, |
| 415 | values, |
| 416 | value_groups, |
| 417 | }; |
| 418 | |
| 419 | // Compute block predecessors and immediate dominators since they are |
| 420 | // not encoded in the dump. |
| 421 | compute_preds_and_dominators(&mut func); |
| 422 | |
| 423 | Ok(func) |
| 424 | } |
| 425 | } |
no test coverage detected