ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaGig.c File Reference
#include "gia.h"
#include "misc/extra/extra.h"
#include "misc/util/utilTruth.h"
Include dependency graph for giaGig.c:

Go to the source code of this file.

Classes

struct  Gls_Man_t_
 

Macros

#define MAX_LINE   1000000
 DECLARATIONS ///.
 

Typedefs

typedef struct Gls_Man_t_ Gls_Man_t
 

Enumerations

enum  {
  GLS_NONE = -1 , GLS_ZERO = 0 , GLS_ONE = 1 , GLS_PI = 2 ,
  GLS_PO = 3 , GLS_BAR = 4 , GLS_SEQ = 5 , GLS_SEL = 6 ,
  GLS_LUT4 = 7 , GLS_LUT6 = 8 , GLS_BOX = 9 , GLS_DEL = 10 ,
  GLS_FINAL
}
 

Functions

Gls_Man_tGls_ManAlloc (Vec_Str_t *vLines, int *pCounts)
 FUNCTION DEFINITIONS ///.
 
void Gls_ManStop (Gls_Man_t *p)
 
Vec_Str_tGls_ManCount (FILE *pFile, int pCounts[GLS_FINAL])
 
int Gls_ManParseOne (char **ppLine)
 
int Gls_ManParse (FILE *pFile, Gls_Man_t *p)
 
Gia_Man_tGls_ManConstruct (Gls_Man_t *p, char *pFileName)
 
Gia_Man_tGia_ManReadGig (char *pFileName)
 

Macro Definition Documentation

◆ MAX_LINE

#define MAX_LINE   1000000

DECLARATIONS ///.

CFile****************************************************************

