From 11c4f998b25b6c07f4081cea10e2532ebcb7f4d4 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sat, 19 Oct 2019 12:36:14 +0800 Subject: [PATCH 01/14] Makefile: break apart steps in `make clean` The `make clean` target consists of a single `rm` call that passes every generated file, object file, and dependency directory. This results in a command line that's around 53,800 characters long. On Linux, the maximum length of a command line is 131,072 or 262,144 characters, however on Windows the limit is 32,768. The 53,800 character command simply fails to run on Windows, which is a problem when the first command that gets run is `make clean`. Break this target into steps, first removing the output files, then the object files, then any generated garbage, and then the object depedency directories. This fixes `make clean` (and as a result yosys) on Windows. Signed-off-by: Sean Cross --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 583bc25bc..641cd6ac1 100644 --- a/Makefile +++ b/Makefile @@ -206,7 +206,10 @@ depend: $(DEP) clean: @echo "$(MSG_PREFIX)\`\` Cleaning up..." - $(VERBOSE)rm -rvf $(PROG) lib$(PROG).a $(OBJ) $(GARBAGE) $(OBJ:.o=.d) + $(VERBOSE)rm -rvf $(PROG) lib$(PROG).a + $(VERBOSE)rm -rvf $(OBJ) + $(VERBOSE)rm -rvf $(GARBAGE) + $(VERBOSE)rm -rvf $(OBJ:.o=.d) tags: etags `find . -type f -regex '.*\.\(c\|h\)'` From 09607e9055381f6e330a054ee600e7bd7117bb76 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 17:02:04 +0000 Subject: [PATCH 02/14] Add support for WASI platform in tmpFile. --- src/misc/util/utilFile.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/misc/util/utilFile.c b/src/misc/util/utilFile.c index 4bb2f4c68..b6835daa2 100644 --- a/src/misc/util/utilFile.c +++ b/src/misc/util/utilFile.c @@ -102,6 +102,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); From eea20ff4667abf36f28679520b06f4b1a6fcacea Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 17:05:49 +0000 Subject: [PATCH 03/14] Add support for WASI platform in cmdCheckShellEscape. Since cmdCheckShellEscape doesn't actually report failure in any way, this code simulates a situation where system() never succeeds. --- src/base/cmd/cmdUtils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/base/cmd/cmdUtils.c b/src/base/cmd/cmdUtils.c index 3409543f1..c10e91341 100644 --- a/src/base/cmd/cmdUtils.c +++ b/src/base/cmd/cmdUtils.c @@ -52,6 +52,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); @@ -70,7 +73,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 From 70ed4da2acbb3ae61d5fbfbd6e02da94cc38da05 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 17:08:33 +0000 Subject: [PATCH 04/14] Add support for WASI platform in Gia_ManGnuplotShow. --- src/base/cmd/cmd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index a00424432..259c9d780 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -2175,7 +2175,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; From 9366e4fa68fe73ba0f514e20f589dab0f5489e56 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 17:12:36 +0000 Subject: [PATCH 05/14] Add support for WASI platform in Abc_ShowFile. --- src/base/abc/abcShow.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/base/abc/abcShow.c b/src/base/abc/abcShow.c index f91397dff..7df1e323f 100644 --- a/src/base/abc/abcShow.c +++ b/src/base/abc/abcShow.c @@ -363,7 +363,11 @@ void Abc_ShowFile( char * FileNameDot ) // 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 ) char CommandPs[1000]; 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; From 2db5f19ab6f86a11d131add176222d0260593a57 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 17:12:47 +0000 Subject: [PATCH 06/14] Add support for WASI platform in Util_SignalSystem. --- src/misc/util/utilSignal.c | 4 ++++ 1 file changed, 4 insertions(+) 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); From fd2c9b1c19216f6b756f88b18f5ca67b759ca128 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 18:41:25 +0000 Subject: [PATCH 07/14] Remove ABC_NO_RLIMIT macro, use defined(__wasm) instead. --- src/base/main/mainReal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/main/mainReal.c b/src/base/main/mainReal.c index 922e05215..68c0c0322 100644 --- a/src/base/main/mainReal.c +++ b/src/base/main/mainReal.c @@ -132,7 +132,7 @@ int Abc_RealMain( int argc, char * argv[] ) break; case 'm': { -#if !defined(WIN32) && !defined(ABC_NO_RLIMIT) +#if !defined(WIN32) && !defined(__wasm) int maxMb = atoi(globalUtilOptarg); printf("Limiting memory use to %d MB\n", maxMb); struct rlimit limit = { @@ -144,7 +144,7 @@ int Abc_RealMain( int argc, char * argv[] ) break; } case 'l': { -#if !defined(WIN32) && !defined(ABC_NO_RLIMIT) +#if !defined(WIN32) && !defined(__wasm) rlim_t maxTime = atoi(globalUtilOptarg); printf("Limiting time to %d seconds\n", (int)maxTime); struct rlimit limit = { From ef2d917562dadb7efc0780aa717ffe0474a4134f Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 22 Jun 2020 02:51:42 +0000 Subject: [PATCH 08/14] Add WASI platform support to main. --- src/base/main/mainReal.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/base/main/mainReal.c b/src/base/main/mainReal.c index 68c0c0322..a13be5e52 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 From 81febe5d69ddd98f23ec645465500effdcddd1ae Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 22 Jun 2020 02:51:26 +0000 Subject: [PATCH 09/14] Add WASI platform support to glucose. --- src/sat/glucose/IntTypes.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 From 2343da6bf1f41995b41a6c49d8a4993df0f7bcd1 Mon Sep 17 00:00:00 2001 From: Baruch Sterin Date: Thu, 19 Nov 2020 22:27:24 +0200 Subject: [PATCH 10/14] Makefile: support ccache for compiling ABC. Surround $(CC), $(CXX) with double quotes when calling depends.sh, to allow space-delimited compilation tools to be used. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 641cd6ac1..ee4172f50 100644 --- a/Makefile +++ b/Makefile @@ -186,15 +186,15 @@ DEP := $(OBJ:.o=.d) %.d: %.c @echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$< - $(VERBOSE)$(ABCSRC)/depends.sh $(CC) `dirname $*.c` $(OPTFLAGS) $(INCLUDES) $(CFLAGS) $< > $@ + $(VERBOSE)$(ABCSRC)/depends.sh "$(CC)" `dirname $*.c` $(OPTFLAGS) $(INCLUDES) $(CFLAGS) $< > $@ %.d: %.cc @echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$< - $(VERBOSE)$(ABCSRC)/depends.sh $(CXX) `dirname $*.cc` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@ + $(VERBOSE)$(ABCSRC)/depends.sh "$(CXX)" `dirname $*.cc` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@ %.d: %.cpp @echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$< - $(VERBOSE)$(ABCSRC)/depends.sh $(CXX) `dirname $*.cpp` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@ + $(VERBOSE)$(ABCSRC)/depends.sh "$(CXX)" `dirname $*.cpp` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@ ifndef ABC_MAKE_NO_DEPS -include $(DEP) From e289a8059eac7d0514f8a20ffe6464fc18db1450 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 29 Dec 2020 13:35:31 +0000 Subject: [PATCH 11/14] Add WASI platform support to bsat2 and glucose. Abort on OOM since there are no C++ exceptions yet. Signed-off-by: Miodrag Milanovic --- src/sat/bsat2/Alloc.h | 8 ++++++++ src/sat/bsat2/Vec.h | 4 ++++ src/sat/bsat2/XAlloc.h | 4 ++++ src/sat/glucose/Alloc.h | 8 ++++++++ src/sat/glucose/Vec.h | 4 ++++ src/sat/glucose/XAlloc.h | 4 ++++ 6 files changed, 32 insertions(+) diff --git a/src/sat/bsat2/Alloc.h b/src/sat/bsat2/Alloc.h index 7f506cb5a..9a65cf0cd 100644 --- a/src/sat/bsat2/Alloc.h +++ b/src/sat/bsat2/Alloc.h @@ -97,7 +97,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); @@ -119,7 +123,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 f0e07d016..5eea6174b 100644 --- a/src/sat/bsat2/Vec.h +++ b/src/sat/bsat2/Vec.h @@ -97,7 +97,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 1da176028..33741e332 100644 --- a/src/sat/bsat2/XAlloc.h +++ b/src/sat/bsat2/XAlloc.h @@ -34,7 +34,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/glucose/Alloc.h b/src/sat/glucose/Alloc.h index e56b54414..a63de032f 100644 --- a/src/sat/glucose/Alloc.h +++ b/src/sat/glucose/Alloc.h @@ -100,7 +100,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); @@ -122,7 +126,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/glucose/Vec.h b/src/sat/glucose/Vec.h index dd1bc20a1..d2781635c 100644 --- a/src/sat/glucose/Vec.h +++ b/src/sat/glucose/Vec.h @@ -100,7 +100,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/glucose/XAlloc.h b/src/sat/glucose/XAlloc.h index 233f834e0..d1f1062af 100644 --- a/src/sat/glucose/XAlloc.h +++ b/src/sat/glucose/XAlloc.h @@ -39,7 +39,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; } From e792072f8a6f016eb5f2c8653f261ba7c88e6392 Mon Sep 17 00:00:00 2001 From: "Mohamed A. Bamakhrama" Date: Mon, 3 Aug 2020 23:19:23 +0200 Subject: [PATCH 12/14] Define S_IREAD|IWRITE macros using IRUSR|IWUSR On platforms such as Android, legacy macros are no longer defined. Hence, we define them in terms of the new POSIX macros if the new ones are defined. Otherwise, we throw an error. Signed-off-by: Mohamed A. Bamakhrama Signed-off-by: Miodrag Milanovic --- src/misc/util/utilFile.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/misc/util/utilFile.c b/src/misc/util/utilFile.c index b6835daa2..f64d71c24 100644 --- a/src/misc/util/utilFile.c +++ b/src/misc/util/utilFile.c @@ -25,6 +25,23 @@ #include #include +// Handle legacy macros +#if !defined(S_IREAD) +#if defined(S_IRUSR) +#define S_IREAD S_IRUSR +#else +#error S_IREAD is undefined +#endif +#endif + +#if !defined(S_IWRITE) +#if defined(S_IWUSR) +#define S_IWRITE S_IWUSR +#else +#error S_IWRITE is undefined +#endif +#endif + #if defined(_MSC_VER) || defined(__MINGW32__) #include #include From f6fa2ddcfc89099726d60386befba874c7ac1e0d Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 11 Nov 2021 18:08:50 +0100 Subject: [PATCH 13/14] Add WASI platform support to glucose2. Signed-off-by: Miodrag Milanovic --- src/sat/glucose2/IntTypes.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 From 264dfc7ed414476438e4a858258f5516d7b863c6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 27 Nov 2021 07:57:15 +0000 Subject: [PATCH 14/14] Extend WASI platform support for glucose2. Abort on OOM since there are no C++ exceptions yet. --- src/sat/glucose2/Alloc.h | 8 ++++++++ src/sat/glucose2/Vec.h | 8 ++++++++ src/sat/glucose2/XAlloc.h | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/src/sat/glucose2/Alloc.h b/src/sat/glucose2/Alloc.h index b7bebacac..427cd3232 100644 --- a/src/sat/glucose2/Alloc.h +++ b/src/sat/glucose2/Alloc.h @@ -100,7 +100,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); @@ -122,7 +126,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/glucose2/Vec.h b/src/sat/glucose2/Vec.h index eaeed2074..bc9892177 100644 --- a/src/sat/glucose2/Vec.h +++ b/src/sat/glucose2/Vec.h @@ -102,14 +102,22 @@ 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 } template void vec::prelocate(int ext_cap) { if (cap >= ext_cap) return; if (ext_cap > INT_MAX || (((data = (T*)::realloc(data, ext_cap * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif cap = ext_cap; } diff --git a/src/sat/glucose2/XAlloc.h b/src/sat/glucose2/XAlloc.h index 716643ef8..86e65a494 100644 --- a/src/sat/glucose2/XAlloc.h +++ b/src/sat/glucose2/XAlloc.h @@ -39,7 +39,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; }