Struct egg::Dot

source · []
pub struct Dot<'a, L: Language, N: Analysis<L>> {
    pub config: Vec<String>,
    pub use_anchors: bool,
    /* private fields */
}
Expand description

A wrapper for an EGraph that can output GraphViz for visualization.

The EGraph::dot method creates Dots.

Example

use egg::{*, rewrite as rw};

let rules = &[
    rw!("mul-commutes"; "(* ?x ?y)" => "(* ?y ?x)"),
    rw!("mul-two";      "(* ?x 2)" => "(<< ?x 1)"),
];

let mut egraph: EGraph<SymbolLang, ()> = Default::default();
egraph.add_expr(&"(/ (* 2 a) 2)".parse().unwrap());
let egraph = Runner::default().with_egraph(egraph).run(rules).egraph;

// Dot implements std::fmt::Display
println!("My egraph dot file: {}", egraph.dot());

// create a Dot and then compile it assuming `dot` is on the system
egraph.dot().to_svg("target/foo.svg").unwrap();
egraph.dot().to_png("target/foo.png").unwrap();
egraph.dot().to_pdf("target/foo.pdf").unwrap();
egraph.dot().to_dot("target/foo.dot").unwrap();

Note that self-edges (from an enode to its containing eclass) will be rendered improperly due to a deficiency in GraphViz. So the example above will render with an from the “+” enode to itself instead of to its own eclass.

Fields

config: Vec<String>

A list of strings to be output top part of the dot file.

use_anchors: bool

Whether or not to anchor the edges in the output. True by default.

Implementations

Writes the Dot to a .dot file with the given filename. Does not require a dot binary.

Adds a line to the dot output. Indentation and a newline will be added automatically.

Set whether or not to anchor the edges in the output.

Renders the Dot to a .png file with the given filename. Requires a dot binary to be on your $PATH.

Renders the Dot to a .svg file with the given filename. Requires a dot binary to be on your $PATH.

Renders the Dot to a .pdf file with the given filename. Requires a dot binary to be on your $PATH.

Invokes dot with the given arguments, piping this formatted Dot into stdin.

Invokes some program with the given arguments, piping this formatted Dot into stdin.

Can be used to run a different binary than dot:

egraph.dot().run(
    "/path/to/my/dot",
    &["arg1", "-o", "outfile"]
).unwrap();

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.