ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sclCon.h
Go to the documentation of this file.
1
20
21#ifndef ABC__scl_Con__h
22#define ABC__scl_Con__h
23
25
29
30typedef struct Scl_Con_t_ Scl_Con_t;
32{
33 char * pFileName; // constraint file name
34 char * pModelName; // current design name
35 char * pInCellDef; // default input driving gate
36 int tInArrDef; // default input arrival time
37 int tInSlewDef; // default input slew
38 int tInLoadDef; // default input load
39 int tOutReqDef; // default output required time
40 int tOutLoadDef; // default output load
41 Vec_Ptr_t vInCells; // input driving gate names
42 Vec_Ptr_t vInCellsPtr; // input driving gates
43 Vec_Int_t vInArrs; // input arrival times
44 Vec_Int_t vInSlews; // input slews
45 Vec_Int_t vInLoads; // input loads
46 Vec_Int_t vOutReqs; // output required times
47 Vec_Int_t vOutLoads; // output loads
48 Abc_Nam_t * pNamI; // input names
49 Abc_Nam_t * pNamO; // output names
50};
51
52#define SCL_INPUT_CELL "input_cell"
53#define SCL_INPUT_ARR "input_arrival"
54#define SCL_INPUT_SLEW "input_slew"
55#define SCL_INPUT_LOAD "input_load"
56#define SCL_OUTPUT_REQ "output_required"
57#define SCL_OUTPUT_LOAD "output_load"
58
59#define SCL_DIRECTIVE(ITEM) "."#ITEM
60#define SCL_DEF_DIRECTIVE(ITEM) ".default_"#ITEM
61
62#define SCL_NUM 1000
63#define SCL_INFINITY (0x3FFFFFFF)
64
65static inline int Scl_Flt2Int( float w ) { return SCL_NUM*w; }
66static inline float Scl_Int2Flt( int i ) { return (float)i/SCL_NUM; }
67
71
83static inline Scl_Con_t * Scl_ConAlloc( char * pFileName, Abc_Nam_t * pNamI, Abc_Nam_t * pNamO )
84{
86 p->pFileName = Abc_UtilStrsav( pFileName );
87 p->pNamI = pNamI;
88 p->pNamO = pNamO;
89 p->pModelName = NULL;
90 p->pInCellDef = NULL;
91 p->tInArrDef = SCL_INFINITY;
92 p->tInSlewDef = SCL_INFINITY;
93 p->tInLoadDef = SCL_INFINITY;
94 p->tOutReqDef = SCL_INFINITY;
95 p->tOutLoadDef = SCL_INFINITY;
96 Vec_PtrFill( &p->vInCells, Abc_NamObjNumMax(pNamI)-1, NULL );
97 Vec_IntFill( &p->vInArrs, Abc_NamObjNumMax(pNamI)-1, SCL_INFINITY );
98 Vec_IntFill( &p->vInSlews, Abc_NamObjNumMax(pNamI)-1, SCL_INFINITY );
99 Vec_IntFill( &p->vInLoads, Abc_NamObjNumMax(pNamI)-1, SCL_INFINITY );
100 Vec_IntFill( &p->vOutReqs, Abc_NamObjNumMax(pNamO)-1, SCL_INFINITY );
101 Vec_IntFill( &p->vOutLoads, Abc_NamObjNumMax(pNamO)-1, SCL_INFINITY );
102 return p;
103}
104static inline void Scl_ConFree( Scl_Con_t * p )
105{
106 Vec_PtrErase( &p->vInCellsPtr );
107 Vec_PtrFreeData( &p->vInCells );
108 Vec_PtrErase( &p->vInCells );
109 Vec_IntErase( &p->vInArrs );
110 Vec_IntErase( &p->vInSlews );
111 Vec_IntErase( &p->vInLoads );
112 Vec_IntErase( &p->vOutReqs );
113 Vec_IntErase( &p->vOutLoads );
114 Abc_NamDeref( p->pNamI );
115 Abc_NamDeref( p->pNamO );
116 ABC_FREE( p->pInCellDef );
117 ABC_FREE( p->pModelName );
118 ABC_FREE( p->pFileName );
119 ABC_FREE( p );
120}
121
122
134static inline int Scl_ConParse( Scl_Con_t * p, Abc_Nam_t * pNamI, Abc_Nam_t * pNamO )
135{
136 char Buffer[1000];
137 char * pToken, * pToken2, * pToken3, * pName;
138 int i, Num = -1, nLines = 0; int Value;
139 FILE * pFile = fopen( p->pFileName, "rb" );
140 while ( fgets( Buffer, 1000, pFile ) )
141 {
142 nLines++;
143 pToken = strtok( Buffer, " \t\r\n" );
144 if ( pToken == NULL )
145 continue;
146 pToken2 = strtok( NULL, " \t\r\n" );
147 if ( pToken2 == NULL )
148 {
149 printf( "Line %d: Skipping directive \"%s\" without argument.\n", nLines, pToken );
150 continue;
151 }
152 pToken3 = strtok( NULL, " \t\r\n" );
153 if ( !strcmp(pToken, ".model") ) p->pModelName = Abc_UtilStrsav(pToken2);
154 else if ( !strcmp(pToken, SCL_DEF_DIRECTIVE(SCL_INPUT_CELL)) ) p->pInCellDef = Abc_UtilStrsav(pToken2);
155 else if ( !strcmp(pToken, SCL_DEF_DIRECTIVE(SCL_INPUT_ARR)) ) p->tInArrDef = Scl_Flt2Int(atof(pToken2));
156 else if ( !strcmp(pToken, SCL_DEF_DIRECTIVE(SCL_INPUT_SLEW)) ) p->tInSlewDef = Scl_Flt2Int(atof(pToken2));
157 else if ( !strcmp(pToken, SCL_DEF_DIRECTIVE(SCL_INPUT_LOAD)) ) p->tInLoadDef = Scl_Flt2Int(atof(pToken2));
158 else if ( !strcmp(pToken, SCL_DEF_DIRECTIVE(SCL_OUTPUT_REQ)) ) p->tOutReqDef = Scl_Flt2Int(atof(pToken2));
159 else if ( !strcmp(pToken, SCL_DEF_DIRECTIVE(SCL_OUTPUT_LOAD))) p->tOutLoadDef = Scl_Flt2Int(atof(pToken2));
160 else if ( pToken3 == NULL ) { printf( "Directive %s should be followed by two arguments.\n", pToken ); continue; }
161 else if ( !strcmp(pToken, SCL_DIRECTIVE(SCL_INPUT_CELL)) ) if ( (Num = Abc_NamStrFind(pNamI, pToken2)) > 0 ) Vec_PtrWriteEntry( &p->vInCells, Num-1, Abc_UtilStrsav(pToken3) ); else printf( "Line %d: Cannot find input \"%s\".\n", nLines, pToken2 );
162 else if ( !strcmp(pToken, SCL_DIRECTIVE(SCL_INPUT_ARR)) ) if ( (Num = Abc_NamStrFind(pNamI, pToken2)) > 0 ) Vec_IntWriteEntry( &p->vInArrs, Num-1, Scl_Flt2Int(atof(pToken3)) ); else printf( "Line %d: Cannot find input \"%s\".\n", nLines, pToken2 );
163 else if ( !strcmp(pToken, SCL_DIRECTIVE(SCL_INPUT_SLEW)) ) if ( (Num = Abc_NamStrFind(pNamI, pToken2)) > 0 ) Vec_IntWriteEntry( &p->vInSlews, Num-1, Scl_Flt2Int(atof(pToken3)) ); else printf( "Line %d: Cannot find input \"%s\".\n", nLines, pToken2 );
164 else if ( !strcmp(pToken, SCL_DIRECTIVE(SCL_INPUT_LOAD)) ) if ( (Num = Abc_NamStrFind(pNamI, pToken2)) > 0 ) Vec_IntWriteEntry( &p->vInLoads, Num-1, Scl_Flt2Int(atof(pToken3)) ); else printf( "Line %d: Cannot find input \"%s\".\n", nLines, pToken2 );
165 else if ( !strcmp(pToken, SCL_DIRECTIVE(SCL_OUTPUT_REQ)) ) if ( (Num = Abc_NamStrFind(pNamO, pToken2)) > 0 ) Vec_IntWriteEntry( &p->vOutReqs, Num-1, Scl_Flt2Int(atof(pToken3)) ); else printf( "Line %d: Cannot find output \"%s\".\n", nLines, pToken2 );
166 else if ( !strcmp(pToken, SCL_DIRECTIVE(SCL_OUTPUT_LOAD)) ) if ( (Num = Abc_NamStrFind(pNamO, pToken2)) > 0 ) Vec_IntWriteEntry( &p->vOutLoads, Num-1, Scl_Flt2Int(atof(pToken3)) ); else printf( "Line %d: Cannot find output \"%s\".\n", nLines, pToken2 );
167 else printf( "Line %d: Skipping unrecognized directive \"%s\".\n", nLines, pToken );
168 }
169 // set missing defaults
170 if ( p->pInCellDef == NULL ) p->pInCellDef = NULL; // consider using buffer from the current library
171 if ( p->tInArrDef == SCL_INFINITY ) p->tInArrDef = 0;
172 if ( p->tInSlewDef == SCL_INFINITY ) p->tInSlewDef = 0;
173 if ( p->tInLoadDef == SCL_INFINITY ) p->tInLoadDef = 0;
174 if ( p->tOutReqDef == SCL_INFINITY ) p->tOutReqDef = 0;
175 if ( p->tOutLoadDef == SCL_INFINITY ) p->tOutLoadDef = 0;
176 // set individual defaults
177 if ( p->pInCellDef )
178 Vec_PtrForEachEntry(char *, &p->vInCells, pName, i) if ( pName == NULL ) Vec_PtrWriteEntry( &p->vInCells, i, Abc_UtilStrsav(p->pInCellDef) );
179 Vec_IntForEachEntry( &p->vInArrs, Value, i ) if ( Value == SCL_INFINITY ) Vec_IntWriteEntry( &p->vInArrs, i, p->tInArrDef );
180 Vec_IntForEachEntry( &p->vInSlews, Value, i ) if ( Value == SCL_INFINITY ) Vec_IntWriteEntry( &p->vInSlews, i, p->tInSlewDef );
181 Vec_IntForEachEntry( &p->vInLoads, Value, i ) if ( Value == SCL_INFINITY ) Vec_IntWriteEntry( &p->vInLoads, i, p->tInLoadDef );
182 Vec_IntForEachEntry( &p->vOutReqs, Value, i ) if ( Value == SCL_INFINITY ) Vec_IntWriteEntry( &p->vOutReqs, i, p->tOutReqDef );
183 Vec_IntForEachEntry( &p->vOutLoads, Value, i ) if ( Value == SCL_INFINITY ) Vec_IntWriteEntry( &p->vOutLoads, i, p->tOutLoadDef );
184
185 fclose( pFile );
186 return 1;
187}
188static inline Scl_Con_t * Scl_ConRead( char * pFileName, Abc_Nam_t * pNamI, Abc_Nam_t * pNamO )
189{
190 Scl_Con_t * p = Scl_ConAlloc( pFileName, pNamI, pNamO );
191 if ( Scl_ConParse(p, pNamI, pNamO) )
192 return p;
193 Scl_ConFree( p );
194 return NULL;
195}
196static inline void Scl_ConWrite( Scl_Con_t * p, char * pFileName )
197{
198 char * pName; int Value; int i;
199 FILE * pFile = pFileName ? fopen( pFileName, "wb" ) : stdout;
200 if ( pFile == NULL )
201 {
202 printf( "Cannot open output file \"%s\".\n", pFileName );
203 return;
204 }
205 fprintf( pFile, ".model %s\n", p->pModelName );
206
207 if ( p->pInCellDef ) fprintf( pFile, ".default_%s %s\n", SCL_INPUT_CELL, p->pInCellDef );
208 if ( p->tInArrDef != 0 ) fprintf( pFile, ".default_%s %.2f\n", SCL_INPUT_ARR, Scl_Int2Flt(p->tInArrDef) );
209 if ( p->tInSlewDef != 0 ) fprintf( pFile, ".default_%s %.2f\n", SCL_INPUT_SLEW, Scl_Int2Flt(p->tInSlewDef) );
210 if ( p->tInLoadDef != 0 ) fprintf( pFile, ".default_%s %.2f\n", SCL_INPUT_LOAD, Scl_Int2Flt(p->tInLoadDef) );
211 if ( p->tOutReqDef != 0 ) fprintf( pFile, ".default_%s %.2f\n", SCL_OUTPUT_REQ, Scl_Int2Flt(p->tOutReqDef) );
212 if ( p->tOutLoadDef != 0 ) fprintf( pFile, ".default_%s %.2f\n", SCL_OUTPUT_LOAD, Scl_Int2Flt(p->tOutLoadDef) );
213
214 Vec_PtrForEachEntry(char *, &p->vInCells, pName, i) if ( pName && (!p->pInCellDef || strcmp(pName,p->pInCellDef)) ) fprintf( pFile, ".%s %s %s\n", SCL_INPUT_CELL, Abc_NamStr(p->pNamI, i+1), pName );
215 Vec_IntForEachEntry( &p->vInArrs, Value, i ) if ( Value != p->tInArrDef ) fprintf( pFile, ".%s %s %.2f\n", SCL_INPUT_ARR, Abc_NamStr(p->pNamI, i+1), Scl_Int2Flt(Value) );
216 Vec_IntForEachEntry( &p->vInSlews, Value, i ) if ( Value != p->tInSlewDef ) fprintf( pFile, ".%s %s %.2f\n", SCL_INPUT_SLEW, Abc_NamStr(p->pNamI, i+1), Scl_Int2Flt(Value) );
217 Vec_IntForEachEntry( &p->vInLoads, Value, i ) if ( Value != p->tInLoadDef ) fprintf( pFile, ".%s %s %.2f\n", SCL_INPUT_LOAD, Abc_NamStr(p->pNamI, i+1), Scl_Int2Flt(Value) );
218 Vec_IntForEachEntry( &p->vOutReqs, Value, i ) if ( Value != p->tOutReqDef ) fprintf( pFile, ".%s %s %.2f\n", SCL_OUTPUT_REQ, Abc_NamStr(p->pNamO, i+1), Scl_Int2Flt(Value) );
219 Vec_IntForEachEntry( &p->vOutLoads, Value, i ) if ( Value != p->tOutLoadDef ) fprintf( pFile, ".%s %s %.2f\n", SCL_OUTPUT_LOAD, Abc_NamStr(p->pNamO, i+1), Scl_Int2Flt(Value) );
220
221 if ( pFile != stdout )
222 fclose ( pFile );
223}
224
236static inline int Scl_ConHasInCells_( Scl_Con_t * p ) { return Vec_PtrCountZero(&p->vInCells) != Vec_PtrSize(&p->vInCells); }
237static inline int Scl_ConHasInArrs_( Scl_Con_t * p ) { return Vec_IntCountZero(&p->vInArrs) != Vec_IntSize(&p->vInArrs); }
238static inline int Scl_ConHasInSlews_( Scl_Con_t * p ) { return Vec_IntCountZero(&p->vInSlews) != Vec_IntSize(&p->vInSlews); }
239static inline int Scl_ConHasInLoads_( Scl_Con_t * p ) { return Vec_IntCountZero(&p->vInLoads) != Vec_IntSize(&p->vInLoads); }
240static inline int Scl_ConHasOutReqs_( Scl_Con_t * p ) { return Vec_IntCountZero(&p->vOutReqs) != Vec_IntSize(&p->vOutReqs); }
241static inline int Scl_ConHasOutLoads_( Scl_Con_t * p ) { return Vec_IntCountZero(&p->vOutLoads) != Vec_IntSize(&p->vOutLoads); }
242
243static inline char * Scl_ConGetInCell_( Scl_Con_t * p, int i ) { return (char*)Vec_PtrEntry( &p->vInCells, i ); }
244static inline int Scl_ConGetInArr_( Scl_Con_t * p, int i ) { return Vec_IntEntry( &p->vInArrs, i ); }
245static inline int Scl_ConGetInSlew_( Scl_Con_t * p, int i ) { return Vec_IntEntry( &p->vInSlews, i ); }
246static inline int Scl_ConGetInLoad_( Scl_Con_t * p, int i ) { return Vec_IntEntry( &p->vInLoads, i ); }
247static inline int Scl_ConGetOutReq_( Scl_Con_t * p, int i ) { return Vec_IntEntry( &p->vOutReqs, i ); }
248static inline int Scl_ConGetOutLoad_( Scl_Con_t * p, int i ) { return Vec_IntEntry( &p->vOutLoads, i ); }
249
261extern Scl_Con_t * Scl_ConReadMan();
262
263static inline int Scl_ConIsRunning() { return Scl_ConReadMan() != NULL; }
264
265static inline int Scl_ConHasInCells() { return Scl_ConHasInCells_ ( Scl_ConReadMan() ); }
266static inline int Scl_ConHasInArrs() { return Scl_ConHasInArrs_ ( Scl_ConReadMan() ); }
267static inline int Scl_ConHasInSlews() { return Scl_ConHasInSlews_ ( Scl_ConReadMan() ); }
268static inline int Scl_ConHasInLoads() { return Scl_ConHasInLoads_ ( Scl_ConReadMan() ); }
269static inline int Scl_ConHasOutReqs() { return Scl_ConHasOutReqs_ ( Scl_ConReadMan() ); }
270static inline int Scl_ConHasOutLoads() { return Scl_ConHasOutLoads_( Scl_ConReadMan() ); }
271
272static inline char * Scl_ConGetInCell( int i ) { return Scl_ConGetInCell_ ( Scl_ConReadMan(), i ); }
273static inline int Scl_ConGetInArr( int i ) { return Scl_ConGetInArr_ ( Scl_ConReadMan(), i ); }
274static inline int Scl_ConGetInSlew( int i ) { return Scl_ConGetInSlew_ ( Scl_ConReadMan(), i ); }
275static inline int Scl_ConGetInLoad( int i ) { return Scl_ConGetInLoad_ ( Scl_ConReadMan(), i ); }
276static inline int Scl_ConGetOutReq( int i ) { return Scl_ConGetOutReq_ ( Scl_ConReadMan(), i ); }
277static inline int Scl_ConGetOutLoad( int i ) { return Scl_ConGetOutLoad_( Scl_ConReadMan(), i ); }
278
279static inline float Scl_ConGetInArrFloat( int i ) { return Scl_Int2Flt( Scl_ConGetInArr(i) ); }
280static inline float Scl_ConGetInSlewFloat( int i ) { return Scl_Int2Flt( Scl_ConGetInSlew(i) ); }
281static inline float Scl_ConGetInLoadFloat( int i ) { return Scl_Int2Flt( Scl_ConGetInLoad(i) ); }
282static inline float Scl_ConGetOutReqFloat( int i ) { return Scl_Int2Flt( Scl_ConGetOutReq(i) ); }
283static inline float Scl_ConGetOutLoadFloat( int i ) { return Scl_Int2Flt( Scl_ConGetOutLoad(i) ); }
284
285
287
288#endif
289
293
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
typedefABC_NAMESPACE_HEADER_START struct Scl_Con_t_ Scl_Con_t
DECLARATIONS ///.
Definition sclCon.h:30
#define SCL_NUM
Definition sclCon.h:62
#define SCL_OUTPUT_REQ
Definition sclCon.h:56
Scl_Con_t * Scl_ConReadMan()
Definition scl.c:62
#define SCL_DEF_DIRECTIVE(ITEM)
Definition sclCon.h:60
#define SCL_INPUT_ARR
Definition sclCon.h:53
#define SCL_INFINITY
Definition sclCon.h:63
#define SCL_INPUT_SLEW
Definition sclCon.h:54
#define SCL_INPUT_LOAD
Definition sclCon.h:55
#define SCL_INPUT_CELL
Definition sclCon.h:52
#define SCL_DIRECTIVE(ITEM)
Definition sclCon.h:59
#define SCL_OUTPUT_LOAD
Definition sclCon.h:57
Vec_Int_t vInArrs
Definition sclCon.h:43
int tOutReqDef
Definition sclCon.h:39
Abc_Nam_t * pNamO
Definition sclCon.h:49
char * pFileName
Definition sclCon.h:33
char * pInCellDef
Definition sclCon.h:35
Vec_Int_t vOutReqs
Definition sclCon.h:46
int tInSlewDef
Definition sclCon.h:37
Vec_Int_t vInSlews
Definition sclCon.h:44
char * pModelName
Definition sclCon.h:34
int tInLoadDef
Definition sclCon.h:38
int tOutLoadDef
Definition sclCon.h:40
Vec_Ptr_t vInCellsPtr
Definition sclCon.h:42
int tInArrDef
Definition sclCon.h:36
Abc_Nam_t * pNamI
Definition sclCon.h:48
Vec_Int_t vOutLoads
Definition sclCon.h:47
Vec_Int_t vInLoads
Definition sclCon.h:45
Vec_Ptr_t vInCells
Definition sclCon.h:41
int Abc_NamStrFind(Abc_Nam_t *p, char *pStr)
Definition utilNam.c:433
int Abc_NamObjNumMax(Abc_Nam_t *p)
Definition utilNam.c:231
void Abc_NamDeref(Abc_Nam_t *p)
Definition utilNam.c:212
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
Definition utilNam.c:555
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
Definition utilNam.h:39
int strcmp()
char * strtok()
double atof()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55