You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
13 KiB

3 months ago
  1. /**CHeaderFile*****************************************************************
  2. FileName [dddmp.h]
  3. PackageName [dddmp]
  4. Synopsis [Functions to read in and write out BDDs, ADDs
  5. and CNF formulas from and to files.]
  6. Description []
  7. Author [Gianpiero Cabodi and Stefano Quer]
  8. Copyright [
  9. Copyright (c) 2002 by Politecnico di Torino.
  10. All Rights Reserved. This software is for educational purposes only.
  11. Permission is given to academic institutions to use, copy, and modify
  12. this software and its documentation provided that this introductory
  13. message is not removed, that this software and its documentation is
  14. used for the institutions' internal research and educational purposes,
  15. and that no monies are exchanged. No guarantee is expressed or implied
  16. by the distribution of this code.
  17. Send bug-reports and/or questions to:
  18. {gianpiero.cabodi,stefano.quer}@polito.it.
  19. ]
  20. ******************************************************************************/
  21. #ifndef _DDDMP
  22. #define _DDDMP
  23. #if 0
  24. #define DDDMP_DEBUG
  25. #endif
  26. /*---------------------------------------------------------------------------*/
  27. /* Nested includes */
  28. /*---------------------------------------------------------------------------*/
  29. #include "util.h"
  30. #include "cudd.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /*---------------------------------------------------------------------------*/
  35. /* Constant declarations */
  36. /*---------------------------------------------------------------------------*/
  37. /*
  38. * Dddmp format version
  39. */
  40. #define DDDMP_VERSION "DDDMP-2.0"
  41. /*
  42. * Returned values (for theorically ALL the function of the package)
  43. */
  44. #define DDDMP_FAILURE 0
  45. #define DDDMP_SUCCESS 1
  46. /*
  47. * Format modes for DD (BDD and ADD) files
  48. */
  49. #define DDDMP_MODE_TEXT ((int)'A')
  50. #define DDDMP_MODE_BINARY ((int)'B')
  51. #define DDDMP_MODE_DEFAULT ((int)'D')
  52. /*---------------------------------------------------------------------------*/
  53. /* Structure declarations */
  54. /*---------------------------------------------------------------------------*/
  55. /*---------------------------------------------------------------------------*/
  56. /* Type declarations */
  57. /*---------------------------------------------------------------------------*/
  58. /**Enum************************************************************************
  59. Synopsis [Format modes for storing CNF files]
  60. Description [Type supported for storing BDDs into CNF
  61. formulas.
  62. Used internally to select the proper storing format:
  63. DDDMP_CNF_MODE_NODE: create a CNF temporary variables for
  64. each BDD node
  65. DDDMP_CNF_MODE_MAXTERM: no temporary variables
  66. DDDMP_CNF_MODE_BEST: trade-off between the two previous methods
  67. ]
  68. ******************************************************************************/
  69. typedef enum {
  70. DDDMP_CNF_MODE_NODE,
  71. DDDMP_CNF_MODE_MAXTERM,
  72. DDDMP_CNF_MODE_BEST
  73. } Dddmp_DecompCnfStoreType;
  74. /**Enum************************************************************************
  75. Synopsis [Format modes for loading CNF files.]
  76. Description [Type supported for loading CNF formulas into BDDs.
  77. Used internally to select the proper returning format:
  78. ]
  79. ******************************************************************************/
  80. typedef enum {
  81. DDDMP_CNF_MODE_NO_CONJ,
  82. DDDMP_CNF_MODE_NO_QUANT,
  83. DDDMP_CNF_MODE_CONJ_QUANT
  84. } Dddmp_DecompCnfLoadType;
  85. /**Enum************************************************************************
  86. Synopsis [Type for supported decomposition types.]
  87. Description [Type for supported decomposition types.
  88. Used internally to select the proper type (bdd, add, ...).
  89. Given externally as information fule content.
  90. ]
  91. ******************************************************************************/
  92. typedef enum {
  93. DDDMP_BDD,
  94. DDDMP_ADD,
  95. DDDMP_CNF,
  96. DDDMP_NONE
  97. } Dddmp_DecompType;
  98. /**Enum************************************************************************
  99. Synopsis [Type for variable extra info.]
  100. Description [Type for variable extra info. Used to specify info stored
  101. in text mode.]
  102. ******************************************************************************/
  103. typedef enum {
  104. DDDMP_VARIDS,
  105. DDDMP_VARPERMIDS,
  106. DDDMP_VARAUXIDS,
  107. DDDMP_VARNAMES,
  108. DDDMP_VARDEFAULT
  109. } Dddmp_VarInfoType;
  110. /**Enum************************************************************************
  111. Synopsis [Type for variable matching in BDD load.]
  112. Description []
  113. ******************************************************************************/
  114. typedef enum {
  115. DDDMP_VAR_MATCHIDS,
  116. DDDMP_VAR_MATCHPERMIDS,
  117. DDDMP_VAR_MATCHAUXIDS,
  118. DDDMP_VAR_MATCHNAMES,
  119. DDDMP_VAR_COMPOSEIDS
  120. } Dddmp_VarMatchType;
  121. /**Enum************************************************************************
  122. Synopsis [Type for BDD root matching in BDD load.]
  123. Description []
  124. ******************************************************************************/
  125. typedef enum {
  126. DDDMP_ROOT_MATCHNAMES,
  127. DDDMP_ROOT_MATCHLIST
  128. } Dddmp_RootMatchType;
  129. typedef struct Dddmp_Hdr_s Dddmp_Hdr_t;
  130. /*---------------------------------------------------------------------------*/
  131. /* Variable declarations */
  132. /*---------------------------------------------------------------------------*/
  133. /*---------------------------------------------------------------------------*/
  134. /* Macro declarations */
  135. /*---------------------------------------------------------------------------*/
  136. /**Macro***********************************************************************
  137. Synopsis [Checks for fatal bugs]
  138. Description [Conditional safety assertion. It prints out the file
  139. name and line number where the fatal error occurred.
  140. Messages are printed out on stderr.
  141. ]
  142. SideEffects [None]
  143. SeeAlso []
  144. ******************************************************************************/
  145. #ifdef DDDMP_DEBUG
  146. # define Dddmp_Assert(expr,errMsg) \
  147. { \
  148. if ((expr) == 0) { \
  149. fprintf (stderr, "FATAL ERROR: %s\n", errMsg); \
  150. fprintf (stderr, " File %s -> Line %d\n", \
  151. __FILE__, __LINE__); \
  152. fflush (stderr); \
  153. exit (DDDMP_FAILURE); \
  154. } \
  155. }
  156. #else
  157. # define Dddmp_Assert(expr,errMsg) \
  158. {}
  159. #endif
  160. /**Macro***********************************************************************
  161. Synopsis [Checks for Warnings: If expr==1 it prints out the warning
  162. on stderr.]
  163. Description []
  164. SideEffects [None]
  165. SeeAlso []
  166. ******************************************************************************/
  167. #define Dddmp_Warning(expr,errMsg) \
  168. { \
  169. if ((expr) == 1) { \
  170. fprintf (stderr, "WARNING: %s\n", errMsg); \
  171. fprintf (stderr, " File %s -> Line %d\n", \
  172. __FILE__, __LINE__); \
  173. fflush (stderr); \
  174. } \
  175. }
  176. /**Macro***********************************************************************
  177. Synopsis [Checks for fatal bugs and return the DDDMP_FAILURE flag.]
  178. Description []
  179. SideEffects [None]
  180. SeeAlso []
  181. ******************************************************************************/
  182. #define Dddmp_CheckAndReturn(expr,errMsg) \
  183. { \
  184. if ((expr) == 1) { \
  185. fprintf (stderr, "FATAL ERROR: %s\n", errMsg); \
  186. fprintf (stderr, " File %s -> Line %d\n", \
  187. __FILE__, __LINE__); \
  188. fflush (stderr); \
  189. return (DDDMP_FAILURE); \
  190. } \
  191. }
  192. /**Macro***********************************************************************
  193. Synopsis [Checks for fatal bugs and go to the label to deal with
  194. the error.
  195. ]
  196. Description []
  197. SideEffects [None]
  198. SeeAlso []
  199. ******************************************************************************/
  200. #define Dddmp_CheckAndGotoLabel(expr,errMsg,label) \
  201. { \
  202. if ((expr) == 1) { \
  203. fprintf (stderr, "FATAL ERROR: %s\n", errMsg); \
  204. fprintf (stderr, " File %s -> Line %d\n", \
  205. __FILE__, __LINE__); \
  206. fflush (stderr); \
  207. goto label; \
  208. } \
  209. }
  210. /**AutomaticStart*************************************************************/
  211. /*---------------------------------------------------------------------------*/
  212. /* Function prototypes */
  213. /*---------------------------------------------------------------------------*/
  214. extern int Dddmp_Text2Bin(char *filein, char *fileout);
  215. extern int Dddmp_Bin2Text(char *filein, char *fileout);
  216. extern int Dddmp_cuddBddDisplayBinary(char *fileIn, char *fileOut);
  217. extern DdNode * Dddmp_cuddBddLoad(DdManager *ddMgr, Dddmp_VarMatchType varMatchMode, char **varmatchnames, int *varmatchauxids, int *varcomposeids, int mode, char *file, FILE *fp);
  218. extern int Dddmp_cuddBddArrayLoad(DdManager *ddMgr, Dddmp_RootMatchType rootMatchMode, char **rootmatchnames, Dddmp_VarMatchType varMatchMode, char **varmatchnames, int *varmatchauxids, int *varcomposeids, int mode, char *file, FILE *fp, DdNode ***pproots);
  219. extern DdNode * Dddmp_cuddAddLoad(DdManager *ddMgr, Dddmp_VarMatchType varMatchMode, char **varmatchnames, int *varmatchauxids, int *varcomposeids, int mode, char *file, FILE *fp);
  220. extern int Dddmp_cuddAddArrayLoad(DdManager *ddMgr, Dddmp_RootMatchType rootMatchMode, char **rootmatchnames, Dddmp_VarMatchType varMatchMode, char **varmatchnames, int *varmatchauxids, int *varcomposeids, int mode, char *file, FILE *fp, DdNode ***pproots);
  221. extern int Dddmp_cuddHeaderLoad (Dddmp_DecompType *ddType, int *nVars, int *nsuppvars, char ***suppVarNames, char ***orderedVarNames, int **varIds, int **composeIds, int **auxIds, int *nRoots, char *file, FILE *fp);
  222. extern int Dddmp_cuddBddLoadCnf(DdManager *ddMgr, Dddmp_VarMatchType varmatchmode, char **varmatchnames, int *varmatchauxids, int *varcomposeids, int mode, char *file, FILE *fp, DdNode ***rootsPtrPtr, int *nRoots);
  223. extern int Dddmp_cuddBddArrayLoadCnf(DdManager *ddMgr, Dddmp_RootMatchType rootmatchmode, char **rootmatchnames, Dddmp_VarMatchType varmatchmode, char **varmatchnames, int *varmatchauxids, int *varcomposeids, int mode, char *file, FILE *fp, DdNode ***rootsPtrPtr, int *nRoots);
  224. extern int Dddmp_cuddHeaderLoadCnf (int *nVars, int *nsuppvars, char ***suppVarNames, char ***orderedVarNames, int **varIds, int **composeIds, int **auxIds, int *nRoots, char *file, FILE *fp);
  225. extern int Dddmp_cuddAddStore(DdManager *ddMgr, char *ddname, DdNode *f, char **varnames, int *auxids, int mode, Dddmp_VarInfoType varinfo, char *fname, FILE *fp);
  226. extern int Dddmp_cuddAddArrayStore(DdManager *ddMgr, char *ddname, int nRoots, DdNode **f, char **rootnames, char **varnames, int *auxids, int mode, Dddmp_VarInfoType varinfo, char *fname, FILE *fp);
  227. extern int Dddmp_cuddBddStore(DdManager *ddMgr, char *ddname, DdNode *f, char **varnames, int *auxids, int mode, Dddmp_VarInfoType varinfo, char *fname, FILE *fp);
  228. extern int Dddmp_cuddBddArrayStore(DdManager *ddMgr, char *ddname, int nRoots, DdNode **f, char **rootnames, char **varnames, int *auxids, int mode, Dddmp_VarInfoType varinfo, char *fname, FILE *fp);
  229. extern int Dddmp_cuddBddStoreCnf(DdManager *ddMgr, DdNode *f, Dddmp_DecompCnfStoreType mode, int noHeader, char **varNames, int *bddIds, int *bddAuxIds, int *cnfIds, int idInitial, int edgeInTh, int pathLengthTh, char *fname, FILE *fp, int *clauseNPtr, int *varNewNPtr);
  230. extern int Dddmp_cuddBddArrayStoreCnf(DdManager *ddMgr, DdNode **f, int rootN, Dddmp_DecompCnfStoreType mode, int noHeader, char **varNames, int *bddIds, int *bddAuxIds, int *cnfIds, int idInitial, int edgeInTh, int pathLengthTh, char *fname, FILE *fp, int *clauseNPtr, int *varNewNPtr);
  231. extern int Dddmp_cuddBddStorePrefix(DdManager *ddMgr, int nRoots, DdNode *f, char **inputNames, char **outputNames, char *modelName, char *fileName, FILE *fp);
  232. extern int Dddmp_cuddBddArrayStorePrefix(DdManager *ddMgr, int nroots, DdNode **f, char **inputNames, char **outputNames, char *modelName, char *fname, FILE *fp);
  233. extern int Dddmp_cuddBddStoreBlif(DdManager *ddMgr, int nRoots, DdNode *f, char **inputNames, char **outputNames, char *modelName, char *fileName, FILE *fp);
  234. extern int Dddmp_cuddBddArrayStoreBlif(DdManager *ddMgr, int nroots, DdNode **f, char **inputNames, char **outputNames, char *modelName, char *fname, FILE *fp);
  235. extern int Dddmp_cuddBddStoreSmv(DdManager *ddMgr, int nRoots, DdNode *f, char **inputNames, char **outputNames, char *modelName, char *fileName, FILE *fp);
  236. extern int Dddmp_cuddBddArrayStoreSmv(DdManager *ddMgr, int nroots, DdNode **f, char **inputNames, char **outputNames, char *modelName, char *fname, FILE *fp);
  237. /**AutomaticEnd***************************************************************/
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. #endif