summaryrefslogtreecommitdiffstats
path: root/src/base/wln/wlnRtl.c
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2022-07-04 16:02:44 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2022-07-04 16:02:44 +0200
commit163af36fee3bdc3fe0e8ce629cba333cb2cff199 (patch)
treec4004a295813151478fe8b36a41725457cc6ea17 /src/base/wln/wlnRtl.c
parent18634305282c81b0f4a08de4ebca6ccc95b11748 (diff)
parentc23cd0a7c5f4264b3209f127885b8d5432f2fd5a (diff)
downloadabc-163af36fee3bdc3fe0e8ce629cba333cb2cff199.tar.gz
abc-163af36fee3bdc3fe0e8ce629cba333cb2cff199.tar.bz2
abc-163af36fee3bdc3fe0e8ce629cba333cb2cff199.zip
Merge remote-tracking branch 'upstream/master' into yosys-experimental
Diffstat (limited to 'src/base/wln/wlnRtl.c')
-rw-r--r--src/base/wln/wlnRtl.c211
1 files changed, 211 insertions, 0 deletions
diff --git a/src/base/wln/wlnRtl.c b/src/base/wln/wlnRtl.c
new file mode 100644
index 00000000..fa0f0cd5
--- /dev/null
+++ b/src/base/wln/wlnRtl.c
@@ -0,0 +1,211 @@
+/**CFile****************************************************************
+
+ FileName [wlnRtl.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Word-level network.]
+
+ Synopsis [Constructing WLN network from Rtl data structure.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - September 23, 2018.]
+
+ Revision [$Id: wlnRtl.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "wln.h"
+#include "base/main/main.h"
+
+#ifdef WIN32
+#include <process.h>
+#define unlink _unlink
+#else
+#include <unistd.h>
+#endif
+
+ABC_NAMESPACE_IMPL_START
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+#define MAX_LINE 1000000
+
+void Rtl_NtkCleanFile( char * pFileName )
+{
+ char * pBuffer, * pFileName2 = "_temp__.rtlil";
+ FILE * pFile = fopen( pFileName, "rb" );
+ FILE * pFile2;
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open file \"%s\" for reading.\n", pFileName );
+ return;
+ }
+ pFile2 = fopen( pFileName2, "wb" );
+ if ( pFile2 == NULL )
+ {
+ fclose( pFile );
+ printf( "Cannot open file \"%s\" for writing.\n", pFileName2 );
+ return;
+ }
+ pBuffer = ABC_ALLOC( char, MAX_LINE );
+ while ( fgets( pBuffer, MAX_LINE, pFile ) != NULL )
+ if ( !strstr(pBuffer, "attribute \\src") )
+ fputs( pBuffer, pFile2 );
+ ABC_FREE( pBuffer );
+ fclose( pFile );
+ fclose( pFile2 );
+}
+
+void Rtl_NtkCleanFile2( char * pFileName )
+{
+ char * pBuffer, * pFileName2 = "_temp__.v";
+ FILE * pFile = fopen( pFileName, "rb" );
+ FILE * pFile2;
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open file \"%s\" for reading.\n", pFileName );
+ return;
+ }
+ pFile2 = fopen( pFileName2, "wb" );
+ if ( pFile2 == NULL )
+ {
+ fclose( pFile );
+ printf( "Cannot open file \"%s\" for writing.\n", pFileName2 );
+ return;
+ }
+ pBuffer = ABC_ALLOC( char, MAX_LINE );
+ while ( fgets( pBuffer, MAX_LINE, pFile ) != NULL )
+ if ( !strstr(pBuffer, "//") )
+ fputs( pBuffer, pFile2 );
+ ABC_FREE( pBuffer );
+ fclose( pFile );
+ fclose( pFile2 );
+}
+
+char * Wln_GetYosysName()
+{
+ char * pYosysName = NULL;
+ char * pYosysNameWin = "yosys.exe";
+ char * pYosysNameUnix = "yosys";
+ if ( Abc_FrameReadFlag("yosyswin") )
+ pYosysNameWin = Abc_FrameReadFlag("yosyswin");
+ if ( Abc_FrameReadFlag("yosysunix") )
+ pYosysNameUnix = Abc_FrameReadFlag("yosysunix");
+#ifdef WIN32
+ pYosysName = pYosysNameWin;
+#else
+ pYosysName = pYosysNameUnix;
+#endif
+ return pYosysName;
+}
+int Wln_ConvertToRtl( char * pCommand, char * pFileTemp )
+{
+ FILE * pFile;
+ if ( system( pCommand ) == -1 )
+ {
+ fprintf( stdout, "Cannot execute \"%s\".\n", pCommand );
+ return 0;
+ }
+ if ( (pFile = fopen(pFileTemp, "r")) == NULL )
+ {
+ fprintf( stdout, "Cannot open intermediate file \"%s\".\n", pFileTemp );
+ return 0;
+ }
+ fclose( pFile );
+ return 1;
+}
+Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, int fCollapse, int fVerbose )
+{
+ Rtl_Lib_t * pNtk = NULL;
+ char Command[1000];
+ char * pFileTemp = "_temp_.rtlil";
+ int fSVlog = strstr(pFileName, ".sv") != NULL;
+ if ( strstr(pFileName, ".rtl") )
+ return Rtl_LibReadFile( pFileName, pFileName );
+ sprintf( Command, "%s -qp \"read_verilog %s%s; hierarchy %s%s; %sproc; write_rtlil %s\"",
+ Wln_GetYosysName(), fSVlog ? "-sv ":"", pFileName,
+ pTopModule ? "-top " : "",
+ pTopModule ? pTopModule : "",
+ fCollapse ? "flatten; " : "",
+ pFileTemp );
+ if ( fVerbose )
+ printf( "%s\n", Command );
+ if ( !Wln_ConvertToRtl(Command, pFileTemp) )
+ return NULL;
+ pNtk = Rtl_LibReadFile( pFileTemp, pFileName );
+ if ( pNtk == NULL )
+ {
+ printf( "Dumped the design into file \"%s\".\n", pFileTemp );
+ return NULL;
+ }
+ Rtl_NtkCleanFile( pFileTemp );
+ unlink( pFileTemp );
+ return pNtk;
+}
+Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pTopModule, int fSkipStrash, int fInvert, int fTechMap, int fVerbose )
+{
+ Gia_Man_t * pGia = NULL;
+ char Command[1000];
+ char * pFileTemp = "_temp_.aig";
+ int fRtlil = strstr(pFileName, ".rtl") != NULL;
+ int fSVlog = strstr(pFileName, ".sv") != NULL;
+ sprintf( Command, "%s -qp \"%s%s%s; hierarchy %s%s; flatten; proc; %saigmap; write_aiger %s\"",
+ Wln_GetYosysName(),
+ fRtlil ? "read_rtlil" : "read_verilog",
+ fSVlog ? " -sv ":" ",
+ pFileName,
+ pTopModule ? "-top " : "-auto-top",
+ pTopModule ? pTopModule : "",
+ fTechMap ? "techmap; setundef -zero; " : "", pFileTemp );
+ if ( fVerbose )
+ printf( "%s\n", Command );
+ if ( !Wln_ConvertToRtl(Command, pFileTemp) )
+ return NULL;
+ pGia = Gia_AigerRead( pFileTemp, 0, fSkipStrash, 0 );
+ if ( pGia == NULL )
+ {
+ printf( "Converting to AIG has failed.\n" );
+ return NULL;
+ }
+ ABC_FREE( pGia->pName );
+ pGia->pName = pTopModule ? Abc_UtilStrsav(pTopModule) :
+ Extra_FileNameGeneric( Extra_FileNameWithoutPath(pFileName) );
+ unlink( pFileTemp );
+ // complement the outputs
+ if ( fInvert )
+ {
+ Gia_Obj_t * pObj; int i;
+ Gia_ManForEachPo( pGia, pObj, i )
+ Gia_ObjFlipFaninC0( pObj );
+ }
+ return pGia;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
+ABC_NAMESPACE_IMPL_END
+