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