abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cba.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cba.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Verilog parser.]
8 
9  Synopsis [External declarations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 29, 2014.]
16 
17  Revision [$Id: cba.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__base__cba__cba_h
22 #define ABC__base__cba__cba_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// INCLUDES ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 #include "aig/gia/gia.h"
30 #include "misc/extra/extra.h"
31 #include "misc/util/utilNam.h"
32 #include "misc/mem/mem.h"
33 #include "misc/extra/extra.h"
34 #include "misc/util/utilTruth.h"
35 #include "misc/vec/vecWec.h"
36 
37 ////////////////////////////////////////////////////////////////////////
38 /// PARAMETERS ///
39 ////////////////////////////////////////////////////////////////////////
40 
42 
43 ////////////////////////////////////////////////////////////////////////
44 /// BASIC TYPES ///
45 ////////////////////////////////////////////////////////////////////////
46 
47 // network objects
48 typedef enum {
49  CBA_OBJ_NONE = 0, // 0: unused
50  CBA_OBJ_BARBUF, // 1: barrier buffer
51  CBA_OBJ_PI, // 2: input
52  CBA_OBJ_PO, // 3: output
53  CBA_OBJ_PIO, // 4: input
54  CBA_OBJ_NODE, // 5: node
55  CBA_OBJ_BOX, // 6: box
56  CBA_OBJ_PIN, // 7: box output
57  CBA_OBJ_LATCH, // 8: latch
58  CBA_OBJ_UNKNOWN // 9: unknown
59 } Cba_ObjType_t;
60 
61 // Verilog predefined models
62 typedef enum {
63  CBA_NODE_NONE = 0, // 0: unused
64  CBA_NODE_CONST, // 1: constant
65  CBA_NODE_BUF, // 2: buffer
66  CBA_NODE_INV, // 3: inverter
67  CBA_NODE_AND, // 4: AND
68  CBA_NODE_NAND, // 5: NAND
69  CBA_NODE_OR, // 6: OR
70  CBA_NODE_NOR, // 7: NOR
71  CBA_NODE_XOR, // 8: XOR
72  CBA_NODE_XNOR, // 9 .XNOR
73  CBA_NODE_MUX, // 10: MUX
74  CBA_NODE_MAJ, // 11: MAJ
75  CBA_NODE_KNOWN, // 12: unknown
76  CBA_NODE_UNKNOWN // 13: unknown
78 
79 
80 // design
81 typedef struct Cba_Man_t_ Cba_Man_t;
82 struct Cba_Man_t_
83 {
84  // design names
85  char * pName; // design name
86  char * pSpec; // spec file name
87  Abc_Nam_t * pNames; // name manager
88  Abc_Nam_t * pModels; // model name manager
89  Abc_Nam_t * pFuncs; // functionality manager
90  Cba_Man_t * pLib; // library
91  // internal data
92  Mem_Flex_t * pMem; // memory
93  Vec_Ptr_t vNtks; // networks
94  int iRoot; // root network
95 };
96 
97 // network
98 typedef struct Cba_Ntk_t_ Cba_Ntk_t;
99 struct Cba_Ntk_t_
100 {
101  char * pName; // name
102  Cba_Man_t * pDesign; // design
103  // interface
104  Vec_Int_t vInouts; // inouts (used by parser to store signals)
105  Vec_Int_t vInputs; // inputs (used by parser to store signals)
106  Vec_Int_t vOutputs; // outputs (used by parser to store signals)
107  Vec_Int_t vWires; // wires (used by parser to store signals)
108  // objects
109  Vec_Int_t vTypes; // types (used by parser to store Cba_PrsType_t)
110  Vec_Int_t vFuncs; // functions (used by parser to store function)
111  Vec_Int_t vInstIds; // instance names (used by parser to store instance name as NameId)
112  Vec_Wec_t vFanins; // fanins (used by parser to store fanin/fanout/range as NameId)
113  // attributes
114  Vec_Int_t vNameIds; // original names as NameId
115  Vec_Int_t vRanges; // ranges as NameId
116  Vec_Int_t vCopies; // copy pointers
117 };
118 
119 
120 static inline char * Cba_ManName( Cba_Man_t * p ) { return p->pName; }
121 static inline int Cba_ManNtkNum( Cba_Man_t * p ) { return Vec_PtrSize(&p->vNtks) - 1; }
122 static inline Cba_Ntk_t * Cba_ManNtk( Cba_Man_t * p, int i ) { assert( i > 0 ); return (Cba_Ntk_t *)Vec_PtrEntry(&p->vNtks, i); }
123 static inline Cba_Ntk_t * Cba_ManRoot( Cba_Man_t * p ) { return Cba_ManNtk(p, p->iRoot); }
124 
125 static inline char * Cba_NtkName( Cba_Ntk_t * p ) { return p->pName; }
126 static inline int Cba_NtkObjNum( Cba_Ntk_t * p ) { return Vec_WecSize(&p->vFanins); }
127 static inline char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pNames, i); }
128 static inline char * Cba_NtkModelStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pModels, i); }
129 static inline char * Cba_NtkFuncStr( Cba_Ntk_t * p, int i ) { return Abc_NamStr(p->pDesign->pFuncs, i); }
130 
131 static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vTypes, i); }
132 static inline int Cba_ObjFuncId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vFuncs, i); }
133 static inline int Cba_ObjInstId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vInstIds, i); }
134 static inline Vec_Int_t * Cba_ObjFanins( Cba_Ntk_t * p, int i ) { return Vec_WecEntry(&p->vFanins, i); }
135 
136 static inline int Cba_ObjNameId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vNameIds, i); }
137 static inline int Cba_ObjRangeId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vRanges, i); }
138 static inline int Cba_ObjCopyId( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vCopies, i); }
139 
140 static inline char * Cba_ObjFuncStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjFuncId(p, i)); }
141 static inline char * Cba_ObjInstStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjInstId(p, i)); }
142 static inline char * Cba_ObjNameStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjNameId(p, i)); }
143 static inline char * Cba_ObjRangeStr( Cba_Ntk_t * p, int i ) { return Cba_NtkStr(p, Cba_ObjRangeId(p, i)); }
144 
145 
146 ////////////////////////////////////////////////////////////////////////
147 /// MACRO DEFINITIONS ///
148 ////////////////////////////////////////////////////////////////////////
149 
150 ////////////////////////////////////////////////////////////////////////
151 /// ITERATORS ///
152 ////////////////////////////////////////////////////////////////////////
153 
154 
155 #define Cba_ManForEachNtk( p, pNtk, i ) \
156  for ( i = 1; (i <= Cba_ManNtkNum(p)) && (((pNtk) = Cba_ManNtk(p, i)), 1); i++ )
157 
158 #define Cba_NtkForEachObjType( p, Type, i ) \
159  for ( i = 0; (i < Cba_NtkObjNum(p)) && (((Type) = Cba_ObjType(p, i)), 1); i++ )
160 #define Cba_NtkForEachObjTypeFuncFanins( p, Type, Func, vFanins, i ) \
161  for ( i = 0; (i < Cba_NtkObjNum(p)) && (((Type) = Cba_ObjType(p, i)), 1) && (((Func) = Cba_ObjFuncId(p, i)), 1) && (((vFanins) = Cba_ObjFanins(p, i)), 1); i++ )
162 
163 
164 ////////////////////////////////////////////////////////////////////////
165 /// FUNCTION DECLARATIONS ///
166 ////////////////////////////////////////////////////////////////////////
167 
168 static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName )
169 {
170  Cba_Ntk_t * pNtk = ABC_CALLOC( Cba_Ntk_t, 1 );
171  pNtk->pDesign = p;
172  pNtk->pName = Abc_UtilStrsav(pName);
173  Vec_PtrPush( &p->vNtks, pNtk );
174  return pNtk;
175 }
176 static inline void Cba_NtkFree( Cba_Ntk_t * p )
177 {
178 // Vec_IntErase( &p->vInouts );
179 // Vec_IntErase( &p->vInputs );
180 // Vec_IntErase( &p->vOutputs );
181 // Vec_IntErase( &p->vWires );
182 
183 // Vec_IntErase( &p->vTypes );
184 // Vec_IntErase( &p->vFuncs );
185 // Vec_IntErase( &p->vInstIds );
186  ABC_FREE( p->vFanins.pArray );
187 
188  Vec_IntErase( &p->vNameIds );
189  Vec_IntErase( &p->vRanges );
190  Vec_IntErase( &p->vCopies );
191  ABC_FREE( p->pName );
192  ABC_FREE( p );
193 }
194 static inline int Cba_NtkMemory( Cba_Ntk_t * p )
195 {
196  return Vec_WecMemory(&p->vFanins);
197 }
198 
199 static inline Cba_Man_t * Cba_ManAlloc( char * pFileName )
200 {
201  Cba_Man_t * p;
202  p = ABC_CALLOC( Cba_Man_t, 1 );
203  // design names
204  p->pName = Extra_FileDesignName( pFileName );
205  p->pSpec = Abc_UtilStrsav( pFileName );
206  p->pNames = Abc_NamStart( 1000, 20 );
207  p->pModels = Abc_NamStart( 1000, 20 );
208  p->pFuncs = Abc_NamStart( 1000, 20 );
209  // internal data
210  p->pMem = Mem_FlexStart();
211  Vec_PtrPush( &p->vNtks, NULL );
212  return p;
213 }
214 static inline void Cba_ManFree( Cba_Man_t * p )
215 {
216  Cba_Ntk_t * pNtk; int i;
217  Cba_ManForEachNtk( p, pNtk, i )
218  Cba_NtkFree( pNtk );
219  ABC_FREE( p->vNtks.pArray );
220  Mem_FlexStop( p->pMem, 0 );
221  // design names
222  Abc_NamStop( p->pNames );
223  Abc_NamStop( p->pModels );
224  Abc_NamStop( p->pFuncs );
225  ABC_FREE( p->pName );
226  ABC_FREE( p->pSpec );
227  ABC_FREE( p );
228 }
229 static inline int Cba_ManMemory( Cba_Man_t * p )
230 {
231  Cba_Ntk_t * pNtk; int i;
232  int nMem = sizeof(Cba_Man_t);
233  nMem += Abc_NamMemUsed(p->pNames);
234  nMem += Abc_NamMemUsed(p->pModels);
235  nMem += Abc_NamMemUsed(p->pFuncs);
236  nMem += Mem_FlexReadMemUsage(p->pMem);
237  nMem += (int)Vec_PtrMemory(&p->vNtks);
238  Cba_ManForEachNtk( p, pNtk, i )
239  nMem += Cba_NtkMemory( pNtk );
240  return nMem;
241 }
242 
243 
244 /*=== cbaReadBlif.c =========================================================*/
245 extern Cba_Man_t * Cba_PrsReadBlif( char * pFileName );
246 /*=== cbaWriteBlif.c ========================================================*/
247 extern void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes );
248 /*=== cbaReadVer.c ==========================================================*/
249 extern Cba_Man_t * Cba_PrsReadVerilog( char * pFileName );
250 /*=== cbaWriteVer.c =========================================================*/
251 extern void Cba_PrsWriteVerilog( char * pFileName, Cba_Man_t * pDes );
252 
253 
254 
256 
257 #endif
258 
259 ////////////////////////////////////////////////////////////////////////
260 /// END OF FILE ///
261 ////////////////////////////////////////////////////////////////////////
262 
Definition: cba.h:99
Abc_Nam_t * pModels
Definition: cba.h:88
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Ptr_t vNtks
Definition: cba.h:93
int iRoot
Definition: cba.h:94
void Abc_NamStop(Abc_Nam_t *p)
Definition: utilNam.c:110
static Cba_Ntk_t * Cba_NtkAlloc(Cba_Man_t *p, char *pName)
FUNCTION DECLARATIONS ///.
Definition: cba.h:168
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition: vecWec.h:42
static Cba_Ntk_t * Cba_ManRoot(Cba_Man_t *p)
Definition: cba.h:123
void Cba_PrsWriteVerilog(char *pFileName, Cba_Man_t *pDes)
Definition: cbaWriteVer.c:207
Definition: cba.h:52
char * pName
Definition: cba.h:85
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Mem_Flex_t * pMem
Definition: cba.h:92
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Int_t vWires
Definition: cba.h:107
static int Cba_ObjFuncId(Cba_Ntk_t *p, int i)
Definition: cba.h:132
static char * Cba_ObjNameStr(Cba_Ntk_t *p, int i)
Definition: cba.h:142
static double Vec_WecMemory(Vec_Wec_t *p)
Definition: vecWec.h:308
Cba_Man_t * pLib
Definition: cba.h:90
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static char * Cba_NtkName(Cba_Ntk_t *p)
Definition: cba.h:125
static void Vec_IntErase(Vec_Int_t *p)
Definition: vecInt.h:266
static int Cba_ObjNameId(Cba_Ntk_t *p, int i)
Definition: cba.h:136
Vec_Int_t vInputs
Definition: cba.h:105
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
char * pName
Definition: cba.h:101
static void Cba_NtkFree(Cba_Ntk_t *p)
Definition: cba.h:176
Abc_Nam_t * pNames
Definition: cba.h:87
static int Vec_WecSize(Vec_Wec_t *p)
Definition: vecWec.h:193
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
Definition: utilNam.c:78
static int Cba_ObjRangeId(Cba_Ntk_t *p, int i)
Definition: cba.h:137
static Cba_Man_t * Cba_ManAlloc(char *pFileName)
Definition: cba.h:199
Vec_Int_t vOutputs
Definition: cba.h:106
static Cba_ObjType_t Cba_ObjType(Cba_Ntk_t *p, int i)
Definition: cba.h:131
static Vec_Int_t * Cba_ObjFanins(Cba_Ntk_t *p, int i)
Definition: cba.h:134
Mem_Flex_t * Mem_FlexStart()
Definition: mem.c:311
Vec_Int_t vFuncs
Definition: cba.h:110
static int Cba_NtkObjNum(Cba_Ntk_t *p)
Definition: cba.h:126
static char * Cba_NtkModelStr(Cba_Ntk_t *p, int i)
Definition: cba.h:128
static int Cba_ObjInstId(Cba_Ntk_t *p, int i)
Definition: cba.h:133
static void Cba_ManFree(Cba_Man_t *p)
Definition: cba.h:214
int Abc_NamMemUsed(Abc_Nam_t *p)
Definition: utilNam.c:202
Definition: cba.h:51
static char * Cba_ObjFuncStr(Cba_Ntk_t *p, int i)
Definition: cba.h:140
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static char * Cba_ManName(Cba_Man_t *p)
Definition: cba.h:120
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
struct Cba_Man_t_ Cba_Man_t
Definition: cba.h:81
Cba_Man_t * Cba_PrsReadBlif(char *pFileName)
Definition: cbaReadBlif.c:400
Cba_NodeType_t
Definition: cba.h:62
static char * Cba_ObjInstStr(Cba_Ntk_t *p, int i)
Definition: cba.h:141
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static double Vec_PtrMemory(Vec_Ptr_t *p)
Definition: vecPtr.h:327
char * pSpec
Definition: cba.h:86
static int Cba_ManMemory(Cba_Man_t *p)
Definition: cba.h:229
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
Cba_Man_t * Cba_PrsReadVerilog(char *pFileName)
Definition: cbaReadVer.c:714
Vec_Wec_t vFanins
Definition: cba.h:112
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
Definition: utilNam.c:479
static int Cba_ObjCopyId(Cba_Ntk_t *p, int i)
Definition: cba.h:138
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
Definition: mem.c:343
static Cba_Ntk_t * Cba_ManNtk(Cba_Man_t *p, int i)
Definition: cba.h:122
Definition: cba.h:82
Vec_Int_t vInstIds
Definition: cba.h:111
static Vec_Int_t * Vec_WecEntry(Vec_Wec_t *p, int i)
Definition: vecWec.h:142
static int Cba_ManNtkNum(Cba_Man_t *p)
Definition: cba.h:121
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
Abc_Nam_t * pFuncs
Definition: cba.h:89
Vec_Int_t vRanges
Definition: cba.h:115
Cba_ObjType_t
INCLUDES ///.
Definition: cba.h:48
#define ABC_FREE(obj)
Definition: abc_global.h:232
static char * Cba_ObjRangeStr(Cba_Ntk_t *p, int i)
Definition: cba.h:143
int Mem_FlexReadMemUsage(Mem_Flex_t *p)
Definition: mem.c:445
char * Extra_FileDesignName(char *pFileName)
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
Vec_Int_t vCopies
Definition: cba.h:116
Vec_Int_t vNameIds
Definition: cba.h:114
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
Definition: utilNam.h:39
void Cba_PrsWriteBlif(char *pFileName, Cba_Man_t *pDes)
Definition: cbaWriteBlif.c:105
#define assert(ex)
Definition: util_old.h:213
static char * Cba_NtkFuncStr(Cba_Ntk_t *p, int i)
Definition: cba.h:129
Vec_Int_t vInouts
Definition: cba.h:104
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static int Cba_NtkMemory(Cba_Ntk_t *p)
Definition: cba.h:194
Cba_Man_t * pDesign
Definition: cba.h:102
Vec_Int_t vTypes
Definition: cba.h:109
#define Cba_ManForEachNtk(p, pNtk, i)
MACRO DEFINITIONS ///.
Definition: cba.h:155