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

Pull build-related changes from YosysHQ fork #315

Merged
merged 8 commits into from
Aug 8, 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.gitcommit export-subst
* text=auto

*.c text
Expand Down
1 change: 1 addition & 0 deletions .gitcommit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%H$
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ AR := ar
LD := $(CXX)

MSG_PREFIX ?=
ABCSRC = .
ABCSRC ?= .
VPATH = $(ABCSRC)

$(info $(MSG_PREFIX)Using CC=$(CC))
$(info $(MSG_PREFIX)Using CXX=$(CXX))
Expand Down Expand Up @@ -41,7 +42,7 @@ default: $(PROG)
ARCHFLAGS_EXE ?= ./arch_flags

$(ARCHFLAGS_EXE) : arch_flags.c
$(CC) arch_flags.c -o $(ARCHFLAGS_EXE)
$(CC) $< -o $(ARCHFLAGS_EXE)

INCLUDES += -I$(ABCSRC)/src

Expand Down Expand Up @@ -137,11 +138,11 @@ endif

# LIBS := -ldl -lrt
LIBS += -lm
ifneq ($(OS), FreeBSD)
ifneq ($(OS), $(filter $(OS), FreeBSD OpenBSD NetBSD))
LIBS += -ldl
endif

ifneq ($(findstring Darwin, $(shell uname)), Darwin)
ifneq ($(OS), $(filter $(OS), FreeBSD OpenBSD NetBSD Darwin))
LIBS += -lrt
endif

Expand Down Expand Up @@ -173,26 +174,32 @@ DEP := $(OBJ:.o=.d)
# implicit rules

%.o: %.c
@mkdir -p $(dir $@)
@echo "$(MSG_PREFIX)\`\` Compiling:" $(LOCAL_PATH)/$<
$(VERBOSE)$(CC) -c $(OPTFLAGS) $(INCLUDES) $(CFLAGS) $< -o $@

%.o: %.cc
@mkdir -p $(dir $@)
@echo "$(MSG_PREFIX)\`\` Compiling:" $(LOCAL_PATH)/$<
$(VERBOSE)$(CXX) -c $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< -o $@

%.o: %.cpp
@mkdir -p $(dir $@)
@echo "$(MSG_PREFIX)\`\` Compiling:" $(LOCAL_PATH)/$<
$(VERBOSE)$(CXX) -c $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< -o $@

%.d: %.c
@mkdir -p $(dir $@)
@echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$<
$(VERBOSE)$(ABCSRC)/depends.sh "$(CC)" `dirname $*.c` $(OPTFLAGS) $(INCLUDES) $(CFLAGS) $< > $@

%.d: %.cc
@mkdir -p $(dir $@)
@echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$<
$(VERBOSE)$(ABCSRC)/depends.sh "$(CXX)" `dirname $*.cc` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@

%.d: %.cpp
@mkdir -p $(dir $@)
@echo "$(MSG_PREFIX)\`\` Generating dependency:" $(LOCAL_PATH)/$<
$(VERBOSE)$(ABCSRC)/depends.sh "$(CXX)" `dirname $*.cpp` $(OPTFLAGS) $(INCLUDES) $(CXXFLAGS) $< > $@

Expand All @@ -206,7 +213,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\)'`
Expand Down
4 changes: 4 additions & 0 deletions src/aig/gia/giaStoch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 8 additions & 0 deletions src/base/abc/abcShow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/base/abci/abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/base/cmd/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/base/cmd/cmdUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/base/main/mainReal.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include <sys/times.h>
#include <sys/resource.h>
#include <unistd.h>
#if !defined(__wasm)
#include <signal.h>
#endif
#include <stdlib.h>
#endif

Expand Down
4 changes: 4 additions & 0 deletions src/base/wln/wlnRtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand Down
4 changes: 2 additions & 2 deletions src/misc/util/abc_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/misc/util/utilFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
#include <fcntl.h>
#include <sys/stat.h>

// 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 <windows.h>
#include <process.h>
Expand Down Expand Up @@ -102,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);
Expand Down
4 changes: 4 additions & 0 deletions src/misc/util/utilSignal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/sat/bmc/bmcMaj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/sat/bsat2/Alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ void RegionAllocator<T>::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);

Expand All @@ -121,7 +125,11 @@ RegionAllocator<T>::alloc(int size)

// Handle overflow:
if (sz < prev_sz)
#ifdef __wasm
abort();
#else
throw OutOfMemoryException();
#endif

return prev_sz;
}
Expand Down
4 changes: 4 additions & 0 deletions src/sat/bsat2/Vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ void vec<T>::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
}


Expand Down
4 changes: 4 additions & 0 deletions src/sat/bsat2/XAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/sat/cnf/cnfUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 6 additions & 8 deletions src/sat/glucose/IntTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
# include <sys/int_fmtio.h>
# include <sys/int_limits.h>

#else
#elif _WIN32

#define __STDC_LIMIT_MACROS
# include "pstdint.h"
//# include <inttypes.h>

#endif
#else

#include <limits.h>
# define __STDC_LIMIT_MACROS
# include <limits.h>
# include <inttypes.h>

#ifndef PRIu64
#define PRIu64 "lu"
#define PRIi64 "ld"
#endif

//=================================================================================================

#include <misc/util/abc_namespaces.h>
Expand Down
Loading
Loading