Merge pull request #447 from mmicko/mingw_wasi

Fix compilation for mingw and wasi (up streaming YosysHQ changes)
This commit is contained in:
alanminko
2025-11-27 08:28:01 -08:00
committed by GitHub
10 changed files with 44 additions and 14 deletions

View File

@@ -614,7 +614,11 @@ namespace eSLIM {
// sprintf( pCommand, "%s -q %s > %s", pKissat, pFileNameIn, pFileNameOut );
sprintf( pCommand, "%s -q %s > %s", pKissat, pFileNameIn, pFileNameOut );
#ifdef __wasm
if ( 1 ) {
#else
if ( system( pCommand ) == -1 ) {
#endif
std::cerr << "Command " << pCommand << " failed\n";
return nullptr;
}

View File

@@ -5981,7 +5981,7 @@ void Closure::rewrite_ite_gate (Gate *g, int dst, int src) {
#endif
} else {
CADICAL_assert (false);
#ifdef WIN32
#if defined(WIN32) && !defined(__MINGW32__)
__assume(false);
#else
__builtin_unreachable ();

View File

@@ -33,7 +33,9 @@ extern "C" {
#else
extern "C" {
#if !defined(__wasm)
#include <sys/wait.h>
#endif
#include <unistd.h>
}
@@ -245,6 +247,7 @@ void File::delete_str_vector (std::vector<char *> &argv) {
FILE *File::open_pipe (Internal *internal, const char *fmt,
const char *path, const char *mode) {
#if !defined(__wasm)
#ifdef CADICAL_QUIET
(void) internal;
#endif
@@ -269,6 +272,9 @@ FILE *File::open_pipe (Internal *internal, const char *fmt,
FILE *res = popen (cmd, mode);
delete[] cmd;
return res;
#else
return 0;
#endif
}
FILE *File::read_pipe (Internal *internal, const char *fmt, const int *sig,
@@ -285,7 +291,7 @@ FILE *File::read_pipe (Internal *internal, const char *fmt, const int *sig,
return open_pipe (internal, fmt, path, "r");
}
#ifndef _WIN32
#if !defined(_WIN32) && !defined(__wasm)
#if defined(__APPLE__) || defined(__MACH__)
static std::mutex compressed_file_writing_mutex;
@@ -420,7 +426,7 @@ File *File::read (Internal *internal, const char *path) {
File *File::write (Internal *internal, const char *path) {
FILE *file;
int close_output = 3, child_pid = 0;
#ifndef _WIN32
#if !defined(_WIN32) && !defined(__wasm)
if (has_suffix (path, ".xz"))
file = write_pipe (internal, "xz -c", path, child_pid);
else if (has_suffix (path, ".bz2"))
@@ -456,12 +462,14 @@ void File::close (bool print) {
MSG ("closing file '%s'", name ());
fclose (file);
}
#if !defined(__wasm)
if (close_file == 2) {
if (print)
MSG ("closing input pipe to read '%s'", name ());
pclose (file);
}
#ifndef _WIN32
#endif
#if !defined(_WIN32) && !defined(__wasm)
if (close_file == 3) {
if (print)
MSG ("closing output pipe to write '%s'", name ());

View File

@@ -84,7 +84,7 @@ ABC_NAMESPACE_IMPL_END
// work. As an additional measure to increase the possibility to get
// different seeds we are now also using network addresses (explicitly).
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
extern "C" {
#include <ifaddrs.h>
@@ -110,7 +110,7 @@ static uint64_t hash_network_addresses () {
// you really need to run 'mobical' on a Windows cluster where each node
// has identical IP addresses.
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
struct ifaddrs *addrs;
if (!getifaddrs (&addrs)) {
for (struct ifaddrs *addr = addrs; addr; addr = addr->ifa_next) {

View File

@@ -131,10 +131,14 @@ uint64_t maximum_resident_set_size () {
// This seems to work on Linux (man page says since Linux 2.6.32).
uint64_t maximum_resident_set_size () {
#ifdef __wasm
return 0;
#else
struct rusage u;
if (getrusage (RUSAGE_SELF, &u))
return 0;
return ((uint64_t) u.ru_maxrss) << 10;
#endif
}
// Unfortunately 'getrusage' on Linux does not support current resident set

View File

@@ -7,11 +7,13 @@
/*------------------------------------------------------------------------*/
#include <cassert>
#if !defined(__wasm)
#include <csignal>
#endif
/*------------------------------------------------------------------------*/
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
extern "C" {
#include <unistd.h>
}
@@ -28,7 +30,7 @@ namespace CaDiCaL {
static volatile bool caught_signal = false;
static Handler *signal_handler;
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
static volatile bool caught_alarm = false;
static volatile bool alarm_set = false;
@@ -38,6 +40,7 @@ void Handler::catch_alarm () { catch_signal (SIGALRM); }
#endif
#if !defined(__wasm)
#define SIGNALS \
SIGNAL (SIGABRT) \
SIGNAL (SIGINT) \
@@ -47,8 +50,9 @@ void Handler::catch_alarm () { catch_signal (SIGALRM); }
#define SIGNAL(SIG) static void (*SIG##_handler) (int);
SIGNALS
#undef SIGNAL
#endif
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
static void (*SIGALRM_handler) (int);
@@ -66,6 +70,7 @@ void Signal::reset_alarm () {
void Signal::reset () {
signal_handler = 0;
#if !defined(__wasm)
#define SIGNAL(SIG) \
(void) signal (SIG, SIG##_handler); \
SIG##_handler = 0;
@@ -73,11 +78,13 @@ void Signal::reset () {
#undef SIGNAL
#ifndef WIN32
reset_alarm ();
#endif
#endif
caught_signal = false;
}
const char *Signal::name (int sig) {
#if !defined(__wasm)
#define SIGNAL(SIG) \
if (sig == SIG) \
return #SIG;
@@ -86,6 +93,7 @@ const char *Signal::name (int sig) {
#ifndef WIN32
if (sig == SIGALRM)
return "SIGALRM";
#endif
#endif
return "UNKNOWN";
}
@@ -97,6 +105,7 @@ const char *Signal::name (int sig) {
// exclusive access to. All these solutions are painful and not elegant.
static void catch_signal (int sig) {
#if !defined(__wasm)
#ifndef WIN32
if (sig == SIGALRM && absolute_real_time () >= alarm_time) {
if (!caught_alarm) {
@@ -116,16 +125,19 @@ static void catch_signal (int sig) {
Signal::reset ();
::raise (sig);
}
#endif
}
void Signal::set (Handler *h) {
#if !defined(__wasm)
signal_handler = h;
#define SIGNAL(SIG) SIG##_handler = signal (SIG, catch_signal);
SIGNALS
#undef SIGNAL
#endif
}
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
void Signal::alarm (int seconds) {
CADICAL_assert (seconds >= 0);

View File

@@ -1501,7 +1501,7 @@ inline std::vector<vivify_ref> &current_refs_schedule (Vivifier &vivifier) {
return vivifier.refs_schedule_irred;
break;
}
#ifdef WIN32
#if defined(WIN32) && !defined(__MINGW32__)
__assume(false);
#else
__builtin_unreachable ();
@@ -1523,7 +1523,7 @@ inline std::vector<Clause *> &current_schedule (Vivifier &vivifier) {
return vivifier.schedule_irred;
break;
}
#ifdef WIN32
#if defined(WIN32) && !defined(__MINGW32__)
__assume(false);
#else
__builtin_unreachable ();

View File

@@ -66,7 +66,7 @@ class File {
const char *mode);
static FILE *read_pipe (Internal *, const char *fmt, const int *sig,
const char *path);
#ifndef WIN32
#if !defined(_WIN32) && !defined(__wasm)
static FILE *write_pipe (Internal *, const char *fmt, const char *path,
int &child_pid);
#endif

View File

@@ -17,7 +17,9 @@
#include <cctype>
#include <climits>
#include <cmath>
#if !defined(__wasm)
#include <csignal>
#endif
#include <cstdio>
#include <cstdlib>
#include <cstring>

View File

@@ -1,6 +1,6 @@
#include "colors.h"
#ifdef WIN32
#if defined(WIN32) && !defined(__MINGW32__)
#define isatty _isatty
#else
#include <unistd.h>