pub struct Aig { /* private fields */ }Expand description
A whole AIG.
Nodes are kept alive artificially to allow rewrites of the structure.
Once you are done with rewriting (ie, your AIG should now be in a relevant state), you can
call the .update() method to remove all unused nodes.
For example, if you just created a node using .new_and(id, fanin0, fanin1), this node isn’t used as a fanin to any
other node for now. It won’t be deleted directly (fortunately!). But if after finishing your rewrite you
call .update() and the node still is not used by any other node, then, it will get deleted.
The use of Rc allows us not to worry about having to drop manually nodes that are no longer used, eg.
nodes that were used before by node A as their fanin0, but A is rewritten to use another fanin0.
Implementations§
Source§impl Aig
impl Aig
Sourcepub fn from_ascii(reader: BufReader<impl Read>) -> Result<Self>
pub fn from_ascii(reader: BufReader<impl Read>) -> Result<Self>
Creates an AIG from an open .aag file using ASCII format.
Use this function if the file is already open with the reader.
Source§impl Aig
impl Aig
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Creates an AIG from an .aig (resp .aag) file using bin (resp. ASCII) AIGER format.
Warning, this uses a homemade “parser” which isn’t super well tested and definitely does not support all AIG features (only the bare minimum). We’re not trying to open weird looking AIG files or do any sequential work for now.
Source§impl Aig
impl Aig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a brand new AIG (constant node AigNode::False included).
Sourcepub fn get_node(&self, id: NodeId) -> Option<AigNodeRef>
pub fn get_node(&self, id: NodeId) -> Option<AigNodeRef>
Retrieves a node from its id.
Sourcepub fn update(&mut self)
pub fn update(&mut self)
Call this function when you are done with your rewrite. All nodes that are not part of the AIG anymore (ie not reachable from an output) will be deleted.
Sourcepub fn get_inputs(&self) -> Vec<AigNodeRef> ⓘ
pub fn get_inputs(&self) -> Vec<AigNodeRef> ⓘ
Retrieves inputs reference.
Sourcepub fn get_inputs_id(&self) -> HashSet<NodeId>
pub fn get_inputs_id(&self) -> HashSet<NodeId>
Retrieves inputs id.
Sourcepub fn get_latches(&self) -> Vec<AigNodeRef> ⓘ
pub fn get_latches(&self) -> Vec<AigNodeRef> ⓘ
Retrieves latches reference.
Sourcepub fn get_latches_id(&self) -> HashSet<NodeId>
pub fn get_latches_id(&self) -> HashSet<NodeId>
Retrieves latches id.
Sourcepub fn get_outputs(&self) -> Vec<AigEdge>
pub fn get_outputs(&self) -> Vec<AigEdge>
Retrieves outputs reference.
Sourcepub fn get_topological_sort(&self) -> Result<Vec<AigNodeRef>>
pub fn get_topological_sort(&self) -> Result<Vec<AigNodeRef>>
Returns a topological sort of the AIG nodes, will error if a cycle is detected.
The “topological” sort makes sense only for the purely combinational part of the AIG, ie only without latches. Indeed, latches are allowed to create cycles through their next-state fanin.
Sourcepub fn add_node(&mut self, node: AigNode) -> Result<AigNodeRef>
pub fn add_node(&mut self, node: AigNode) -> Result<AigNodeRef>
Create a new (or retrieve existing) node within the AIG.
This will fail if a different node with the same id already exists in the AIG,
or if a node uses id 0 (reserved for constant node AigNode::False).
use mutaig::{Aig, AigEdge, AigNode};
let mut aig = Aig::new();
let node_false = aig.add_node(AigNode::False).unwrap();
let i1 = aig.add_node(AigNode::Input(1)).unwrap();
let i1_ = aig.add_node(AigNode::Input(1)).unwrap(); // will simply retrieve the existing node
assert_eq!(i1, i1_);
let and_gate =
aig.add_node(AigNode::And {
id: 2,
fanin0: AigEdge::new(i1.clone(), false),
fanin1: AigEdge::new(i1.clone(), true)
}).unwrap(); // represent i1 ^ !i1 so will be false all the time (just an example)
// Some stuff we cannot do
// Node with id 0
assert!(aig.add_node(AigNode::Input(0)).is_err());
// Id 1 is already taken by an input
assert!(
aig.add_node(AigNode::And {
id: 1,
fanin0: AigEdge::new(i1.clone(), false),
fanin1: AigEdge::new(i1.clone(), false)
})
.is_err()
);Sourcepub fn new_and(
&mut self,
id: NodeId,
fanin0: AigEdge,
fanin1: AigEdge,
) -> Result<AigNodeRef>
pub fn new_and( &mut self, id: NodeId, fanin0: AigEdge, fanin1: AigEdge, ) -> Result<AigNodeRef>
Create a new and node (or retrieve it if the exact same node already exists).
Sourcepub fn add_output(&mut self, id: NodeId, complement: bool) -> Result<()>
pub fn add_output(&mut self, id: NodeId, complement: bool) -> Result<()>
Mark an existing node as an output.
Sourcepub fn remove_output(
&mut self,
id: NodeId,
complement: bool,
) -> Option<AigNodeRef>
pub fn remove_output( &mut self, id: NodeId, complement: bool, ) -> Option<AigNodeRef>
Remove a fanin from the outputs. Do not error if node refered by fanin does not exist or if fanin was not an output, simply returns None instead of the node.
Sourcepub fn replace_fanin(
&mut self,
parent_id: NodeId,
fanin_id: FaninId,
child_id: NodeId,
complement: bool,
) -> Result<()>
pub fn replace_fanin( &mut self, parent_id: NodeId, fanin_id: FaninId, child_id: NodeId, complement: bool, ) -> Result<()>
Replace the given fanin of a node by a new fanin Both nodes need to already exist in the AIG
Sourcepub fn check_integrity(&self) -> Result<()>
pub fn check_integrity(&self) -> Result<()>
Checking if the AIG structure is correct. This function was written for debug purposes, as the library is supposed to maintain integrity of the AIG at any moment.