summaryrefslogtreecommitdiff
path: root/include/compiler.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-02-20 00:36:53 -0800
committerH. Peter Anvin <hpa@zytor.com>2017-02-20 00:36:53 -0800
commit9b4b92b0143987b7e8989b01d96f92af27c1bbbe (patch)
treeca33c7b990ccacc4f76b1a855c6bfd7de0d677d3 /include/compiler.h
parent2902fbc1d8d084f10bfee4d18a01b90266c6adae (diff)
downloadnasm-9b4b92b0143987b7e8989b01d96f92af27c1bbbe.tar.gz
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 <hpa@zytor.com>
Diffstat (limited to 'include/compiler.h')
-rw-r--r--include/compiler.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/compiler.h b/include/compiler.h
index 061b3441..4cecf9ce 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -81,6 +81,7 @@
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
+#include <limits.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
@@ -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 */