abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaGig.c File Reference
#include "gia.h"
#include "misc/extra/extra.h"
#include "misc/util/utilTruth.h"

Go to the source code of this file.

Enumerations

enum  {
  GIG_NONE = 0, GIG_RESET = 1, GIG_PI = 2, GIG_PO = 3,
  GIG_SEQ = 4, GIG_LUT = 5, GIG_DELAY = 6, GIG_BOX = 7,
  GIG_SEL = 8, GIG_BAR = 9, GIG_UNUSED = 10
}
 DECLARATIONS ///. More...
 

Functions

int * Gia_ManGigCount (Vec_Int_t *vObjs, Vec_Int_t *vStore)
 FUNCTION DEFINITIONS ///. More...
 
void Gia_ManGigPrint (int *nObjs)
 
void Gia_ManPrintDelays (Vec_Int_t *vObjs, Vec_Int_t *vStore)
 
Gia_Man_tGia_ManBuildGig2 (Vec_Int_t *vObjs, Vec_Int_t *vStore, char *pFileName)
 
Gia_Man_tGia_ManBuildGig (Vec_Int_t *vObjs, Vec_Int_t *vStore, char *pFileName)
 
Gia_Man_tGia_ManReadGig (char *pFileName)
 

Variables

static char * s_GigNames [GIG_UNUSED]
 

Enumeration Type Documentation

anonymous enum

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

]

Enumerator
GIG_NONE 
GIG_RESET 
GIG_PI 
GIG_PO 
GIG_SEQ 
GIG_LUT 
GIG_DELAY 
GIG_BOX 
GIG_SEL 
GIG_BAR 
GIG_UNUSED 

Definition at line 32 of file giaGig.c.

32  {
33  GIG_NONE = 0,
34  GIG_RESET = 1,
35  GIG_PI = 2,
36  GIG_PO = 3,
37  GIG_SEQ = 4,
38  GIG_LUT = 5,
39  GIG_DELAY = 6,
40  GIG_BOX = 7,
41  GIG_SEL = 8,
42  GIG_BAR = 9,
43  GIG_UNUSED = 10
44 };
Definition: giaGig.c:38
Definition: giaGig.c:37
Definition: giaGig.c:42
Definition: giaGig.c:36
Definition: giaGig.c:35
Definition: giaGig.c:40
Definition: giaGig.c:41

Function Documentation

Gia_Man_t* Gia_ManBuildGig ( Vec_Int_t vObjs,
Vec_Int_t vStore,
char *  pFileName 
)

Definition at line 185 of file giaGig.c.

