static int DddmpCuddDdArrayStorePrefixBody ( DdManager *ddMgr /* IN: Manager */, int n /* IN: Number of output nodes to be dumped */, DdNode **f /* IN: Array of output nodes to be dumped */, char **inputNames /* IN: Array of input names (or NULL) */, char **outputNames /* IN: Array of output names (or NULL) */, FILE *fp /* IN: Pointer to the dump file */ ) { st_table *visited = NULL; int retValue; int i; /* Initialize symbol table for visited nodes. */ visited = st_init_table(st_ptrcmp, st_ptrhash); Dddmp_CheckAndGotoLabel (visited==NULL, "Error if function st_init_table.", failure); /* Call the function that really gets the job done. */ for (i = 0; i < n; i++) { retValue = DddmpCuddDdArrayStorePrefixStep (ddMgr, Cudd_Regular(f[i]), fp, visited, inputNames); Dddmp_CheckAndGotoLabel (retValue==0, "Error if function DddmpCuddDdArrayStorePrefixStep.", failure); } /* To account for the possible complement on the root, ** we put either a buffer or an inverter at the output of ** the multiplexer representing the top node. */ for (i=0; i<n; i++) { if (outputNames == NULL) { retValue = fprintf (fp, "(BUF outNode%d ", i); } else { retValue = fprintf (fp, "(BUF %s ", outputNames[i]); } Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); if (Cudd_IsComplement(f[i])) { retValue = fprintf (fp, "(NOT node%" PRIxPTR "))\n", (ptruint) f[i] / sizeof(DdNode)); } else { retValue = fprintf (fp, "node%" PRIxPTR ")\n", (ptruint) f[i] / sizeof(DdNode)); } Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); } st_free_table (visited); return(1); failure: if (visited != NULL) st_free_table(visited); return(0); }
int Dddmp_cuddHeaderLoad ( Dddmp_DecompType *ddType /* OUT: selects the proper decomp type */, int *nVars /* OUT: number of DD variables */, int *nsuppvars /* OUT: number of support variables */, char ***suppVarNames /* OUT: array of support variable names */, char ***orderedVarNames /* OUT: array of variable names */, int **varIds /* OUT: array of variable ids */, int **varComposeIds /* OUT: array of permids ids */, int **varAuxIds /* OUT: array of variable aux ids */, int *nRoots /* OUT: number of root in the file */, char *file /* IN: file name */, FILE *fp /* IN: file pointer */ ) { Dddmp_Hdr_t *Hdr; int i, fileToClose; int *tmpVarIds = NULL; int *tmpVarComposeIds = NULL; int *tmpVarAuxIds = NULL; fileToClose = 0; if (fp == NULL) { fp = fopen (file, "r"); Dddmp_CheckAndGotoLabel (fp==NULL, "Error opening file.", failure); fileToClose = 1; } Hdr = DddmpBddReadHeader (NULL, fp); Dddmp_CheckAndGotoLabel (Hdr->nnodes==0, "Zero number of nodes.", failure); /* * Type, number of variables (tot and support) */ *ddType = Hdr->ddType; *nVars = Hdr->nVars; *nsuppvars = Hdr->nsuppvars; /* * Support Varnames */ if (Hdr->suppVarNames != NULL) { *suppVarNames = DDDMP_ALLOC (char *, *nsuppvars); Dddmp_CheckAndGotoLabel (*suppVarNames==NULL, "Error allocating memory.", failure); for (i=0; i<*nsuppvars; i++) { (*suppVarNames)[i] = DDDMP_ALLOC (char, (strlen (Hdr->suppVarNames[i]) + 1)); Dddmp_CheckAndGotoLabel (Hdr->suppVarNames[i]==NULL, "Support Variable Name Missing in File.", failure); strcpy ((*suppVarNames)[i], Hdr->suppVarNames[i]); } } else {
static int DddmpCuddDdArrayStoreBlif ( DdManager *ddMgr /* IN: Manager */, int n /* IN: Number of output nodes to be dumped */, DdNode **f /* IN: Array of output nodes to be dumped */, char **inputNames /* IN: Array of input names (or NULL) */, char **outputNames /* IN: Array of output names (or NULL) */, char *modelName /* IN: Model name (or NULL) */, FILE *fp /* IN: Pointer to the dump file */ ) { DdNode *support = NULL; DdNode *scan; int *sorted = NULL; int nVars = ddMgr->size; int retValue; int i; /* Build a bit array with the support of f. */ sorted = ALLOC (int, nVars); if (sorted == NULL) { ddMgr->errorCode = CUDD_MEMORY_OUT; Dddmp_CheckAndGotoLabel (1, "Allocation Error.", failure); } for (i = 0; i < nVars; i++) { sorted[i] = 0; } /* Take the union of the supports of each output function. */ support = Cudd_VectorSupport(ddMgr,f,n); Dddmp_CheckAndGotoLabel (support==NULL, "Error in function Cudd_VectorSupport.", failure); cuddRef(support); scan = support; while (!cuddIsConstant(scan)) { sorted[scan->index] = 1; scan = cuddT(scan); } Cudd_RecursiveDeref(ddMgr,support); support = NULL; /* so that we do not try to free it in case of failure */ /* Write the header (.model .inputs .outputs). */ if (modelName == NULL) { retValue = fprintf(fp,".model DD\n.inputs"); } else { retValue = fprintf(fp,".model %s\n.inputs", modelName); } if (retValue == EOF) { return(0); } /* Write the input list by scanning the support array. */ for (i = 0; i < nVars; i++) { if (sorted[i]) { if (inputNames == NULL || (inputNames[i] == NULL)) { retValue = fprintf(fp," inNode%d", i); } else { retValue = fprintf(fp," %s", inputNames[i]); } Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); } } FREE(sorted); sorted = NULL; /* Write the .output line. */ retValue = fprintf(fp,"\n.outputs"); Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); for (i = 0; i < n; i++) { if (outputNames == NULL || (outputNames[i] == NULL)) { retValue = fprintf(fp," outNode%d", i); } else { retValue = fprintf(fp," %s", outputNames[i]); } Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); } retValue = fprintf(fp,"\n"); Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); retValue = DddmpCuddDdArrayStoreBlifBody(ddMgr, n, f, inputNames, outputNames, fp); Dddmp_CheckAndGotoLabel (retValue==0, "Error if function DddmpCuddDdArrayStoreBlifBody.", failure); /* Write trailer and return. */ retValue = fprintf (fp, ".end\n"); Dddmp_CheckAndGotoLabel (retValue==EOF, "Error during file store.", failure); return(1); failure: if (sorted != NULL) { FREE(sorted); } if (support != NULL) { Cudd_RecursiveDeref(ddMgr,support); } return(0); }
int Dddmp_cuddBddArrayStoreSmv ( DdManager *ddMgr /* IN: DD Manager */, int nroots /* IN: number of output BDD roots to be stored */, DdNode **f /* IN: array of BDD roots to be stored */, char **inputNames /* IN: array of variable names (or NULL) */, char **outputNames /* IN: array of root names (or NULL) */, char *modelName /* IN: Model Name */, char *fname /* IN: File name */, FILE *fp /* IN: File pointer to the store file */ ) { int retValue; int fileToClose = 0; #ifdef DDDMP_DEBUG #ifndef __alpha__ int retValueBis; retValueBis = Cudd_DebugCheck (ddMgr); if (retValueBis == 1) { fprintf (stderr, "Inconsistency Found During BDD Store.\n"); fflush (stderr); } else { if (retValueBis == CUDD_OUT_OF_MEM) { fprintf (stderr, "Out of Memory During BDD Store.\n"); fflush (stderr); } } #endif #endif /* * Check if File needs to be opened in the proper mode. */ if (fp == NULL) { fp = fopen (fname, "w"); Dddmp_CheckAndGotoLabel (fp==NULL, "Error opening file.", failure); fileToClose = 1; } retValue = DddmpCuddDdArrayStoreSmv (ddMgr, nroots, f, inputNames, outputNames, modelName, fp); if (fileToClose) { fclose (fp); } #ifdef DDDMP_DEBUG #ifndef __alpha__ retValueBis = Cudd_DebugCheck (ddMgr); if (retValueBis == 1) { fprintf (stderr, "Inconsistency Found During BDD Store.\n"); fflush (stderr); } else { if (retValueBis == CUDD_OUT_OF_MEM) { fprintf (stderr, "Out of Memory During BDD Store.\n"); fflush (stderr); } } #endif #endif return (retValue); failure: return (DDDMP_FAILURE); }