[project @ 1996-06-30 15:56:44 by partain]
[ghc-hetmet.git] / ghc / compiler / nativeGen / Stix.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-1996
3 %
4
5 \begin{code}
6 #include "HsVersions.h"
7
8 module Stix (
9         CodeSegment(..), StixReg(..), StixTree(..), SYN_IE(StixTreeList),
10         sStLitLbl,
11
12         stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg,
13         stgSpA, stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
14         stgStdUpdRetVecReg, stgStkStubReg,
15         getUniqLabelNCG
16     ) where
17
18 IMP_Ubiq(){-uitous-}
19 IMPORT_1_3(Ratio(Rational))
20
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) )
26 \end{code}
27
28 Here is the tag at the nodes of our @StixTree@.  Notice its
29 relationship with @PrimOp@ in prelude/PrimOp.
30
31 \begin{code}
32 data StixTree
33   = -- Segment (text or data)
34
35     StSegment CodeSegment
36
37     -- We can tag the leaves with constants/immediates.
38
39   | StInt       Integer     -- ** add Kind at some point
40   | StDouble    Rational
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
46
47     -- Abstract registers of various kinds
48
49   | StReg StixReg
50
51     -- A typed offset from a base location
52
53   | StIndex PrimRep StixTree StixTree -- kind, base, offset
54
55     -- An indirection from an address to its contents.
56
57   | StInd PrimRep StixTree
58
59     -- Assignment is typed to determine size and register placement
60
61   | StAssign PrimRep StixTree StixTree -- dst, src
62
63     -- A simple assembly label that we might jump to.
64
65   | StLabel CLabel
66
67     -- A function header and footer
68
69   | StFunBegin CLabel
70   | StFunEnd CLabel
71
72     -- An unconditional jump. This instruction is terminal.
73     -- Dynamic targets are allowed
74
75   | StJump StixTree
76
77     -- A fall-through, from slow to fast
78
79   | StFallThrough CLabel
80
81     -- A conditional jump. This instruction can be non-terminal :-)
82     -- Only static, local, forward labels are allowed
83
84   | StCondJump CLabel StixTree
85
86     -- Raw data (as in an info table).
87
88   | StData PrimRep [StixTree]
89
90     -- Primitive Operations
91
92   | StPrim PrimOp [StixTree]
93
94     -- Calls to C functions
95
96   | StCall FAST_STRING PrimRep [StixTree]
97
98     -- Assembly-language comments
99
100   | StComment FAST_STRING
101
102 sStLitLbl :: FAST_STRING -> StixTree
103 sStLitLbl s = StLitLbl (uppPStr s)
104 \end{code}
105
106 Stix registers can have two forms.  They {\em may} or {\em may not}
107 map to real, machine-level registers.
108
109 \begin{code}
110 data StixReg
111   = StixMagicId MagicId -- Regs which are part of the abstract machine model
112
113   | StixTemp Unique PrimRep -- "Regs" which model local variables (CTemps) in
114                                         -- the abstract C.
115 \end{code}
116
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
119 together).
120
121 \begin{code}
122 data CodeSegment = DataSegment | TextSegment deriving Eq
123
124 type StixTreeList = [StixTree] -> [StixTree]
125 \end{code}
126
127 Stix Trees for STG registers:
128 \begin{code}
129 stgBaseReg, stgStkOReg, stgNode, stgTagReg, stgRetReg, stgSpA,
130     stgSuA, stgSpB, stgSuB, stgHp, stgHpLim, stgLivenessReg,
131     stgStdUpdRetVecReg, stgStkStubReg :: StixTree
132
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)
148
149 getUniqLabelNCG :: UniqSM CLabel
150 getUniqLabelNCG
151   = getUnique         `thenUs` \ u ->
152     returnUs (mkAsmTempLabel u)
153 \end{code}