[project @ 1996-01-11 14:06:51 by partain]
[ghc-hetmet.git] / ghc / compiler / nativeGen / Stix.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-1995
3 %
4
5 \begin{code}
6 #include "HsVersions.h"
7
8 module Stix (
9         CodeSegment(..), StixReg(..), StixTree(..), StixTreeList(..),
10         sStLitLbl,
11
12         stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg, 
13         stgSpA, stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
14 --      stgActivityReg,
15         stgStdUpdRetVecReg, stgStkStubReg,
16         getUniqLabelNCG,
17
18         -- And for self-sufficiency, by golly...
19         MagicId, CLabel, PrimKind, PrimOp, Unique,
20         SplitUniqSupply, SUniqSM(..)
21     ) where
22
23 import AbsCSyn      ( MagicId(..), kindFromMagicId, node, infoptr )
24 import AbsPrel      ( showPrimOp, PrimOp
25                       IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
26                           IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
27                     )
28 import CLabelInfo   ( CLabel, mkAsmTempLabel )
29 import Outputable
30 import PrimKind     ( PrimKind(..) )
31 import SplitUniq
32 import Unique
33 import Unpretty 
34 import Util
35 \end{code}
36
37 Here is the tag at the nodes of our @StixTree@.  Notice its
38 relationship with @PrimOp@ in prelude/PrimOps.
39
40 \begin{code}
41
42 data StixTree =
43
44         -- Segment (text or data)
45
46         StSegment CodeSegment
47
48         -- We can tag the leaves with constants/immediates.
49
50       | StInt     Integer      -- ** add Kind at some point
51 #if __GLASGOW_HASKELL__ <= 22
52       | StDouble  Double
53 #else
54       | StDouble  Rational
55 #endif
56       | StString  FAST_STRING
57       | StLitLbl  Unpretty      -- literal labels (will be _-prefixed on some machines)
58       | StLitLit  FAST_STRING   -- innards from CLitLit
59       | StCLbl    CLabel        -- labels that we might index into
60
61         -- Abstract registers of various kinds
62
63       | StReg StixReg
64
65         -- A typed offset from a base location
66
67       | StIndex PrimKind StixTree StixTree -- kind, base, offset
68
69         -- An indirection from an address to its contents.
70
71       | StInd PrimKind StixTree
72
73         -- Assignment is typed to determine size and register placement
74
75       | StAssign PrimKind StixTree StixTree -- dst, src
76
77         -- A simple assembly label that we might jump to.
78
79       | StLabel CLabel
80
81         -- A function header and footer
82
83       | StFunBegin CLabel
84       | StFunEnd CLabel
85
86         -- An unconditional jump. This instruction is terminal.
87         -- Dynamic targets are allowed
88
89       | StJump StixTree
90
91         -- A fall-through, from slow to fast
92
93       | StFallThrough CLabel
94
95         -- A conditional jump.  This instruction can be non-terminal :-)
96         -- Only static, local, forward labels are allowed
97
98       | StCondJump CLabel StixTree
99
100         -- Raw data (as in an info table).
101
102       | StData PrimKind [StixTree]
103
104         -- Primitive Operations
105
106       | StPrim PrimOp [StixTree]
107
108         -- Calls to C functions
109
110       | StCall FAST_STRING PrimKind [StixTree]
111
112         -- Comments, of course
113
114       | StComment FAST_STRING   -- For assembly comments
115
116       deriving ()
117
118 sStLitLbl :: FAST_STRING -> StixTree
119 sStLitLbl s = StLitLbl (uppPStr s)
120 \end{code}
121
122 Stix registers can have two forms.  They {\em may} or {\em may not}
123 map to real, machine level registers.
124
125 \begin{code}
126
127 data StixReg = StixMagicId MagicId      -- Regs which are part of the abstract machine model
128
129              | StixTemp Unique PrimKind -- "Regs" which model local variables (CTemps) in
130                                         -- the abstract C.
131              deriving ()
132
133 \end{code}
134
135 We hope that every machine supports the idea of data segment and text
136 segment (or that it has no segments at all, and we can lump these together).
137
138 \begin{code}
139
140 data CodeSegment = DataSegment | TextSegment deriving (Eq)
141
142 type StixTreeList = [StixTree] -> [StixTree]
143
144 \end{code}
145
146 -- Stix Trees for STG registers
147
148 \begin{code}
149
150 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg, stgSpA, stgSuA,
151     stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg{-, stgActivityReg-}, stgStdUpdRetVecReg,
152     stgStkStubReg :: StixTree
153
154 stgBaseReg = StReg (StixMagicId BaseReg)
155 stgStkOReg = StReg (StixMagicId StkOReg)
156 stgNode = StReg (StixMagicId node)
157 stgInfoPtr = StReg (StixMagicId infoptr)
158 stgTagReg = StReg (StixMagicId TagReg)
159 stgRetReg = StReg (StixMagicId RetReg)
160 stgSpA = StReg (StixMagicId SpA)
161 stgSuA = StReg (StixMagicId SuA)
162 stgSpB = StReg (StixMagicId SpB)
163 stgSuB = StReg (StixMagicId SuB)
164 stgHp = StReg (StixMagicId Hp)
165 stgHpLim = StReg (StixMagicId HpLim)
166 stgLivenessReg = StReg (StixMagicId LivenessReg)
167 --stgActivityReg = StReg (StixMagicId ActivityReg)
168 stgStdUpdRetVecReg = StReg (StixMagicId StdUpdRetVecReg)
169 stgStkStubReg = StReg (StixMagicId StkStubReg)
170
171 getUniqLabelNCG :: SUniqSM CLabel
172 getUniqLabelNCG = 
173       getSUnique              `thenSUs` \ u ->
174       returnSUs (mkAsmTempLabel u)
175
176 \end{code}