2 % (c) The AQUA Project, Glasgow University, 1993-1995
6 #include "HsVersions.h"
9 CodeSegment(..), StixReg(..), StixTree(..), StixTreeList(..),
12 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg,
13 stgSpA, stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
14 stgActivityReg, stgStdUpdRetVecReg, stgStkStubReg,
17 -- And for self-sufficiency, by golly...
18 MagicId, CLabel, PrimKind, PrimOp, Unique,
19 SplitUniqSupply, SUniqSM(..)
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)
27 import CLabelInfo ( CLabel, mkAsmTempLabel )
29 import PrimKind ( PrimKind(..) )
36 Here is the tag at the nodes of our @StixTree@. Notice its
37 relationship with @PrimOp@ in prelude/PrimOps.
43 -- Segment (text or data)
47 -- We can tag the leaves with constants/immediates.
49 | StInt Integer -- ** add Kind at some point
50 #if __GLASGOW_HASKELL__ <= 22
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
60 -- Abstract registers of various kinds
64 -- A typed offset from a base location
66 | StIndex PrimKind StixTree StixTree -- kind, base, offset
68 -- An indirection from an address to its contents.
70 | StInd PrimKind StixTree
72 -- Assignment is typed to determine size and register placement
74 | StAssign PrimKind StixTree StixTree -- dst, src
76 -- A simple assembly label that we might jump to.
80 -- A function header and footer
85 -- An unconditional jump. This instruction is terminal.
86 -- Dynamic targets are allowed
90 -- A fall-through, from slow to fast
92 | StFallThrough CLabel
94 -- A conditional jump. This instruction can be non-terminal :-)
95 -- Only static, local, forward labels are allowed
97 | StCondJump CLabel StixTree
99 -- Raw data (as in an info table).
101 | StData PrimKind [StixTree]
103 -- Primitive Operations
105 | StPrim PrimOp [StixTree]
107 -- Calls to C functions
109 | StCall FAST_STRING PrimKind [StixTree]
111 -- Comments, of course
113 | StComment FAST_STRING -- For assembly comments
117 sStLitLbl :: FAST_STRING -> StixTree
118 sStLitLbl s = StLitLbl (uppPStr s)
121 Stix registers can have two forms. They {\em may} or {\em may not}
122 map to real, machine level registers.
126 data StixReg = StixMagicId MagicId -- Regs which are part of the abstract machine model
128 | StixTemp Unique PrimKind -- "Regs" which model local variables (CTemps) in
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).
139 data CodeSegment = DataSegment | TextSegment deriving (Eq)
141 type StixTreeList = [StixTree] -> [StixTree]
145 -- Stix Trees for STG registers
149 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg, stgSpA, stgSuA,
150 stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg, stgActivityReg, stgStdUpdRetVecReg,
151 stgStkStubReg :: StixTree
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)
170 getUniqLabelNCG :: SUniqSM CLabel
172 getSUnique `thenSUs` \ u ->
173 returnSUs (mkAsmTempLabel u)