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.

885 lines
26 KiB

  1. /**CFile***********************************************************************
  2. FileName [cuddCheck.c]
  3. PackageName [cudd]
  4. Synopsis [Functions to check consistency of data structures.]
  5. Description [External procedures included in this module:
  6. <ul>
  7. <li> Cudd_DebugCheck()
  8. <li> Cudd_CheckKeys()
  9. </ul>
  10. Internal procedures included in this module:
  11. <ul>
  12. <li> cuddHeapProfile()
  13. <li> cuddPrintNode()
  14. <li> cuddPrintVarGroups()
  15. </ul>
  16. Static procedures included in this module:
  17. <ul>
  18. <li> debugFindParent()
  19. </ul>
  20. ]
  21. SeeAlso []
  22. Author [Fabio Somenzi]
  23. Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado
  24. All rights reserved.
  25. Redistribution and use in source and binary forms, with or without
  26. modification, are permitted provided that the following conditions
  27. are met:
  28. Redistributions of source code must retain the above copyright
  29. notice, this list of conditions and the following disclaimer.
  30. Redistributions in binary form must reproduce the above copyright
  31. notice, this list of conditions and the following disclaimer in the
  32. documentation and/or other materials provided with the distribution.
  33. Neither the name of the University of Colorado nor the names of its
  34. contributors may be used to endorse or promote products derived from
  35. this software without specific prior written permission.
  36. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  40. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  41. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  42. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  44. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  46. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  47. POSSIBILITY OF SUCH DAMAGE.]
  48. ******************************************************************************/
  49. #include "util.h"
  50. #include "cuddInt.h"
  51. /*---------------------------------------------------------------------------*/
  52. /* Constant declarations */
  53. /*---------------------------------------------------------------------------*/
  54. /*---------------------------------------------------------------------------*/
  55. /* Stucture declarations */
  56. /*---------------------------------------------------------------------------*/
  57. /*---------------------------------------------------------------------------*/
  58. /* Type declarations */
  59. /*---------------------------------------------------------------------------*/
  60. /*---------------------------------------------------------------------------*/
  61. /* Variable declarations */
  62. /*---------------------------------------------------------------------------*/
  63. #ifndef lint
  64. static char rcsid[] DD_UNUSED = "$Id: cuddCheck.c,v 1.37 2012/02/05 01:07:18 fabio Exp $";
  65. #endif
  66. /*---------------------------------------------------------------------------*/
  67. /* Macro declarations */
  68. /*---------------------------------------------------------------------------*/
  69. /**AutomaticStart*************************************************************/
  70. /*---------------------------------------------------------------------------*/
  71. /* Static function prototypes */
  72. /*---------------------------------------------------------------------------*/
  73. static void debugFindParent (DdManager *table, DdNode *node);
  74. #if 0
  75. static void debugCheckParent (DdManager *table, DdNode *node);
  76. #endif
  77. /**AutomaticEnd***************************************************************/
  78. /*---------------------------------------------------------------------------*/
  79. /* Definition of exported functions */
  80. /*---------------------------------------------------------------------------*/
  81. /**Function********************************************************************
  82. Synopsis [Checks for inconsistencies in the DD heap.]
  83. Description [Checks for inconsistencies in the DD heap:
  84. <ul>
  85. <li> node has illegal index
  86. <li> live node has dead children
  87. <li> node has illegal Then or Else pointers
  88. <li> BDD/ADD node has identical children
  89. <li> ZDD node has zero then child
  90. <li> wrong number of total nodes
  91. <li> wrong number of dead nodes
  92. <li> ref count error at node
  93. </ul>
  94. Returns 0 if no inconsistencies are found; DD_OUT_OF_MEM if there is
  95. not enough memory; 1 otherwise.]
  96. SideEffects [None]
  97. SeeAlso [Cudd_CheckKeys]
  98. ******************************************************************************/
  99. int
  100. Cudd_DebugCheck(
  101. DdManager * table)
  102. {
  103. unsigned int i;
  104. int j,count;
  105. int slots;
  106. DdNodePtr *nodelist;
  107. DdNode *f;
  108. DdNode *sentinel = &(table->sentinel);
  109. st_table *edgeTable; /* stores internal ref count for each node */
  110. st_generator *gen;
  111. int flag = 0;
  112. int totalNode;
  113. int deadNode;
  114. int index;
  115. int shift;
  116. edgeTable = st_init_table(st_ptrcmp,st_ptrhash);
  117. if (edgeTable == NULL) return(CUDD_OUT_OF_MEM);
  118. /* Check the BDD/ADD subtables. */
  119. for (i = 0; i < (unsigned) table->size; i++) {
  120. index = table->invperm[i];
  121. if (i != (unsigned) table->perm[index]) {
  122. (void) fprintf(table->err,
  123. "Permutation corrupted: invperm[%u] = %d\t perm[%d] = %d\n",
  124. i, index, index, table->perm[index]);
  125. }
  126. nodelist = table->subtables[i].nodelist;
  127. slots = table->subtables[i].slots;
  128. shift = table->subtables[i].shift;
  129. totalNode = 0;
  130. deadNode = 0;
  131. for (j = 0; j < slots; j++) { /* for each subtable slot */
  132. f = nodelist[j];
  133. while (f != sentinel) {
  134. totalNode++;
  135. if (cuddT(f) != NULL && cuddE(f) != NULL && f->ref != 0) {
  136. if ((int) f->index != index) {
  137. (void) fprintf(table->err,
  138. "Error: node has illegal index\n");
  139. cuddPrintNode(f,table->err);
  140. flag = 1;
  141. }
  142. if ((unsigned) cuddI(table,cuddT(f)->index) <= i ||
  143. (unsigned) cuddI(table,Cudd_Regular(cuddE(f))->index)
  144. <= i) {
  145. (void) fprintf(table->err,
  146. "Error: node has illegal children\n");
  147. cuddPrintNode(f,table->err);
  148. flag = 1;
  149. }
  150. if (Cudd_Regular(cuddT(f)) != cuddT(f)) {
  151. (void) fprintf(table->err,
  152. "Error: node has illegal form\n");
  153. cuddPrintNode(f,table->err);
  154. flag = 1;
  155. }
  156. if (cuddT(f) == cuddE(f)) {
  157. (void) fprintf(table->err,
  158. "Error: node has identical children\n");
  159. cuddPrintNode(f,table->err);
  160. flag = 1;
  161. }
  162. if (cuddT(f)->ref == 0 || Cudd_Regular(cuddE(f))->ref == 0) {
  163. (void) fprintf(table->err,
  164. "Error: live node has dead children\n");
  165. cuddPrintNode(f,table->err);
  166. flag =1;
  167. }
  168. if (ddHash(cuddT(f),cuddE(f),shift) != j) {
  169. (void) fprintf(table->err, "Error: misplaced node\n");
  170. cuddPrintNode(f,table->err);
  171. flag =1;
  172. }
  173. /* Increment the internal reference count for the
  174. ** then child of the current node.
  175. */
  176. if (st_lookup_int(edgeTable,(char *)cuddT(f),&count)) {
  177. count++;
  178. } else {
  179. count = 1;
  180. }
  181. if (st_insert(edgeTable,(char *)cuddT(f),
  182. (char *)(long)count) == ST_OUT_OF_MEM) {
  183. st_free_table(edgeTable);
  184. return(CUDD_OUT_OF_MEM);
  185. }
  186. /* Increment the internal reference count for the
  187. ** else child of the current node.
  188. */
  189. if (st_lookup_int(edgeTable,(char *)Cudd_Regular(cuddE(f)),
  190. &count)) {
  191. count++;
  192. } else {
  193. count = 1;
  194. }
  195. if (st_insert(edgeTable,(char *)Cudd_Regular(cuddE(f)),
  196. (char *)(long)count) == ST_OUT_OF_MEM) {
  197. st_free_table(edgeTable);
  198. return(CUDD_OUT_OF_MEM);
  199. }
  200. } else if (cuddT(f) != NULL && cuddE(f) != NULL && f->ref == 0) {
  201. deadNode++;
  202. #if 0
  203. debugCheckParent(table,f);
  204. #endif
  205. } else {
  206. fprintf(table->err,
  207. "Error: node has illegal Then or Else pointers\n");
  208. cuddPrintNode(f,table->err);
  209. flag = 1;
  210. }
  211. f = f->next;
  212. } /* for each element of the collision list */
  213. } /* for each subtable slot */
  214. if ((unsigned) totalNode != table->subtables[i].keys) {
  215. fprintf(table->err,"Error: wrong number of total nodes\n");
  216. flag = 1;
  217. }
  218. if ((unsigned) deadNode != table->subtables[i].dead) {
  219. fprintf(table->err,"Error: wrong number of dead nodes\n");
  220. flag = 1;
  221. }
  222. } /* for each BDD/ADD subtable */
  223. /* Check the ZDD subtables. */
  224. for (i = 0; i < (unsigned) table->sizeZ; i++) {
  225. index = table->invpermZ[i];
  226. if (i != (unsigned) table->permZ[index]) {
  227. (void) fprintf(table->err,
  228. "Permutation corrupted: invpermZ[%u] = %d\t permZ[%d] = %d in ZDD\n",
  229. i, index, index, table->permZ[index]);
  230. }
  231. nodelist = table->subtableZ[i].nodelist;
  232. slots = table->subtableZ[i].slots;
  233. totalNode = 0;
  234. deadNode = 0;
  235. for (j = 0; j < slots; j++) { /* for each subtable slot */
  236. f = nodelist[j];
  237. while (f != NULL) {
  238. totalNode++;
  239. if (cuddT(f) != NULL && cuddE(f) != NULL && f->ref != 0) {
  240. if ((int) f->index != index) {
  241. (void) fprintf(table->err,
  242. "Error: ZDD node has illegal index\n");
  243. cuddPrintNode(f,table->err);
  244. flag = 1;
  245. }
  246. if (Cudd_IsComplement(cuddT(f)) ||
  247. Cudd_IsComplement(cuddE(f))) {
  248. (void) fprintf(table->err,
  249. "Error: ZDD node has complemented children\n");
  250. cuddPrintNode(f,table->err);
  251. flag = 1;
  252. }
  253. if ((unsigned) cuddIZ(table,cuddT(f)->index) <= i ||
  254. (unsigned) cuddIZ(table,cuddE(f)->index) <= i) {
  255. (void) fprintf(table->err,
  256. "Error: ZDD node has illegal children\n");
  257. cuddPrintNode(f,table->err);
  258. cuddPrintNode(cuddT(f),table->err);
  259. cuddPrintNode(cuddE(f),table->err);
  260. flag = 1;
  261. }
  262. if (cuddT(f) == DD_ZERO(table)) {
  263. (void) fprintf(table->err,
  264. "Error: ZDD node has zero then child\n");
  265. cuddPrintNode(f,table->err);
  266. flag = 1;
  267. }
  268. if (cuddT(f)->ref == 0 || cuddE(f)->ref == 0) {
  269. (void) fprintf(table->err,
  270. "Error: ZDD live node has dead children\n");
  271. cuddPrintNode(f,table->err);
  272. flag =1;
  273. }
  274. /* Increment the internal reference count for the
  275. ** then child of the current node.
  276. */
  277. if (st_lookup_int(edgeTable,(char *)cuddT(f),&count)) {
  278. count++;
  279. } else {
  280. count = 1;
  281. }
  282. if (st_insert(edgeTable,(char *)cuddT(f),
  283. (char *)(long)count) == ST_OUT_OF_MEM) {
  284. st_free_table(edgeTable);
  285. return(CUDD_OUT_OF_MEM);
  286. }
  287. /* Increment the internal reference count for the
  288. ** else child of the current node.
  289. */
  290. if (st_lookup_int(edgeTable,(char *)cuddE(f),&count)) {
  291. count++;
  292. } else {
  293. count = 1;
  294. }
  295. if (st_insert(edgeTable,(char *)cuddE(f),
  296. (char *)(long)count) == ST_OUT_OF_MEM) {
  297. st_free_table(edgeTable);
  298. table->errorCode = CUDD_MEMORY_OUT;
  299. return(CUDD_OUT_OF_MEM);
  300. }
  301. } else if (cuddT(f) != NULL && cuddE(f) != NULL && f->ref == 0) {
  302. deadNode++;
  303. #if 0
  304. debugCheckParent(table,f);
  305. #endif
  306. } else {
  307. fprintf(table->err,
  308. "Error: ZDD node has illegal Then or Else pointers\n");
  309. cuddPrintNode(f,table->err);
  310. flag = 1;
  311. }
  312. f = f->next;
  313. } /* for each element of the collision list */
  314. } /* for each subtable slot */
  315. if ((unsigned) totalNode != table->subtableZ[i].keys) {
  316. fprintf(table->err,
  317. "Error: wrong number of total nodes in ZDD\n");
  318. flag = 1;
  319. }
  320. if ((unsigned) deadNode != table->subtableZ[i].dead) {
  321. fprintf(table->err,
  322. "Error: wrong number of dead nodes in ZDD\n");
  323. flag = 1;
  324. }
  325. } /* for each ZDD subtable */
  326. /* Check the constant table. */
  327. nodelist = table->constants.nodelist;
  328. slots = table->constants.slots;
  329. totalNode = 0;
  330. deadNode = 0;
  331. for (j = 0; j < slots; j++) {
  332. f = nodelist[j];
  333. while (f != NULL) {
  334. totalNode++;
  335. if (f->ref != 0) {
  336. if (f->index != CUDD_CONST_INDEX) {
  337. fprintf(table->err,"Error: node has illegal index\n");
  338. #if SIZEOF_VOID_P == 8
  339. fprintf(table->err,
  340. " node 0x%lx, id = %u, ref = %u, value = %g\n",
  341. (ptruint)f,f->index,f->ref,cuddV(f));
  342. #else
  343. fprintf(table->err,
  344. " node 0x%x, id = %hu, ref = %hu, value = %g\n",
  345. (ptruint)f,f->index,f->ref,cuddV(f));
  346. #endif
  347. flag = 1;
  348. }
  349. } else {
  350. deadNode++;
  351. }
  352. f = f->next;
  353. }
  354. }
  355. if ((unsigned) totalNode != table->constants.keys) {
  356. (void) fprintf(table->err,
  357. "Error: wrong number of total nodes in constants\n");
  358. flag = 1;
  359. }
  360. if ((unsigned) deadNode != table->constants.dead) {
  361. (void) fprintf(table->err,
  362. "Error: wrong number of dead nodes in constants\n");
  363. flag = 1;
  364. }
  365. gen = st_init_gen(edgeTable);
  366. while (st_gen(gen, &f, &count)) {
  367. if (count > (int)(f->ref) && f->ref != DD_MAXREF) {
  368. #if SIZEOF_VOID_P == 8
  369. fprintf(table->err,"ref count error at node 0x%lx, count = %d, id = %u, ref = %u, then = 0x%lx, else = 0x%lx\n",(ptruint)f,count,f->index,f->ref,(ptruint)cuddT(f),(ptruint)cuddE(f));
  370. #else
  371. fprintf(table->err,"ref count error at node 0x%x, count = %d, id = %hu, ref = %hu, then = 0x%x, else = 0x%x\n",(ptruint)f,count,f->index,f->ref,(ptruint)cuddT(f),(ptruint)cuddE(f));
  372. #endif
  373. debugFindParent(table,f);
  374. flag = 1;
  375. }
  376. }
  377. st_free_gen(gen);
  378. st_free_table(edgeTable);
  379. return (flag);
  380. } /* end of Cudd_DebugCheck */
  381. /**Function********************************************************************
  382. Synopsis [Checks for several conditions that should not occur.]
  383. Description [Checks for the following conditions:
  384. <ul>
  385. <li>Wrong sizes of subtables.
  386. <li>Wrong number of keys found in unique subtable.
  387. <li>Wrong number of dead found in unique subtable.
  388. <li>Wrong number of keys found in the constant table
  389. <li>Wrong number of dead found in the constant table
  390. <li>Wrong number of total slots found
  391. <li>Wrong number of maximum keys found
  392. <li>Wrong number of total dead found
  393. </ul>
  394. Reports the average length of non-empty lists. Returns the number of
  395. subtables for which the number of keys is wrong.]
  396. SideEffects [None]
  397. SeeAlso [Cudd_DebugCheck]
  398. ******************************************************************************/
  399. int
  400. Cudd_CheckKeys(
  401. DdManager * table)
  402. {
  403. int size;
  404. int i,j;
  405. DdNodePtr *nodelist;
  406. DdNode *node;
  407. DdNode *sentinel = &(table->sentinel);
  408. DdSubtable *subtable;
  409. int keys;
  410. int dead;
  411. int count = 0;
  412. int totalKeys = 0;
  413. int totalSlots = 0;
  414. int totalDead = 0;
  415. int nonEmpty = 0;
  416. unsigned int slots;
  417. int logSlots;
  418. int shift;
  419. size = table->size;
  420. for (i = 0; i < size; i++) {
  421. subtable = &(table->subtables[i]);
  422. nodelist = subtable->nodelist;
  423. keys = subtable->keys;
  424. dead = subtable->dead;
  425. totalKeys += keys;
  426. slots = subtable->slots;
  427. shift = subtable->shift;
  428. logSlots = sizeof(int) * 8 - shift;
  429. if (((slots >> logSlots) << logSlots) != slots) {
  430. (void) fprintf(table->err,
  431. "Unique table %d is not the right power of 2\n", i);
  432. (void) fprintf(table->err,
  433. " slots = %u shift = %d\n", slots, shift);
  434. }
  435. totalSlots += slots;
  436. totalDead += dead;
  437. for (j = 0; (unsigned) j < slots; j++) {
  438. node = nodelist[j];
  439. if (node != sentinel) {
  440. nonEmpty++;
  441. }
  442. while (node != sentinel) {
  443. keys--;
  444. if (node->ref == 0) {
  445. dead--;
  446. }
  447. node = node->next;
  448. }
  449. }
  450. if (keys != 0) {
  451. (void) fprintf(table->err, "Wrong number of keys found \
  452. in unique table %d (difference=%d)\n", i, keys);
  453. count++;
  454. }
  455. if (dead != 0) {
  456. (void) fprintf(table->err, "Wrong number of dead found \
  457. in unique table no. %d (difference=%d)\n", i, dead);
  458. }
  459. } /* for each BDD/ADD subtable */
  460. /* Check the ZDD subtables. */
  461. size = table->sizeZ;
  462. for (i = 0; i < size; i++) {
  463. subtable = &(table->subtableZ[i]);
  464. nodelist = subtable->nodelist;
  465. keys = subtable->keys;
  466. dead = subtable->dead;
  467. totalKeys += keys;
  468. totalSlots += subtable->slots;
  469. totalDead += dead;
  470. for (j = 0; (unsigned) j < subtable->slots; j++) {
  471. node = nodelist[j];
  472. if (node != NULL) {
  473. nonEmpty++;
  474. }
  475. while (node != NULL) {
  476. keys--;
  477. if (node->ref == 0) {
  478. dead--;
  479. }
  480. node = node->next;
  481. }
  482. }
  483. if (keys != 0) {
  484. (void) fprintf(table->err, "Wrong number of keys found \
  485. in ZDD unique table no. %d (difference=%d)\n", i, keys);
  486. count++;
  487. }
  488. if (dead != 0) {
  489. (void) fprintf(table->err, "Wrong number of dead found \
  490. in ZDD unique table no. %d (difference=%d)\n", i, dead);
  491. }
  492. } /* for each ZDD subtable */
  493. /* Check the constant table. */
  494. subtable = &(table->constants);
  495. nodelist = subtable->nodelist;
  496. keys = subtable->keys;
  497. dead = subtable->dead;
  498. totalKeys += keys;
  499. totalSlots += subtable->slots;
  500. totalDead += dead;
  501. for (j = 0; (unsigned) j < subtable->slots; j++) {
  502. node = nodelist[j];
  503. if (node != NULL) {
  504. nonEmpty++;
  505. }
  506. while (node != NULL) {
  507. keys--;
  508. if (node->ref == 0) {
  509. dead--;
  510. }
  511. node = node->next;
  512. }
  513. }
  514. if (keys != 0) {
  515. (void) fprintf(table->err, "Wrong number of keys found \
  516. in the constant table (difference=%d)\n", keys);
  517. count++;
  518. }
  519. if (dead != 0) {
  520. (void) fprintf(table->err, "Wrong number of dead found \
  521. in the constant table (difference=%d)\n", dead);
  522. }
  523. if ((unsigned) totalKeys != table->keys + table->keysZ) {
  524. (void) fprintf(table->err, "Wrong number of total keys found \
  525. (difference=%d)\n", (int) (totalKeys-table->keys));
  526. }
  527. if ((unsigned) totalSlots != table->slots) {
  528. (void) fprintf(table->err, "Wrong number of total slots found \
  529. (difference=%d)\n", (int) (totalSlots-table->slots));
  530. }
  531. if (table->minDead != (unsigned) (table->gcFrac * table->slots)) {
  532. (void) fprintf(table->err, "Wrong number of minimum dead found \
  533. (%u vs. %u)\n", table->minDead,
  534. (unsigned) (table->gcFrac * (double) table->slots));
  535. }
  536. if ((unsigned) totalDead != table->dead + table->deadZ) {
  537. (void) fprintf(table->err, "Wrong number of total dead found \
  538. (difference=%d)\n", (int) (totalDead-table->dead));
  539. }
  540. (void) fprintf(table->out,"Average length of non-empty lists = %g\n",
  541. (double) table->keys / (double) nonEmpty);
  542. return(count);
  543. } /* end of Cudd_CheckKeys */
  544. /*---------------------------------------------------------------------------*/
  545. /* Definition of internal functions */
  546. /*---------------------------------------------------------------------------*/
  547. /**Function********************************************************************
  548. Synopsis [Prints information about the heap.]
  549. Description [Prints to the manager's stdout the number of live nodes for each
  550. level of the DD heap that contains at least one live node. It also
  551. prints a summary containing:
  552. <ul>
  553. <li> total number of tables;
  554. <li> number of tables with live nodes;
  555. <li> table with the largest number of live nodes;
  556. <li> number of nodes in that table.
  557. </ul>
  558. If more than one table contains the maximum number of live nodes,
  559. only the one of lowest index is reported. Returns 1 in case of success
  560. and 0 otherwise.]
  561. SideEffects [None]
  562. SeeAlso []
  563. ******************************************************************************/
  564. int
  565. cuddHeapProfile(
  566. DdManager * dd)
  567. {
  568. int ntables = dd->size;
  569. DdSubtable *subtables = dd->subtables;
  570. int i, /* loop index */
  571. nodes, /* live nodes in i-th layer */
  572. retval, /* return value of fprintf */
  573. largest = -1, /* index of the table with most live nodes */
  574. maxnodes = -1, /* maximum number of live nodes in a table */
  575. nonempty = 0; /* number of tables with live nodes */
  576. /* Print header. */
  577. #if SIZEOF_VOID_P == 8
  578. retval = fprintf(dd->out,"*** DD heap profile for 0x%lx ***\n",
  579. (ptruint) dd);
  580. #else
  581. retval = fprintf(dd->out,"*** DD heap profile for 0x%x ***\n",
  582. (ptruint) dd);
  583. #endif
  584. if (retval == EOF) return 0;
  585. /* Print number of live nodes for each nonempty table. */
  586. for (i=0; i<ntables; i++) {
  587. nodes = subtables[i].keys - subtables[i].dead;
  588. if (nodes) {
  589. nonempty++;
  590. retval = fprintf(dd->out,"%5d: %5d nodes\n", i, nodes);
  591. if (retval == EOF) return 0;
  592. if (nodes > maxnodes) {
  593. maxnodes = nodes;
  594. largest = i;
  595. }
  596. }
  597. }
  598. nodes = dd->constants.keys - dd->constants.dead;
  599. if (nodes) {
  600. nonempty++;
  601. retval = fprintf(dd->out,"const: %5d nodes\n", nodes);
  602. if (retval == EOF) return 0;
  603. if (nodes > maxnodes) {
  604. maxnodes = nodes;
  605. largest = CUDD_CONST_INDEX;
  606. }
  607. }
  608. /* Print summary. */
  609. retval = fprintf(dd->out,"Summary: %d tables, %d non-empty, largest: %d ",
  610. ntables+1, nonempty, largest);
  611. if (retval == EOF) return 0;
  612. retval = fprintf(dd->out,"(with %d nodes)\n", maxnodes);
  613. if (retval == EOF) return 0;
  614. return(1);
  615. } /* end of cuddHeapProfile */
  616. /**Function********************************************************************
  617. Synopsis [Prints out information on a node.]
  618. Description [Prints out information on a node.]
  619. SideEffects [None]
  620. SeeAlso []
  621. ******************************************************************************/
  622. void
  623. cuddPrintNode(
  624. DdNode * f,
  625. FILE *fp)
  626. {
  627. f = Cudd_Regular(f);
  628. #if SIZEOF_VOID_P == 8
  629. (void) fprintf(fp," node 0x%lx, id = %u, ref = %u, then = 0x%lx, else = 0x%lx\n",(ptruint)f,f->index,f->ref,(ptruint)cuddT(f),(ptruint)cuddE(f));
  630. #else
  631. (void) fprintf(fp," node 0x%x, id = %hu, ref = %hu, then = 0x%x, else = 0x%x\n",(ptruint)f,f->index,f->ref,(ptruint)cuddT(f),(ptruint)cuddE(f));
  632. #endif
  633. } /* end of cuddPrintNode */
  634. /**Function********************************************************************
  635. Synopsis [Prints the variable groups as a parenthesized list.]
  636. Description [Prints the variable groups as a parenthesized list.
  637. For each group the level range that it represents is printed. After
  638. each group, the group's flags are printed, preceded by a `|'. For
  639. each flag (except MTR_TERMINAL) a character is printed.
  640. <ul>
  641. <li>F: MTR_FIXED
  642. <li>N: MTR_NEWNODE
  643. <li>S: MTR_SOFT
  644. </ul>
  645. The second argument, silent, if different from 0, causes
  646. Cudd_PrintVarGroups to only check the syntax of the group tree.]
  647. SideEffects [None]
  648. SeeAlso []
  649. ******************************************************************************/
  650. void
  651. cuddPrintVarGroups(
  652. DdManager * dd /* manager */,
  653. MtrNode * root /* root of the group tree */,
  654. int zdd /* 0: BDD; 1: ZDD */,
  655. int silent /* flag to check tree syntax only */)
  656. {
  657. MtrNode *node;
  658. int level;
  659. assert(root != NULL);
  660. assert(root->younger == NULL || root->younger->elder == root);
  661. assert(root->elder == NULL || root->elder->younger == root);
  662. if (zdd) {
  663. level = dd->permZ[root->index];
  664. } else {
  665. level = dd->perm[root->index];
  666. }
  667. if (!silent) (void) printf("(%d",level);
  668. if (MTR_TEST(root,MTR_TERMINAL) || root->child == NULL) {
  669. if (!silent) (void) printf(",");
  670. } else {
  671. node = root->child;
  672. while (node != NULL) {
  673. assert(node->low >= root->low && (int) (node->low + node->size) <= (int) (root->low + root->size));
  674. assert(node->parent == root);
  675. cuddPrintVarGroups(dd,node,zdd,silent);
  676. node = node->younger;
  677. }
  678. }
  679. if (!silent) {
  680. (void) printf("%d", (int) (level + root->size - 1));
  681. if (root->flags != MTR_DEFAULT) {
  682. (void) printf("|");
  683. if (MTR_TEST(root,MTR_FIXED)) (void) printf("F");
  684. if (MTR_TEST(root,MTR_NEWNODE)) (void) printf("N");
  685. if (MTR_TEST(root,MTR_SOFT)) (void) printf("S");
  686. }
  687. (void) printf(")");
  688. if (root->parent == NULL) (void) printf("\n");
  689. }
  690. assert((root->flags &~(MTR_TERMINAL | MTR_SOFT | MTR_FIXED | MTR_NEWNODE)) == 0);
  691. return;
  692. } /* end of cuddPrintVarGroups */
  693. /*---------------------------------------------------------------------------*/
  694. /* Definition of static functions */
  695. /*---------------------------------------------------------------------------*/
  696. /**Function********************************************************************
  697. Synopsis [Searches the subtables above node for its parents.]
  698. Description []
  699. SideEffects [None]
  700. SeeAlso []
  701. ******************************************************************************/
  702. static void
  703. debugFindParent(
  704. DdManager * table,
  705. DdNode * node)
  706. {
  707. int i,j;
  708. int slots;
  709. DdNodePtr *nodelist;
  710. DdNode *f;
  711. for (i = 0; i < cuddI(table,node->index); i++) {
  712. nodelist = table->subtables[i].nodelist;
  713. slots = table->subtables[i].slots;
  714. for (j=0;j<slots;j++) {
  715. f = nodelist[j];
  716. while (f != NULL) {
  717. if (cuddT(f) == node || Cudd_Regular(cuddE(f)) == node) {
  718. #if SIZEOF_VOID_P == 8
  719. (void) fprintf(table->out,"parent is at 0x%lx, id = %u, ref = %u, then = 0x%lx, else = 0x%lx\n",
  720. (ptruint)f,f->index,f->ref,(ptruint)cuddT(f),(ptruint)cuddE(f));
  721. #else
  722. (void) fprintf(table->out,"parent is at 0x%x, id = %hu, ref = %hu, then = 0x%x, else = 0x%x\n",
  723. (ptruint)f,f->index,f->ref,(ptruint)cuddT(f),(ptruint)cuddE(f));
  724. #endif
  725. }
  726. f = f->next;
  727. }
  728. }
  729. }
  730. } /* end of debugFindParent */
  731. #if 0
  732. /**Function********************************************************************
  733. Synopsis [Reports an error if a (dead) node has a non-dead parent.]
  734. Description [Searches all the subtables above node. Very expensive.
  735. The same check is now implemented more efficiently in ddDebugCheck.]
  736. SideEffects [None]
  737. SeeAlso [debugFindParent]
  738. ******************************************************************************/
  739. static void
  740. debugCheckParent(
  741. DdManager * table,
  742. DdNode * node)
  743. {
  744. int i,j;
  745. int slots;
  746. DdNode **nodelist,*f;
  747. for (i = 0; i < cuddI(table,node->index); i++) {
  748. nodelist = table->subtables[i].nodelist;
  749. slots = table->subtables[i].slots;
  750. for (j=0;j<slots;j++) {
  751. f = nodelist[j];
  752. while (f != NULL) {
  753. if ((Cudd_Regular(cuddE(f)) == node || cuddT(f) == node) && f->ref != 0) {
  754. (void) fprintf(table->err,
  755. "error with zero ref count\n");
  756. (void) fprintf(table->err,"parent is 0x%x, id = %u, ref = %u, then = 0x%x, else = 0x%x\n",f,f->index,f->ref,cuddT(f),cuddE(f));
  757. (void) fprintf(table->err,"child is 0x%x, id = %u, ref = %u, then = 0x%x, else = 0x%x\n",node,node->index,node->ref,cuddT(node),cuddE(node));
  758. }
  759. f = f->next;
  760. }
  761. }
  762. }
  763. }
  764. #endif