2 % (c) The AQUA Project, Glasgow University, 1993-1996
6 #include "HsVersions.h"
9 CodeSegment(..), StixReg(..), StixTree(..), SYN_IE(StixTreeList),
12 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg,
13 stgSpA, stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
14 stgStdUpdRetVecReg, stgStkStubReg,
19 IMPORT_1_3(Ratio(Rational))
21 import AbsCSyn ( node, infoptr, MagicId(..) )
22 import AbsCUtils ( magicIdPrimRep )
23 import CLabel ( mkAsmTempLabel, CLabel )
24 import PrimRep ( PrimRep )
25 import PrimOp ( PrimOp )
26 import Unique ( Unique )
27 import UniqSupply ( returnUs, thenUs, getUnique, SYN_IE(UniqSM) )
28 import Pretty ( ptext, Doc )
31 Here is the tag at the nodes of our @StixTree@. Notice its
32 relationship with @PrimOp@ in prelude/PrimOp.
36 = -- Segment (text or data)
40 -- We can tag the leaves with constants/immediates.
42 | StInt Integer -- ** add Kind at some point
44 | StString FAST_STRING
45 | StLitLbl Doc -- literal labels
46 -- (will be _-prefixed on some machines)
47 | StLitLit FAST_STRING -- innards from CLitLit
48 | StCLbl CLabel -- labels that we might index into
50 -- Abstract registers of various kinds
54 -- A typed offset from a base location
56 | StIndex PrimRep StixTree StixTree -- kind, base, offset
58 -- An indirection from an address to its contents.
60 | StInd PrimRep StixTree
62 -- Assignment is typed to determine size and register placement
64 | StAssign PrimRep StixTree StixTree -- dst, src
66 -- A simple assembly label that we might jump to.
70 -- A function header and footer
75 -- An unconditional jump. This instruction is terminal.
76 -- Dynamic targets are allowed
80 -- A fall-through, from slow to fast
82 | StFallThrough CLabel
84 -- A conditional jump. This instruction can be non-terminal :-)
85 -- Only static, local, forward labels are allowed
87 | StCondJump CLabel StixTree
89 -- Raw data (as in an info table).
91 | StData PrimRep [StixTree]
93 -- Primitive Operations
95 | StPrim PrimOp [StixTree]
97 -- Calls to C functions
99 | StCall FAST_STRING PrimRep [StixTree]
101 -- Assembly-language comments
103 | StComment FAST_STRING
105 sStLitLbl :: FAST_STRING -> StixTree
106 sStLitLbl s = StLitLbl (ptext s)
109 Stix registers can have two forms. They {\em may} or {\em may not}
110 map to real, machine-level registers.
114 = StixMagicId MagicId -- Regs which are part of the abstract machine model
116 | StixTemp Unique PrimRep -- "Regs" which model local variables (CTemps) in
120 We hope that every machine supports the idea of data segment and text
121 segment (or that it has no segments at all, and we can lump these
125 data CodeSegment = DataSegment | TextSegment deriving Eq
127 type StixTreeList = [StixTree] -> [StixTree]
130 Stix Trees for STG registers:
132 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg, stgSpA,
133 stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
134 stgStdUpdRetVecReg, stgStkStubReg :: StixTree
136 stgBaseReg = StReg (StixMagicId BaseReg)
137 stgStkOReg = StReg (StixMagicId StkOReg)
138 stgNode = StReg (StixMagicId node)
139 stgInfoPtr = StReg (StixMagicId infoptr)
140 stgTagReg = StReg (StixMagicId TagReg)
141 stgRetReg = StReg (StixMagicId RetReg)
142 stgSpA = StReg (StixMagicId SpA)
143 stgSuA = StReg (StixMagicId SuA)
144 stgSpB = StReg (StixMagicId SpB)
145 stgSuB = StReg (StixMagicId SuB)
146 stgHp = StReg (StixMagicId Hp)
147 stgHpLim = StReg (StixMagicId HpLim)
148 stgLivenessReg = StReg (StixMagicId LivenessReg)
149 stgStdUpdRetVecReg = StReg (StixMagicId StdUpdRetVecReg)
150 stgStkStubReg = StReg (StixMagicId StkStubReg)
152 getUniqLabelNCG :: UniqSM CLabel
154 = getUnique `thenUs` \ u ->
155 returnUs (mkAsmTempLabel u)