diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-24 16:49:14 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-28 00:52:07 +0100 |
commit | 6bca188679d235ddbad2e97aa3e4186a4730686e (patch) | |
tree | c65def4c0940b6c4d1bd2afe0c611fe3b2c02cee | |
parent | 61b8e17e1456b272dbc9c14e599fb6a20984aaf6 (diff) | |
download | sparse-6bca188679d235ddbad2e97aa3e4186a4730686e.tar.gz |
arch: use a variable for the OS
There are a few OS-specific settings and handling them
with #ifdef is 1) ugly, 2) can only work with when specifically
built for this OS (either a native or cross-build).
So, use a variable to hold the OS and initialize it to the one
used to compile sparse. This avoid the ugly #ifdef and allow
simpler transition if if the future sparse would take the OS
in parameter (maybe as triple).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | lib.c | 1 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | machine.h | 26 | ||||
-rw-r--r-- | target.c | 24 |
4 files changed, 41 insertions, 11 deletions
@@ -329,6 +329,7 @@ static int arch_msize_long = 0; int arch_m64 = ARCH_M64_DEFAULT; int arch_big_endian = ARCH_BIG_ENDIAN; int arch_mach = MACH_NATIVE; +int arch_os = OS_NATIVE; int arch_cmodel = CMODEL_UNKNOWN; @@ -207,6 +207,7 @@ extern int funsigned_char; extern int arch_m64; extern int arch_big_endian; extern int arch_mach; +extern int arch_os; enum { CMODEL_UNKNOWN, @@ -70,4 +70,30 @@ enum machine { #define MACH_NATIVE MACH_UNKNOWN #endif + +enum { + OS_CYGWIN, + OS_DARWIN, + OS_FREEBSD, + OS_LINUX, + OS_NETBSD, + OS_OPENBSD, + OS_SUNOS, + OS_UNKNOWN, +}; + +#if defined(__linux__) || defined(__linux) +#define OS_NATIVE OS_LINUX +#elif defined(__FreeBSD__) +#define OS_NATIVE OS_FREEBSD +#elif defined(__APPLE__) +#define OS_NATIVE OS_DARWIN +#elif defined(__CYGWIN__) +#define OS_NATIVE OS_CYGWIN +#elif defined(__sun__) && defined(__sun) +#define OS_NATIVE OS_SUNOS +#else +#define OS_NATIVE OS_UNKNOWN +#endif + #endif @@ -83,13 +83,19 @@ void init_target(void) wchar_ctype = &long_ctype; /* fall through */ case MACH_X86_64: -#if defined(__APPLE__) - int64_ctype = &llong_ctype; - uint64_ctype = &ullong_ctype; -#endif -#if defined(__FreeBSD__) || defined(__APPLE__) - wint_ctype = &int_ctype; -#endif + switch (arch_os) { + case OS_CYGWIN: + wchar_ctype = &ushort_ctype; + break; + case OS_DARWIN: + int64_ctype = &llong_ctype; + uint64_ctype = &ullong_ctype; + wint_ctype = &int_ctype; + break; + case OS_FREEBSD: + wint_ctype = &int_ctype; + break; + } break; case MACH_M68K: case MACH_SPARC32: @@ -178,8 +184,4 @@ void init_target(void) pointer_alignment = 8; break; } - -#if defined(__CYGWIN__) - wchar_ctype = &ushort_ctype; -#endif } |