FileName [giaGig.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Parser for Gate-Inverter Graph by Niklas Een.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
giaGig.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 32 of file giaGig.c.

Typedef Documentation

◆ Gls_Man_t

typedef struct Gls_Man_t_ Gls_Man_t

Definition at line 66 of file giaGig.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GLS_NONE 
GLS_ZERO 
GLS_ONE 
GLS_PI 
GLS_PO 
GLS_BAR 
GLS_SEQ 
GLS_SEL 
GLS_LUT4 
GLS_LUT6 
GLS_BOX 
GLS_DEL 
GLS_FINAL 

Definition at line 35 of file giaGig.c.

35 {
36 GLS_NONE = -1, // not used
37 GLS_ZERO = 0, // zero
38 GLS_ONE = 1, // one
39 GLS_PI = 2, // primary input
40 GLS_PO = 3, // primary output
41 GLS_BAR = 4, // barrier
42 GLS_SEQ = 5, // sequential
43 GLS_SEL = 6, // fan
44 GLS_LUT4 = 7, // LUT4
45 GLS_LUT6 = 8, // LUT6
46 GLS_BOX = 9, // sequential box
47 GLS_DEL = 10, // delay box
49};
@ GLS_BOX
Definition giaGig.c:46
@ GLS_ONE
Definition giaGig.c:38
@ GLS_PI
Definition giaGig.c:39
@ GLS_PO
Definition giaGig.c:40
@ GLS_LUT4
Definition giaGig.c:44
@ GLS_BAR
Definition giaGig.c:41
@ GLS_NONE
Definition giaGig.c:36
@ GLS_SEL
Definition giaGig.c:43
@ GLS_LUT6
Definition giaGig.c:45
@ GLS_FINAL
Definition giaGig.c:48
@ GLS_DEL
Definition giaGig.c:47
@ GLS_ZERO
Definition giaGig.c:37
@ GLS_SEQ
Definition giaGig.c:42

Function Documentation

◆ Gia_ManReadGig()

Gia_Man_t * Gia_ManReadGig ( char * pFileName)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 470 of file giaGig.c.

471{
472 abctime clk = Abc_Clock();
473 Gls_Man_t * p = NULL;
474 Gia_Man_t * pGia = NULL;
475 Vec_Str_t * vLines;
476 int i, pCounts[GLS_FINAL];
477 FILE * pFile = fopen( pFileName, "rb" );
478 if ( pFile == NULL )
479 {
480 printf( "Cannot read file \"%s\".\n", pFileName );
481 return NULL;
482 }
483 vLines = Gls_ManCount( pFile, pCounts );
484 rewind( pFile );
485 // statistics
486 for ( i = 0; i < GLS_FINAL; i++ )
487 if ( pCounts[i] )
488 printf( "%s=%d ", s_Strs[i], pCounts[i] );
489 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
490 // collect data and derive AIG
491 p = Gls_ManAlloc( vLines, pCounts );
492 if ( Gls_ManParse( pFile, p ) )
493 pGia = Gls_ManConstruct( p, pFileName );
494 Gls_ManStop( p );
495 fclose( pFile );
496 //printf( "\n" );
497 return pGia;
498}
ABC_INT64_T abctime
Definition abc_global.h:332
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Cube * p
Definition exorList.c:222
int Gls_ManParse(FILE *pFile, Gls_Man_t *p)
Definition giaGig.c:236
Gia_Man_t * Gls_ManConstruct(Gls_Man_t *p, char *pFileName)
Definition giaGig.c:380
Vec_Str_t * Gls_ManCount(FILE *pFile, int pCounts[GLS_FINAL])
Definition giaGig.c:163
void Gls_ManStop(Gls_Man_t *p)
Definition giaGig.c:129
Gls_Man_t * Gls_ManAlloc(Vec_Str_t *vLines, int *pCounts)
FUNCTION DEFINITIONS ///.
Definition giaGig.c:106
struct Gls_Man_t_ Gls_Man_t
Definition giaGig.c:66
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
VOID_HACK rewind()
Here is the call graph for this function:

◆ Gls_ManAlloc()

Gls_Man_t * Gls_ManAlloc ( Vec_Str_t * vLines,
int * pCounts )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 106 of file giaGig.c.

107{
109 p->vLines = vLines;
110 p->vTypes = Vec_StrStart( Vec_StrSize(vLines)+100 );
111 p->vIndexes = Vec_IntStart( Vec_StrSize(vLines)+100 );
112 p->vLut4s = Vec_IntAlloc( 4 * pCounts[GLS_LUT4] );
113 p->vLut4TTs = Vec_IntAlloc( pCounts[GLS_LUT4] );
114 p->vLut6s = Vec_IntAlloc( 6 * pCounts[GLS_LUT6] );
115 p->vLut6TTs = Vec_WrdAlloc( pCounts[GLS_LUT6] );
116 p->vBoxes = Vec_IntAlloc( 5 * pCounts[GLS_BOX] );
117 p->vDelays = Vec_IntAlloc( pCounts[GLS_DEL] );
118 p->vDelayIns = Vec_WecAlloc( pCounts[GLS_DEL] );
119 p->vDelayOuts = Vec_WecAlloc( pCounts[GLS_DEL] );
120 // ordering
121 p->vOrderPis = Vec_IntAlloc( pCounts[GLS_PI] );
122 p->vOrderPos = Vec_IntAlloc( pCounts[GLS_PO] );
123 p->vOrderBoxes = Vec_IntAlloc( pCounts[GLS_BOX] );
124 p->vOrderDelays = Vec_IntAlloc( pCounts[GLS_DEL] );
125 p->vOrderLuts = Vec_IntAlloc( pCounts[GLS_LUT4] + pCounts[GLS_LUT6] + 2*pCounts[GLS_BAR] );
126 p->vOrderSeqs = Vec_IntAlloc( pCounts[GLS_SEQ] );
127 return p;
128}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
Here is the caller graph for this function:

◆ Gls_ManConstruct()

Gia_Man_t * Gls_ManConstruct ( Gls_Man_t * p,
char * pFileName )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 380 of file giaGig.c.

381{
382 extern int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash );
383 Gia_Man_t * pGia = NULL;
384 Vec_Int_t * vMap, * vArray;
385 Vec_Int_t * vCover = Vec_IntAlloc(0);
386 Vec_Int_t * vLeaves = Vec_IntAlloc(6);
387 int k, iObj, iLit, Index; char Type;
388 // create new manager
389 pGia = Gia_ManStart( Vec_StrSize(p->vTypes) );
390 pGia->pName = Abc_UtilStrsav( pFileName );
391 pGia->pSpec = Abc_UtilStrsav( pFileName );
392 // create constants
393 vMap = Vec_IntStartFull( Vec_StrSize(p->vTypes) );
394 Vec_IntWriteEntry( vMap, 0, 0 );
395 Vec_IntWriteEntry( vMap, 1, 1 );
396 // create primary inputs
397 Vec_IntForEachEntry( p->vOrderPis, iObj, k )
398 Vec_IntWriteEntry( vMap, iObj, Gia_ManAppendCi(pGia) );
399 // create box outputs
400 Vec_IntForEachEntry( p->vOrderBoxes, iObj, k )
401 Vec_IntWriteEntry( vMap, iObj, Gia_ManAppendCi(pGia) );
402 // create delay outputs
403 Vec_IntForEachEntry( p->vOrderDelays, iObj, Index )
404 {
405 assert( Index == Vec_IntEntry(p->vIndexes, iObj) );
406 vArray = Vec_WecEntry(p->vDelayOuts, Index);
407 if ( Vec_IntSize(vArray) == 0 )
408 Vec_IntWriteEntry( vMap, iObj, Gia_ManAppendCi(pGia) );
409 else
410 Vec_IntForEachEntry( vArray, iObj, k )
411 Vec_IntWriteEntry( vMap, iObj, Gia_ManAppendCi(pGia) );
412 }
413 // construct LUTs
414 Vec_IntForEachEntry( p->vOrderLuts, iObj, Index )
415 {
416 Type = Vec_StrEntry( p->vTypes, iObj );
417 if ( Type == GLS_LUT4 || Type == GLS_LUT6 )
418 {
419 int Limit = Type == GLS_LUT4 ? 4 : 6;
420 int Index = Vec_IntEntry(p->vIndexes, iObj);
421 int * pFanins = Type == GLS_LUT4 ? Vec_IntEntryP(p->vLut4s, 4*Index) : Vec_IntEntryP(p->vLut6s, 6*Index);
422 word Truth = Type == GLS_LUT4 ? (word)Vec_IntEntry(p->vLut4TTs, Index) : Vec_WrdEntry(p->vLut6TTs, Index);
423 Vec_IntClear( vLeaves );
424 for ( k = 0; k < Limit; k++ )
425 Vec_IntPush( vLeaves, pFanins[k] == GLS_NONE ? 0 : Vec_IntEntry(vMap, pFanins[k]) );
426 iLit = Kit_TruthToGia( pGia, (unsigned *)&Truth, Vec_IntSize(vLeaves), vCover, vLeaves, 0 );
427 Vec_IntWriteEntry( vMap, iObj, iLit );
428 }
429 else if ( Type == GLS_BAR || Type == GLS_SEL )
430 {
431 iLit = Vec_IntEntry( vMap, Vec_IntEntry(p->vIndexes, iObj) );
432 Vec_IntWriteEntry( vMap, iObj, iLit );
433 }
434 }
435 // delay inputs
436 Vec_IntForEachEntry( p->vOrderDelays, iObj, Index )
437 {
438 vArray = Vec_WecEntry(p->vDelayIns, Index);
439 assert( Vec_IntSize(vArray) > 0 );
440 Vec_IntForEachEntry( vArray, iObj, k )
441 Gia_ManAppendCo( pGia, Vec_IntEntry(vMap, iObj) );
442 }
443 // create primary outputs
444 Vec_IntForEachEntry( p->vOrderPos, iObj, k )
445 Gia_ManAppendCo( pGia, Vec_IntEntry(vMap, Vec_IntEntry(p->vIndexes, iObj)) );
446 // create sequential nodes
447 Vec_IntForEachEntry( p->vOrderSeqs, iObj, k )
448 Gia_ManAppendCo( pGia, Vec_IntEntry(vMap, Vec_IntEntry(p->vIndexes, iObj)) );
449 Vec_IntFree( vMap );
450 Vec_IntFree( vCover );
451 Vec_IntFree( vLeaves );
452 // print delay boxes
453// for ( k = 0; k < Vec_IntSize(p->vDelays); k++ )
454// printf( "%d:%d ", Vec_IntSize(Vec_WecEntry(p->vDelayIns, k)), Vec_IntSize(Vec_WecEntry(p->vDelayOuts, k)) );
455// printf( "\n" );
456 return pGia;
457}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ABC_NAMESPACE_IMPL_START int Kit_TruthToGia(Gia_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory, Vec_Int_t *vLeaves, int fHash)
DECLARATIONS ///.
Definition kitHop.c:80
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
char * pSpec
Definition gia.h:100
char * pName
Definition gia.h:99
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gls_ManCount()

