This is incompatible with MSVC and TCC on Win32. Bounds checking appears to be broken (test4).
Unified · Split
| @@ -108,20 +108,20 @@ test3: test.ref · 107 unmodified lines | ||
| 108 | 108 | test4: test.ref |
| 109 | 109 | @echo ------------ $@ ------------ |
| 110 | 110 | # object + link output |
| 111 | − $(TCC) -c -o tcctest3.o tcctest.c | |
| 111 | + $(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c | |
| 112 | 112 | $(TCC) -o tcctest3 tcctest3.o |
| 113 | 113 | ./tcctest3 > test3.out |
| 114 | 114 | @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi |
| 115 | 115 | # dynamic output |
| 116 | − $(TCC) -o tcctest1 tcctest.c | |
| 116 | + $(TCC) -o tcctest1 $(SRCDIR)/tcctest.c | |
| 117 | 117 | ./tcctest1 > test1.out |
| 118 | 118 | @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi |
| 119 | 119 | # dynamic output + bound check |
| 120 | − $(TCC) -b -o tcctest4 tcctest.c | |
| 120 | + $(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c | |
| 121 | 121 | ./tcctest4 > test4.out |
| 122 | 122 | @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi |
| 123 | 123 | # static output |
| 124 | − $(TCC) -static -o tcctest2 tcctest.c | |
| 124 | + $(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c | |
| 125 | 125 | ./tcctest2 > test2.out |
| 126 | 126 | @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi |
| 127 | 127 | |
| @@ -188,8 +188,8 @@ abitest-tcc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC) · 60 unmodified lines | ||
| 188 | 188 | |
| 189 | 189 | abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF) |
| 190 | 190 | @echo ------------ $@ ------------ |
| 191 | − ./abitest-cc$(EXESUF) lib_path=.. | |
| 192 | − ./abitest-tcc$(EXESUF) lib_path=.. | |
| 191 | + ./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include" | |
| 192 | + ./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include" | |
| 193 | 193 | |
| 194 | 194 | # targets for development |
| 195 | 195 | %.bin: %.c tcc |
| @@ -4,7 +4,17 @@ · 3 unmodified lines | ||
| 4 | 4 | #include <string.h> |
| 5 | 5 | #include <stdarg.h> |
| 6 | 6 | |
| 7 | +// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC | |
| 8 | +#if defined(_WIN32) && defined(__GNUC__) | |
| 9 | +#define LONG_DOUBLE double | |
| 10 | +#define LONG_DOUBLE_LITERAL(x) x | |
| 11 | +#else | |
| 12 | +#define LONG_DOUBLE long double | |
| 13 | +#define LONG_DOUBLE_LITERAL(x) x ## L | |
| 14 | +#endif | |
| 15 | + | |
| 7 | 16 | static const char *tccdir = NULL; |
| 17 | +static const char *include_dir = NULL; | |
| 8 | 18 | |
| 9 | 19 | typedef int (*callback_type) (void*); |
| 10 | 20 | |
| @@ -21,6 +31,10 @@ static int run_callback(const char *src, callback_type callback) { · 10 unmodified lines | ||
| 21 | 31 | return -1; |
| 22 | 32 | if (tccdir) |
| 23 | 33 | tcc_set_lib_path(s, tccdir); |
| 34 | + if (include_dir) { | |
| 35 | + if (tcc_add_include_path(s, include_dir) == -1) | |
| 36 | + return -1; | |
| 37 | + } | |
| 24 | 38 | if (tcc_set_output_type(s, TCC_OUTPUT_MEMORY) == -1) |
| 25 | 39 | return -1; |
| 26 | 40 | if (tcc_compile_string(s, src) == -1) |
| @@ -38,6 +52,9 @@ static int run_callback(const char *src, callback_type callback) { · 11 unmodified lines | ||
| 38 | 52 | return result; |
| 39 | 53 | } |
| 40 | 54 | |
| 55 | +#define STR2(x) #x | |
| 56 | +#define STR(x) STR2(x) | |
| 57 | + | |
| 41 | 58 | #define RET_PRIMITIVE_TEST(name, type, val) \ |
| 42 | 59 | static int ret_ ## name ## _test_callback(void *ptr) { \ |
| 43 | 60 | type (*callback) (type) = (type(*)(type))ptr; \ |
| @@ -47,7 +64,7 @@ static int run_callback(const char *src, callback_type callback) { · 3 unmodified lines | ||
| 47 | 64 | } \ |
| 48 | 65 | \ |
| 49 | 66 | static int ret_ ## name ## _test(void) { \ |
| 50 | − const char *src = #type " f(" #type " x) {return x+x;}"; \ | |
| 67 | + const char *src = STR(type) " f(" STR(type) " x) {return x+x;}"; \ | |
| 51 | 68 | return run_callback(src, ret_ ## name ## _test_callback); \ |
| 52 | 69 | } |
| 53 | 70 | |
| @@ -55,7 +72,7 @@ RET_PRIMITIVE_TEST(int, int, 70000) · 1 unmodified line | ||
| 55 | 72 | RET_PRIMITIVE_TEST(longlong, long long, 4333369356528LL) |
| 56 | 73 | RET_PRIMITIVE_TEST(float, float, 63.0) |
| 57 | 74 | RET_PRIMITIVE_TEST(double, double, 14789798.0) |
| 58 | −RET_PRIMITIVE_TEST(longdouble, long double, 378943892.0) | |
| 75 | +RET_PRIMITIVE_TEST(longdouble, LONG_DOUBLE, LONG_DOUBLE_LITERAL(378943892.0)) | |
| 59 | 76 | |
| 60 | 77 | /* |
| 61 | 78 | * ret_2float_test: |
| @@ -303,6 +320,8 @@ int main(int argc, char **argv) { · 241 unmodified lines | ||
| 303 | 320 | tccdir = argv[i] + 9; |
| 304 | 321 | else if (!memcmp(argv[i], "run_test=", 9)) |
| 305 | 322 | testname = argv[i] + 9; |
| 323 | + else if (!memcmp(argv[i], "include=", 8)) | |
| 324 | + include_dir = argv[i] + 8; | |
| 306 | 325 | } |
| 307 | 326 | |
| 308 | 327 | RUN_TEST(ret_int_test); |