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.

825 lines
24 KiB

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