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