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.

187 lines
7.8 KiB

  1. /**CHeaderFile*****************************************************************
  2. FileName [bnet.h]
  3. PackageName [bnet]
  4. Synopsis [Simple-minded package to read a blif file.]
  5. Description []
  6. SeeAlso []
  7. Author [Fabio Somenzi]
  8. Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado
  9. All rights reserved.
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions
  12. are met:
  13. Redistributions of source code must retain the above copyright
  14. notice, this list of conditions and the following disclaimer.
  15. Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  18. Neither the name of the University of Colorado nor the names of its
  19. contributors may be used to endorse or promote products derived from
  20. this software without specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. POSSIBILITY OF SUCH DAMAGE.]
  33. Revision [$Id: bnet.h,v 1.13 2012/02/05 01:53:01 fabio Exp fabio $]
  34. ******************************************************************************/
  35. #ifndef _BNET
  36. #define _BNET
  37. /*---------------------------------------------------------------------------*/
  38. /* Nested includes */
  39. /*---------------------------------------------------------------------------*/
  40. #include "util.h"
  41. #include "st.h"
  42. #include "cudd.h"
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /*---------------------------------------------------------------------------*/
  47. /* Constant declarations */
  48. /*---------------------------------------------------------------------------*/
  49. /* Different types of nodes. (Used in the "BnetNode" type.) */
  50. #define BNET_CONSTANT_NODE 0
  51. #define BNET_INPUT_NODE 1
  52. #define BNET_PRESENT_STATE_NODE 2
  53. #define BNET_INTERNAL_NODE 3
  54. #define BNET_OUTPUT_NODE 4
  55. #define BNET_NEXT_STATE_NODE 5
  56. /* Type of DD of a node. */
  57. #define BNET_LOCAL_DD 0
  58. #define BNET_GLOBAL_DD 1
  59. /*---------------------------------------------------------------------------*/
  60. /* Stucture declarations */
  61. /*---------------------------------------------------------------------------*/
  62. /*---------------------------------------------------------------------------*/
  63. /* Type declarations */
  64. /*---------------------------------------------------------------------------*/
  65. /* The following types implement a very simple data structure for a boolean
  66. ** network. The intent is to be able to read a minimal subset of the blif
  67. ** format in a data structure from which it's easy to build DDs for the
  68. ** circuit.
  69. */
  70. /* Type to store a line of the truth table of a node. The entire truth table
  71. ** implemented as a linked list of objects of this type.
  72. */
  73. typedef struct BnetTabline {
  74. char *values; /* string of 1, 0, and - */
  75. struct BnetTabline *next; /* pointer to next table line */
  76. } BnetTabline;
  77. /* Node of the boolean network. There is one node in the network for each
  78. ** primary input and for each .names directive. This structure
  79. ** has a field to point to the DD of the node function. The function may
  80. ** be either in terms of primary inputs, or it may be in terms of the local
  81. ** inputs. The latter implies that each node has a variable index
  82. ** associated to it at some point in time. The field "var" stores that
  83. ** variable index, and "active" says if the association is currently valid.
  84. ** (It is indeed possible for an index to be associated to different nodes
  85. ** at different times.)
  86. */
  87. typedef struct BnetNode {
  88. char *name; /* name of the output signal */
  89. int type; /* input, internal, constant, ... */
  90. int ninp; /* number of inputs to the node */
  91. int nfo; /* number of fanout nodes for this node */
  92. char **inputs; /* input names */
  93. BnetTabline *f; /* truth table for this node */
  94. int polarity; /* f is the onset (0) or the offset (1) */
  95. int active; /* node has variable associated to it (1) or not (0) */
  96. int var; /* DD variable index associated to this node */
  97. DdNode *dd; /* decision diagram for the function of this node */
  98. int exdc_flag; /* whether an exdc node or not */
  99. struct BnetNode *exdc; /* pointer to exdc of dd node */
  100. int count; /* auxiliary field for DD dropping */
  101. int level; /* maximum distance from the inputs */
  102. int visited; /* flag for search */
  103. struct BnetNode *next; /* pointer to implement the linked list of nodes */
  104. } BnetNode;
  105. /* Very simple boolean network data structure. */
  106. typedef struct BnetNetwork {
  107. char *name; /* network name: from the .model directive */
  108. int npis; /* number of primary inputs */
  109. int ninputs; /* number of inputs */
  110. char **inputs; /* primary input names: from the .inputs directive */
  111. int npos; /* number of primary outputs */
  112. int noutputs; /* number of outputs */
  113. char **outputs; /* primary output names: from the .outputs directive */
  114. int nlatches; /* number of latches */
  115. char ***latches; /* next state names: from the .latch directives */
  116. BnetNode *nodes; /* linked list of the nodes */
  117. st_table *hash; /* symbol table to access nodes by name */
  118. char *slope; /* wire_load_slope */
  119. } BnetNetwork;
  120. /*---------------------------------------------------------------------------*/
  121. /* Variable declarations */
  122. /*---------------------------------------------------------------------------*/
  123. /*---------------------------------------------------------------------------*/
  124. /* Macro declarations */
  125. /*---------------------------------------------------------------------------*/
  126. #ifndef TRUE
  127. # define TRUE 1
  128. #endif
  129. #ifndef FALSE
  130. # define FALSE 0
  131. #endif
  132. /**AutomaticStart*************************************************************/
  133. /*---------------------------------------------------------------------------*/
  134. /* Function prototypes */
  135. /*---------------------------------------------------------------------------*/
  136. extern BnetNetwork * Bnet_ReadNetwork (FILE *fp, int pr);
  137. extern void Bnet_PrintNetwork (BnetNetwork *net);
  138. extern void Bnet_FreeNetwork (BnetNetwork *net);
  139. extern int Bnet_BuildNodeBDD (DdManager *dd, BnetNode *nd, st_table *hash, int params, int nodrop);
  140. extern int Bnet_DfsVariableOrder (DdManager *dd, BnetNetwork *net);
  141. extern int Bnet_bddDump (DdManager *dd, BnetNetwork *network, char *dfile, int dumpFmt, int reencoded);
  142. extern int Bnet_bddArrayDump (DdManager *dd, BnetNetwork *network, char *dfile, DdNode **outputs, char **onames, int noutputs, int dumpFmt);
  143. extern int Bnet_ReadOrder (DdManager *dd, char *ordFile, BnetNetwork *net, int locGlob, int nodrop);
  144. extern int Bnet_PrintOrder (BnetNetwork * net, DdManager *dd);
  145. /**AutomaticEnd***************************************************************/
  146. #ifdef __cplusplus
  147. } /* end of extern "C" */
  148. #endif
  149. #endif /* _BNET */