diff --git a/src/aig/gia/giaStoch.c b/src/aig/gia/giaStoch.c index 03f80513b..68e23019e 100644 --- a/src/aig/gia/giaStoch.c +++ b/src/aig/gia/giaStoch.c @@ -114,7 +114,11 @@ Gia_Man_t * Gia_StochProcessOne( Gia_Man_t * p, char * pScript, int Rand, int Ti sprintf( FileName, "%06x.aig", Rand ); Gia_AigerWrite( p, FileName, 0, 0, 0 ); sprintf( Command, "./abc -q \"&read %s; %s; &write %s\"", FileName, pScript, FileName ); +#if defined(__wasm) + if ( 1 ) +#else if ( system( (char *)Command ) ) +#endif { fprintf( stderr, "The following command has returned non-zero exit status:\n" ); fprintf( stderr, "\"%s\"\n", (char *)Command ); diff --git a/src/base/abc/abcShow.c b/src/base/abc/abcShow.c index 88b8cbf69..cdd53fc20 100644 --- a/src/base/abc/abcShow.c +++ b/src/base/abc/abcShow.c @@ -363,7 +363,11 @@ void Abc_ShowFile( char * FileNameDot, int fKeepDot ) // generate the PostScript file using DOT sprintf( CommandDot, "%s -Tps -o %s %s", pDotName, FileNamePs, FileNameDot ); +#if defined(__wasm) + RetValue = -1; +#else RetValue = system( CommandDot ); +#endif if ( RetValue == -1 ) { fprintf( stdout, "Command \"%s\" did not succeed.\n", CommandDot ); @@ -401,7 +405,11 @@ void Abc_ShowFile( char * FileNameDot, int fKeepDot ) char CommandPs[1000]; if ( !fKeepDot ) unlink( FileNameDot ); sprintf( CommandPs, "%s %s &", pGsNameUnix, FileNamePs ); +#if defined(__wasm) + if ( 1 ) +#else if ( system( CommandPs ) == -1 ) +#endif { fprintf( stdout, "Cannot execute \"%s\".\n", CommandPs ); return; diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index a78706032..e12728bd9 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -7295,7 +7295,11 @@ int Abc_CommandRunSat( Abc_Frame_t * pAbc, int argc, char ** argv ) sprintf( pCommand, "kissat -q --seed=%d %s", i, pFileCnf ); else if ( fWalk ) sprintf( pCommand, "walk -s%d %s", i, pFileCnf ); +#if defined(__wasm) + if (1) { +#else if (system(pCommand) == -1) { +#endif fprintf(stdout, "Command \"%s\" did not succeed.\n", pCommand); return 0; } diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index d1408b6c1..20d0f0c38 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -2412,7 +2412,11 @@ void Gia_ManGnuplotShow( char * pPlotFileName ) { char Command[1000]; sprintf( Command, "%s %s ", pProgNameGnuplot, pPlotFileName ); +#if defined(__wasm) + if ( 1 ) +#else if ( system( Command ) == -1 ) +#endif { fprintf( stdout, "Cannot execute \"%s\".\n", Command ); return; diff --git a/src/base/cmd/cmdUtils.c b/src/base/cmd/cmdUtils.c index a5dc6972b..e8e28078f 100644 --- a/src/base/cmd/cmdUtils.c +++ b/src/base/cmd/cmdUtils.c @@ -53,6 +53,9 @@ int cmdCheckShellEscape( Abc_Frame_t * pAbc, int argc, char ** argv) int RetValue; if (argv[0][0] == '!') { +#if defined(__wasm) + RetValue = -1; +#else const int size = 4096; int i; char * buffer = ABC_ALLOC(char, 10000); @@ -71,7 +74,7 @@ int cmdCheckShellEscape( Abc_Frame_t * pAbc, int argc, char ** argv) // the parts, we lose information. So a command like // `!ls "file name"` will be sent to the system as // `ls file name` which is a BUG - +#endif return 1; } else diff --git a/src/base/main/mainReal.c b/src/base/main/mainReal.c index 922e05215..420f2cf10 100644 --- a/src/base/main/mainReal.c +++ b/src/base/main/mainReal.c @@ -49,7 +49,9 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#if !defined(__wasm) #include +#endif #include #endif diff --git a/src/base/wln/wlnRtl.c b/src/base/wln/wlnRtl.c index 36801c862..f7364bded 100644 --- a/src/base/wln/wlnRtl.c +++ b/src/base/wln/wlnRtl.c @@ -121,6 +121,9 @@ char * Wln_GetYosysName() } int Wln_ConvertToRtl( char * pCommand, char * pFileTemp ) { +#if defined(__wasm) + return 0; +#else FILE * pFile; if ( system( pCommand ) == -1 ) { @@ -134,6 +137,7 @@ int Wln_ConvertToRtl( char * pCommand, char * pFileTemp ) } fclose( pFile ); return 1; +#endif } Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, int fCollapse, int fVerbose ) { diff --git a/src/misc/util/abc_global.h b/src/misc/util/abc_global.h index 8fdda44bf..96944d7cc 100644 --- a/src/misc/util/abc_global.h +++ b/src/misc/util/abc_global.h @@ -334,7 +334,7 @@ static inline abctime Abc_Clock() #else #define APPLE_MACH 0 #endif -#if (defined(LIN) || defined(LIN64)) && !APPLE_MACH && !defined(__MINGW32__) +#if (defined(LIN) || defined(LIN64)) && !APPLE_MACH && !defined(__MINGW32__) && !defined(__wasm) struct timespec ts; if ( clock_gettime(CLOCK_MONOTONIC, &ts) < 0 ) return (abctime)-1; @@ -353,7 +353,7 @@ static inline abctime Abc_ThreadClock() #else #define APPLE_MACH 0 #endif -#if (defined(LIN) || defined(LIN64)) && !APPLE_MACH && !defined(__MINGW32__) +#if (defined(LIN) || defined(LIN64)) && !APPLE_MACH && !defined(__MINGW32__) && !defined(__wasm) struct timespec ts; if ( clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) < 0 ) return (abctime)-1; diff --git a/src/misc/util/utilFile.c b/src/misc/util/utilFile.c index b096cabb6..f64d71c24 100644 --- a/src/misc/util/utilFile.c +++ b/src/misc/util/utilFile.c @@ -119,6 +119,17 @@ int tmpFile(const char* prefix, const char* suffix, char** out_name) } assert(0); // -- could not open temporary file return 0; +#elif defined(__wasm) + static int seq = 0; // no risk of collision since we're in a sandbox + int fd; + *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 9); + sprintf(*out_name, "%s%08d%s", prefix, seq++, suffix); + fd = open(*out_name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE); + if (fd == -1){ + free(*out_name); + *out_name = NULL; + } + return fd; #else int fd; *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 7); diff --git a/src/misc/util/utilSignal.c b/src/misc/util/utilSignal.c index 03af81d13..137ff54b8 100644 --- a/src/misc/util/utilSignal.c +++ b/src/misc/util/utilSignal.c @@ -43,7 +43,11 @@ ABC_NAMESPACE_IMPL_START int Util_SignalSystem(const char* cmd) { +#if defined(__wasm) + return -1; +#else return system(cmd); +#endif } int tmpFile(const char* prefix, const char* suffix, char** out_name); diff --git a/src/sat/bmc/bmcMaj.c b/src/sat/bmc/bmcMaj.c index ef1717403..5e9c1310c 100644 --- a/src/sat/bmc/bmcMaj.c +++ b/src/sat/bmc/bmcMaj.c @@ -1642,7 +1642,11 @@ Vec_Int_t * Exa4_ManSolve( char * pFileNameIn, char * pFileNameOut, int TimeOut, sprintf( pCommand, "%s --time=%d %s %s > %s", pKissat, TimeOut, fVerboseSolver ? "": "-q", pFileNameIn, pFileNameOut ); else sprintf( pCommand, "%s %s %s > %s", pKissat, fVerboseSolver ? "": "-q", pFileNameIn, pFileNameOut ); +#ifdef __wasm + if ( 1 ) +#else if ( system( pCommand ) == -1 ) +#endif { fprintf( stdout, "Command \"%s\" did not succeed.\n", pCommand ); return 0; diff --git a/src/sat/bsat2/Alloc.h b/src/sat/bsat2/Alloc.h index a9786a9a8..1bf5784fc 100644 --- a/src/sat/bsat2/Alloc.h +++ b/src/sat/bsat2/Alloc.h @@ -99,7 +99,11 @@ void RegionAllocator::capacity(uint32_t min_cap) cap += delta; if (cap <= prev_cap) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } // printf(" .. (%p) cap = %u\n", this, cap); @@ -121,7 +125,11 @@ RegionAllocator::alloc(int size) // Handle overflow: if (sz < prev_sz) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif return prev_sz; } diff --git a/src/sat/bsat2/Vec.h b/src/sat/bsat2/Vec.h index f5f5499ea..6937d7256 100644 --- a/src/sat/bsat2/Vec.h +++ b/src/sat/bsat2/Vec.h @@ -98,7 +98,11 @@ void vec::capacity(int min_cap) { if (cap >= min_cap) return; int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } diff --git a/src/sat/bsat2/XAlloc.h b/src/sat/bsat2/XAlloc.h index fdebe502a..3e9e39674 100644 --- a/src/sat/bsat2/XAlloc.h +++ b/src/sat/bsat2/XAlloc.h @@ -38,7 +38,11 @@ static inline void* xrealloc(void *ptr, size_t size) { void* mem = realloc(ptr, size); if (mem == NULL && errno == ENOMEM){ +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif }else return mem; } diff --git a/src/sat/cnf/cnfUtil.c b/src/sat/cnf/cnfUtil.c index e67328171..3a47ae796 100644 --- a/src/sat/cnf/cnfUtil.c +++ b/src/sat/cnf/cnfUtil.c @@ -82,7 +82,11 @@ Vec_Int_t *Cnf_RunSolverOnce(int Id, int Rand, int TimeOut, int fVerbose) FILE * pFile = fopen(FileNameIn, "rb"); if ( pFile != NULL ) { fclose( pFile ); +#if defined(__wasm) + if ( 1 ) { +#else if (system(pCommand) == -1) { +#endif fprintf(stdout, "Command \"%s\" did not succeed.\n", pCommand); return 0; } @@ -764,7 +768,11 @@ void Cnf_SplitCnfFile(char * pFileName, int nParts, int iVarBeg, int iVarEnd, in char Command[1000]; sprintf(Command, "satelite --verbosity=0 -pre temp.cnf %s", FileName); Cnf_DataWriteIntoFile(pCnf, "temp.cnf", 0, NULL, NULL); +#if defined(__wasm) + if ( 1 ) { +#else if (system(Command) == -1) { +#endif fprintf(stdout, "Command \"%s\" did not succeed. Preprocessing skipped.\n", Command); Cnf_DataWriteIntoFile(pCnf, FileName, 0, NULL, NULL); } diff --git a/src/sat/glucose/IntTypes.h b/src/sat/glucose/IntTypes.h index 3f75862b1..5c4176b29 100644 --- a/src/sat/glucose/IntTypes.h +++ b/src/sat/glucose/IntTypes.h @@ -28,20 +28,18 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA # include # include +#elif _WIN32 + +# include "pstdint.h" + #else -#define __STDC_LIMIT_MACROS -# include "pstdint.h" -//# include +# define __STDC_LIMIT_MACROS +# include +# include #endif -#include - -#ifndef PRIu64 -#define PRIu64 "lu" -#define PRIi64 "ld" -#endif //================================================================================================= #include diff --git a/src/sat/glucose2/IntTypes.h b/src/sat/glucose2/IntTypes.h index 3f75862b1..5c4176b29 100644 --- a/src/sat/glucose2/IntTypes.h +++ b/src/sat/glucose2/IntTypes.h @@ -28,20 +28,18 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA # include # include +#elif _WIN32 + +# include "pstdint.h" + #else -#define __STDC_LIMIT_MACROS -# include "pstdint.h" -//# include +# define __STDC_LIMIT_MACROS +# include +# include #endif -#include - -#ifndef PRIu64 -#define PRIu64 "lu" -#define PRIi64 "ld" -#endif //================================================================================================= #include