abc/src/aig/ivy/ivySeq.c
/**Function*************************************************************

  Synopsis    [Counts the number of new nodes added when using this graph.]

  Description [AIG nodes for the fanins should be assigned to pNode->pFunc 
  of the leaves of the graph before calling this procedure. 
  Returns -1 if the number of nodes and levels exceeded the given limit or 
  the number of levels exceeded the maximum allowed level.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Counts the number of new nodes added when using this graph.]

Description [AIG nodes for the fanins should be assigned to pNode->pFunc
of the leaves of the graph before calling this procedure.
Returns -1 if the number of nodes and levels exceeded the given limit or
the number of levels exceeded the maximum allowed level.]




Function Synopsis [ Counts the number of new nodes added when using this graph . ] Description [ AIG nodes for the fanins should be assigned to pNode - > pFunc of the leaves of the graph before calling this procedure . Returns - 1 if the number of nodes and levels exceeded the given limit or the number of levels exceeded the maximum allowed level . ]
int Ivy_GraphToNetworkSeqCountSeq( Ivy_Man_t * p, Ivy_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax )
{
    Dec_Node_t * pNode, * pNode0, * pNode1;
    Ivy_Obj_t * pAnd, * pAnd0, * pAnd1;
    int i, k, Counter, fCompl;
    if ( Dec_GraphIsConst(pGraph) || Dec_GraphIsVar(pGraph) )
        return 0;
    Counter = 0;
    Dec_GraphForEachNode( pGraph, pNode, i )
    {
        pNode0 = Dec_GraphNode( pGraph, pNode->eEdge0.Node );
        pNode1 = Dec_GraphNode( pGraph, pNode->eEdge1.Node );
        pAnd0 = (Ivy_Obj_t *)pNode0->pFunc; 
        pAnd1 = (Ivy_Obj_t *)pNode1->pFunc; 
        for ( k = 0; pAnd0 && k < (int)pNode->nLat0; k++ )
        {
            fCompl = Ivy_IsComplement(pAnd0);
            pAnd0 = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, Ivy_Regular(pAnd0), NULL, IVY_LATCH, IVY_INIT_DC) );
            if ( pAnd0 )
                pAnd0 = Ivy_NotCond( pAnd0, fCompl );
        }
        for ( k = 0; pAnd1 && k < (int)pNode->nLat1; k++ )
        {
            fCompl = Ivy_IsComplement(pAnd1);
            pAnd1 = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, Ivy_Regular(pAnd1), NULL, IVY_LATCH, IVY_INIT_DC) );
            if ( pAnd1 )
                pAnd1 = Ivy_NotCond( pAnd1, fCompl );
        }
        if ( pAnd0 && pAnd1 )
        {
            pAnd0 = Ivy_NotCond( pAnd0, pNode->eEdge0.fCompl );
            pAnd1 = Ivy_NotCond( pAnd1, pNode->eEdge1.fCompl );
            assert( !Ivy_ObjIsLatch(Ivy_Regular(pAnd0)) || !Ivy_ObjIsLatch(Ivy_Regular(pAnd1)) );
            if ( Ivy_Regular(pAnd0) == Ivy_Regular(pAnd1) || Ivy_ObjIsConst1(Ivy_Regular(pAnd0)) || Ivy_ObjIsConst1(Ivy_Regular(pAnd1)) )
                pAnd = Ivy_And( p, pAnd0, pAnd1 );
            else
                pAnd = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, pAnd0, pAnd1, IVY_AND, IVY_INIT_NONE) );
            if ( Ivy_Regular(pAnd) == pRoot )
                return -1;
        }
        else
            pAnd = NULL;
        if ( pAnd == NULL || Ivy_ObjIsTravIdCurrent(p, Ivy_Regular(pAnd)) )
        {
            if ( ++Counter > NodeMax )
                return -1;
        }
        pNode->pFunc = pAnd;
    }
    return Counter;
}
int Ivy_GraphToNetworkSeqCountSeq ( Ivy_Man_t * p , Ivy_Obj_t * pRoot , Dec_Graph_t * pGraph , int NodeMax ) { Dec_Node_t * pNode , * pNode0 , * pNode1 ; Ivy_Obj_t * pAnd , * pAnd0 , * pAnd1 ; int i , k , Counter , fCompl ; if ( Dec_GraphIsConst ( pGraph ) || Dec_GraphIsVar ( pGraph ) ) return 0 ; Counter = 0 ; Dec_GraphForEachNode ( pGraph , pNode , i ) { pNode0 = Dec_GraphNode ( pGraph , pNode -> eEdge0 . Node ) ; pNode1 = Dec_GraphNode ( pGraph , pNode -> eEdge1 . Node ) ; pAnd0 = ( Ivy_Obj_t * ) pNode0 -> pFunc ; pAnd1 = ( Ivy_Obj_t * ) pNode1 -> pFunc ; for ( k = 0 ; pAnd0 && k < ( int ) pNode -> nLat0 ; k ++ ) { fCompl = Ivy_IsComplement ( pAnd0 ) ; pAnd0 = Ivy_TableLookup ( p , Ivy_ObjCreateGhost ( p , Ivy_Regular ( pAnd0 ) , NULL , IVY_LATCH , IVY_INIT_DC ) ) ; if ( pAnd0 ) pAnd0 = Ivy_NotCond ( pAnd0 , fCompl ) ; } for ( k = 0 ; pAnd1 && k < ( int ) pNode -> nLat1 ; k ++ ) { fCompl = Ivy_IsComplement ( pAnd1 ) ; pAnd1 = Ivy_TableLookup ( p , Ivy_ObjCreateGhost ( p , Ivy_Regular ( pAnd1 ) , NULL , IVY_LATCH , IVY_INIT_DC ) ) ; if ( pAnd1 ) pAnd1 = Ivy_NotCond ( pAnd1 , fCompl ) ; } if ( pAnd0 && pAnd1 ) { pAnd0 = Ivy_NotCond ( pAnd0 , pNode -> eEdge0 . fCompl ) ; pAnd1 = Ivy_NotCond ( pAnd1 , pNode -> eEdge1 . fCompl ) ; assert ( ! Ivy_ObjIsLatch ( Ivy_Regular ( pAnd0 ) ) || ! Ivy_ObjIsLatch ( Ivy_Regular ( pAnd1 ) ) ) ; if ( Ivy_Regular ( pAnd0 ) == Ivy_Regular ( pAnd1 ) || Ivy_ObjIsConst1 ( Ivy_Regular ( pAnd0 ) ) || Ivy_ObjIsConst1 ( Ivy_Regular ( pAnd1 ) ) ) pAnd = Ivy_And ( p , pAnd0 , pAnd1 ) ; else pAnd = Ivy_TableLookup ( p , Ivy_ObjCreateGhost ( p , pAnd0 , pAnd1 , IVY_AND , IVY_INIT_NONE ) ) ; if ( Ivy_Regular ( pAnd ) == pRoot ) return -1 ; } else pAnd = NULL ; if ( pAnd == NULL || Ivy_ObjIsTravIdCurrent ( p , Ivy_Regular ( pAnd ) ) ) { if ( ++ Counter > NodeMax ) return -1 ; } pNode -> pFunc = pAnd ; } return Counter ; }
Function
Synopsis    [Counts the number of new nodes added when using this graph.]
Function Synopsis [ Counts the number of new nodes added when using this graph . ]
// check for constant function or a literal // compute the AIG size after adding the internal nodes // get the children of this node // get the AIG nodes corresponding to the children  // skip the latches // get the new node // if they are both present, find the resulting node // return -1 if the node is the same as the original root // count the number of added nodes