diff --git a/source/toy_common.h b/source/toy_common.h index 6dbfeef..d31dc10 100644 --- a/source/toy_common.h +++ b/source/toy_common.h @@ -5,27 +5,37 @@ #include #include - //TOY_API is platform-dependant, and marks publicly usable API functions -#if defined(__linux__) || defined(__MINGW32__) || defined(__GNUC__) - -//GCC support -#define TOY_API extern - +#if defined(__GNUC__) + #define TOY_API extern #elif defined(_MSC_VER) - -//MSVC support -#ifndef TOY_EXPORT -#define TOY_API __declspec(dllimport) + #ifndef TOY_EXPORT + #define TOY_API __declspec(dllimport) + #else + #define TOY_API __declspec(dllexport) + #endif #else -#define TOY_API __declspec(dllexport) + //generic solution + #define TOY_API extern #endif +//TOY_BITNESS is used to encourage memory-cache friendliness +//source: https://www.linuxquestions.org/questions/programming-9/c-preprocessor-define-for-32-vs-64-bit-long-int-4175658579/ +#if defined(__GNUC__) + #if defined(__x86_64) + #define TOY_BITNESS 64 + #else + #define TOY_BITNESS 32 + #endif +#elif defined(_MSC_VER) + #if defined(_M_X64) + #define TOY_BITNESS 64 + #else + #define TOY_BITNESS 32 + #endif #else - -//generic -#define TOY_API extern - + //generic solution + #define TOY_BITNESS -1 #endif //bytecode version specifiers, embedded as the header diff --git a/tests/cases/test_ast.c b/tests/cases/test_ast.c index 5da6b78..e9b08e5 100644 --- a/tests/cases/test_ast.c +++ b/tests/cases/test_ast.c @@ -3,7 +3,7 @@ #include -int test_sizeof_ast() { +int test_sizeof_ast_32bit() { #define TEST_SIZEOF(type, size) \ if (sizeof(type) != size) { \ fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \ @@ -223,12 +223,16 @@ int main() { //run each test set, returning the total errors given int total = 0, res = 0; - res = test_sizeof_ast(); +#if TOY_BITNESS == 32 + res = test_sizeof_ast_32bit(); total += res; if (res == 0) { printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET); } +#else + fprintf(stderr, TOY_CC_WARN "WARNING: Skipping test_sizeof_ast_32bit(); Can't determine the 'bitness' of this platform\n" TOY_CC_RESET); +#endif res = test_type_emission(); total += res;