1 //===-- jitcs_base.h C++ ------------------------------------------------*-===//
3 // Definition of basic types and basic macros.
5 //===----------------------------------------------------------------------===//
14 // import nullptr, offsetof
18 // TODO: check the existence of nullptr
20 // first a few checks if the types are correctly defined,
21 // the architecture is 32 or 64 bit
22 static_assert(sizeof(int8_t) == 1 && sizeof(uint8_t) == 1,
23 "wrong size of int8_t");
24 static_assert(sizeof(int16_t) == 2 && sizeof(uint16_t) == 2,
25 "wrong size of int16_t");
26 static_assert(sizeof(int32_t) == 4 && sizeof(uint32_t) == 4,
27 "wrong size of int32_t");
28 static_assert(sizeof(int64_t) == 8 && sizeof(uint64_t) == 8,
29 "wrong size of int64_t");
31 static_assert(sizeof(float) == 4 && sizeof(double) == 8,
32 "wrong size of float or double");
34 static_assert(sizeof(intptr_t) == sizeof(void*), "wrong size of intptr_t");
35 static_assert(sizeof(uintptr_t) == sizeof(void*), "wrong size of uintptr_t");
37 static_assert(sizeof(int) == 4 || sizeof(int) == 8, "wrong size of int");
38 static_assert(sizeof(void*) == 4 || sizeof(void*) == 8, "wrong size of void*");
39 static_assert(sizeof(int) <= sizeof(void*), "wrong size of void* < int");
43 // type shortcut alias
44 typedef unsigned int uint
;
46 // type constructors for use in templates
47 template <unsigned N
> struct Int
{};
48 template <> struct Int
<8> { typedef int8_t Type
; };
49 template <> struct Int
<16> { typedef int16_t Type
; };
50 template <> struct Int
<32> { typedef int32_t Type
; };
51 template <> struct Int
<64> { typedef int64_t Type
; };
53 template <unsigned N
> struct UInt
{};
54 template <> struct UInt
<8> { typedef uint8_t Type
; };
55 template <> struct UInt
<16> { typedef uint16_t Type
; };
56 template <> struct UInt
<32> { typedef uint32_t Type
; };
57 template <> struct UInt
<64> { typedef uint64_t Type
; };
59 template <unsigned N
> struct Float
{};
60 template <> struct Float
<32> { typedef float Type
; };
61 template <> struct Float
<64> { typedef double Type
; };
73 typedef intptr_t iptr
;
74 typedef uintptr_t uptr
;
77 } // end of namespace jitcs
79 // ------------------------------
81 #define _JITCS_ALWAYS_CHECK_(X) do { if (!(X)) throw ("Assertion failed in " __FILE__ ": " #X); } while (0)
83 #if defined(_DEBUG) && !defined(JITCS_DEBUG)
87 #if defined(_NDEBUG) && defined(JITCS_DEBUG)
93 #define _JITCS_DBG_CHECK_(X) _JITCS_ALWAYS_CHECK_(X)
94 #define _JITCS_DBG_EXPR_(X) X
95 #define _JITCS_DBG_PARAM_(X) ,X
97 #define _JITCS_DBG_CHECK_(X)
98 #define _JITCS_DBG_EXPR_(X)
99 #define _JITCS_DBG_PARAM_(X)
122 #if defined(__i386__)
127 #if defined(__x86_64__)
132 #if defined(__CC_ARM) || defined(__ARMCC__) \
133 || defined(__arm__) || defined(__thumb__)
138 #if defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
139 #define JITCS_WINDOWS