Vec_Str_t * Gls_ManCount ( FILE * pFile,
int pCounts[GLS_FINAL] )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 163 of file giaGig.c.

164{
165 char * pLine, * pBuffer = ABC_ALLOC(char, MAX_LINE); int Type;
166 Vec_Str_t * vLines = Vec_StrAlloc( 10000 );
167 memset( pCounts, 0, sizeof(int)*GLS_FINAL );
168 while ( fgets( pBuffer, MAX_LINE, pFile ) != NULL )
169 {
170 pLine = pBuffer;
171 while ( *pLine )
172 if ( *pLine++ == '=' )
173 break;
174 while ( *pLine == ' ' )
175 pLine++;
176 if ( *pLine == 'L' )
177 {
178 if ( pLine[3] == '4' )
179 Type = GLS_LUT4;
180 else if ( pLine[3] == '6' )
181 Type = GLS_LUT6;
182 else assert( 0 );
183 }
184 else if ( *pLine == 'P' )
185 {
186 if ( pLine[1] == 'I' )
187 Type = GLS_PI;
188 else if ( pLine[1] == 'O' )
189 Type = GLS_PO;
190 else assert( 0 );
191 }
192 else if ( *pLine == 'B' )
193 {
194 if ( pLine[1] == 'o' )
195 Type = GLS_BOX;
196 else if ( pLine[1] == 'a' )
197 Type = GLS_BAR;
198 else assert( 0 );
199 }
200 else if ( *pLine == 'S' )
201 {
202 if ( pLine[2] == 'l' )
203 Type = GLS_SEL;
204 else if ( pLine[2] == 'q' )
205 Type = GLS_SEQ;
206 else assert( 0 );
207 }
208 else if ( *pLine == 'D' )
209 Type = GLS_DEL;
210 else assert( 0 );
211 Vec_StrPush( vLines, (char)Type );
212 pCounts[Type]++;
213 }
214 ABC_FREE( pBuffer );
215 return vLines;
216}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define MAX_LINE
DECLARATIONS ///.
Definition giaGig.c:32
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gls_ManParse()

