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.

216 lines
7.8 KiB

3 months ago
  1. /**CHeaderFile*****************************************************************
  2. FileName [dddmpInt.h]
  3. PackageName [dddmp]
  4. Synopsis [Low level functions to read in and write out bdds to file]
  5. Description [A set of internal low-level routines of the dddmp package
  6. doing:
  7. <ul>
  8. <li> read and write of node codes in binary mode,
  9. <li> read and write of integers in binary mode,
  10. <li> marking/unmarking nodes as visited,
  11. <li> numbering nodes.
  12. </ul>
  13. ]
  14. Author [Gianpiero Cabodi and Stefano Quer]
  15. Copyright [
  16. Copyright (c) 2002 by Politecnico di Torino.
  17. All Rights Reserved. This software is for educational purposes only.
  18. Permission is given to academic institutions to use, copy, and modify
  19. this software and its documentation provided that this introductory
  20. message is not removed, that this software and its documentation is
  21. used for the institutions' internal research and educational purposes,
  22. and that no monies are exchanged. No guarantee is expressed or implied
  23. by the distribution of this code.
  24. Send bug-reports and/or questions to:
  25. {gianpiero.cabodi,stefano.quer}@polito.it.
  26. ]
  27. ******************************************************************************/
  28. #ifndef _DDDMPINT
  29. #define _DDDMPINT
  30. #include "dddmp.h"
  31. #include "cuddInt.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /*---------------------------------------------------------------------------*/
  36. /* Constant declarations */
  37. /*---------------------------------------------------------------------------*/
  38. /* constants for code fields */
  39. #define DDDMP_TERMINAL 0
  40. #define DDDMP_ABSOLUTE_ID 1
  41. #define DDDMP_RELATIVE_ID 2
  42. #define DDDMP_RELATIVE_1 3
  43. #define DDDMP_MAXSTRLEN 500
  44. /*---------------------------------------------------------------------------*/
  45. /* Type declarations */
  46. /*---------------------------------------------------------------------------*/
  47. /*---------------------------------------------------------------------------*/
  48. /* Structure declarations */
  49. /*---------------------------------------------------------------------------*/
  50. /**Struct**********************************************************************
  51. Synopsis [used in binary mode to store code info of a dd node]
  52. Description [V , T , E store the mode used to represent variable, Then
  53. and Else indexes. An index is either an absolute
  54. ( DDDMP_ABSOLUTE_ID ),
  55. a relative numbers ( DDDMP_RELATIVE_ID , DDDMP_RELATIVE_1 ) or
  56. a terminal node ( DDDMP_TERMINAL ) .
  57. Ecomp is used for the complemented edge attribute.
  58. ]
  59. SideEffect [none]
  60. SeeAlso [DddmpWriteCode DddmpReadCode]
  61. ******************************************************************************/
  62. struct binary_dd_code {
  63. unsigned Unused : 1;
  64. unsigned V : 2;
  65. unsigned T : 2;
  66. unsigned Ecompl : 1;
  67. unsigned E : 2;
  68. };
  69. /**Struct*********************************************************************
  70. Synopsis [BDD file header]
  71. Description [Structure containing the BDD header file infos]
  72. ******************************************************************************/
  73. struct Dddmp_Hdr_s {
  74. char *ver;
  75. char mode;
  76. Dddmp_DecompType ddType;
  77. Dddmp_VarInfoType varinfo;
  78. char *dd;
  79. int nnodes;
  80. int nVars;
  81. int nsuppvars;
  82. char **orderedVarNames;
  83. char **suppVarNames;
  84. int *ids;
  85. int *permids;
  86. int *auxids;
  87. int *cnfids;
  88. int nRoots;
  89. int *rootids;
  90. char **rootnames;
  91. int nAddedCnfVar;
  92. int nVarsCnf;
  93. int nClausesCnf;
  94. };
  95. /*---------------------------------------------------------------------------*/
  96. /* Variable declarations */
  97. /*---------------------------------------------------------------------------*/
  98. /*---------------------------------------------------------------------------*/
  99. /* Macro declarations */
  100. /*---------------------------------------------------------------------------*/
  101. /**Macro***********************************************************************
  102. Synopsis [Memory Allocation Macro for DDDMP]
  103. Description []
  104. SideEffects [None]
  105. SeeAlso []
  106. ******************************************************************************/
  107. #ifdef ALLOC
  108. # define DDDMP_ALLOC(type, num) ALLOC(type,num)
  109. #else
  110. # define DDDMP_ALLOC(type, num) \
  111. ((type *) malloc(sizeof(type) * (num)))
  112. #endif
  113. /**Macro***********************************************************************
  114. Synopsis [Memory Free Macro for DDDMP]
  115. Description []
  116. SideEffects [None]
  117. SeeAlso []
  118. ******************************************************************************/
  119. #ifdef FREE
  120. #define DDDMP_FREE(p) (FREE(p))
  121. #else
  122. #define DDDMP_FREE(p) \
  123. ((p)!=NULL)?(free(p)):0)
  124. #endif
  125. /**AutomaticStart*************************************************************/
  126. /*---------------------------------------------------------------------------*/
  127. /* Function prototypes */
  128. /*---------------------------------------------------------------------------*/
  129. extern int DddmpWriteCode(FILE *fp, struct binary_dd_code code);
  130. extern int DddmpReadCode(FILE *fp, struct binary_dd_code *pcode);
  131. extern int DddmpWriteInt(FILE *fp, int id);
  132. extern int DddmpReadInt(FILE *fp, int *pid);
  133. extern int DddmpNumberAddNodes(DdManager *ddMgr, DdNode **f, int n);
  134. extern void DddmpUnnumberAddNodes(DdManager *ddMgr, DdNode **f, int n);
  135. extern void DddmpWriteNodeIndexAdd(DdNode *f, int id);
  136. extern int DddmpReadNodeIndexAdd(DdNode *f);
  137. extern int DddmpVisitedAdd(DdNode *f);
  138. extern void DddmpSetVisitedAdd(DdNode *f);
  139. extern void DddmpClearVisitedAdd(DdNode *f);
  140. extern int DddmpNumberBddNodes(DdManager *ddMgr, DdNode **f, int n);
  141. extern void DddmpUnnumberBddNodes(DdManager *ddMgr, DdNode **f, int n);
  142. extern void DddmpWriteNodeIndexBdd(DdNode *f, int id);
  143. extern int DddmpReadNodeIndexBdd(DdNode *f);
  144. extern int DddmpVisitedBdd(DdNode *f);
  145. extern void DddmpSetVisitedBdd(DdNode *f);
  146. extern void DddmpClearVisitedBdd(DdNode *f);
  147. extern int DddmpNumberDdNodesCnf(DdManager *ddMgr, DdNode **f, int rootN, int *cnfIds, int id);
  148. extern int DddmpDdNodesCountEdgesAndNumber(DdManager *ddMgr, DdNode **f, int rootN, int edgeInTh, int pathLengthTh, int *cnfIds, int id);
  149. extern void DddmpUnnumberDdNodesCnf(DdManager *ddMgr, DdNode **f, int rootN);
  150. extern int DddmpPrintBddAndNext(DdManager *ddMgr, DdNode **f, int rootN);
  151. extern int DddmpWriteNodeIndexCnf(DdNode *f, int id);
  152. extern int DddmpVisitedCnf(DdNode *f);
  153. extern void DddmpSetVisitedCnf(DdNode *f);
  154. extern int DddmpReadNodeIndexCnf(DdNode *f);
  155. extern int DddmpCuddDdArrayStoreBdd(Dddmp_DecompType ddType, DdManager *ddMgr, char *ddname, int nRoots, DdNode **f, char **rootnames, char **varnames, int *auxids, int mode, Dddmp_VarInfoType varinfo, char *fname, FILE *fp);
  156. extern int DddmpCuddBddArrayStore(Dddmp_DecompType ddType, DdManager *ddMgr, char *ddname, int nRoots, DdNode **f, char **rootnames, char **varnames, int *auxids, int mode, Dddmp_VarInfoType varinfo, char *fname, FILE *fp);
  157. extern int QsortStrcmp(const void *ps1, const void *ps2);
  158. extern int FindVarname(char *name, char **array, int n);
  159. extern char * DddmpStrDup(char *str);
  160. extern char ** DddmpStrArrayDup(char **array, int n);
  161. extern char ** DddmpStrArrayRead(FILE *fp, int n);
  162. extern int DddmpStrArrayWrite(FILE *fp, char **array, int n);
  163. extern void DddmpStrArrayFree(char **array, int n);
  164. extern int * DddmpIntArrayDup(int *array, int n);
  165. extern int * DddmpIntArrayRead(FILE *fp, int n);
  166. extern int DddmpIntArrayWrite(FILE *fp, int *array, int n);
  167. /**AutomaticEnd***************************************************************/
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif