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 )
24 import UniqSupply ( returnUs, thenUs, getUnique, SYN_IE(UniqSM) )
25 import Unpretty ( uppPStr, SYN_IE(Unpretty) )
28 Here is the tag at the nodes of our @StixTree@. Notice its
29 relationship with @PrimOp@ in prelude/PrimOp.
33 = -- Segment (text or data)
37 -- We can tag the leaves with constants/immediates.
39 | StInt Integer -- ** add Kind at some point
41 | StString FAST_STRING
42 | StLitLbl Unpretty -- literal labels
43 -- (will be _-prefixed on some machines)
44 | StLitLit FAST_STRING -- innards from CLitLit
45 | StCLbl CLabel -- labels that we might index into
47 -- Abstract registers of various kinds
51 -- A typed offset from a base location
53 | StIndex PrimRep StixTree StixTree -- kind, base, offset
55 -- An indirection from an address to its contents.
57 | StInd PrimRep StixTree
59 -- Assignment is typed to determine size and register placement
61 | StAssign PrimRep StixTree StixTree -- dst, src
63 -- A simple assembly label that we might jump to.
67 -- A function header and footer
72 -- An unconditional jump. This instruction is terminal.
73 -- Dynamic targets are allowed
77 -- A fall-through, from slow to fast
79 | StFallThrough CLabel
81 -- A conditional jump. This instruction can be non-terminal :-)
82 -- Only static, local, forward labels are allowed
84 | StCondJump CLabel StixTree
86 -- Raw data (as in an info table).
88 | StData PrimRep [StixTree]
90 -- Primitive Operations
92 | StPrim PrimOp [StixTree]
94 -- Calls to C functions
96 | StCall FAST_STRING PrimRep [StixTree]
98 -- Assembly-language comments
100 | StComment FAST_STRING
102 sStLitLbl :: FAST_STRING -> StixTree
103 sStLitLbl s = StLitLbl (uppPStr s)
106 Stix registers can have two forms. They {\em may} or {\em may not}
107 map to real, machine-level registers.
111 = StixMagicId MagicId -- Regs which are part of the abstract machine model
113 | StixTemp Unique PrimRep -- "Regs" which model local variables (CTemps) in
117 We hope that every machine supports the idea of data segment and text
118 segment (or that it has no segments at all, and we can lump these
122 data CodeSegment = DataSegment | TextSegment deriving Eq
124 type StixTreeList = [StixTree] -> [StixTree]
127 Stix Trees for STG registers:
129 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg, stgSpA,
130 stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
131 stgStdUpdRetVecReg, stgStkStubReg :: StixTree
133 stgBaseReg = StReg (StixMagicId BaseReg)
134 stgStkOReg = StReg (StixMagicId StkOReg)
135 stgNode = StReg (StixMagicId node)
136 stgInfoPtr = StReg (StixMagicId infoptr)
137 stgTagReg = StReg (StixMagicId TagReg)
138 stgRetReg = StReg (StixMagicId RetReg)
139 stgSpA = StReg (StixMagicId SpA)
140 stgSuA = StReg (StixMagicId SuA)
141 stgSpB = StReg (StixMagicId SpB)
142 stgSuB = StReg (StixMagicId SuB)
143 stgHp = StReg (StixMagicId Hp)
144 stgHpLim = StReg (StixMagicId HpLim)
145 stgLivenessReg = StReg (StixMagicId LivenessReg)
146 stgStdUpdRetVecReg = StReg (StixMagicId StdUpdRetVecReg)
147 stgStkStubReg = StReg (StixMagicId StkStubReg)
149 getUniqLabelNCG :: UniqSM CLabel
151 = getUnique `thenUs` \ u ->
152 returnUs (mkAsmTempLabel u)