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