abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cbaPrs.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cbaPrs.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: cbaPrs.h,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__base__prs__prs_h
22 #define ABC__base__prs__prs_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// INCLUDES ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// PARAMETERS ///
31 ////////////////////////////////////////////////////////////////////////
32 
34 
35 // parser objects (object types after parsing)
36 typedef enum {
37  CBA_PRS_NONE = 0, // 0: unused
38  CBA_PRS_NODE, // 1: .names/assign/box2 (box without formal/actual binding)
39  CBA_PRS_BOX, // 2: .subckt/.gate/box (box with formal/actual binding)
40  CBA_PRS_LATCH, // 3: .latch
41  CBA_PRS_CONCAT, // 4: concatenation
42  CBA_PRS_UNKNOWN // 5: unknown
43 } Cba_PrsType_t;
44 
45 ////////////////////////////////////////////////////////////////////////
46 /// BASIC TYPES ///
47 ////////////////////////////////////////////////////////////////////////
48 
49 // parser
50 typedef struct Cba_Prs_t_ Cba_Prs_t;
51 struct Cba_Prs_t_
52 {
53  // input data
54  char * pName; // file name
55  char * pBuffer; // file contents
56  char * pLimit; // end of file
57  char * pCur; // current position
58  // construction
61  // interface collected by the parser
62  int iModuleName; // name Id
63  Vec_Int_t vInoutsCur; // inouts
64  Vec_Int_t vInputsCur; // inputs
65  Vec_Int_t vOutputsCur; // outputs
66  Vec_Int_t vWiresCur; // wires
67  // objects collected by the parser
68  Vec_Int_t vTypesCur; // Cba_PrsType_t
69  Vec_Int_t vFuncsCur; // functions (node->func; box->module; gate->cell; latch->init; concat->unused)
70  Vec_Int_t vInstIdsCur; // instance names
71  Vec_Wec_t vFaninsCur; // instances
72  // temporary data
73  Vec_Str_t vCover; // one SOP cover
74  Vec_Int_t vTemp; // array of tokens
75  Vec_Int_t vTemp2; // array of tokens
76  // statistics
80  // error handling
81  char ErrorStr[1000]; // error
82 };
83 
84 #define Cba_PrsForEachModelVec( vVec, p, pName, i ) \
85  for ( i = 0; (i < Vec_IntSize(vVec)) && ((pName) = Abc_NamStr(p->pDesign->pNames, Vec_IntEntry(vVec,i))); i++ )
86 
87 ////////////////////////////////////////////////////////////////////////
88 /// MACRO DEFINITIONS ///
89 ////////////////////////////////////////////////////////////////////////
90 
91 // create error message
92 static inline int Cba_PrsErrorSet( Cba_Prs_t * p, char * pError, int Value )
93 {
94  assert( !p->ErrorStr[0] );
95  sprintf( p->ErrorStr, "%s", pError );
96  return Value;
97 }
98 // clear error message
99 static inline void Cba_PrsErrorClear( Cba_Prs_t * p )
100 {
101  p->ErrorStr[0] = '\0';
102 }
103 // print error message
104 static inline int Cba_PrsErrorPrint( Cba_Prs_t * p )
105 {
106  char * pThis; int iLine = 0;
107  if ( !p->ErrorStr[0] ) return 1;
108  for ( pThis = p->pBuffer; pThis < p->pCur; pThis++ )
109  iLine += (int)(*pThis == '\n');
110  printf( "Line %d: %s\n", iLine, p->ErrorStr );
111  return 0;
112 }
113 
114 
115 // copy contents to the vector
116 static inline void Cba_PrsSetupVecInt( Cba_Prs_t * p, Vec_Int_t * vTo, Vec_Int_t * vFrom )
117 {
118  if ( Vec_IntSize(vFrom) == 0 )
119  return;
120  vTo->nSize = vTo->nCap = Vec_IntSize(vFrom);
121  vTo->pArray = (int *)Mem_FlexEntryFetch( p->pDesign->pMem, sizeof(int) * Vec_IntSize(vFrom) );
122  memcpy( Vec_IntArray(vTo), Vec_IntArray(vFrom), sizeof(int) * Vec_IntSize(vFrom) );
123  Vec_IntClear( vFrom );
124 }
125 static inline Cba_Ntk_t * Cba_PrsAddCurrentModel( Cba_Prs_t * p, int iNameId )
126 {
127  Cba_Ntk_t * pNtk = Cba_NtkAlloc( p->pDesign, Abc_NamStr(p->pDesign->pNames, iNameId) );
128  assert( Vec_IntSize(&p->vInputsCur) != 0 || Vec_IntSize(&p->vOutputsCur) != 0 );
129  Cba_PrsSetupVecInt( p, &pNtk->vInouts, &p->vInoutsCur );
130  Cba_PrsSetupVecInt( p, &pNtk->vInputs, &p->vInputsCur );
131  Cba_PrsSetupVecInt( p, &pNtk->vOutputs, &p->vOutputsCur );
132  Cba_PrsSetupVecInt( p, &pNtk->vWires, &p->vWiresCur );
133  Cba_PrsSetupVecInt( p, &pNtk->vTypes, &p->vTypesCur );
134  Cba_PrsSetupVecInt( p, &pNtk->vFuncs, &p->vFuncsCur );
135  Cba_PrsSetupVecInt( p, &pNtk->vInstIds, &p->vInstIdsCur );
136  pNtk->vFanins = p->vFaninsCur;
137  Vec_WecZero( &p->vFaninsCur );
138  return pNtk;
139 }
140 
141 
142 
143 static inline char * Cba_PrsLoadFile( char * pFileName, char ** ppLimit )
144 {
145  char * pBuffer;
146  int nFileSize, RetValue;
147  FILE * pFile = fopen( pFileName, "rb" );
148  if ( pFile == NULL )
149  {
150  printf( "Cannot open input file.\n" );
151  return NULL;
152  }
153  // get the file size, in bytes
154  fseek( pFile, 0, SEEK_END );
155  nFileSize = ftell( pFile );
156  // move the file current reading position to the beginning
157  rewind( pFile );
158  // load the contents of the file into memory
159  pBuffer = ABC_ALLOC( char, nFileSize + 3 );
160  pBuffer[0] = '\n';
161  RetValue = fread( pBuffer+1, nFileSize, 1, pFile );
162  // terminate the string with '\0'
163  pBuffer[nFileSize + 0] = '\n';
164  pBuffer[nFileSize + 1] = '\0';
165  *ppLimit = pBuffer + nFileSize + 2;
166  return pBuffer;
167 }
168 static inline Cba_Prs_t * Cba_PrsAlloc( char * pFileName )
169 {
170  Cba_Prs_t * p;
171  char * pBuffer, * pLimit;
172  pBuffer = Cba_PrsLoadFile( pFileName, &pLimit );
173  if ( pBuffer == NULL )
174  return NULL;
175  p = ABC_CALLOC( Cba_Prs_t, 1 );
176  p->pName = pFileName;
177  p->pBuffer = pBuffer;
178  p->pLimit = pLimit;
179  p->pCur = pBuffer;
180  p->pDesign = Cba_ManAlloc( pFileName );
181  return p;
182 }
183 static inline void Cba_PrsFree( Cba_Prs_t * p )
184 {
185  if ( p->pDesign )
186  Cba_ManFree( p->pDesign );
187  Vec_IntErase( &p->vInoutsCur );
188  Vec_IntErase( &p->vInputsCur );
189  Vec_IntErase( &p->vOutputsCur );
190  Vec_IntErase( &p->vWiresCur );
191 
192  Vec_IntErase( &p->vTypesCur );
193  Vec_IntErase( &p->vFuncsCur );
194  Vec_IntErase( &p->vInstIdsCur );
195  ABC_FREE( p->vFaninsCur.pArray );
196  // temporary
197  Vec_StrErase( &p->vCover );
198  Vec_IntErase( &p->vTemp );
199  Vec_IntErase( &p->vTemp2 );
200 
201  Vec_IntErase( &p->vKnown );
202  Vec_IntErase( &p->vFailed );
203  Vec_IntErase( &p->vSucceeded );
204  ABC_FREE( p->pBuffer );
205  ABC_FREE( p );
206 }
207 
208 ////////////////////////////////////////////////////////////////////////
209 /// ITERATORS ///
210 ////////////////////////////////////////////////////////////////////////
211 
212 ////////////////////////////////////////////////////////////////////////
213 /// FUNCTION DECLARATIONS ///
214 ////////////////////////////////////////////////////////////////////////
215 
216 /*=== cba.c ========================================================*/
217 
218 
220 
221 #endif
222 
223 ////////////////////////////////////////////////////////////////////////
224 /// END OF FILE ///
225 ////////////////////////////////////////////////////////////////////////
226 
Definition: cba.h:99
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static int Cba_PrsErrorSet(Cba_Prs_t *p, char *pError, int Value)
MACRO DEFINITIONS ///.
Definition: cbaPrs.h:92
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 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 vTypesCur
Definition: cbaPrs.h:68
Vec_Int_t vKnown
Definition: cbaPrs.h:77
Vec_Int_t vSucceeded
Definition: cbaPrs.h:79
Vec_Int_t vWires
Definition: cba.h:107
#define SEEK_END
Definition: zconf.h:392
Vec_Int_t vTemp2
Definition: cbaPrs.h:75
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static void Vec_IntErase(Vec_Int_t *p)
Definition: vecInt.h:266
Vec_Int_t vInputs
Definition: cba.h:105
Abc_Nam_t * pNames
Definition: cba.h:87
Vec_Int_t vFailed
Definition: cbaPrs.h:78
Vec_Int_t vInoutsCur
Definition: cbaPrs.h:63
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
Definition: mem.c:372
static Cba_Man_t * Cba_ManAlloc(char *pFileName)
Definition: cba.h:199
Vec_Int_t vInputsCur
Definition: cbaPrs.h:64
Vec_Str_t vCover
Definition: cbaPrs.h:73
static void Vec_WecZero(Vec_Wec_t *p)
Definition: vecWec.h:330
Vec_Int_t vOutputs
Definition: cba.h:106
Vec_Int_t vFuncs
Definition: cba.h:110
int iModuleName
Definition: cbaPrs.h:62
Vec_Int_t vFuncsCur
Definition: cbaPrs.h:69
static void Cba_ManFree(Cba_Man_t *p)
Definition: cba.h:214
static void Cba_PrsErrorClear(Cba_Prs_t *p)
Definition: cbaPrs.h:99
static void Cba_PrsSetupVecInt(Cba_Prs_t *p, Vec_Int_t *vTo, Vec_Int_t *vFrom)
Definition: cbaPrs.h:116
Cba_Man_t * pDesign
Definition: cbaPrs.h:60
Cba_PrsType_t
INCLUDES ///.
Definition: cbaPrs.h:36
Vec_Int_t vWiresCur
Definition: cbaPrs.h:66
char * pCur
Definition: cbaPrs.h:57
static Cba_Prs_t * Cba_PrsAlloc(char *pFileName)
Definition: cbaPrs.h:168
char * sprintf()
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
Vec_Wec_t vFaninsCur
Definition: cbaPrs.h:71
static int Cba_PrsErrorPrint(Cba_Prs_t *p)
Definition: cbaPrs.h:104
Vec_Int_t vOutputsCur
Definition: cbaPrs.h:65
static Cba_Ntk_t * Cba_PrsAddCurrentModel(Cba_Prs_t *p, int iNameId)
Definition: cbaPrs.h:125
char ErrorStr[1000]
Definition: cbaPrs.h:81
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
Vec_Wec_t vFanins
Definition: cba.h:112
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
Definition: utilNam.c:479
Definition: cba.h:82
Vec_Int_t vInstIds
Definition: cba.h:111
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
char * pBuffer
Definition: cbaPrs.h:55
Cba_Man_t * pLibrary
Definition: cbaPrs.h:59
Vec_Int_t vInstIdsCur
Definition: cbaPrs.h:70
char * pName
Definition: cbaPrs.h:54
char * pLimit
Definition: cbaPrs.h:56
static void Cba_PrsFree(Cba_Prs_t *p)
Definition: cbaPrs.h:183
#define ABC_FREE(obj)
Definition: abc_global.h:232
Vec_Int_t vTemp
Definition: cbaPrs.h:74
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
static char * Cba_PrsLoadFile(char *pFileName, char **ppLimit)
Definition: cbaPrs.h:143
Vec_Int_t vInouts
Definition: cba.h:104
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
VOID_HACK rewind()
static void Vec_StrErase(Vec_Str_t *p)
Definition: vecStr.h:210
Vec_Int_t vTypes
Definition: cba.h:109