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

Make WASI and w2c2_base.h compile on MSVC 4.0 #101

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 34 additions & 11 deletions w2c2/w2c2_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <math.h>
#include <string.h>
#include <stdlib.h>
#ifndef __NeXT__
#if !(defined(__NeXT__) || (defined(_MSC_VER) && _MSC_VER <= 1000))
#include <stdint.h>
#endif

Expand Down Expand Up @@ -35,8 +35,13 @@ typedef signed short I16;
typedef unsigned int U32;
typedef signed int I32;

#if defined(_MSC_VER) && _MSC_VER <= 1000
typedef unsigned __int64 U64;
typedef signed __int64 I64;
#else
typedef unsigned long long int U64;
typedef signed long long int I64;
#endif

typedef float F32;
typedef double F64;
Expand Down Expand Up @@ -185,6 +190,12 @@ typedef double F64;
#define UNUSED
#endif

#if defined(_MSC_VER) && _MSC_VER <= 1000
#define LLONG_MIN (-0x7fffffffffffffffi64-1)
SergioFLS marked this conversation as resolved.
Show resolved Hide resolved
#define LLONG_MAX 0x7fffffffffffffffi64
#define INT64_MAX 9223372036854775807i64
#define UINT64_MAX 18446744073709551615Ui64
#else /* defined(_MSC_VER) && _MSC_VER <= 1000 */
#ifndef LLONG_MIN
#define LLONG_MIN (-0x7fffffffffffffffLL-1)
#endif
Expand All @@ -193,6 +204,15 @@ typedef double F64;
#define LLONG_MAX 0x7fffffffffffffffLL
#endif

#ifndef INT64_MAX
#define INT64_MAX 9223372036854775807LL
#endif

#ifndef UINT64_MAX
#define UINT64_MAX 18446744073709551615ULL
#endif
#endif /* defined(_MSC_VER) && _MSC_VER <= 1000 */

#ifndef INT32_MAX
#define INT32_MAX 2147483647
#endif
Expand All @@ -201,22 +221,13 @@ typedef double F64;
#define INT32_MIN (-INT32_MAX - 1)
#endif

#ifndef INT64_MAX
#define INT64_MAX 9223372036854775807LL
#endif

#ifndef INT64_MIN
#define INT64_MIN (-INT64_MAX - 1)
#endif

#ifndef UINT32_MAX
#define UINT32_MAX 4294967295U
#endif

#ifndef UINT64_MAX
#define UINT64_MAX 18446744073709551615ULL
#endif

#if defined(_MSC_VER) && _MSC_VER <= 1500

/* disable warning C4756: overflow in constant arithmetic */
Expand Down Expand Up @@ -341,10 +352,17 @@ I32_POPCNT(
static
W2C2_INLINE
U64 I64_POPCNT(U64 x) {
#if defined(_MSC_VER) && _MSC_VER <= 1000
x -= ((x >> 1) & 0x5555555555555555ui64);
x = ((x >> 2) & 0x3333333333333333ui64) + (x & 0x3333333333333333ui64);
x = ((x >> 4) + x) & 0xf0f0f0f0f0f0f0fui64;
x *= 0x101010101010101ui64;
#else
x -= ((x >> 1) & 0x5555555555555555ull);
x = ((x >> 2) & 0x3333333333333333ull) + (x & 0x3333333333333333ull);
x = ((x >> 4) + x) & 0xf0f0f0f0f0f0f0full;
x *= 0x101010101010101ull;
#endif
return (x >> 56);
}
#endif
Expand Down Expand Up @@ -1049,8 +1067,13 @@ DEFINE_SWAP(32, i, int)
DEFINE_SWAP(32, I, unsigned int)
DEFINE_SWAP(32, l, long)
DEFINE_SWAP(32, L, unsigned long)
#if defined(_MSC_VER) && _MSC_VER <= 1000
DEFINE_SWAP(64, q, signed __int64)
DEFINE_SWAP(64, Q, unsigned __int64)
#else
DEFINE_SWAP(64, q, long long)
DEFINE_SWAP(64, Q, unsigned long long)
#endif
DEFINE_SWAP(32, f, float)
DEFINE_SWAP(64, d, double)

Expand Down Expand Up @@ -1110,7 +1133,7 @@ typedef struct wasmModuleInstance {
#define __has_extension __has_feature
#endif

#ifdef _MSC_VER
#if defined(_MSC_VER) && _MSC_VER >= 1500
#define WASM_ATOMICS_MSVC
#elif defined(__GNUC__) && (GCC_VERSION >= 40700 || __has_extension(c_atomic))
#define WASM_ATOMICS_GCC
Expand Down
16 changes: 14 additions & 2 deletions wasi/wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
#endif /* HAS_UNISTD */

#ifdef _MSC_VER
#if _MSC_VER <= 1000
typedef signed int ssize_t; /* assuming target machine is ILP32 ! */
#else
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
#define INT64_C(val) val##i64
#endif /* _MSC_VER */

Expand Down Expand Up @@ -1662,11 +1666,19 @@ WASI_IMPORT(U32, fd_close, (
})

#ifndef NSEC_PER_SEC
#if defined(_MSC_VER) && _MSC_VER <= 1000
#define NSEC_PER_SEC 1000000000i64
#else
#define NSEC_PER_SEC 1000000000LL
#endif
#endif
#ifndef NSEC_PER_USEC
#if defined(_MSC_VER) && _MSC_VER <= 1000
#define NSEC_PER_USEC 1000i64
#else
#define NSEC_PER_USEC 1000LL
#endif
#endif

static
W2C2_INLINE
Expand Down Expand Up @@ -3901,7 +3913,7 @@ wasiRandomGet(

bufferStart = memory->data + bufferPointer;

#ifdef _WIN32
#if defined(_WIN32) && !(defined(_MSC_VER) && _MSC_VER <= 1000)
#include <wincrypt.h>
{
HCRYPTPROV provider;
Expand Down Expand Up @@ -3970,7 +3982,7 @@ wasiRandomGet(
return WASI_ERRNO_SUCCESS;
}
}
#if defined(__MWERKS__) && defined(macintosh)
#if (defined(__MWERKS__) && defined(macintosh)) || (defined(_MSC_VER) && _MSC_VER <= 1000)
/* Fall back to rand */
{
U32 i = 0;
Expand Down
21 changes: 21 additions & 0 deletions wasi/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
extern "C" {
#endif

/* defines for MSVC 4.0 */
#ifndef ERROR_DELETE_PENDING
#define ERROR_DELETE_PENDING 303
#endif

#ifndef ERROR_CANT_RESOLVE_FILENAME
#define ERROR_CANT_RESOLVE_FILENAME 1921
#endif

#ifndef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES (~0u)
#endif

#ifndef FILE_ATTRIBUTE_REPARSE_POINT
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#endif

#ifndef IO_REPARSE_TAG_MOUNT_POINT
#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003l
#endif

struct dirent {
long d_ino;
unsigned short d_reclen;
Expand Down
Loading