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