abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mioRead.c File Reference
#include <ctype.h>
#include "mioInt.h"
#include "base/io/ioAbc.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START
Mio_Library_t
Mio_LibraryReadOne (char *FileName, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
 DECLARATIONS ///. More...
 
static Mio_Library_tMio_LibraryReadBuffer (char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
 
static int Mio_LibraryReadInternal (Mio_Library_t *pLib, char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
 
static Mio_Gate_tMio_LibraryReadGate (char **ppToken, int fExtendedFormat)
 
static Mio_Pin_tMio_LibraryReadPin (char **ppToken, int fExtendedFormat)
 
static char * chomp (char *s)
 
static void Mio_LibraryDetectSpecialGates (Mio_Library_t *pLib)
 
static void Io_ReadFileRemoveComments (char *pBuffer, int *pnDots, int *pnLines)
 
Mio_Library_tMio_LibraryRead (char *FileName, char *pBuffer, char *ExcludeFile, int fVerbose)
 
char * Mio_ReadFile (char *FileName, int fAddEnd)
 
int Mio_LibraryCompareGatesByArea (Mio_Gate_t **pp1, Mio_Gate_t **pp2)
 
int Mio_LibraryCompareGatesByName (Mio_Gate_t **pp1, Mio_Gate_t **pp2)
 
void Mio_LibrarySortGates (Mio_Library_t *pLib)
 
static Mio_Gate_tMio_GateCompare (Mio_Gate_t *pThis, Mio_Gate_t *pNew, word uTruth)
 
int Mio_LibraryReadExclude (char *ExcludeFile, st__table *tExcludeGate)
 

Function Documentation

char * chomp ( char *  s)
static

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

Synopsis [Duplicates string and returns it with leading and trailing spaces removed.]

Description []

SideEffects []

SeeAlso []

Definition at line 483 of file mioRead.c.

484 {
485  char *a, *b, *c;
486  // remove leading spaces
487  for ( b = s; *b; b++ )
488  if ( !isspace(*b) )
489  break;
490  // strsav the string
491  a = strcpy( ABC_ALLOC(char, strlen(b)+1), b );
492  // remove trailing spaces
493  for ( c = a+strlen(a); c > a; c-- )
494  if ( *c == 0 || isspace(*c) )
495  *c = 0;
496  else
497  break;
498  return a;
499 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * strcpy()
int strlen()
void Io_ReadFileRemoveComments ( char *  pBuffer,
int *  pnDots,
int *  pnLines 
)
static

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

Synopsis [Eliminates comments from the input file.]

Description [As a byproduct, this procedure also counts the number lines and dot-statements in the input file. This also joins non-comment lines that are joined with a backspace '\']

SideEffects []

SeeAlso []

Definition at line 698 of file mioRead.c.

699 {
700  char * pCur;
701  int nDots, nLines;
702  // scan through the buffer and eliminate comments
703  // (in the BLIF file, comments are lines starting with "#")
704  nDots = nLines = 0;
705  for ( pCur = pBuffer; *pCur; pCur++ )
706  {
707  // if this is the beginning of comment
708  // clean it with spaces until the new line statement
709  if ( *pCur == '#' )
710  while ( *pCur != '\n' )
711  *pCur++ = ' ';
712 
713  // count the number of new lines and dots
714  if ( *pCur == '\n' ) {
715  if (*(pCur-1)=='\r') {
716  // DOS(R) file support
717  if (*(pCur-2)!='\\') nLines++;
718  else {
719  // rewind to backslash and overwrite with a space
720  *(pCur-2) = ' ';
721  *(pCur-1) = ' ';
722  *pCur = ' ';
723  }
724  } else {
725  // UNIX(TM) file support
726  if (*(pCur-1)!='\\') nLines++;
727  else {
728  // rewind to backslash and overwrite with a space
729  *(pCur-1) = ' ';
730  *pCur = ' ';
731  }
732  }
733  }
734  else if ( *pCur == '.' )
735  nDots++;
736  }
737  if ( pnDots )
738  *pnDots = nDots;
739  if ( pnLines )
740  *pnLines = nLines;
741 }
static Mio_Gate_t* Mio_GateCompare ( Mio_Gate_t pThis,
Mio_Gate_t pNew,
word  uTruth 
)
inlinestatic

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 591 of file mioRead.c.

592 {
593  if ( pNew->uTruth != uTruth )
594  return pThis;
595  if ( pThis == NULL )
596  return pNew;
597  if ( pThis->dArea > pNew->dArea || (pThis->dArea == pNew->dArea && strcmp(pThis->pName, pNew->pName) > 0) )
598  return pNew;
599  return pThis;
600 }
char * pName
Definition: mioInt.h:82
int strcmp()
double dArea
Definition: mioInt.h:83
int Mio_LibraryCompareGatesByArea ( Mio_Gate_t **  pp1,
Mio_Gate_t **  pp2 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 512 of file mioRead.c.

513 {
514  double Diff = (*pp1)->dArea - (*pp2)->dArea;
515  if ( Diff < 0.0 )
516  return -1;
517  if ( Diff > 0.0 )
518  return 1;
519  return 0;
520 }
int Mio_LibraryCompareGatesByName ( Mio_Gate_t **  pp1,
Mio_Gate_t **  pp2 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 533 of file mioRead.c.

534 {
535  int Diff = strcmp( (*pp1)->pName, (*pp2)->pName );
536  if ( Diff < 0.0 )
537  return -1;
538  if ( Diff > 0.0 )
539  return 1;
540  return 0;
541 }
int strcmp()
void Mio_LibraryDetectSpecialGates ( Mio_Library_t pLib)
static

Definition at line 601 of file mioRead.c.

602 {
603  Mio_Gate_t * pGate;
604  word uFuncBuf, uFuncInv, uFuncNand2, uFuncAnd2;
605 
606  Mio_LibrarySortGates( pLib );
607 
608  uFuncBuf = ABC_CONST(0xAAAAAAAAAAAAAAAA);
609  uFuncAnd2 = ABC_CONST(0xAAAAAAAAAAAAAAAA) & ABC_CONST(0xCCCCCCCCCCCCCCCC);
610  uFuncInv = ~uFuncBuf;
611  uFuncNand2 = ~uFuncAnd2;
612 
613  // get smallest-area buffer
614  Mio_LibraryForEachGate( pLib, pGate )
615  pLib->pGateBuf = Mio_GateCompare( pLib->pGateBuf, pGate, uFuncBuf );
616  if ( pLib->pGateBuf == NULL )
617  {
618  printf( "Warnings: genlib library reader cannot detect the buffer gate.\n" );
619  printf( "Some parts of the supergate-based technology mapper may not work correctly.\n" );
620  }
621 
622  // get smallest-area inverter
623  Mio_LibraryForEachGate( pLib, pGate )
624  pLib->pGateInv = Mio_GateCompare( pLib->pGateInv, pGate, uFuncInv );
625  if ( pLib->pGateInv == NULL )
626  {
627  printf( "Warnings: genlib library reader cannot detect the invertor gate.\n" );
628  printf( "Some parts of the supergate-based technology mapper may not work correctly.\n" );
629  }
630 
631  // get smallest-area NAND2/AND2 gates
632  Mio_LibraryForEachGate( pLib, pGate )
633  pLib->pGateNand2 = Mio_GateCompare( pLib->pGateNand2, pGate, uFuncNand2 );
634  Mio_LibraryForEachGate( pLib, pGate )
635  pLib->pGateAnd2 = Mio_GateCompare( pLib->pGateAnd2, pGate, uFuncAnd2 );
636  if ( pLib->pGateAnd2 == NULL && pLib->pGateNand2 == NULL )
637  {
638  printf( "Warnings: genlib library reader cannot detect the AND2 or NAND2 gate.\n" );
639  printf( "Some parts of the supergate-based technology mapper may not work correctly.\n" );
640  }
641 }
void Mio_LibrarySortGates(Mio_Library_t *pLib)
Definition: mioRead.c:554
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
if(last==0)
Definition: sparse_int.h:34
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206
static Mio_Gate_t * Mio_GateCompare(Mio_Gate_t *pThis, Mio_Gate_t *pNew, word uTruth)
Definition: mioRead.c:591
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition: mio.h:65
Mio_Library_t* Mio_LibraryRead ( char *  FileName,
char *  pBuffer,
char *  ExcludeFile,
int  fVerbose 
)

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

Synopsis [Read the genlib type of library.]

Description []

SideEffects []

SeeAlso []

Definition at line 54 of file mioRead.c.

55 {
56  Mio_Library_t * pLib;
57  int num;
58 
59  st__table * tExcludeGate = 0;
60 
61  if ( ExcludeFile )
62  {
63  tExcludeGate = st__init_table(strcmp, st__strhash);
64  if ( (num = Mio_LibraryReadExclude( ExcludeFile, tExcludeGate )) == -1 )
65  {
66  st__free_table( tExcludeGate );
67  tExcludeGate = 0;
68  return 0;
69  }
70  fprintf ( stdout, "Read %d gates from exclude file\n", num );
71  }
72 
73  if ( pBuffer == NULL )
74  pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, fVerbose ); // try normal format first ..
75  else
76  {
77  pLib = Mio_LibraryReadBuffer( pBuffer, 0, tExcludeGate, fVerbose ); // try normal format first ..
78  if ( pLib )
79  pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
80  }
81  if ( pLib == NULL )
82  {
83  if ( pBuffer == NULL )
84  pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, fVerbose ); // try normal format first ..
85  else
86  {
87  pLib = Mio_LibraryReadBuffer( pBuffer, 1, tExcludeGate, fVerbose ); // try normal format first ..
88  if ( pLib )
89  pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
90  }
91  if ( pLib != NULL )
92  printf ( "Warning: Read extended genlib format but ignoring extensions\n" );
93  }
94  if ( tExcludeGate )
95  st__free_table( tExcludeGate );
96 
97  return pLib;
98 }
void st__free_table(st__table *table)
Definition: st.c:81
int strcmp()
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
int Mio_LibraryReadExclude(char *ExcludeFile, st__table *tExcludeGate)
Definition: mioRead.c:654
int st__strhash(const char *string, int modulus)
Definition: st.c:449
Definition: st.h:52
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
static Mio_Library_t * Mio_LibraryReadBuffer(char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
Definition: mioRead.c:152
static ABC_NAMESPACE_IMPL_START Mio_Library_t * Mio_LibraryReadOne(char *FileName, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
DECLARATIONS ///.
Definition: mioRead.c:196
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
Mio_Library_t * Mio_LibraryReadBuffer ( char *  pBuffer,
int  fExtendedFormat,
st__table tExcludeGate,
int  fVerbose 
)
static

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

Synopsis [Read the genlib type of library.]

Description []

SideEffects []

SeeAlso []

Definition at line 152 of file mioRead.c.

153 {
154  Mio_Library_t * pLib;
155 
156  // allocate the genlib structure
157  pLib = ABC_CALLOC( Mio_Library_t, 1 );
159  pLib->pMmFlex = Mem_FlexStart();
160  pLib->vCube = Vec_StrAlloc( 100 );
161 
162  Io_ReadFileRemoveComments( pBuffer, NULL, NULL );
163 
164  // parse the contents of the file
165  if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, fVerbose ) )
166  {
167  Mio_LibraryDelete( pLib );
168  return NULL;
169  }
170 
171  // derive the functinality of gates
172  if ( Mio_LibraryParseFormulas( pLib ) )
173  {
174  printf( "Mio_LibraryRead: Had problems parsing formulas.\n" );
175  Mio_LibraryDelete( pLib );
176  return NULL;
177  }
178 
179  // detect INV and NAND2
181 //Mio_WriteLibrary( stdout, pLib );
182  return pLib;
183 }
int Mio_LibraryParseFormulas(Mio_Library_t *pLib)
FUNCTION DEFINITIONS ///.
Definition: mioForm.c:58
void Mio_LibraryDelete(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition: mioUtils.c:48
Mem_Flex_t * pMmFlex
Definition: mioInt.h:75
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
int strcmp()
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
int st__strhash(const char *string, int modulus)
Definition: st.c:449
Mem_Flex_t * Mem_FlexStart()
Definition: mem.c:311
Vec_Str_t * vCube
Definition: mioInt.h:76
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
static void Mio_LibraryDetectSpecialGates(Mio_Library_t *pLib)
Definition: mioRead.c:601
static int Mio_LibraryReadInternal(Mio_Library_t *pLib, char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
Definition: mioRead.c:225
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
st__table * tName2Gate
Definition: mioInt.h:74
static void Io_ReadFileRemoveComments(char *pBuffer, int *pnDots, int *pnLines)
Definition: mioRead.c:698
int Mio_LibraryReadExclude ( char *  ExcludeFile,
st__table tExcludeGate 
)

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

Synopsis [populate hash table of gates to be exlcuded from genlib]

Description []

SideEffects []

SeeAlso []

Definition at line 654 of file mioRead.c.

655 {
656  int nDel = 0;
657  FILE *pEx;
658  char buffer[128];
659 
660  assert ( tExcludeGate );
661 
662  if ( ExcludeFile )
663  {
664  pEx = fopen( ExcludeFile, "r" );
665 
666  if ( pEx == NULL )
667  {
668  fprintf ( stdout, "Error: Could not open exclude file %s. Stop.\n", ExcludeFile );
669  return -1;
670  }
671 
672  while (1 == fscanf( pEx, "%127s", buffer ))
673  {
674  //printf ("Read: '%s'\n", buffer );
675  st__insert( tExcludeGate, Abc_UtilStrsav( buffer ), (char *)0 );
676  nDel++;
677  }
678 
679  fclose( pEx );
680  }
681 
682  return nDel;
683 }
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define assert(ex)
Definition: util_old.h:213
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
Mio_Gate_t * Mio_LibraryReadGate ( char **  ppToken,
int  fExtendedFormat 
)
static

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

Synopsis [Read the genlib type of gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 332 of file mioRead.c.

333 {
334  Mio_Gate_t * pGate;
335  Mio_Pin_t * pPin, ** ppPin;
336  char * pToken = *ppToken;
337 
338  // allocate the gate structure
339  pGate = ABC_CALLOC( Mio_Gate_t, 1 );
340 
341  // read the name
342  pToken = strtok( NULL, " \t\r\n" );
343  pGate->pName = Abc_UtilStrsav( pToken );
344 
345  // read the area
346  pToken = strtok( NULL, " \t\r\n" );
347  pGate->dArea = atof( pToken );
348 
349  // read the formula
350 
351  // first the output name
352  pToken = strtok( NULL, "=" );
353  pGate->pOutName = chomp( pToken );
354 
355  // then rest of the expression
356  pToken = strtok( NULL, ";" );
357  pGate->pForm = chomp( pToken );
358 
359  // read the pin info
360  // start the linked list of pins
361  pGate->pPins = NULL;
362  ppPin = &pGate->pPins;
363 
364  // read gates one by one
365  pToken = strtok( NULL, " \t\r\n" );
366  while ( pToken && strcmp( pToken, MIO_STRING_PIN ) == 0 )
367  {
368  // derive the next gate
369  pPin = Mio_LibraryReadPin( &pToken, fExtendedFormat );
370  if ( pPin == NULL )
371  {
372  Mio_GateDelete( pGate );
373  *ppToken = pToken;
374  return NULL;
375  }
376  // add this pin to the list
377  *ppPin = pPin;
378  ppPin = &pPin->pNext;
379  // get the next token
380  pToken = strtok( NULL, " \t\r\n" );
381  }
382 
383  *ppToken = pToken;
384  return pGate;
385 }
char * pName
Definition: mioInt.h:82
Mio_Pin_t * pNext
Definition: mioInt.h:114
#define MIO_STRING_PIN
Definition: mioInt.h:45
char * pOutName
Definition: mioInt.h:86
char * strtok()
static char * chomp(char *s)
Definition: mioRead.c:483
void Mio_GateDelete(Mio_Gate_t *pGate)
Definition: mioUtils.c:81
Mio_Pin_t * pPins
Definition: mioInt.h:85
int strcmp()
char * pForm
Definition: mioInt.h:84
double atof()
static Mio_Pin_t * Mio_LibraryReadPin(char **ppToken, int fExtendedFormat)
Definition: mioRead.c:400
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
double dArea
Definition: mioInt.h:83
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
int Mio_LibraryReadInternal ( Mio_Library_t pLib,
char *  pBuffer,
int  fExtendedFormat,
st__table tExcludeGate,
int  fVerbose 
)
static

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

Synopsis [Read the genlib type of library.]

Description []

SideEffects []

SeeAlso []

Definition at line 225 of file mioRead.c.

226 {
227  Mio_Gate_t * pGate, ** ppGate;
228  char * pToken;
229  int nGates = 0;
230  int nDel = 0;
231 
232  // start the linked list of gates
233  pLib->pGates = NULL;
234  ppGate = &pLib->pGates;
235 
236  // read gates one by one
237  pToken = strtok( pBuffer, " \t\r\n" );
238  while ( pToken && (strcmp( pToken, MIO_STRING_GATE ) == 0 || strcmp( pToken, MIO_STRING_LATCH ) == 0) )
239  {
240  // skip latches
241  if ( strcmp( pToken, MIO_STRING_LATCH ) == 0 )
242  {
243  while ( pToken && strcmp( pToken, MIO_STRING_GATE ) != 0 && strcmp( pToken, ".end" ) != 0 )
244  {
245  if ( strcmp( pToken, MIO_STRING_LATCH ) == 0 )
246  {
247  pToken = strtok( NULL, " \t\r\n" );
248  printf( "Skipping latch \"%s\"...\n", pToken );
249  continue;
250  }
251  pToken = strtok( NULL, " \t\r\n" );
252  }
253  if ( !(pToken && strcmp( pToken, MIO_STRING_GATE ) == 0) )
254  break;
255  }
256 
257  // derive the next gate
258  pGate = Mio_LibraryReadGate( &pToken, fExtendedFormat );
259  if ( pGate == NULL )
260  return 1;
261 
262  // skip the gate if its formula has problems
263  if ( !Mio_ParseCheckFormula(pGate, pGate->pForm) )
264  {
265  Mio_GateDelete( pGate );
266  continue;
267  }
268 
269  // set the library
270  pGate->pLib = pLib;
271 
272  // printf ("Processing: '%s'\n", pGate->pName);
273 
274  if ( tExcludeGate && st__is_member( tExcludeGate, pGate->pName ) )
275  {
276  //printf ("Excluding: '%s'\n", pGate->pName);
277  Mio_GateDelete( pGate );
278  nDel++;
279  }
280  else
281  {
282  // add this gate to the list
283  *ppGate = pGate;
284  ppGate = &pGate->pNext;
285  nGates++;
286 
287  // remember this gate by name
288  if ( ! st__is_member( pLib->tName2Gate, pGate->pName ) )
289  st__insert( pLib->tName2Gate, pGate->pName, (char *)pGate );
290  else
291  {
292  Mio_Gate_t * pBase = Mio_LibraryReadGateByName( pLib, pGate->pName, NULL );
293  if ( pBase->pTwin != NULL )
294  {
295  printf( "Gates with more than 2 outputs are not supported.\n" );
296  continue;
297  }
298  pBase->pTwin = pGate;
299  pGate->pTwin = pBase;
300 // printf( "Gate \"%s\" appears two times. Creating a 2-output gate.\n", pGate->pName );
301  }
302  }
303  }
304 
305  if ( nGates == 0 )
306  {
307  printf( "The library contains no gates.\n" );
308  return 1;
309  }
310 
311  // check what is the last word read
312  if ( pToken && strcmp( pToken, ".end" ) != 0 )
313  return 1;
314 
315  if ( nDel != 0 )
316  printf( "Actually excluded %d cells\n", nDel );
317 
318  return 0;
319 }
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
Definition: mioApi.c:99
char * pName
Definition: mioInt.h:82
int Mio_ParseCheckFormula(Mio_Gate_t *pGate, char *pForm)
Definition: mioParse.c:444
Mio_Gate_t * pTwin
Definition: mioInt.h:91
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
Mio_Gate_t * pGates
Definition: mioInt.h:67
char * strtok()
Mio_Library_t * pLib
Definition: mioInt.h:88
#define MIO_STRING_LATCH
Definition: mioInt.h:44
#define st__is_member(table, key)
Definition: st.h:70
void Mio_GateDelete(Mio_Gate_t *pGate)
Definition: mioUtils.c:81
int strcmp()
#define MIO_STRING_GATE
INCLUDES ///.
Definition: mioInt.h:43
char * pForm
Definition: mioInt.h:84
static Mio_Gate_t * Mio_LibraryReadGate(char **ppToken, int fExtendedFormat)
Definition: mioRead.c:332
Mio_Gate_t * pNext
Definition: mioInt.h:90
st__table * tName2Gate
Definition: mioInt.h:74
Mio_Library_t * Mio_LibraryReadOne ( char *  FileName,
int  fExtendedFormat,
st__table tExcludeGate,
int  fVerbose 
)
static

DECLARATIONS ///.

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

FileName [mioRead.c]

PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

Synopsis [File reading/writing for technology mapping.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - September 8, 2003.]

Revision [

Id:
mioRead.c,v 1.9 2004/10/19 06:40:16 satrajit Exp

]FUNCTION DEFINITIONS ///

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

Synopsis [Read the genlib type of library.]

Description []

SideEffects []

SeeAlso []

Definition at line 196 of file mioRead.c.

197 {
198  Mio_Library_t * pLib;
199  char * pBuffer;
200  // read the file and clean comments
201  // pBuffer = Io_ReadFileFileContents( FileName, NULL );
202  // we don't use above function but actually do the same thing explicitly
203  // to handle open_path expansion correctly
204  pBuffer = Mio_ReadFile( FileName, 1 );
205  if ( pBuffer == NULL )
206  return NULL;
207  pLib = Mio_LibraryReadBuffer( pBuffer, fExtendedFormat, tExcludeGate, fVerbose );
208  ABC_FREE( pBuffer );
209  if ( pLib )
210  pLib->pName = Abc_UtilStrsav( FileName );
211  return pLib;
212 }
char * Mio_ReadFile(char *FileName, int fAddEnd)
Definition: mioRead.c:111
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
static Mio_Library_t * Mio_LibraryReadBuffer(char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int fVerbose)
Definition: mioRead.c:152
#define ABC_FREE(obj)
Definition: abc_global.h:232
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
Mio_Pin_t * Mio_LibraryReadPin ( char **  ppToken,
int  fExtendedFormat 
)
static

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

Synopsis [Read the genlib type of pin.]

Description []

SideEffects []

SeeAlso []

Definition at line 400 of file mioRead.c.

401 {
402  Mio_Pin_t * pPin;
403  char * pToken = *ppToken;
404 
405  // allocate the gate structure
406  pPin = ABC_CALLOC( Mio_Pin_t, 1 );
407 
408  // read the name
409  pToken = strtok( NULL, " \t\r\n" );
410  pPin->pName = Abc_UtilStrsav( pToken );
411 
412  // read the pin phase
413  pToken = strtok( NULL, " \t\r\n" );
414  if ( strcmp( pToken, MIO_STRING_UNKNOWN ) == 0 )
415  pPin->Phase = MIO_PHASE_UNKNOWN;
416  else if ( strcmp( pToken, MIO_STRING_INV ) == 0 )
417  pPin->Phase = MIO_PHASE_INV;
418  else if ( strcmp( pToken, MIO_STRING_NONINV ) == 0 )
419  pPin->Phase = MIO_PHASE_NONINV;
420  else
421  {
422  printf( "Cannot read pin phase specification\n" );
423  Mio_PinDelete( pPin );
424  *ppToken = pToken;
425  return NULL;
426  }
427 
428  pToken = strtok( NULL, " \t\r\n" );
429  pPin->dLoadInput = atof( pToken );
430 
431  pToken = strtok( NULL, " \t\r\n" );
432  pPin->dLoadMax = atof( pToken );
433 
434  pToken = strtok( NULL, " \t\r\n" );
435  pPin->dDelayBlockRise = atof( pToken );
436 
437  pToken = strtok( NULL, " \t\r\n" );
438  pPin->dDelayFanoutRise = atof( pToken );
439 
440  pToken = strtok( NULL, " \t\r\n" );
441  pPin->dDelayBlockFall = atof( pToken );
442 
443  pToken = strtok( NULL, " \t\r\n" );
444  pPin->dDelayFanoutFall = atof( pToken );
445 
446  if ( fExtendedFormat )
447  {
448  /* In extended format, the field after dDelayFanoutRise
449  * is to be ignored
450  **/
451 
452  pPin->dDelayBlockFall = pPin->dDelayFanoutFall;
453 
454  pToken = strtok( NULL, " \t" );
455  pPin->dDelayFanoutFall = atof( pToken );
456 
457  /* last field is ignored */
458  pToken = strtok( NULL, " \t\r\n" );
459  }
460 
461  if ( pPin->dDelayBlockRise > pPin->dDelayBlockFall )
462  pPin->dDelayBlockMax = pPin->dDelayBlockRise;
463  else
464  pPin->dDelayBlockMax = pPin->dDelayBlockFall;
465 
466  *ppToken = pToken;
467  return pPin;
468 }
double dDelayBlockMax
Definition: mioInt.h:113
char * strtok()
char * pName
Definition: mioInt.h:105
int strcmp()
#define MIO_STRING_UNKNOWN
Definition: mioInt.h:48
void Mio_PinDelete(Mio_Pin_t *pPin)
Definition: mioUtils.c:108
double dDelayFanoutFall
Definition: mioInt.h:112
double dDelayBlockFall
Definition: mioInt.h:111
#define MIO_STRING_INV
Definition: mioInt.h:47
Mio_PinPhase_t Phase
Definition: mioInt.h:106
double atof()
double dLoadMax
Definition: mioInt.h:108
double dLoadInput
Definition: mioInt.h:107
double dDelayFanoutRise
Definition: mioInt.h:110
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
double dDelayBlockRise
Definition: mioInt.h:109
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
#define MIO_STRING_NONINV
Definition: mioInt.h:46
void Mio_LibrarySortGates ( Mio_Library_t pLib)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 554 of file mioRead.c.

555 {
556  Mio_Gate_t ** ppGates, * pGate;
557  int i = 0;
558  ppGates = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
559  Mio_LibraryForEachGate( pLib, pGate )
560  ppGates[i++] = pGate;
561  assert( i == pLib->nGates );
562  // sort gates by area
563  pLib->ppGates0 = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
564  for ( i = 0; i < pLib->nGates; i++ )
565  pLib->ppGates0[i] = ppGates[i];
566  qsort( (void *)ppGates, pLib->nGates, sizeof(void *),
567  (int (*)(const void *, const void *)) Mio_LibraryCompareGatesByArea );
568  for ( i = 0; i < pLib->nGates; i++ )
569  ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL;
570  pLib->pGates = ppGates[0];
571  ABC_FREE( ppGates );
572  // sort gates by name
573  pLib->ppGatesName = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
574  for ( i = 0; i < pLib->nGates; i++ )
575  pLib->ppGatesName[i] = pLib->ppGates0[i];
576  qsort( (void *)pLib->ppGatesName, pLib->nGates, sizeof(void *),
577  (int (*)(const void *, const void *)) Mio_LibraryCompareGatesByName );
578 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Mio_LibraryCompareGatesByArea(Mio_Gate_t **pp1, Mio_Gate_t **pp2)
Definition: mioRead.c:512
for(p=first;p->value< newval;p=p->next)
int Mio_LibraryCompareGatesByName(Mio_Gate_t **pp1, Mio_Gate_t **pp2)
Definition: mioRead.c:533
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
#define const
Definition: zconf.h:196
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition: mio.h:65
char* Mio_ReadFile ( char *  FileName,
int  fAddEnd 
)

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

Synopsis [Read contents of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file mioRead.c.

112 {
113  char * pBuffer;
114  FILE * pFile;
115  int nFileSize;
116  int RetValue;
117 
118  // open the BLIF file for binary reading
119  pFile = Io_FileOpen( FileName, "open_path", "rb", 1 );
120 // pFile = fopen( FileName, "rb" );
121  // if we got this far, file should be okay otherwise would
122  // have been detected by caller
123  assert ( pFile != NULL );
124  // get the file size, in bytes
125  fseek( pFile, 0, SEEK_END );
126  nFileSize = ftell( pFile );
127  // move the file current reading position to the beginning
128  rewind( pFile );
129  // load the contents of the file into memory
130  pBuffer = ABC_ALLOC( char, nFileSize + 10 );
131  RetValue = fread( pBuffer, nFileSize, 1, pFile );
132  // terminate the string with '\0'
133  pBuffer[ nFileSize ] = '\0';
134  if ( fAddEnd )
135  strcat( pBuffer, "\n.end\n" );
136  // close file
137  fclose( pFile );
138  return pBuffer;
139 }
FILE * Io_FileOpen(const char *FileName, const char *PathVar, const char *Mode, int fVerbose)
Definition: ioUtil.c:819
#define SEEK_END
Definition: zconf.h:392
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * strcat()
#define assert(ex)
Definition: util_old.h:213
VOID_HACK rewind()