abc/src/bdd/cudd/cuddExport.c
/**Function********************************************************************

  Synopsis    [Writes a blif file representing the argument BDDs.]

  Description [Writes a blif file representing the argument BDDs as a
  network of multiplexers. One multiplexer is written for each BDD
  node. It returns 1 in case of success; 0 otherwise (e.g.,
  out-of-memory, file system full, or an ADD with constants different
  from 0 and 1).  Cudd_DumpBlif does not close the file: This is the
  caller responsibility. Cudd_DumpBlif uses a minimal unique subset of
  the hexadecimal address of a node as name for it.  If the argument
  inames is non-null, it is assumed to hold the pointers to the names
  of the inputs. Similarly for onames.]

  SideEffects [None]

  SeeAlso     [Cudd_DumpBlifBody Cudd_DumpDot Cudd_PrintDebug Cudd_DumpDDcal
  Cudd_DumpDaVinci Cudd_DumpFactoredForm]

******************************************************************************/
Function
Synopsis    [Writes a blif file representing the argument BDDs.]

Description [Writes a blif file representing the argument BDDs as a
network of multiplexers. One multiplexer is written for each BDD
node. It returns 1 in case of success; 0 otherwise .  Cudd_DumpBlif does not close the file: This is the
caller responsibility. Cudd_DumpBlif uses a minimal unique subset of
the hexadecimal address of a node as name for it.  If the argument
inames is non-null, it is assumed to hold the pointers to the names
of the inputs. Similarly for onames.]




Function Synopsis [ Writes a blif file representing the argument BDDs . ] Description [ Writes a blif file representing the argument BDDs as a network of multiplexers . One multiplexer is written for each BDD node . It returns 1 in case of success ; 0 otherwise . Cudd_DumpBlif does not close the file : This is the caller responsibility . Cudd_DumpBlif uses a minimal unique subset of the hexadecimal address of a node as name for it . If the argument inames is non - null it is assumed to hold the pointers to the names of the inputs . Similarly for onames . ]
int
Cudd_DumpBlif(
  DdManager * dd ,
  int  n ,
  DdNode ** f ,
  char ** inames ,
  char ** onames ,
  char * mname ,
  FILE * fp ,
  int mv )
{
    DdNode      *support = NULL;
    DdNode      *scan;
    int         *sorted = NULL;
    int         nvars = dd->size;
    int         retval;
    int         i;
    sorted = ABC_ALLOC(int,nvars);
    if (sorted == NULL) {
        dd->errorCode = CUDD_MEMORY_OUT;
        goto failure;
    }
    for (i = 0; i < nvars; i++) sorted[i] = 0;
    support = Cudd_VectorSupport(dd,f,n);
    if (support == NULL) goto failure;
    cuddRef(support);
    scan = support;
    while (!cuddIsConstant(scan)) {
        sorted[scan->index] = 1;
        scan = cuddT(scan);
    }
    Cudd_RecursiveDeref(dd,support);
    support = NULL; 
    if (mname == NULL) {
        retval = fprintf(fp,".model DD\n.inputs");
    } else {
        retval = fprintf(fp,".model %s\n.inputs",mname);
    }
    if (retval == EOF) {
        ABC_FREE(sorted);
        return(0);
    }
    for (i = 0; i < nvars; i++) {
        if (sorted[i]) {
            if (inames == NULL) {
                retval = fprintf(fp," %d", i);
            } else {
                retval = fprintf(fp," %s", inames[i]);
            }
            if (retval == EOF) goto failure;
        }
    }
    ABC_FREE(sorted);
    sorted = NULL;
    retval = fprintf(fp,"\n.outputs");
    if (retval == EOF) goto failure;
    for (i = 0; i < n; i++) {
        if (onames == NULL) {
            retval = fprintf(fp," f%d", i);
        } else {
            retval = fprintf(fp," %s", onames[i]);
        }
        if (retval == EOF) goto failure;
    }
    retval = fprintf(fp,"\n");
    if (retval == EOF) goto failure;
    retval = Cudd_DumpBlifBody(dd, n, f, inames, onames, fp, mv);
    if (retval == 0) goto failure;
    retval = fprintf(fp,".end\n");
    if (retval == EOF) goto failure;
    return(1);
failure:
    if (sorted != NULL) ABC_FREE(sorted);
    if (support != NULL) Cudd_RecursiveDeref(dd,support);
    return(0);
}
int Cudd_DumpBlif ( DdManager * dd , int n , DdNode * * f , char * * inames , char * * onames , char * mname , FILE * fp , int mv ) { DdNode * support = NULL ; DdNode * scan ; int * sorted = NULL ; int nvars = dd -> size ; int retval ; int i ; sorted = ABC_ALLOC ( int , nvars ) ; if ( sorted == NULL ) { dd -> errorCode = CUDD_MEMORY_OUT ; goto failure ; } for ( i = 0 ; i < nvars ; i ++ ) sorted [ i ] = 0 ; support = Cudd_VectorSupport ( dd , f , n ) ; if ( support == NULL ) goto failure ; cuddRef ( support ) ; scan = support ; while ( ! cuddIsConstant ( scan ) ) { sorted [ scan -> index ] = 1 ; scan = cuddT ( scan ) ; } Cudd_RecursiveDeref ( dd , support ) ; support = NULL ; if ( mname == NULL ) { retval = fprintf ( fp , " \n " ) ; } else { retval = fprintf ( fp , " \n " , mname ) ; } if ( retval == EOF ) { ABC_FREE ( sorted ) ; return ( 0 ) ; } for ( i = 0 ; i < nvars ; i ++ ) { if ( sorted [ i ] ) { if ( inames == NULL ) { retval = fprintf ( fp , " " , i ) ; } else { retval = fprintf ( fp , " " , inames [ i ] ) ; } if ( retval == EOF ) goto failure ; } } ABC_FREE ( sorted ) ; sorted = NULL ; retval = fprintf ( fp , " \n " ) ; if ( retval == EOF ) goto failure ; for ( i = 0 ; i < n ; i ++ ) { if ( onames == NULL ) { retval = fprintf ( fp , " " , i ) ; } else { retval = fprintf ( fp , " " , onames [ i ] ) ; } if ( retval == EOF ) goto failure ; } retval = fprintf ( fp , " \n " ) ; if ( retval == EOF ) goto failure ; retval = Cudd_DumpBlifBody ( dd , n , f , inames , onames , fp , mv ) ; if ( retval == 0 ) goto failure ; retval = fprintf ( fp , " \n " ) ; if ( retval == EOF ) goto failure ; return ( 1 ) ; failure : if ( sorted != NULL ) ABC_FREE ( sorted ) ; if ( support != NULL ) Cudd_RecursiveDeref ( dd , support ) ; return ( 0 ) ; }
Function
Synopsis    [Writes a blif file representing the argument BDDs.]
Function Synopsis [ Writes a blif file representing the argument BDDs . ]
/* manager */ /* number of output nodes to be dumped */ /* array of output nodes to be dumped */ /* array of input names (or NULL) */ /* array of output names (or NULL) */ /* model name (or NULL) */ /* pointer to the dump file */ /* 0: blif, 1: blif-MV */ /* Build a bit array with the support of f. */ /* Take the union of the supports of each output function. */ /* so that we do not try to free it in case of failure */ /* Write the header (.model .inputs .outputs). */ /* Write the input list by scanning the support array. */ /* Write the .output line. */ /* Write trailer and return. */