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