The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

191 lines
7.5 KiB

4 weeks ago
  1. /**
  2. @file
  3. @ingroup nanotrav
  4. @brief Simple-minded package to read a blif file.
  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. #ifndef _BNET
  35. #define _BNET
  36. /*---------------------------------------------------------------------------*/
  37. /* Nested includes */
  38. /*---------------------------------------------------------------------------*/
  39. #include "util.h"
  40. #include "st.h"
  41. #include "cudd.h"
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /*---------------------------------------------------------------------------*/
  46. /* Constant declarations */
  47. /*---------------------------------------------------------------------------*/
  48. /* Different types of nodes. (Used in the "BnetNode" type.) */
  49. #define BNET_CONSTANT_NODE 0
  50. #define BNET_INPUT_NODE 1
  51. #define BNET_PRESENT_STATE_NODE 2
  52. #define BNET_INTERNAL_NODE 3
  53. #define BNET_OUTPUT_NODE 4
  54. #define BNET_NEXT_STATE_NODE 5
  55. /* Type of DD of a node. */
  56. #define BNET_LOCAL_DD 0
  57. #define BNET_GLOBAL_DD 1
  58. /*---------------------------------------------------------------------------*/
  59. /* Stucture declarations */
  60. /*---------------------------------------------------------------------------*/
  61. /*---------------------------------------------------------------------------*/
  62. /* Type declarations */
  63. /*---------------------------------------------------------------------------*/
  64. /* The following types implement a very simple data structure for a boolean
  65. ** network. The intent is to be able to read a minimal subset of the blif
  66. ** format in a data structure from which it's easy to build DDs for the
  67. ** circuit.
  68. */
  69. /**
  70. ** @brief Type to store a line of the truth table of a node.
  71. **
  72. ** @details The entire truth table implemented as a linked list of
  73. ** objects of this type.
  74. */
  75. typedef struct BnetTabline {
  76. char *values; /**< string of 1, 0, and - */
  77. struct BnetTabline *next; /**< pointer to next table line */
  78. } BnetTabline;
  79. /**
  80. ** @brief Node of the boolean network.
  81. **
  82. ** @details There is one node in the network for each primary input
  83. ** and for each .names directive. This structure has a field to point
  84. ** to the DD of the node function. The function may be either in
  85. ** terms of primary inputs, or it may be in terms of the local
  86. ** inputs. The latter implies that each node has a variable index
  87. ** associated to it at some point in time. The field "var" stores
  88. ** that variable index, and "active" says if the association is
  89. ** currently valid. (It is indeed possible for an index to be
  90. ** associated to different nodes at different times.)
  91. */
  92. typedef struct BnetNode {
  93. char *name; /**< name of the output signal */
  94. int type; /**< input, internal, constant, ... */
  95. int ninp; /**< number of inputs to the node */
  96. int nfo; /**< number of fanout nodes for this node */
  97. char **inputs; /**< input names */
  98. BnetTabline *f; /**< truth table for this node */
  99. int polarity; /**< f is the onset (0) or the offset (1) */
  100. int active; /**< node has variable associated to it (1) or not (0) */
  101. int var; /**< %DD variable index associated to this node */
  102. DdNode *dd; /**< decision diagram for the function of this node */
  103. int exdc_flag; /**< whether an exdc node or not */
  104. struct BnetNode *exdc; /**< pointer to exdc of dd node */
  105. int count; /**< auxiliary field for %DD dropping */
  106. int level; /**< maximum distance from the inputs */
  107. int visited; /**< flag for search */
  108. struct BnetNode *next; /**< pointer to implement the linked list of nodes */
  109. } BnetNode;
  110. /**
  111. ** @brief Very simple boolean network data structure.
  112. */
  113. typedef struct BnetNetwork {
  114. char *name; /**< network name: from the .model directive */
  115. int npis; /**< number of primary inputs */
  116. int ninputs; /**< number of inputs */
  117. char **inputs; /**< primary input names: from the .inputs directive */
  118. int npos; /**< number of primary outputs */
  119. int noutputs; /**< number of outputs */
  120. char **outputs; /**< primary output names: from the .outputs directive */
  121. int nlatches; /**< number of latches */
  122. char ***latches; /**< next state names: from the .latch directives */
  123. BnetNode *nodes; /**< linked list of the nodes */
  124. st_table *hash; /**< symbol table to access nodes by name */
  125. char *slope; /**< wire_load_slope */
  126. } BnetNetwork;
  127. /*---------------------------------------------------------------------------*/
  128. /* Variable declarations */
  129. /*---------------------------------------------------------------------------*/
  130. /*---------------------------------------------------------------------------*/
  131. /* Macro declarations */
  132. /*---------------------------------------------------------------------------*/
  133. #ifndef TRUE
  134. # define TRUE 1
  135. #endif
  136. #ifndef FALSE
  137. # define FALSE 0
  138. #endif
  139. /** \cond */
  140. /*---------------------------------------------------------------------------*/
  141. /* Function prototypes */
  142. /*---------------------------------------------------------------------------*/
  143. extern BnetNetwork * Bnet_ReadNetwork (FILE *fp, int pr);
  144. extern void Bnet_PrintNetwork (BnetNetwork *net);
  145. extern void Bnet_FreeNetwork (BnetNetwork *net);
  146. extern int Bnet_BuildNodeBDD (DdManager *dd, BnetNode *nd, st_table *hash, int params, int nodrop);
  147. extern int Bnet_DfsVariableOrder (DdManager *dd, BnetNetwork *net);
  148. extern int Bnet_bddDump (DdManager *dd, BnetNetwork *network, char *dfile, int dumpFmt, int reencoded);
  149. extern int Bnet_bddArrayDump (DdManager *dd, BnetNetwork *network, char *dfile, DdNode **outputs, char **onames, int noutputs, int dumpFmt);
  150. extern int Bnet_ReadOrder (DdManager *dd, char *ordFile, BnetNetwork *net, int locGlob, int nodrop);
  151. extern int Bnet_PrintOrder (BnetNetwork * net, DdManager *dd);
  152. /** \endcond */
  153. #ifdef __cplusplus
  154. } /* end of extern "C" */
  155. #endif
  156. #endif /* _BNET */