abc/src/sat/csat/csat_apis.c
/**Function*************************************************************

  Synopsis    [Adds a gate to the circuit.]

  Description [The meaning of the parameters are:
    type: the type of the gate to be added
    name: the name of the gate to be added, name should be unique in a circuit.
    nofi: number of fanins of the gate to be added;
    fanins: the name array of fanins of the gate to be added.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Adds a gate to the circuit.]

Description [The meaning of the parameters are:
type: the type of the gate to be added
name: the name of the gate to be added, name should be unique in a circuit.
nofi: number of fanins of the gate to be added;
fanins: the name array of fanins of the gate to be added.]




Function Synopsis [ Adds a gate to the circuit . ] Description [ The meaning of the parameters are : type : the type of the gate to be added name : the name of the gate to be added name should be unique in a circuit . nofi : number of fanins of the gate to be added ; fanins : the name array of fanins of the gate to be added . ]
int ABC_AddGate( ABC_Manager mng, enum GateType type, char * name, int nofi, char ** fanins, int dc_attr )
{
    Abc_Obj_t * pObj = NULL; 
    Abc_Obj_t * pFanin;
    char * pSop = NULL; 
    char * pNewName;
    int i;
    pNewName = Mem_FlexEntryFetch( mng->pMmNames, strlen(name) + 1 );
    strcpy( pNewName, name );
    name = pNewName;
    switch( type )
    {
    case CSAT_BPI:
    case CSAT_BPPI:
        if ( nofi != 0 )
            { printf( "ABC_AddGate: The PI/PPI gate \"%s\" has fanins.\n", name ); return 0; }
        pObj = Abc_NtkCreatePi( mng->pNtk );
        stmm_insert( mng->tNode2Name, (char *)pObj, name );
        break;
    case CSAT_CONST:
    case CSAT_BAND:
    case CSAT_BNAND:
    case CSAT_BOR:
    case CSAT_BNOR:
    case CSAT_BXOR:
    case CSAT_BXNOR:
    case CSAT_BINV:
    case CSAT_BBUF:
        pObj = Abc_NtkCreateNode( mng->pNtk );
        for ( i = 0; i < nofi; i++ )
        {
            if ( !stmm_lookup( mng->tName2Node, fanins[i], (char **)&pFanin ) )
                { printf( "ABC_AddGate: The fanin gate \"%s\" is not in the network.\n", fanins[i] ); return 0; }
            Abc_ObjAddFanin( pObj, pFanin );
        }
         function
        switch( type )
        {
            case CSAT_CONST:
                if ( nofi != 0 )
                    { printf( "ABC_AddGate: The constant gate \"%s\" has fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateConst1( (Mem_Flex_t *)mng->pNtk->pManFunc );
                break;
            case CSAT_BAND:
                if ( nofi < 1 )
                    { printf( "ABC_AddGate: The AND gate \"%s\" no fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateAnd( (Mem_Flex_t *)mng->pNtk->pManFunc, nofi, NULL );
                break;
            case CSAT_BNAND:
                if ( nofi < 1 )
                    { printf( "ABC_AddGate: The NAND gate \"%s\" no fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateNand( (Mem_Flex_t *)mng->pNtk->pManFunc, nofi );
                break;
            case CSAT_BOR:
                if ( nofi < 1 )
                    { printf( "ABC_AddGate: The OR gate \"%s\" no fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateOr( (Mem_Flex_t *)mng->pNtk->pManFunc, nofi, NULL );
                break;
            case CSAT_BNOR:
                if ( nofi < 1 )
                    { printf( "ABC_AddGate: The NOR gate \"%s\" no fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateNor( (Mem_Flex_t *)mng->pNtk->pManFunc, nofi );
                break;
            case CSAT_BXOR:
                if ( nofi < 1 )
                    { printf( "ABC_AddGate: The XOR gate \"%s\" no fanins.\n", name ); return 0; }
                if ( nofi > 2 )
                    { printf( "ABC_AddGate: The XOR gate \"%s\" has more than two fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateXor( (Mem_Flex_t *)mng->pNtk->pManFunc, nofi );
                break;
            case CSAT_BXNOR:
                if ( nofi < 1 )
                    { printf( "ABC_AddGate: The XNOR gate \"%s\" no fanins.\n", name ); return 0; }
                if ( nofi > 2 )
                    { printf( "ABC_AddGate: The XNOR gate \"%s\" has more than two fanins.\n", name ); return 0; }
                pSop = Abc_SopCreateNxor( (Mem_Flex_t *)mng->pNtk->pManFunc, nofi );
                break;
            case CSAT_BINV:
                if ( nofi != 1 )
                    { printf( "ABC_AddGate: The inverter gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
                pSop = Abc_SopCreateInv( (Mem_Flex_t *)mng->pNtk->pManFunc );
                break;
            case CSAT_BBUF:
                if ( nofi != 1 )
                    { printf( "ABC_AddGate: The buffer gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
                pSop = Abc_SopCreateBuf( (Mem_Flex_t *)mng->pNtk->pManFunc );
                break;
            default :
                break;
        }
        Abc_ObjSetData( pObj, pSop );
        break;
    case CSAT_BPPO:
    case CSAT_BPO:
        if ( nofi != 1 )
            { printf( "ABC_AddGate: The PO/PPO gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
        pObj = Abc_NtkCreatePo( mng->pNtk );
        stmm_insert( mng->tNode2Name, (char *)pObj, name );
        if ( !stmm_lookup( mng->tName2Node, fanins[0], (char **)&pFanin ) )
            { printf( "ABC_AddGate: The fanin gate \"%s\" is not in the network.\n", fanins[0] ); return 0; }
        Abc_ObjAddFanin( pObj, pFanin );
        break;
    default:
        printf( "ABC_AddGate: Unknown gate type.\n" );
        break;
    }
    if ( stmm_insert( mng->tName2Node, name, (char *)pObj ) )
        { printf( "ABC_AddGate: The same gate \"%s\" is added twice.\n", name ); return 0; }
    return 1;
}
int ABC_AddGate ( ABC_Manager mng , enum GateType type , char * name , int nofi , char * * fanins , int dc_attr ) { Abc_Obj_t * pObj = NULL ; Abc_Obj_t * pFanin ; char * pSop = NULL ; char * pNewName ; int i ; pNewName = Mem_FlexEntryFetch ( mng -> pMmNames , strlen ( name ) + 1 ) ; strcpy ( pNewName , name ) ; name = pNewName ; switch ( type ) { case CSAT_BPI : case CSAT_BPPI : if ( nofi != 0 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pObj = Abc_NtkCreatePi ( mng -> pNtk ) ; stmm_insert ( mng -> tNode2Name , ( char * ) pObj , name ) ; break ; case CSAT_CONST : case CSAT_BAND : case CSAT_BNAND : case CSAT_BOR : case CSAT_BNOR : case CSAT_BXOR : case CSAT_BXNOR : case CSAT_BINV : case CSAT_BBUF : pObj = Abc_NtkCreateNode ( mng -> pNtk ) ; for ( i = 0 ; i < nofi ; i ++ ) { if ( ! stmm_lookup ( mng -> tName2Node , fanins [ i ] , ( char * * ) & pFanin ) ) { printf ( " \" \" \n " , fanins [ i ] ) ; return 0 ; } Abc_ObjAddFanin ( pObj , pFanin ) ; } switch ( type ) { case CSAT_CONST : if ( nofi != 0 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateConst1 ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc ) ; break ; case CSAT_BAND : if ( nofi < 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateAnd ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc , nofi , NULL ) ; break ; case CSAT_BNAND : if ( nofi < 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateNand ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc , nofi ) ; break ; case CSAT_BOR : if ( nofi < 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateOr ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc , nofi , NULL ) ; break ; case CSAT_BNOR : if ( nofi < 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateNor ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc , nofi ) ; break ; case CSAT_BXOR : if ( nofi < 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } if ( nofi > 2 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateXor ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc , nofi ) ; break ; case CSAT_BXNOR : if ( nofi < 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } if ( nofi > 2 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateNxor ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc , nofi ) ; break ; case CSAT_BINV : if ( nofi != 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateInv ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc ) ; break ; case CSAT_BBUF : if ( nofi != 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pSop = Abc_SopCreateBuf ( ( Mem_Flex_t * ) mng -> pNtk -> pManFunc ) ; break ; default : break ; } Abc_ObjSetData ( pObj , pSop ) ; break ; case CSAT_BPPO : case CSAT_BPO : if ( nofi != 1 ) { printf ( " \" \" \n " , name ) ; return 0 ; } pObj = Abc_NtkCreatePo ( mng -> pNtk ) ; stmm_insert ( mng -> tNode2Name , ( char * ) pObj , name ) ; if ( ! stmm_lookup ( mng -> tName2Node , fanins [ 0 ] , ( char * * ) & pFanin ) ) { printf ( " \" \" \n " , fanins [ 0 ] ) ; return 0 ; } Abc_ObjAddFanin ( pObj , pFanin ) ; break ; default : printf ( " \n " ) ; break ; } if ( stmm_insert ( mng -> tName2Node , name , ( char * ) pObj ) ) { printf ( " \" \" \n " , name ) ; return 0 ; } return 1 ; }
Function
Synopsis    [Adds a gate to the circuit.]
Function Synopsis [ Adds a gate to the circuit . ]
// Suppress "might be used uninitialized" // Suppress "might be used uninitialized" // save the name in the local memory manager // consider different cases, create the node, and map the node into the name // create the PI // create the node // create the fanins // create the node function // create the PO // connect to the PO fanin // map the name into the node