int Gls_ManParse ( FILE * pFile,
Gls_Man_t * p )

Definition at line 236 of file giaGig.c.

237{
238 char * pLine, * pBuffer = ABC_ALLOC(char, MAX_LINE);
239 int i, k, Type, iObj, Entry, iItem; word Truth;
240 for ( i = 0; fgets( pBuffer, MAX_LINE, pFile ) != NULL; i++ )
241 {
242 pLine = pBuffer;
243 Type = Vec_StrEntry( p->vLines, i );
244 iObj = Gls_ManParseOne( &pLine );
245 Vec_StrWriteEntry( p->vTypes, iObj, (char)Type );
246 if ( Type == GLS_PI )
247 {
248 Vec_IntPush( p->vOrderPis, iObj );
249 Vec_IntWriteEntry( p->vIndexes, iObj, -1 );
250 continue;
251 }
252 while ( *pLine )
253 if ( *pLine++ == '(' )
254 break;
255 Entry = Gls_ManParseOne( &pLine );
256 if ( Type == GLS_PO || Type == GLS_BAR || Type == GLS_SEQ || Type == GLS_SEL )
257 {
258 if ( Type == GLS_PO )
259 Vec_IntPush( p->vOrderPos, iObj );
260 else if ( Type == GLS_BAR )
261 Vec_IntPush( p->vOrderLuts, iObj );
262 else if ( Type == GLS_SEQ )
263 Vec_IntPush( p->vOrderSeqs, iObj );
264 else if ( Type == GLS_SEL )
265 {
266 if ( (int)Vec_StrEntry(p->vTypes, Entry) == GLS_DEL )
267 {
268 Vec_Int_t * vOuts = Vec_WecEntry( p->vDelayOuts, Vec_IntEntry(p->vIndexes, Entry) );
269 Vec_IntPush( vOuts, iObj );
270 }
271 else if ( (int)Vec_StrEntry(p->vTypes, Entry) == GLS_BAR )
272 Vec_IntPush( p->vOrderLuts, iObj );
273 else assert( 0 );
274 }
275 Vec_IntWriteEntry( p->vIndexes, iObj, Entry );
276 continue;
277 }
278 if ( Type == GLS_LUT4 )
279 {
280 Vec_IntWriteEntry( p->vIndexes, iObj, Vec_IntSize(p->vLut4TTs) );
281 Vec_IntPush( p->vLut4s, Entry );
282 for ( k = 1; ; k++ )
283 {
284 if ( *pLine != ',' ) break;
285 pLine++;
286 Entry = Gls_ManParseOne( &pLine );
287 Vec_IntPush( p->vLut4s, Entry );
288 }
289 assert( *pLine == ')' );
290 assert( k == 4 );
291 pLine++;
292 while ( *pLine )
293 if ( *pLine++ == '[' )
294 break;
295 Abc_TtReadHex( &Truth, pLine );
296 Vec_IntPush( p->vLut4TTs, (unsigned)Truth );
297 Vec_IntPush( p->vOrderLuts, iObj );
298 }
299 else if ( Type == GLS_LUT6 )
300 {
301 Vec_IntWriteEntry( p->vIndexes, iObj, Vec_WrdSize(p->vLut6TTs) );
302 Vec_IntPush( p->vLut6s, Entry );
303 for ( k = 1; ; k++ )
304 {
305 if ( *pLine != ',' ) break;
306 pLine++;
307 Entry = Gls_ManParseOne( &pLine );
308 Vec_IntPush( p->vLut6s, Entry );
309 }
310 assert( *pLine == ')' );
311 assert( k == 4 );
312 pLine++;
313 while ( *pLine )
314 if ( *pLine++ == '[' )
315 break;
316 Abc_TtReadHex( &Truth, pLine );
317 Vec_WrdPush( p->vLut6TTs, Truth );
318 Vec_IntPush( p->vOrderLuts, iObj );
319 }
320 else if ( Type == GLS_BOX )
321 {
322 Vec_IntWriteEntry( p->vIndexes, iObj, Vec_IntSize(p->vBoxes)/5 );
323 Vec_IntPush( p->vBoxes, Entry );
324 for ( k = 1; ; k++ )
325 {
326 if ( *pLine != ',' ) break;
327 pLine++;
328 Entry = Gls_ManParseOne( &pLine );
329 Vec_IntPush( p->vBoxes, Entry );
330 }
331 assert( *pLine == ')' );
332 assert( k == 4 || k == 5 );
333 if ( k == 4 )
334 Vec_IntPush( p->vBoxes, GLS_NONE );
335 Vec_IntPush( p->vOrderBoxes, iObj );
336 }
337 else if ( Type == GLS_DEL )
338 {
339 Vec_Int_t * vIns = Vec_WecPushLevel( p->vDelayIns );
340 Vec_Int_t * vOuts = Vec_WecPushLevel( p->vDelayOuts );
341 Vec_IntWriteEntry( p->vIndexes, iObj, Vec_IntSize(p->vDelays) );
342 Vec_IntPush( vIns, Entry );
343 if ( *pLine != ')' )
344 {
345 for ( k = 1; ; k++ )
346 {
347 if ( *pLine != ',' ) break;
348 pLine++;
349 Entry = Gls_ManParseOne( &pLine );
350 Vec_IntPush( vIns, Entry );
351 }
352 }
353 assert( *pLine == ')' );
354 pLine++;
355 while ( *pLine )
356 if ( *pLine++ == '[' )
357 break;
358 iItem = atoi(pLine);
359 Vec_IntPush( p->vDelays, iItem );
360 Vec_IntPush( p->vOrderDelays, iObj );
361 vOuts = vIns; // harmless use to prevent a compiler warning
362 }
363 else assert( 0 );
364 }
365 ABC_FREE( pBuffer );
366 return 1;
367}
int Gls_ManParseOne(char **ppLine)
Definition giaGig.c:217
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gls_ManParseOne()

