ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mioRead.c File Reference
#include <ctype.h>
#include "mioInt.h"
#include "base/io/ioAbc.h"
Include dependency graph for mioRead.c:

Go to the source code of this file.

Functions

Mio_Library_tMio_LibraryReadBuffer (char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int nFaninLimit, int fVerbose)
 
Mio_Library_tMio_LibraryRead (char *FileName, char *pBuffer, char *ExcludeFile, int nFaninLimit, int fVerbose)
 
char * Mio_ReadFile (char *FileName, int fAddEnd)
 
char * Mio_LibraryCleanStr (char *p)
 
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)
 
int Mio_LibraryReadExclude (char *ExcludeFile, st__table *tExcludeGate)
 

Function Documentation

◆ Mio_LibraryCleanStr()

char * Mio_LibraryCleanStr ( char * p)

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

Synopsis [Read the genlib type of gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 349 of file mioRead.c.

350{
351 int i, k;
352 int whitespace_state = 0;
353 char * pRes = Abc_UtilStrsav( p );
354 for ( i = k = 0; pRes[i]; i++ )
355 if ( pRes[i] != ' ' && pRes[i] != '\t' && pRes[i] != '\r' && pRes[i] != '\n' )
356 {
357 if ( pRes[i] != '(' && pRes[i] != ')' && pRes[i] != '+' && pRes[i] != '*' && pRes[i] != '|' && pRes[i] != '&' && pRes[i] != '^' && pRes[i] != '\'' && pRes[i] != '!' )
358 {
359 if (whitespace_state == 2)
360 pRes[k++] = ' ';
361 whitespace_state = 1;
362 }
363 else
364 whitespace_state = 0;
365 pRes[k++] = pRes[i];
366 }
367 else
368 whitespace_state = whitespace_state ? 2 : 0;
369 pRes[k] = 0;
370 return pRes;
371}
Cube * p
Definition exorList.c:222

◆ Mio_LibraryCompareGatesByArea()

int Mio_LibraryCompareGatesByArea ( Mio_Gate_t ** pp1,
Mio_Gate_t ** pp2 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 555 of file mioRead.c.

556{
557 double Diff = (*pp1)->dArea - (*pp2)->dArea;
558 if ( Diff < 0.0 )
559 return -1;
560 if ( Diff > 0.0 )
561 return 1;
562 return 0;
563}

◆ Mio_LibraryCompareGatesByName()

int Mio_LibraryCompareGatesByName ( Mio_Gate_t ** pp1,
Mio_Gate_t ** pp2 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 576 of file mioRead.c.

577{
578 int Diff = strcmp( (*pp1)->pName, (*pp2)->pName );
579 if ( Diff < 0 )
580 return -1;
581 if ( Diff > 0 )
582 return 1;
583 return 0;
584}
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_LibraryRead()

Mio_Library_t * Mio_LibraryRead ( char * FileName,
char * pBuffer,
char * ExcludeFile,
int nFaninLimit,
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 char * pBufferCopy;
59
60 st__table * tExcludeGate = 0;
61
62 if ( ExcludeFile )
63 {
64 tExcludeGate = st__init_table(strcmp, st__strhash);
65 if ( (num = Mio_LibraryReadExclude( ExcludeFile, tExcludeGate )) == -1 )
66 {
67 st__free_table( tExcludeGate );
68 tExcludeGate = 0;
69 return 0;
70 }
71 fprintf ( stdout, "Read %d gates from exclude file\n", num );
72 }
73
74 pBufferCopy = Abc_UtilStrsav(pBuffer);
75 if ( pBuffer == NULL )
76 pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first ..
77 else
78 {
79 pLib = Mio_LibraryReadBuffer( pBuffer, 0, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first ..
80 if ( pLib )
81 pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
82 }
83 if ( pLib == NULL )
84 {
85 if ( pBuffer == NULL )
86 pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first ..
87 else
88 {
89 pLib = Mio_LibraryReadBuffer( pBufferCopy, 1, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first ..
90 if ( pLib )
91 pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
92 }
93 if ( pLib != NULL )
94 printf ( "Warning: Read extended genlib format but ignoring extensions\n" );
95 }
96 ABC_FREE( pBufferCopy );
97 if ( tExcludeGate )
98 st__free_table( tExcludeGate );
99
100 pLib->pFileName = Abc_UtilStrsav( FileName );
101 return pLib;
102}
#define ABC_FREE(obj)
Definition abc_global.h:267
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
Mio_Library_t * Mio_LibraryReadBuffer(char *pBuffer, int fExtendedFormat, st__table *tExcludeGate, int nFaninLimit, int fVerbose)
Definition mioRead.c:156
int Mio_LibraryReadExclude(char *ExcludeFile, st__table *tExcludeGate)
Definition mioRead.c:699
struct Mio_LibraryStruct_t_ Mio_Library_t
Definition mio.h:42
int st__strhash(const char *string, int modulus)
Definition st.c:449
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition st.c:72
void st__free_table(st__table *table)
Definition st.c:81
Definition st.h:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_LibraryReadBuffer()

Mio_Library_t * Mio_LibraryReadBuffer ( char * pBuffer,
int fExtendedFormat,
st__table * tExcludeGate,
int nFaninLimit,
int fVerbose )

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

Synopsis [Read the genlib type of library.]

Description []

SideEffects []

SeeAlso []

Definition at line 156 of file mioRead.c.

157{
158 Mio_Library_t * pLib;
159
160 // allocate the genlib structure
161 pLib = ABC_CALLOC( Mio_Library_t, 1 );
163 pLib->pMmFlex = Mem_FlexStart();
164 pLib->vCube = Vec_StrAlloc( 100 );
165
166 Io_ReadFileRemoveComments( pBuffer, NULL, NULL );
167
168 // parse the contents of the file
169 if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, nFaninLimit, fVerbose ) )
170 {
171 Mio_LibraryDelete( pLib );
172 return NULL;
173 }
174
175 // derive the functinality of gates
176 if ( Mio_LibraryParseFormulas( pLib ) )
177 {
178 printf( "Mio_LibraryRead: Had problems parsing formulas.\n" );
179 Mio_LibraryDelete( pLib );
180 return NULL;
181 }
182
183 // detect INV and NAND2
184 Mio_LibraryDetectSpecialGates( pLib );
185//Mio_WriteLibrary( stdout, pLib );
186 return pLib;
187}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
Mem_Flex_t * Mem_FlexStart()
Definition mem.c:327
void Mio_LibraryDelete(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition mioUtils.c:51
int Mio_LibraryParseFormulas(Mio_Library_t *pLib)
FUNCTION DEFINITIONS ///.
Definition mioForm.c:58
st__table * tName2Gate
Definition mioInt.h:77
Vec_Str_t * vCube
Definition mioInt.h:79
Mem_Flex_t * pMmFlex
Definition mioInt.h:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_LibraryReadExclude()

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 699 of file mioRead.c.

700{
701 int nDel = 0;
702 FILE *pEx;
703 char buffer[128];
704
705 assert ( tExcludeGate );
706
707 if ( ExcludeFile )
708 {
709 pEx = fopen( ExcludeFile, "r" );
710
711 if ( pEx == NULL )
712 {
713 fprintf ( stdout, "Error: Could not open exclude file %s. Stop.\n", ExcludeFile );
714 return -1;
715 }
716
717 while (1 == fscanf( pEx, "%127s", buffer ))
718 {
719 //printf ("Read: '%s'\n", buffer );
720 st__insert( tExcludeGate, Abc_UtilStrsav( buffer ), (char *)0 );
721 nDel++;
722 }
723
724 fclose( pEx );
725 }
726
727 return nDel;
728}
int st__insert(st__table *table, const char *key, char *value)
Definition st.c:171
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Mio_LibrarySortGates()

void Mio_LibrarySortGates ( Mio_Library_t * pLib)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 597 of file mioRead.c.

598{
599 Mio_Gate_t ** ppGates, * pGate;
600 int i = 0;
601 ppGates = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
602 Mio_LibraryForEachGate( pLib, pGate )
603 {
604 pGate->Cell = i;
605 ppGates[i++] = pGate;
606 }
607 assert( i == pLib->nGates );
608 // sort gates by name
609 pLib->ppGates0 = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
610 for ( i = 0; i < pLib->nGates; i++ )
611 pLib->ppGates0[i] = ppGates[i];
612 qsort( (void *)ppGates, (size_t)pLib->nGates, sizeof(void *),
613 (int (*)(const void *, const void *)) Mio_LibraryCompareGatesByName );
614 for ( i = 0; i < pLib->nGates; i++ )
615 ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL;
616 pLib->pGates = ppGates[0];
617 pLib->ppGatesName = ppGates;
618}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
int Mio_LibraryCompareGatesByName(Mio_Gate_t **pp1, Mio_Gate_t **pp2)
Definition mioRead.c:576
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition mio.h:81
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
Mio_Gate_t ** ppGates0
Definition mioInt.h:66
Mio_Gate_t ** ppGatesName
Definition mioInt.h:67
Mio_Gate_t * pGates
Definition mioInt.h:68
Here is the call graph for this function:

◆ Mio_ReadFile()

char * Mio_ReadFile ( char * FileName,
int fAddEnd )

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

Synopsis [Read contents of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 115 of file mioRead.c.

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