3a08eb2f8501e7c7f46511a91f2b0f06f110cceb
[ghc.git] / includes / stg / Types.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2004
4 *
5 * Various C datatypes used in the run-time system. This is the
6 * lowest-level include file, after ghcconfig.h and RtsConfig.h.
7 *
8 * Do not #include this file directly: #include "Rts.h" instead.
9 *
10 * To understand the structure of the RTS headers, see the wiki:
11 * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
12 *
13 * NOTE: assumes #include "ghcconfig.h"
14 *
15 * Works with or without _POSIX_SOURCE.
16 *
17 * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
18 *
19 * ---------------------------------------------------------------------------*/
20
21 #ifndef STGTYPES_H
22 #define STGTYPES_H
23
24 #if defined(mingw32_HOST_OS)
25 /* Inform mingw we want the ISO rather than Windows printf format specifiers. */
26 #define __USE_MINGW_ANSI_STDIO 1
27 #endif
28
29 /* ISO C 99 says:
30 * "C++ implementations should define these macros only when
31 * __STDC_LIMIT_MACROS is defined before <stdint.h> is included."
32 *
33 * So we need to define it for now to compile with C++ compilers.
34 * However, C++11 does not require it anymore so we can remove this once we
35 * upgrade to requiring C++11 or newer.
36 */
37 #define __STDC_LIMIT_MACROS
38 #include <inttypes.h>
39
40
41 /*
42 * This module should define types *only*, all beginning with "Stg".
43 *
44 * Specifically:
45
46 StgInt8, 16, 32, 64
47 StgWord8, 16, 32, 64
48 StgChar, StgFloat, StgDouble
49
50 ***** All the same size (i.e. sizeof(void *)): *****
51 StgPtr Basic pointer type
52 StgWord Unit of heap allocation
53 StgInt Signed version of StgWord
54 StgAddr Generic address type
55
56 StgBool, StgVoid, StgPtr, StgOffset,
57 StgCode, StgStablePtr, StgFunPtr,
58 StgUnion.
59 */
60
61 /*
62 * First, platform-dependent definitions of size-specific integers.
63 */
64
65 typedef int8_t StgInt8;
66 typedef uint8_t StgWord8;
67
68 #define STG_INT8_MIN INT8_MIN
69 #define STG_INT8_MAX INT8_MAX
70 #define STG_WORD8_MAX UINT8_MAX
71
72 typedef int16_t StgInt16;
73 typedef uint16_t StgWord16;
74
75 #define STG_INT16_MIN INT16_MIN
76 #define STG_INT16_MAX INT16_MAX
77 #define STG_WORD16_MAX UINT16_MAX
78
79 typedef int32_t StgInt32;
80 typedef uint32_t StgWord32;
81
82 #define STG_INT32_MIN INT32_MIN
83 #define STG_INT32_MAX INT32_MAX
84 #define STG_WORD32_MAX UINT32_MAX
85
86 #define FMT_Word32 PRIu32
87 #define FMT_HexWord32 PRIx32
88 #define FMT_Int32 PRId32
89
90 typedef int64_t StgInt64;
91 typedef uint64_t StgWord64;
92
93 #define STG_INT64_MIN INT64_MIN
94 #define STG_INT64_MAX INT64_MAX
95 #define STG_WORD64_MAX UINT64_MAX
96
97 #define FMT_Word64 PRIu64
98 #define FMT_HexWord64 PRIx64
99 #define FMT_Int64 PRId64
100
101 typedef struct { StgWord64 h; StgWord64 l; } StgWord128;
102
103 typedef struct { StgWord128 h; StgWord128 l; } StgWord256;
104
105 typedef struct { StgWord256 h; StgWord256 l; } StgWord512;
106
107 /*
108 * Stg{Int,Word} are defined such that they have the exact same size as a
109 * void pointer.
110 */
111
112 #if SIZEOF_VOID_P == 8
113 typedef int64_t StgInt;
114 typedef uint64_t StgWord;
115
116 typedef int32_t StgHalfInt;
117 typedef uint32_t StgHalfWord;
118
119 #define STG_INT_MIN INT64_MIN
120 #define STG_INT_MAX INT64_MAX
121 #define STG_WORD_MAX UINT64_MAX
122
123 #define FMT_Word FMT_Word64
124 #define FMT_HexWord FMT_HexWord64
125 #define FMT_Int FMT_Int64
126
127 #define strToStgWord strtoull
128
129 #elif SIZEOF_VOID_P == 4
130 typedef int32_t StgInt;
131 typedef uint32_t StgWord;
132
133 typedef int16_t StgHalfInt;
134 typedef uint16_t StgHalfWord;
135
136 #define STG_INT_MIN INT32_MIN
137 #define STG_INT_MAX INT32_MAX
138 #define STG_WORD_MAX UINT32_MAX
139
140 #define FMT_Word FMT_Word32
141 #define FMT_HexWord FMT_HexWord32
142 #define FMT_Int FMT_Int32
143
144 #define strToStgWord strtoul
145
146 #else
147 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
148 #endif
149
150 #define W_MASK (sizeof(W_)-1)
151
152 /*
153 * Other commonly-used STG datatypes.
154 */
155
156 typedef void* StgAddr;
157 typedef StgWord32 StgChar;
158 typedef int StgBool;
159 typedef float StgFloat;
160 typedef double StgDouble;
161 typedef StgWord* StgPtr; /* heap or stack pointer */
162 typedef StgWord volatile* StgVolatilePtr; /* pointer to volatile word */
163 typedef StgWord StgOffset; /* byte offset within closure */
164 typedef StgWord8 StgCode; /* close enough */
165 typedef void* StgStablePtr;
166 typedef StgWord8* StgByteArray;
167
168 /*
169 Types for generated C functions when compiling via C.
170
171 The C functions take no arguments, and return a pointer to the next
172 function to be called use: Ptr to Fun that returns a Ptr to Fun
173 which returns Ptr to void
174
175 Note: Neither StgFunPtr not StgFun is quite right (that is,
176 StgFunPtr != StgFun*). So, the functions we define all have type
177 StgFun but we always have to cast them to StgFunPtr when we assign
178 them to something.
179 The only way round this would be to write a recursive type but
180 C only allows that if you're defining a struct or union.
181 */
182
183 typedef void *(*(*StgFunPtr)(void))(void);
184 typedef StgFunPtr StgFun(void);
185
186 #endif /* STGTYPES_H */