abc/src/map/mapper/mapperLib.c

259 lines
7.9 KiB
C
Raw Normal View History

2005-07-29 17:01:00 +02:00
/**CFile****************************************************************
FileName [mapperLib.c]
PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
Synopsis [Generic technology mapping engine.]
Author [MVSIS Group]
Affiliation [UC Berkeley]
Date [Ver. 2.0. Started - June 1, 2004.]
Revision [$Id: mapperLib.c,v 1.6 2005/01/23 06:59:44 alanmi Exp $]
***********************************************************************/
2008-07-02 17:01:00 +02:00
#define _BSD_SOURCE
#ifndef WIN32
#include <unistd.h>
#endif
2005-07-29 17:01:00 +02:00
#include "mapperInt.h"
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_START
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
2008-01-31 05:01:00 +01:00
/// FUNCTION DEFINITIONS ///
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Reads in the supergate library and prepares it for use.]
Description [The supergates library comes in a .super file. This file
contains descriptions of supergates along with some relevant information.
This procedure reads the supergate file, canonicizes the supergates,
and constructs an additional lookup table, which can be used to map
truth tables of the cuts into the pair (phase, supergate). The phase
indicates how the current truth table should be phase assigned to
match the canonical form of the supergate. The resulting phase is the
bitwise EXOR of the phase needed to canonicize the supergate and the
phase needed to transform the truth table into its canonical form.]
SideEffects []
SeeAlso []
***********************************************************************/
2010-11-01 09:35:04 +01:00
Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
2005-07-29 17:01:00 +02:00
{
Map_SuperLib_t * p;
int clk;
// start the supergate library
2009-02-15 17:01:00 +01:00
p = ABC_ALLOC( Map_SuperLib_t, 1 );
2005-07-29 17:01:00 +02:00
memset( p, 0, sizeof(Map_SuperLib_t) );
p->pName = pFileName;
p->fVerbose = fVerbose;
p->mmSupers = Extra_MmFixedStart( sizeof(Map_Super_t) );
p->mmEntries = Extra_MmFixedStart( sizeof(Map_HashEntry_t) );
p->mmForms = Extra_MmFlexStart();
Map_MappingSetupTruthTables( p->uTruths );
// start the hash table
p->tTableC = Map_SuperTableCreate( p );
p->tTable = Map_SuperTableCreate( p );
// read the supergate library from file
clk = clock();
if ( fAlgorithm )
{
if ( !Map_LibraryReadTree( p, pFileName, pExcludeFile ) )
{
Map_SuperLibFree( p );
return NULL;
}
}
else
{
if ( pExcludeFile != 0 )
{
Map_SuperLibFree( p );
2005-07-29 17:01:00 +02:00
printf ("Error: Exclude file support not present for old format. Stop.\n");
return NULL;
}
if ( !Map_LibraryRead( p, pFileName ) )
{
Map_SuperLibFree( p );
return NULL;
}
}
assert( p->nVarsMax > 0 );
// report the stats
if ( fVerbose ) {
printf( "Loaded %d unique %d-input supergates from \"%s\". ",
p->nSupersReal, p->nVarsMax, pFileName );
2009-02-15 17:01:00 +01:00
ABC_PRT( "Time", clock() - clk );
2005-07-29 17:01:00 +02:00
}
// assign the interver parameters
p->pGateInv = Mio_LibraryReadInv( p->pGenlib );
p->tDelayInv.Rise = Mio_LibraryReadDelayInvRise( p->pGenlib );
p->tDelayInv.Fall = Mio_LibraryReadDelayInvFall( p->pGenlib );
p->tDelayInv.Worst = MAP_MAX( p->tDelayInv.Rise, p->tDelayInv.Fall );
p->AreaInv = Mio_LibraryReadAreaInv( p->pGenlib );
2005-09-04 17:01:00 +02:00
p->AreaBuf = Mio_LibraryReadAreaBuf( p->pGenlib );
2005-07-29 17:01:00 +02:00
// assign the interver supergate
p->pSuperInv = (Map_Super_t *)Extra_MmFixedEntryFetch( p->mmSupers );
memset( p->pSuperInv, 0, sizeof(Map_Super_t) );
p->pSuperInv->Num = -1;
p->pSuperInv->nGates = 1;
p->pSuperInv->nFanins = 1;
p->pSuperInv->nFanLimit = 10;
p->pSuperInv->pFanins[0] = p->ppSupers[0];
p->pSuperInv->pRoot = p->pGateInv;
p->pSuperInv->Area = p->AreaInv;
p->pSuperInv->tDelayMax = p->tDelayInv;
p->pSuperInv->tDelaysR[0].Rise = MAP_NO_VAR;
p->pSuperInv->tDelaysR[0].Fall = p->tDelayInv.Rise;
p->pSuperInv->tDelaysF[0].Rise = p->tDelayInv.Fall;
p->pSuperInv->tDelaysF[0].Fall = MAP_NO_VAR;
return p;
}
/**Function*************************************************************
Synopsis [Deallocates the supergate library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Map_SuperLibFree( Map_SuperLib_t * p )
{
if ( p == NULL ) return;
if ( p->pGenlib )
{
2005-09-05 17:01:00 +02:00
assert( p->pGenlib == Abc_FrameReadLibGen() );
2005-07-29 17:01:00 +02:00
Mio_LibraryDelete( p->pGenlib );
2005-09-05 17:01:00 +02:00
Abc_FrameSetLibGen( NULL );
2005-07-29 17:01:00 +02:00
}
if ( p->tTableC )
Map_SuperTableFree( p->tTableC );
if ( p->tTable )
Map_SuperTableFree( p->tTable );
2008-01-31 05:01:00 +01:00
Extra_MmFixedStop( p->mmSupers );
Extra_MmFixedStop( p->mmEntries );
Extra_MmFlexStop( p->mmForms );
2009-02-15 17:01:00 +01:00
ABC_FREE( p->ppSupers );
ABC_FREE( p );
2005-07-29 17:01:00 +02:00
}
/**Function*************************************************************
Synopsis [Derives the library from the genlib library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib )
{
Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
char * pNameGeneric;
char * FileNameGenlib;
char * FileNameSuper;
char * CommandSuper;
char * CommandRead;
2005-07-29 17:01:00 +02:00
FILE * pFile;
if ( pLib == NULL )
return 0;
FileNameGenlib = ABC_ALLOC( char, 10000 );
FileNameSuper = ABC_ALLOC( char, 10000 );
CommandSuper = ABC_ALLOC( char, 10000 );
CommandRead = ABC_ALLOC( char, 10000 );
2005-07-29 17:01:00 +02:00
// write the current library into the file
2008-01-31 05:01:00 +01:00
sprintf( FileNameGenlib, "%s_temp", Mio_LibraryReadName(pLib) );
2005-07-29 17:01:00 +02:00
pFile = fopen( FileNameGenlib, "w" );
Mio_WriteLibrary( pFile, pLib, 0 );
fclose( pFile );
// get the file name with the library
pNameGeneric = Extra_FileNameGeneric( Mio_LibraryReadName(pLib) );
sprintf( FileNameSuper, "%s.super", pNameGeneric );
2009-02-15 17:01:00 +01:00
ABC_FREE( pNameGeneric );
2005-07-29 17:01:00 +02:00
sprintf( CommandSuper, "super -l 1 -i 5 -d 10000000 -a 10000000 -t 100 %s", FileNameGenlib );
if ( Cmd_CommandExecute( pAbc, CommandSuper ) )
{
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
2005-07-29 17:01:00 +02:00
fprintf( stdout, "Cannot execute command \"%s\".\n", CommandSuper );
return 0;
}
//#ifdef WIN32
// _unlink( FileNameGenlib );
//#else
// unlink( FileNameGenlib );
//#endif
printf( "A simple supergate library is derived from gate library \"%s\".\n", Mio_LibraryReadName(pLib) );
fflush( stdout );
2005-07-29 17:01:00 +02:00
sprintf( CommandRead, "read_super %s", FileNameSuper );
if ( Cmd_CommandExecute( pAbc, CommandRead ) )
{
//#ifdef WIN32
// _unlink( FileNameSuper );
//#else
// unlink( FileNameSuper );
//#endif
2005-07-29 17:01:00 +02:00
fprintf( stdout, "Cannot execute command \"%s\".\n", CommandRead );
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
2005-07-29 17:01:00 +02:00
return 0;
}
//#ifdef WIN32
// _unlink( FileNameSuper );
//#else
// unlink( FileNameSuper );
//#endif
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
return 1;
2005-07-29 17:01:00 +02:00
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_END