Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save cell mapping as new 'M' AIGER extension #327

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/aig/gia/giaAiger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,18 @@ void Gia_AigerWriteS( Gia_Man_t * pInit, char * pFileName, int fWriteSymbols, in
Vec_StrFree( vStrExt );
if ( fVerbose ) printf( "Finished writing extension \"m\".\n" );
}
// write cell mapping
if ( Gia_ManHasCellMapping(p) )
{
extern Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p );
fprintf( pFile, "M" );
vStrExt = Gia_AigerWriteCellMappingDoc( p );
Gia_FileWriteBufferSize( pFile, Vec_StrSize(vStrExt) );
fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
Vec_StrFree( vStrExt );
if ( fVerbose ) printf( "Finished writing extension \"M\".\n" );

}
// write placement
if ( p->pPlacement )
{
Expand Down
98 changes: 98 additions & 0 deletions src/aig/gia/giaAigerExt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
***********************************************************************/

#include "gia.h"
#include "misc/st/st.h"
#include "map/mio/mio.h"
#include "map/mio/mioInt.h"

ABC_NAMESPACE_IMPL_START

Expand Down Expand Up @@ -288,6 +291,101 @@ Vec_Str_t * Gia_AigerWriteMappingDoc( Gia_Man_t * p )
return Vec_StrAllocArray( (char *)pBuffer, 4*nSize );
}

int Gia_AigerWriteCellMappingInstance( Gia_Man_t * p, unsigned char * pBuffer, int nSize2, int i )
{
int k, iFan;
if ( !Gia_ObjIsCellInv(p, i) ) {
Gia_AigerWriteInt( pBuffer + nSize2, Gia_ObjCellId(p, i) ); nSize2 += 4;
Gia_AigerWriteInt( pBuffer + nSize2, i ); nSize2 += 4;
Gia_CellForEachFanin( p, i, iFan, k )
{
Gia_AigerWriteInt( pBuffer + nSize2, iFan );
nSize2 += 4;
}
} else {
Gia_AigerWriteInt( pBuffer + nSize2, 3 ); nSize2 += 4;
Gia_AigerWriteInt( pBuffer + nSize2, i ); nSize2 += 4;
Gia_AigerWriteInt( pBuffer + nSize2, Abc_LitNot(i) ); nSize2 += 4;
}

return nSize2;
}

Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p )
{
unsigned char * pBuffer;
int i, iFan, nCells = 0, nInstances = 0, nSize = 8, nSize2 = 0;
Mio_Cell2_t * pCells = Mio_CollectRootsNewDefault2( 6, &nCells, 0 );
assert( pCells );

for (int i = 0; i < nCells; i++)
{
Mio_Gate_t *pGate = (Mio_Gate_t *) pCells[i].pMioGate;
Mio_Pin_t *pPin;
nSize += strlen(Mio_GateReadName(pGate)) + 1;
nSize += strlen(Mio_GateReadOutName(pGate)) + 1 + 4;
Mio_GateForEachPin( pGate, pPin )
nSize += strlen(Mio_PinReadName(pPin)) + 1;
}

Gia_ManForEachCell( p, i )
{
assert ( !Gia_ObjIsCellBuf(p, i) ); // not implemented
nInstances++;
if ( Gia_ObjIsCellInv(p, i) )
nSize += 12;
else
nSize += Gia_ObjCellSize(p, i) * 4 + 8;
}

pBuffer = ABC_ALLOC( unsigned char, nSize );
Gia_AigerWriteInt( pBuffer + nSize2, nCells ); nSize2 += 4;
Gia_AigerWriteInt( pBuffer + nSize2, nInstances ); nSize2 += 4;

for (int i = 0; i < nCells; i++)
{
int nPins = 0;
Mio_Gate_t *pGate = (Mio_Gate_t *) pCells[i].pMioGate;
Mio_Pin_t *pPin;

strcpy((char *) pBuffer + nSize2, Mio_GateReadName(pGate));
nSize2 += strlen(Mio_GateReadName(pGate)) + 1;
strcpy((char *) pBuffer + nSize2, Mio_GateReadOutName(pGate));
nSize2 += strlen(Mio_GateReadOutName(pGate)) + 1;

Mio_GateForEachPin( pGate, pPin )
nPins++;
Gia_AigerWriteInt( pBuffer + nSize2, nPins ); nSize2 += 4;

Mio_GateForEachPin( pGate, pPin )
{
strcpy((char *) pBuffer + nSize2, Mio_PinReadName(pPin));
nSize2 += strlen(Mio_PinReadName(pPin)) + 1;
}
}

Gia_ManForEachCell( p, i )
{
if ( Gia_ObjIsCellBuf(p, i) )
continue;

if ( Gia_ObjIsCellInv(p, i) && !Abc_LitIsCompl(i) ) {
// swap the order so that the inverter is after the driver
// of the inverter's input
nSize2 = Gia_AigerWriteCellMappingInstance(p, pBuffer, nSize2, Abc_LitNot(i) );
nSize2 = Gia_AigerWriteCellMappingInstance(p, pBuffer, nSize2, i );
i += 1;
continue;
}

nSize2 = Gia_AigerWriteCellMappingInstance(p, pBuffer, nSize2, i );
}

assert( nSize2 == nSize );
ABC_FREE( pCells );
return Vec_StrAllocArray( (char *)pBuffer, nSize );
}

/**Function*************************************************************

Synopsis [Read/write packing information.]
Expand Down
2 changes: 1 addition & 1 deletion src/aig/gia/giaIf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ void Gia_ManMappingVerify( Gia_Man_t * p )
continue;
if ( !Gia_ObjIsLut(p, Gia_ObjId(p, pFanin)) )
{
Abc_Print( -1, "Gia_ManMappingVerify: CO driver %d does not have mapping.\n", Gia_ObjId(p, pFanin) );
Abc_Print( -1, "Gia_ManMappingVerify: Buffer driver %d does not have mapping.\n", Gia_ObjId(p, pFanin) );
Result = 0;
continue;
}
Expand Down
Loading