186 {
187  printf( "Parsed %d objects and %d tokens.\n", Vec_IntSize(vObjs), Vec_IntSize(vStore) );
188  Gia_ManGigPrint( Gia_ManGigCount(vObjs, vStore) );
189  Gia_ManPrintDelays( vObjs, vStore );
190  return NULL;
191 }
void Gia_ManPrintDelays(Vec_Int_t *vObjs, Vec_Int_t *vStore)
Definition: giaGig.c:104
int * Gia_ManGigCount(Vec_Int_t *vObjs, Vec_Int_t *vStore)
FUNCTION DEFINITIONS ///.
Definition: giaGig.c:75
void Gia_ManGigPrint(int *nObjs)
Definition: giaGig.c:84
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Gia_Man_t* Gia_ManBuildGig2 ( Vec_Int_t vObjs,
Vec_Int_t vStore,
char *  pFileName 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 138 of file giaGig.c.

139 {
140  Gia_Man_t * pNew, * pTemp;
141  //int * nObjs = Gia_ManGigCount( vObjs, vStore );
142  Vec_Int_t * vNets = Vec_IntAlloc( Vec_IntSize(vObjs) );
143  Vec_Int_t * vTypes = Vec_IntAlloc( Vec_IntSize(vObjs) );
144  Vec_Int_t * vMap;
145  int i, Type;
146  // connect net IDs
147  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
148  {
149  Vec_IntPush( vNets, Vec_IntEntry(vStore, Vec_IntEntry(vObjs,i)) );
150  Vec_IntPush( vTypes, Vec_IntEntry(vStore, Vec_IntEntry(vObjs,i) + 1) );
151  }
152  // create mapping for net IDs into GIA IDs
153  vMap = Vec_IntStartFull( Vec_IntFindMax(vNets) + 1 );
154  Vec_IntWriteEntry( vMap, 0, 0 );
155  Vec_IntWriteEntry( vMap, 1, 1 );
156  // create new manager
157  pNew = Gia_ManStart( Vec_IntSize(vObjs) );
158  pNew->pName = Abc_UtilStrsav( pFileName );
159  pNew->pSpec = Abc_UtilStrsav( pFileName );
160  // create primary inputs
161  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
162  if ( Vec_IntEntry(vTypes, i) == GIG_PI )
163  Vec_IntWriteEntry( vMap, Vec_IntEntry(vNets, i), Gia_ManAppendCi(pNew) );
164  // create box outputs
165  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
166  if ( Vec_IntEntry(vTypes, i) == GIG_BOX )
167  Vec_IntWriteEntry( vMap, Vec_IntEntry(vNets, i), Gia_ManAppendCi(pNew) );
168  // create internal nodes
169  Gia_ManHashAlloc( pNew );
170  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
171  {
172  Type = Vec_IntEntry(vTypes, i);
173  if ( Type != GIG_LUT && Type != GIG_DELAY && Type != GIG_BAR )
174  continue;
175 
176  }
177  Vec_IntFree( vMap );
178  Vec_IntFree( vNets );
179  Vec_IntFree( vTypes );
180  // rehash
181  pNew = Gia_ManCleanup( pTemp = pNew );
182  Gia_ManStop( pTemp );
183  return pNew;
184 }
Definition: giaGig.c:38
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
static Vec_Int_t * Vec_IntStartFull(int nSize)
Definition: vecInt.h:119
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
char * pName
Definition: gia.h:97
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Vec_IntFindMax(Vec_Int_t *p)
Definition: vecInt.h:996
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Definition: giaGig.c:42
Definition: gia.h:95
Definition: giaGig.c:35
Definition: giaGig.c:40
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
int* Gia_ManGigCount ( Vec_Int_t vObjs,
Vec_Int_t vStore 
)

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 75 of file giaGig.c.

76 {
77  static int nObjs[GIG_UNUSED]; int i;
78  for ( i = 0; i < GIG_UNUSED; i++ )
79  nObjs[i] = 0;
80  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
81  nObjs[Vec_IntEntry(vStore, Vec_IntEntry(vObjs,i) + 1)]++;
82  return nObjs;
83 }
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
void Gia_ManGigPrint ( int *  nObjs)

Definition at line 84 of file giaGig.c.

85 {
86  int i;
87  printf( "Statistics: " );
88  for ( i = 1; i < GIG_UNUSED; i++ )
89  printf( "%s = %d ", s_GigNames[i], nObjs[i] );
90  printf( "\n" );
91 }
static char * s_GigNames[GIG_UNUSED]
Definition: giaGig.c:46
void Gia_ManPrintDelays ( Vec_Int_t vObjs,
Vec_Int_t vStore 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file giaGig.c.

105 {
106  Vec_Int_t * vFanCount = Vec_IntStart( Vec_IntSize(vObjs) + 100 );
107  int i, * pEntry;//, Counter = 0;
108  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
109  {
110  pEntry = Vec_IntEntryP( vStore, Vec_IntEntry(vObjs,i) );
111  if ( pEntry[1] != GIG_SEL )
112  continue;
113  assert( pEntry[2] == 1 );
114  Vec_IntAddToEntry( vFanCount, pEntry[3], 1 );
115  }
116  for ( i = 0; i < Vec_IntSize(vObjs); i++ )
117  {
118  pEntry = Vec_IntEntryP( vStore, Vec_IntEntry(vObjs,i) );
119  if ( pEntry[1] != GIG_DELAY )
120  continue;
121  printf( "(%d,%d,%d) ", pEntry[2], Vec_IntEntry(vFanCount, pEntry[0]), pEntry[3+pEntry[2]] );
122  }
123  printf( "\n" );
124  Vec_IntFree( vFanCount );
125 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
static int * Vec_IntEntryP(Vec_Int_t *p, int i)
Definition: vecInt.h:417
Definition: giaGig.c:41
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Gia_Man_t* Gia_ManReadGig ( char *  pFileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 204 of file giaGig.c.

205 {
206  Gia_Man_t * pNew;
207  int Type, Offset, fEndOfLine, Digit, nObjs;
208  char * pChars = " w(-,)]\r\t";
209  char * pBuffer = Extra_FileReadContents( pFileName );
210  char * pStart = pBuffer, * pToken;
211  Vec_Int_t * vObjs, * vStore;
212  if ( pBuffer == NULL )
213  printf( "Cannot open input file %s\n", pFileName );
214  // count objects
215  for ( nObjs = 0, pToken = pBuffer; *pToken; pToken++ )
216  nObjs += (int)(*pToken == '\n');
217  // read objects
218  vObjs = Vec_IntAlloc( nObjs );
219  vStore = Vec_IntAlloc( 10*nObjs );
220  while ( 1 )
221  {
222  // read net ID
223  pToken = strtok( pStart, pChars );
224  pStart = NULL;
225  if ( pToken == NULL )
226  break;
227  // start new object
228  Vec_IntPush( vObjs, Vec_IntSize(vStore) );
229  // save net ID
230  assert( pToken[0] >= '0' && pToken[0] <= '9' );
231  Vec_IntPush( vStore, atoi(pToken) );
232  // read equal
233  pToken = strtok( pStart, pChars );
234  assert( pToken[0] == '=' );
235  // read type
236  pToken = strtok( pStart, pChars );
237  fEndOfLine = 0;
238  if ( pToken[strlen(pToken)-1] == '\n' )
239  {
240  pToken[strlen(pToken)-1] = 0;
241  fEndOfLine = 1;
242  }
243  for ( Type = GIG_RESET; Type < GIG_UNUSED; Type++ )
244  if ( !strcmp(pToken, s_GigNames[Type]) )
245  break;
246  assert( Type < GIG_UNUSED );
247  Vec_IntPush( vStore, Type );
248  if ( fEndOfLine )
249  continue;
250  // read fanins
251  Offset = Vec_IntSize(vStore);
252  Vec_IntPush( vStore, 0 );
253  while ( 1 )
254  {
255  pToken = strtok( pStart, pChars );
256  if ( pToken == NULL || pToken[0] == '\n' || pToken[0] == '[' )
257  break;
258  assert( pToken[0] >= '0' && pToken[0] <= '9' );
259  Vec_IntPush( vStore, atoi(pToken) );
260  Vec_IntAddToEntry( vStore, Offset, 1 );
261  }
262  assert( pToken != NULL );
263  if ( pToken[0] == '\n' )
264  continue;
265  assert( pToken[0] == '[' );
266  // read attribute
267  pToken++;
268  if ( Type == GIG_LUT )
269  {
270  assert( strlen(pToken) == 4 );
271  Digit = Abc_TtReadHexDigit(pToken[0]);
272  Digit |= Abc_TtReadHexDigit(pToken[1]) << 4;
273  Digit |= Abc_TtReadHexDigit(pToken[2]) << 8;
274  Digit |= Abc_TtReadHexDigit(pToken[3]) << 12;
275  Vec_IntPush( vStore, Digit );
276  }
277  else
278  {
279  assert( Type == GIG_DELAY );
280  Vec_IntPush( vStore, atoi(pToken) );
281  }
282  // read end of line
283  pToken = strtok( pStart, pChars );
284  assert( pToken[0] == '\n' );
285  }
286  ABC_FREE( pBuffer );
287  // create AIG
288  pNew = Gia_ManBuildGig( vObjs, vStore, pFileName );
289  // cleanup
290  Vec_IntFree( vObjs );
291  Vec_IntFree( vStore );
292  return pNew;
293 }
Definition: giaGig.c:38
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
char * strtok()
static int Abc_TtReadHexDigit(char HexChar)
Definition: utilTruth.h:756
int strcmp()
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
Gia_Man_t * Gia_ManBuildGig(Vec_Int_t *vObjs, Vec_Int_t *vStore, char *pFileName)
Definition: giaGig.c:185
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
#define assert(ex)
Definition: util_old.h:213
int strlen()
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
char * Extra_FileReadContents(char *pFileName)
static char * s_GigNames[GIG_UNUSED]
Definition: giaGig.c:46

Variable Documentation

char* s_GigNames[GIG_UNUSED]
static
Initial value:
=
{
"NONE",
"Reset",
"PI",
"PO",
"Seq",
"Lut4",
"Delay",
"Box",
"Sel",
"Bar"
}

Definition at line 46 of file giaGig.c.