int Gls_ManParseOne ( char ** ppLine)

Definition at line 217 of file giaGig.c.

218{
219 int Entry;
220 char * pLine = *ppLine;
221 while ( *pLine == ' ' ) pLine++;
222 if ( *pLine == '-' )
223 Entry = GLS_NONE;
224 else if ( *pLine == '0' )
225 Entry = 0;
226 else if ( *pLine == '1' )
227 Entry = 1;
228 else if ( *pLine == 'w' )
229 Entry = atoi(++pLine);
230 else assert( 0 );
231 while ( *pLine == '-' || (*pLine >= '0' && *pLine <= '9') ) pLine++;
232 while ( *pLine == ' ' ) pLine++;
233 *ppLine = pLine;
234 return Entry;
235}
Here is the caller graph for this function:

◆ Gls_ManStop()

void Gls_ManStop ( Gls_Man_t * p)

Definition at line 129 of file giaGig.c.

130{
131 Vec_StrFree( p->vLines );
132 Vec_StrFree( p->vTypes );
133 Vec_IntFree( p->vIndexes );
134 Vec_IntFree( p->vLut4s );
135 Vec_IntFree( p->vLut4TTs );
136 Vec_IntFree( p->vLut6s );
137 Vec_WrdFree( p->vLut6TTs );
138 Vec_IntFree( p->vBoxes );
139 Vec_IntFree( p->vDelays );
140 Vec_WecFree( p->vDelayIns );
141 Vec_WecFree( p->vDelayOuts );
142 // ordering
143 Vec_IntFree( p->vOrderPis );
144 Vec_IntFree( p->vOrderPos );
145 Vec_IntFree( p->vOrderBoxes );
146 Vec_IntFree( p->vOrderDelays );
147 Vec_IntFree( p->vOrderLuts );
148 Vec_IntFree( p->vOrderSeqs );
149 ABC_FREE( p );
150}
Here is the caller graph for this function: