MCPcopy Create free account
hub / github.com/Amanieu/regalloc3 / parse

Method parse

src/debug_utils/generic_function/parse.rs:386–424  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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}

Callers 1

parse_numberFunction · 0.45

Calls 4

parse_value_declarationFunction · 0.85
parse_block_labelFunction · 0.85
parse_instructionFunction · 0.85

Tested by

no test coverage detected