1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Various C datatypes used in the run-time system. This is the
6 * lowest-level include file, after ghcconfig.h and RtsConfig.h.
8 * Do not #include this file directly: #include "Rts.h" instead.
10 * To understand the structure of the RTS headers, see the wiki:
11 * https://gitlab.haskell.org/ghc/ghc/wikis/commentary/source-tree/includes
13 * NOTE: assumes #include "ghcconfig.h"
15 * Works with or without _POSIX_SOURCE.
17 * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
19 * ---------------------------------------------------------------------------*/
23 #if defined(mingw32_HOST_OS)
24 # if defined(__USE_MINGW_ANSI_STDIO)
25 # if __USE_MINGW_ANSI_STDIO != 1
26 # warning "Mismatch between __USE_MINGW_ANSI_STDIO definitions. \
27 If using Rts.h make sure it is the first header included."
30 /* Inform mingw we want the ISO rather than Windows printf format specifiers. */
31 # define __USE_MINGW_ANSI_STDIO 1
36 * "C++ implementations should define these macros only when
37 * __STDC_LIMIT_MACROS is defined before <stdint.h> is included."
39 * So we need to define it for now to compile with C++ compilers.
40 * However, C++11 does not require it anymore so we can remove this once we
41 * upgrade to requiring C++11 or newer.
43 #define __STDC_LIMIT_MACROS
48 * This module should define types *only*, all beginning with "Stg".
54 StgChar, StgFloat, StgDouble
56 ***** All the same size (i.e. sizeof(void *)): *****
57 StgPtr Basic pointer type
58 StgWord Unit of heap allocation
59 StgInt Signed version of StgWord
60 StgAddr Generic address type
62 StgBool, StgVoid, StgPtr, StgOffset,
63 StgCode, StgStablePtr, StgFunPtr,
68 * First, platform-dependent definitions of size-specific integers.
71 typedef int8_t StgInt8
;
72 typedef uint8_t StgWord8
;
74 #define STG_INT8_MIN INT8_MIN
75 #define STG_INT8_MAX INT8_MAX
76 #define STG_WORD8_MAX UINT8_MAX
78 #define FMT_Word8 PRIu8
80 typedef int16_t StgInt16
;
81 typedef uint16_t StgWord16
;
83 #define STG_INT16_MIN INT16_MIN
84 #define STG_INT16_MAX INT16_MAX
85 #define STG_WORD16_MAX UINT16_MAX
87 #define FMT_Word16 PRIu16
89 typedef int32_t StgInt32
;
90 typedef uint32_t StgWord32
;
92 #define STG_INT32_MIN INT32_MIN
93 #define STG_INT32_MAX INT32_MAX
94 #define STG_WORD32_MAX UINT32_MAX
96 #define FMT_Word32 PRIu32
97 #define FMT_HexWord32 PRIx32
98 #define FMT_Int32 PRId32
100 typedef int64_t StgInt64
;
101 typedef uint64_t StgWord64
;
103 #define STG_INT64_MIN INT64_MIN
104 #define STG_INT64_MAX INT64_MAX
105 #define STG_WORD64_MAX UINT64_MAX
107 #define FMT_Word64 PRIu64
108 #define FMT_HexWord64 PRIx64
109 #define FMT_Int64 PRId64
111 typedef struct { StgWord64 h
; StgWord64 l
; } StgWord128
;
113 typedef struct { StgWord128 h
; StgWord128 l
; } StgWord256
;
115 typedef struct { StgWord256 h
; StgWord256 l
; } StgWord512
;
118 * Stg{Int,Word} are defined such that they have the exact same size as a
122 #if SIZEOF_VOID_P == 8
123 typedef int64_t StgInt
;
124 typedef uint64_t StgWord
;
126 typedef int32_t StgHalfInt
;
127 typedef uint32_t StgHalfWord
;
129 #define STG_INT_MIN INT64_MIN
130 #define STG_INT_MAX INT64_MAX
131 #define STG_WORD_MAX UINT64_MAX
133 #define FMT_Word FMT_Word64
134 #define FMT_HexWord FMT_HexWord64
135 #define FMT_Int FMT_Int64
137 #define strToStgWord strtoull
139 #elif SIZEOF_VOID_P == 4
140 typedef int32_t StgInt
;
141 typedef uint32_t StgWord
;
143 typedef int16_t StgHalfInt
;
144 typedef uint16_t StgHalfWord
;
146 #define STG_INT_MIN INT32_MIN
147 #define STG_INT_MAX INT32_MAX
148 #define STG_WORD_MAX UINT32_MAX
150 #define FMT_Word FMT_Word32
151 #define FMT_HexWord FMT_HexWord32
152 #define FMT_Int FMT_Int32
154 #define strToStgWord strtoul
157 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
160 #define W_MASK (sizeof(W_)-1)
163 * Other commonly-used STG datatypes.
166 typedef void* StgAddr
;
167 typedef StgWord32 StgChar
;
169 typedef float StgFloat
;
170 typedef double StgDouble
;
171 typedef StgWord
* StgPtr
; /* heap or stack pointer */
172 typedef StgWord
volatile* StgVolatilePtr
; /* pointer to volatile word */
173 typedef StgWord StgOffset
; /* byte offset within closure */
174 typedef StgWord8 StgCode
; /* close enough */
175 typedef void* StgStablePtr
;
176 typedef StgWord8
* StgByteArray
;
179 Types for generated C functions when compiling via C.
181 The C functions take no arguments, and return a pointer to the next
182 function to be called use: Ptr to Fun that returns a Ptr to Fun
183 which returns Ptr to void
185 Note: Neither StgFunPtr not StgFun is quite right (that is,
186 StgFunPtr != StgFun*). So, the functions we define all have type
187 StgFun but we always have to cast them to StgFunPtr when we assign
189 The only way round this would be to write a recursive type but
190 C only allows that if you're defining a struct or union.
193 typedef void *(*(*StgFunPtr
)(void))(void);
194 typedef StgFunPtr
StgFun(void);
196 // Forward declarations for the unregisterised backend, which
197 // only depends upon Stg.h and not the entirety of Rts.h, which
198 // is where these are defined.