From b12af2cd171f26b1a41afcc9866918d0ae214abf Mon Sep 17 00:00:00 2001
From: Chris Marshall
Date: Fri, 20 May 2016 08:02:03 -0400
Subject: [PATCH] Basic port to cygwin of mob tcc
The remaining issues appear to be ones relating to include file
problems. Specifically, the local include/stddef.h and others
seem to be inconsistent with those from the native gcc (as in
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/stddef.h or others.
---
conftest.c | 2 ++
lib/libtcc1.c | 5 +++++
libtcc.c | 3 +++
tccrun.c | 8 ++++++++
4 files changed, 18 insertions(+)
diff --git a/conftest.c b/conftest.c
index fa07a1b..8fe2e01 100644
--- a/conftest.c
+++ b/conftest.c
@@ -18,6 +18,8 @@
# define TRIPLET_OS "linux"
#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
# define TRIPLET_OS "kfreebsd"
+#elif defined (__CYGWIN__)
+# define TRIPLET_OS "cygwin"
#elif !defined (__GNU__)
# define TRIPLET_OS "unknown"
#endif
diff --git a/lib/libtcc1.c b/lib/libtcc1.c
index a5fee7b..05ec15b 100644
--- a/lib/libtcc1.c
+++ b/lib/libtcc1.c
@@ -28,6 +28,11 @@ the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+#define __INTPTR_TYPE__ long int
+#define __INTPTR_MAX__ 9223372036854775807L
+#define __INT32_TYPE__ int
+#define __INT32_MAX__ 2147483647
+
#include
#define W_TYPE_SIZE 32
diff --git a/libtcc.c b/libtcc.c
index 4e69b4b..df3382c 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1133,6 +1133,9 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__linux__", NULL);
tcc_define_symbol(s, "__linux", NULL);
# endif
+# if defined(__CYGWIN__)
+ tcc_define_symbol(s, "__CYGWIN__", NULL);
+# endif
# if defined(__FreeBSD__)
tcc_define_symbol(s, "__FreeBSD__", "__FreeBSD__");
# endif
diff --git a/tccrun.c b/tccrun.c
index 4903f90..d8ec443 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -492,6 +492,8 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
*paddr = uc->uc_mcontext->__ss.__eip;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
*paddr = uc->uc_mcontext.mc_eip;
+#elif defined(__CYGWIN__)
+ *paddr = uc->uc_mcontext.eip;
#elif defined(__dietlibc__)
*paddr = uc->uc_mcontext.eip;
#elif defined(__NetBSD__)
@@ -505,6 +507,8 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
fp = uc->uc_mcontext->__ss.__ebp;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
fp = uc->uc_mcontext.mc_ebp;
+#elif defined(__CYGWIN__)
+ fp = uc->uc_mcontext.ebp;
#elif defined(__dietlibc__)
fp = uc->uc_mcontext.ebp;
#elif defined(__NetBSD__)
@@ -540,6 +544,8 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
*paddr = uc->uc_mcontext.mc_rip;
#elif defined(__NetBSD__)
*paddr = uc->uc_mcontext.__gregs[_REG_RIP];
+#elif defined(__CYGWIN__)
+ *paddr = uc->uc_mcontext.rip;
#else
*paddr = uc->uc_mcontext.gregs[REG_RIP];
#endif
@@ -551,6 +557,8 @@ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
fp = uc->uc_mcontext.mc_rbp;
#elif defined(__NetBSD__)
fp = uc->uc_mcontext.__gregs[_REG_RBP];
+#elif defined(__CYGWIN__)
+ fp = uc->uc_mcontext.rbp;
#else
fp = uc->uc_mcontext.gregs[REG_RBP];
#endif
--
2.5.3