From 9b4b92b0143987b7e8989b01d96f92af27c1bbbe Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 20 Feb 2017 00:36:53 -0800 Subject: [PATCH] watcom.h: horrific hack to support OpenWatcom switch limitations OpenWatcom still doesn't have proper support for 64-bit switch statements. Hack around it in a truly vile way. Signed-off-by: H. Peter Anvin --- config/watcom.h | 1 + include/compiler.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/config/watcom.h b/config/watcom.h index b43b7fb45..029a36f86 100644 --- a/config/watcom.h +++ b/config/watcom.h @@ -69,5 +69,6 @@ #define HAVE_UNISTD_H 1 #define HAVE_VSNPRINTF 1 #define STDC_HEADERS 1 +#define inline __inline #endif /* NASM_CONFIG_WATCOM_H */ diff --git a/include/compiler.h b/include/compiler.h index 061b34415..4cecf9ce9 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -81,6 +81,7 @@ #include #include #include +#include #ifdef HAVE_SYS_TYPES_H # include @@ -248,4 +249,20 @@ char *strsep(char **, const char *); # define pure_func #endif +/* Watcom doesn't handle switch statements with 64-bit types, hack around it */ +#ifdef __WATCOM__ +# define BOGUS_CASE 0x76543210 + +static inline unsigned int watcom_switch_hack(uint64_t x) +{ + if (x > UINT_MAX) + return BOGUS_CASE; + else + return (unsigned int)x; +} + +# define switch(x) switch(watcom_switch_hack(x)) +# define default case BOGUS_CASE: default +#endif + #endif /* NASM_COMPILER_H */