Commit dccd3992 by Alan Mishchenko

Adding dynamic memory alloc for the buffer in Liberty file reader.

parent 1bb50384
...@@ -29,7 +29,7 @@ ABC_NAMESPACE_IMPL_START ...@@ -29,7 +29,7 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS /// /// DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
#define ABC_MAX_LIB_STR_LEN 5000 // #define ABC_MAX_LIB_STR_LEN 5000
// entry types // entry types
typedef enum { typedef enum {
...@@ -70,6 +70,7 @@ struct Scl_Tree_t_ ...@@ -70,6 +70,7 @@ struct Scl_Tree_t_
Scl_Item_t * pItems; // the items Scl_Item_t * pItems; // the items
char * pError; // the error string char * pError; // the error string
abctime clkStart; // beginning time abctime clkStart; // beginning time
Vec_Str_t * vBuffer; // temp string buffer
}; };
static inline Scl_Item_t * Scl_LibertyRoot( Scl_Tree_t * p ) { return p->pItems; } static inline Scl_Item_t * Scl_LibertyRoot( Scl_Tree_t * p ) { return p->pItems; }
...@@ -340,8 +341,11 @@ static inline Scl_Item_t * Scl_LibertyNewItem( Scl_Tree_t * p, int Type ) ...@@ -340,8 +341,11 @@ static inline Scl_Item_t * Scl_LibertyNewItem( Scl_Tree_t * p, int Type )
***********************************************************************/ ***********************************************************************/
char * Scl_LibertyReadString( Scl_Tree_t * p, Scl_Pair_t Pair ) char * Scl_LibertyReadString( Scl_Tree_t * p, Scl_Pair_t Pair )
{ {
static char Buffer[ABC_MAX_LIB_STR_LEN]; // static char Buffer[ABC_MAX_LIB_STR_LEN];
assert( Pair.End-Pair.Beg < ABC_MAX_LIB_STR_LEN ); char * Buffer;
if ( Pair.End - Pair.Beg + 2 > Vec_StrSize(p->vBuffer) )
Vec_StrFill( p->vBuffer, Pair.End - Pair.Beg + 100, '\0' );
Buffer = Vec_StrArray( p->vBuffer );
strncpy( Buffer, p->pContents+Pair.Beg, Pair.End-Pair.Beg ); strncpy( Buffer, p->pContents+Pair.Beg, Pair.End-Pair.Beg );
if ( Pair.Beg < Pair.End && Buffer[0] == '\"' ) if ( Pair.Beg < Pair.End && Buffer[0] == '\"' )
{ {
...@@ -572,6 +576,7 @@ Scl_Tree_t * Scl_LibertyStart( char * pFileName ) ...@@ -572,6 +576,7 @@ Scl_Tree_t * Scl_LibertyStart( char * pFileName )
p->pItems = ABC_CALLOC( Scl_Item_t, p->nItermAlloc ); p->pItems = ABC_CALLOC( Scl_Item_t, p->nItermAlloc );
p->nItems = 0; p->nItems = 0;
p->nLines = 1; p->nLines = 1;
p->vBuffer = Vec_StrStart( 10 );
return p; return p;
} }
void Scl_LibertyStop( Scl_Tree_t * p, int fVerbose ) void Scl_LibertyStop( Scl_Tree_t * p, int fVerbose )
...@@ -581,6 +586,7 @@ void Scl_LibertyStop( Scl_Tree_t * p, int fVerbose ) ...@@ -581,6 +586,7 @@ void Scl_LibertyStop( Scl_Tree_t * p, int fVerbose )
printf( "Memory = %7.2f MB. ", 1.0 * (p->nContents + p->nItermAlloc * sizeof(Scl_Item_t))/(1<<20) ); printf( "Memory = %7.2f MB. ", 1.0 * (p->nContents + p->nItermAlloc * sizeof(Scl_Item_t))/(1<<20) );
ABC_PRT( "Time", Abc_Clock() - p->clkStart ); ABC_PRT( "Time", Abc_Clock() - p->clkStart );
} }
Vec_StrFree( p->vBuffer );
ABC_FREE( p->pFileName ); ABC_FREE( p->pFileName );
ABC_FREE( p->pContents ); ABC_FREE( p->pContents );
ABC_FREE( p->pItems ); ABC_FREE( p->pItems );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment