summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2021-08-17 16:52:29 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2021-08-17 16:52:29 -0700
commit4da6cc890433e8d782f8a1805fa9ec617955464d (patch)
tree9db4715495b190ef385d88e4943d6a35f9df1d6f
parente9b487666d7cab3cc8a02faa34160d2ed4cb6178 (diff)
downloadabc-4da6cc890433e8d782f8a1805fa9ec617955464d.tar.gz
abc-4da6cc890433e8d782f8a1805fa9ec617955464d.tar.bz2
abc-4da6cc890433e8d782f8a1805fa9ec617955464d.zip
Improving AIG to Verilog converter.
-rw-r--r--abclib.dsp2
-rw-r--r--src/aig/gia/gia.h2
-rw-r--r--src/aig/gia/giaMan.c89
-rw-r--r--src/base/abci/abc.c11
4 files changed, 76 insertions, 28 deletions
diff --git a/abclib.dsp b/abclib.dsp
index d202ce83..fcbe343b 100644
--- a/abclib.dsp
+++ b/abclib.dsp
@@ -5103,7 +5103,7 @@ SOURCE=.\src\aig\gia\giaResub2.c
# End Source File
# Begin Source File
-SOURCE=.\src\aig\gia\giaResub3_new5.c
+SOURCE=.\src\aig\gia\giaResub3.c
# End Source File
# Begin Source File
diff --git a/src/aig/gia/gia.h b/src/aig/gia/gia.h
index 3517502d..8a5137fe 100644
--- a/src/aig/gia/gia.h
+++ b/src/aig/gia/gia.h
@@ -1488,7 +1488,7 @@ extern void Gia_ManPrintStatsMiter( Gia_Man_t * p, int fVerbose )
extern void Gia_ManSetRegNum( Gia_Man_t * p, int nRegs );
extern void Gia_ManReportImprovement( Gia_Man_t * p, Gia_Man_t * pNew );
extern void Gia_ManPrintNpnClasses( Gia_Man_t * p );
-extern void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs );
+extern void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs, int fVerBufs );
/*=== giaMem.c ===========================================================*/
extern Gia_MmFixed_t * Gia_MmFixedStart( int nEntrySize, int nEntriesMax );
extern void Gia_MmFixedStop( Gia_MmFixed_t * p, int fVerbose );
diff --git a/src/aig/gia/giaMan.c b/src/aig/gia/giaMan.c
index b5748401..e4c9afd0 100644
--- a/src/aig/gia/giaMan.c
+++ b/src/aig/gia/giaMan.c
@@ -1270,13 +1270,14 @@ void Gia_ManWriteNames( FILE * pFile, char c, int n, Vec_Ptr_t * vNames, int Sta
fFirst = 0;
}
}
-void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs )
+void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs, int fVerBufs )
{
FILE * pFile;
Gia_Obj_t * pObj;
Vec_Bit_t * vInvs, * vUsed;
- int nDigits = Abc_Base10Log( Gia_ManObjNum(p) );
- int nDigits2 = Abc_Base10Log( Gia_ManPiNum(p) );
+ int nDigits = Abc_Base10Log( Gia_ManObjNum(p) );
+ int nDigitsI = Abc_Base10Log( Gia_ManPiNum(p) );
+ int nDigitsO = Abc_Base10Log( Gia_ManPoNum(p) );
int i, k, iObj;
if ( Gia_ManRegNum(p) )
{
@@ -1301,20 +1302,63 @@ void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs )
fprintf( pFile, "%c", p->pName[i] );
else
fprintf( pFile, "_" );
- fprintf( pFile, " (\n " );
- Gia_ManWriteNames( pFile, 'x', Gia_ManPiNum(p), p->vNamesIn, 4, 4, NULL );
- fprintf( pFile, ",\n " );
- Gia_ManWriteNames( pFile, 'z', Gia_ManPoNum(p), p->vNamesOut, 4, 4, NULL );
- fprintf( pFile, "\n );\n\n" );
+ if ( fVerBufs )
+ {
+ fprintf( pFile, " (\n " );
+ Gia_ManWriteNames( pFile, 'a', Gia_ManPiNum(p), NULL, 4, 4, NULL );
+ fprintf( pFile, ",\n " );
+
+ Gia_ManWriteNames( pFile, 'y', Gia_ManPoNum(p), NULL, 4, 4, NULL );
+ fprintf( pFile, "\n );\n\n" );
+
+ fprintf( pFile, " input " );
+ Gia_ManWriteNames( pFile, 'a', Gia_ManPiNum(p), NULL, 8, 4, NULL );
+ fprintf( pFile, ";\n\n" );
+
+ fprintf( pFile, " output " );
+ Gia_ManWriteNames( pFile, 'y', Gia_ManPoNum(p), NULL, 9, 4, NULL );
+ fprintf( pFile, ";\n\n" );
+
+ fprintf( pFile, " wire " );
+ Gia_ManWriteNames( pFile, 'x', Gia_ManPiNum(p), p->vNamesIn, 8, 4, NULL );
+ fprintf( pFile, ";\n\n" );
- fprintf( pFile, " input " );
- Gia_ManWriteNames( pFile, 'x', Gia_ManPiNum(p), p->vNamesIn, 8, 4, NULL );
- fprintf( pFile, ";\n\n" );
+ fprintf( pFile, " wire " );
+ Gia_ManWriteNames( pFile, 'z', Gia_ManPoNum(p), p->vNamesOut, 9, 4, NULL );
+ fprintf( pFile, ";\n\n" );
- fprintf( pFile, " output " );
- Gia_ManWriteNames( pFile, 'z', Gia_ManPoNum(p), p->vNamesOut, 9, 4, NULL );
- fprintf( pFile, ";\n\n" );
+ Gia_ManForEachPi( p, pObj, i )
+ {
+ fprintf( pFile, " buf ( %s,", Gia_ObjGetDumpName(p->vNamesIn, 'x', i, nDigitsI) );
+ fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(NULL, 'a', i, nDigitsI) );
+ }
+ fprintf( pFile, "\n" );
+
+ Gia_ManForEachPo( p, pObj, i )
+ {
+ fprintf( pFile, " buf ( %s,", Gia_ObjGetDumpName(NULL, 'y', i, nDigitsO) );
+ fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(p->vNamesOut, 'z', i, nDigitsO) );
+ }
+ fprintf( pFile, "\n" );
+ }
+ else
+ {
+ fprintf( pFile, " (\n " );
+ Gia_ManWriteNames( pFile, 'x', Gia_ManPiNum(p), p->vNamesIn, 4, 4, NULL );
+ fprintf( pFile, ",\n " );
+
+ Gia_ManWriteNames( pFile, 'z', Gia_ManPoNum(p), p->vNamesOut, 4, 4, NULL );
+ fprintf( pFile, "\n );\n\n" );
+
+ fprintf( pFile, " input " );
+ Gia_ManWriteNames( pFile, 'x', Gia_ManPiNum(p), p->vNamesIn, 8, 4, NULL );
+ fprintf( pFile, ";\n\n" );
+
+ fprintf( pFile, " output " );
+ Gia_ManWriteNames( pFile, 'z', Gia_ManPoNum(p), p->vNamesOut, 9, 4, NULL );
+ fprintf( pFile, ";\n\n" );
+ }
if ( Vec_BitCount(vUsed) )
{
@@ -1338,7 +1382,7 @@ void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs )
fprintf( pFile, ";\n\n" );
Vec_IntForEachEntry( vObjs, iObj, i )
{
- fprintf( pFile, " buf( %s,", Gia_ObjGetDumpName(NULL, 'n', iObj, nDigits) );
+ fprintf( pFile, " buf ( %s,", Gia_ObjGetDumpName(NULL, 'n', iObj, nDigits) );
fprintf( pFile, " t_%d );\n", i );
}
fprintf( pFile, "\n" );
@@ -1349,13 +1393,13 @@ void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs )
{
if ( Vec_BitEntry(vUsed, Gia_ObjId(p, pObj)) )
{
- fprintf( pFile, " buf( %s,", Gia_ObjGetDumpName(NULL, 'n', Gia_ObjId(p, pObj), nDigits) );
- fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(p->vNamesIn, 'x', i, nDigits2) );
+ fprintf( pFile, " buf ( %s,", Gia_ObjGetDumpName(NULL, 'n', Gia_ObjId(p, pObj), nDigits) );
+ fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(p->vNamesIn, 'x', i, nDigitsI) );
}
if ( Vec_BitEntry(vInvs, Gia_ObjId(p, pObj)) )
{
- fprintf( pFile, " not( %s,", Gia_ObjGetDumpName(NULL, 'i', Gia_ObjId(p, pObj), nDigits) );
- fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(p->vNamesIn, 'x', i, nDigits2) );
+ fprintf( pFile, " not ( %s,", Gia_ObjGetDumpName(NULL, 'i', Gia_ObjId(p, pObj), nDigits) );
+ fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(p->vNamesIn, 'x', i, nDigitsI) );
}
}
@@ -1374,20 +1418,19 @@ void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs )
}
if ( !fSkip )
{
- fprintf( pFile, " and( %s,", Gia_ObjGetDumpName(NULL, 'n', i, nDigits) );
+ fprintf( pFile, " and ( %s,", Gia_ObjGetDumpName(NULL, 'n', i, nDigits) );
fprintf( pFile, " %s,", Gia_ObjGetDumpName(NULL, (char)(Gia_ObjFaninC0(pObj)? 'i':'n'), Gia_ObjFaninId0(pObj, i), nDigits) );
fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(NULL, (char)(Gia_ObjFaninC1(pObj)? 'i':'n'), Gia_ObjFaninId1(pObj, i), nDigits) );
}
if ( Vec_BitEntry(vInvs, i) )
{
- fprintf( pFile, " not( %s,", Gia_ObjGetDumpName(NULL, 'i', i, nDigits) );
+ fprintf( pFile, " not ( %s,", Gia_ObjGetDumpName(NULL, 'i', i, nDigits) );
fprintf( pFile, " %s );\n", Gia_ObjGetDumpName(NULL, 'n', i, nDigits) );
}
}
// output drivers
fprintf( pFile, "\n" );
- nDigits2 = Abc_Base10Log( Gia_ManPoNum(p) );
Gia_ManForEachPo( p, pObj, i )
{
/*
@@ -1397,7 +1440,7 @@ void Gia_ManDumpVerilog( Gia_Man_t * p, char * pFileName, Vec_Int_t * vObjs )
else
fprintf( pFile, "%s;\n", Gia_ObjGetDumpName(NULL, (char)(Gia_ObjFaninC0(pObj)? 'i':'n'), Gia_ObjFaninId0p(p, pObj), nDigits) );
*/
- fprintf( pFile, " buf( %s, ", Gia_ObjGetDumpName(p->vNamesOut, 'z', i, nDigits2) );
+ fprintf( pFile, " buf ( %s, ", Gia_ObjGetDumpName(p->vNamesOut, 'z', i, nDigitsO) );
if ( Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
fprintf( pFile, "1\'b%d );\n", Gia_ObjFaninC0(pObj) );
else
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index d6871a3c..259f4686 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -31219,12 +31219,13 @@ int Abc_CommandAbc9Write( Abc_Frame_t * pAbc, int argc, char ** argv )
int c, nArgcNew;
int fUnique = 0;
int fVerilog = 0;
+ int fVerBufs = 0;
int fMiniAig = 0;
int fMiniLut = 0;
int fWriteNewLine = 0;
int fVerbose = 0;
Extra_UtilGetoptReset();
- while ( ( c = Extra_UtilGetopt( argc, argv, "upmlnvh" ) ) != EOF )
+ while ( ( c = Extra_UtilGetopt( argc, argv, "upbmlnvh" ) ) != EOF )
{
switch ( c )
{
@@ -31234,6 +31235,9 @@ int Abc_CommandAbc9Write( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'p':
fVerilog ^= 1;
break;
+ case 'b':
+ fVerBufs ^= 1;
+ break;
case 'm':
fMiniAig ^= 1;
break;
@@ -31272,7 +31276,7 @@ int Abc_CommandAbc9Write( Abc_Frame_t * pAbc, int argc, char ** argv )
Gia_ManStop( pGia );
}
else if ( fVerilog )
- Gia_ManDumpVerilog( pAbc->pGia, pFileName, NULL );
+ Gia_ManDumpVerilog( pAbc->pGia, pFileName, NULL, fVerBufs );
else if ( fMiniAig )
Gia_ManWriteMiniAig( pAbc->pGia, pFileName );
else if ( fMiniLut )
@@ -31282,10 +31286,11 @@ int Abc_CommandAbc9Write( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
- Abc_Print( -2, "usage: &w [-upmlnvh] <file>\n" );
+ Abc_Print( -2, "usage: &w [-upbmlnvh] <file>\n" );
Abc_Print( -2, "\t writes the current AIG into the AIGER file\n" );
Abc_Print( -2, "\t-u : toggle writing canonical AIG structure [default = %s]\n", fUnique? "yes" : "no" );
Abc_Print( -2, "\t-p : toggle writing Verilog with 'and' and 'not' [default = %s]\n", fVerilog? "yes" : "no" );
+ Abc_Print( -2, "\t-b : toggle writing additional buffers in Verilog [default = %s]\n", fVerBufs? "yes" : "no" );
Abc_Print( -2, "\t-m : toggle writing MiniAIG rather than AIGER [default = %s]\n", fMiniAig? "yes" : "no" );
Abc_Print( -2, "\t-l : toggle writing MiniLUT rather than AIGER [default = %s]\n", fMiniLut? "yes" : "no" );
Abc_Print( -2, "\t-n : toggle writing \'\\n\' after \'c\' in the AIGER file [default = %s]\n", fWriteNewLine? "yes": "no" );