[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / includes / StgDirections.h
1 #ifndef STGDIRECTION_H
2 #define STGDIRECTION_H
3
4 /* Here's where we hide things about heap and stack directions.
5
6    NB: The call to "setNewHeapUsage 0 words_required" in CgClosure in
7    the code generator is also direction-sensitive.
8 */
9
10 /* for now --
11     heap:       grows upwards
12     A stack:    grows downwards
13     B stack:    grows upwards
14 */
15
16 /*      ALL THE ARITHMETIC IN HERE IS IN UNITS OF WORDS         */
17
18
19 /****************************************************************
20 *                                                               *
21 *               Heapery                                         *
22 *                                                               *
23 * ***************************************************************/
24
25 /*      HEAP_FRAME_BASE( low-addr, size ) gives the address of the
26         first word to be allocated in the heap space 
27         starting at address low-addr.  size is in words.
28
29         HEAP_FRAME_LIMIT( low-addr, size ) gives the address of the
30         last word to be allocated.
31 */
32 #define HEAP_FRAME_BASE(space,size)     (space)
33 #define HEAP_FRAME_LIMIT(space,size)    (((P_) (space)) + (size) - 1)
34
35
36 /*      Hp + HREL(n) addresses the n'th word into already-allocated space
37         from Hp.  n=0 addresses the ``most recently allocated'' word.
38
39 OBSOLETE BECAUSE WE'VE FIXED THE DIRECTION OF HEAP GROWTH (upwards)
40
41 #define HREL(offset)    (-(offset))
42 */
43
44
45
46 /*      HEAP_OVERFLOW_OP( heap-ptr, heap-limit ) is true if the heap has
47         overflowed.
48 */
49 #define HEAP_OVERFLOW_OP(a,hplim) ((a) > (hplim))
50
51
52 /****************************************************************
53 *                                                               *
54 *               Stackery                                        *
55 *                                                               *
56 * ***************************************************************/
57
58 /*      STK_A_FRAME_BASE( low-addr, size ) gives the address of the bottom-most
59         word of A stack, given that A and B stack are to be allocated 
60         from a block of store starting at low-addr.  size is in words
61
62         STK_B_FRAME_BASE( low-addr, size) does the same for B stack
63 */
64 #define STK_A_FRAME_BASE(space,size)    (((PP_) (space)) + (size) - 1)
65 #define STK_B_FRAME_BASE(space,size)    (space)
66
67
68 /*      SpA + AREL(n) addresses the n'th word from the top of A stack
69                         (0'th is top one)
70         Similarly BREL 
71 */
72 #define AREL(offset)    (offset)
73 #define BREL(offset)    (-(offset))
74
75
76 /*      STKS_OVERFLOW_OP( a-stack-space, b-stack-space ) is true if SpA and SpB
77         have collided.
78
79         We cast SpA to StgPtr, because it is normally an StgPtrPtr.
80 */
81 #define STKS_OVERFLOW_OP(a,b) ((P_)(SpA) - AREL((a) + (b)) <= SpB)
82
83 /*      And a version that generates slightly-worse
84         code, but which does not need to know about
85         SpA and SpB (used in RTS)
86 */
87 #define UNREG_STKS_OVERFLOW_OP(a,b) ((P_)(a) <= (b))
88
89 #endif /* ! STGDIRECTION_H */