Struct Aig

Source
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

Source

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

Source

pub fn from_bin(reader: BufReader<impl Read>) -> Result<Self>

Source§

impl Aig

Source

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

Source

pub fn new() -> Self

Create a brand new AIG (constant node AigNode::False included).

Source

pub fn get_node(&self, id: NodeId) -> Option<AigNodeRef>

Retrieves a node from its id.

Source

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.

Source

pub fn get_inputs(&self) -> Vec<AigNodeRef>

Retrieves inputs reference.

Source

pub fn get_inputs_id(&self) -> HashSet<NodeId>

Retrieves inputs id.

Source

pub fn get_latches(&self) -> Vec<AigNodeRef>

Retrieves latches reference.

Source

pub fn get_latches_id(&self) -> HashSet<NodeId>

Retrieves latches id.

Source

pub fn get_outputs(&self) -> Vec<AigEdge>

Retrieves outputs reference.

Source

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.

Source

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()
);
Source

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).

Source

pub fn add_output(&mut self, id: NodeId, complement: bool) -> Result<()>

Mark an existing node as an output.

Source

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.

Source

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

Source

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.

Trait Implementations§

Source§

impl Clone for Aig

Source§

fn clone(&self) -> Aig

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Aig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Aig

Source§

fn eq(&self, other: &Self) -> bool

Compares the two AIGs. They are equal iff:

  • their inputs are equal (in terms of set)
  • their outputs are equal
  • their latches are equal
  • their valid nodes are equal.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Aig

§

impl !RefUnwindSafe for Aig

§

impl !Send for Aig

§

impl !Sync for Aig

§

impl Unpin for Aig

§

impl !UnwindSafe for Aig

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.