[][src]Module souper_ir::parse

Parsing the Souper IR text format.

This module provides both high- and low-level parsing utilities:

  • The high-level parsing functions are parse_*_file and parse_*_string which can be used to parse full replacements, LHSes, or RHSes either from files on disk or from an in-memory string.

  • The low-level parsing utilities are the Parse trait and the Parser struct. These can be used to parse a single instance of an LHS or RHS, for example.

Example

use souper_ir::parse::parse_replacements_str;
use std::path::Path;

let replacements = parse_replacements_str("
    ;; First replacement.
    %x:i32 = var
    %2lx = slt 2, %x
    pc %2lx 1
    %1lx = slt 1, %x
    cand %1lx 1

    ;; Second replacement.
    %bb = block 3
    %phi1 = phi %bb, 1:i32, 2, 3
    %phi2 = phi %bb, 2:i32, 4, 6
    %phi1x2 = mul %phi1, 2
    cand %phi2 %phi1x2
", Some(Path::new("example.souper")))?;

assert_eq!(replacements.len(), 2);

Structs

ParseError

An error that occurs during parsing.

Parser

A Souper text parser buffer.

Traits

Parse

A trait for AST nodes that can be parsed from text.

Peek

A trait for whether an AST node looks like it comes next.

Functions

parse_left_hand_sides_file

Parse a sequence of LeftHandSides from a file on disk.

parse_left_hand_sides_str

Parse a sequence of LeftHandSides from an in-memory string.

parse_replacements_file

Parse a sequence of Replacements from a file on disk.

parse_replacements_str

Parse a sequence of Replacements from an in-memory string.

parse_right_hand_sides_file

Parse a sequence of RightHandSides from a file on disk.

parse_right_hand_sides_str

Parse a sequence of RightHandSides from an in-memory string.

Type Definitions

Result

A Result type for parsing.