cmm: Expose machine's stack and return address register
[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 /*
25 * This module should define types *only*, all beginning with "Stg".
26 *
27 * Specifically:
28
29 StgInt8, 16, 32, 64
30 StgWord8, 16, 32, 64
31 StgChar, StgFloat, StgDouble
32
33 ***** All the same size (i.e. sizeof(void *)): *****
34 StgPtr Basic pointer type
35 StgWord Unit of heap allocation
36 StgInt Signed version of StgWord
37 StgAddr Generic address type
38
39 StgBool, StgVoid, StgPtr, StgOffset,
40 StgCode, StgStablePtr, StgFunPtr,
41 StgUnion.
42 */
43
44 /*
45 * First, platform-dependent definitions of size-specific integers.
46 */
47
48 typedef signed char StgInt8;
49 typedef unsigned char StgWord8;
50
51 typedef signed short StgInt16;
52 typedef unsigned short StgWord16;
53
54 #if SIZEOF_INT == 4
55 typedef signed int StgInt32;
56 typedef unsigned int StgWord32;
57 #define FMT_Word32 "u"
58 #define FMT_HexWord32 "x"
59 #define FMT_Int32 "d"
60 #elif SIZEOF_LONG == 4
61 typedef signed long StgInt32;
62 typedef unsigned long StgWord32;
63 #define FMT_Word32 "lu"
64 #define FMT_HexWord32 "lx"
65 #define FMT_Int32 "ld"
66 #else
67 #error GHC untested on this architecture: sizeof(int) != 4
68 #endif
69
70 #if SIZEOF_LONG == 8
71 typedef signed long StgInt64;
72 typedef unsigned long StgWord64;
73 #define FMT_Word64 "lu"
74 #define FMT_HexWord64 "lx"
75 #define FMT_Int64 "ld"
76 #elif SIZEOF_LONG_LONG == 8
77 typedef signed long long int StgInt64;
78 typedef unsigned long long int StgWord64;
79 #define FMT_Word64 "llu"
80 #define FMT_HexWord64 "llx"
81 #define FMT_Int64 "lld"
82 #else
83 #error cannot find a way to define StgInt64
84 #endif
85
86 typedef struct { StgWord64 h; StgWord64 l; } StgWord128;
87
88 typedef struct { StgWord128 h; StgWord128 l; } StgWord256;
89
90 typedef struct { StgWord256 h; StgWord256 l; } StgWord512;
91
92 /*
93 * Define the standard word size we'll use on this machine: make it
94 * big enough to hold a pointer.
95 */
96
97 #if SIZEOF_VOID_P == 8
98 typedef StgInt64 StgInt;
99 typedef StgWord64 StgWord;
100 typedef StgInt32 StgHalfInt;
101 typedef StgWord32 StgHalfWord;
102 #define FMT_Word FMT_Word64
103 #define FMT_HexWord FMT_HexWord64
104 #define FMT_Int FMT_Int64
105 #else
106 #if SIZEOF_VOID_P == 4
107 typedef StgInt32 StgInt;
108 typedef StgWord32 StgWord;
109 typedef StgInt16 StgHalfInt;
110 typedef StgWord16 StgHalfWord;
111 #define FMT_Word FMT_Word32
112 #define FMT_HexWord FMT_HexWord32
113 #define FMT_Int FMT_Int32
114 #else
115 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
116 #endif
117 #endif
118
119 #define W_MASK (sizeof(W_)-1)
120
121 /*
122 * Other commonly-used STG datatypes.
123 */
124
125 typedef void* StgAddr;
126 typedef StgWord32 StgChar;
127 typedef int StgBool;
128 typedef float StgFloat;
129 typedef double StgDouble;
130 typedef StgWord* StgPtr; /* heap or stack pointer */
131 typedef StgWord volatile* StgVolatilePtr; /* pointer to volatile word */
132 typedef StgWord StgOffset; /* byte offset within closure */
133 typedef StgWord8 StgCode; /* close enough */
134 typedef void* StgStablePtr;
135 typedef StgWord8* StgByteArray;
136
137 /*
138 Types for generated C functions when compiling via C.
139
140 The C functions take no arguments, and return a pointer to the next
141 function to be called use: Ptr to Fun that returns a Ptr to Fun
142 which returns Ptr to void
143
144 Note: Neither StgFunPtr not StgFun is quite right (that is,
145 StgFunPtr != StgFun*). So, the functions we define all have type
146 StgFun but we always have to cast them to StgFunPtr when we assign
147 them to something.
148 The only way round this would be to write a recursive type but
149 C only allows that if you're defining a struct or union.
150 */
151
152 typedef void *(*(*StgFunPtr)(void))(void);
153 typedef StgFunPtr StgFun(void);
154
155 #endif /* STGTYPES_H */