[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / compiler / nativeGen / Stix.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-1998
3 %
4
5 \begin{code}
6 module Stix (
7         CodeSegment(..), StixReg(..), StixTree(..), StixTreeList,
8         sStLitLbl,
9
10         stgBaseReg, stgNode, stgSp, stgSu, stgSpLim, stgHp, stgHpLim, stgTagReg,
11         getUniqLabelNCG,
12
13         fixedHS, arrHS
14     ) where
15
16 #include "HsVersions.h"
17
18 import Ratio            ( Rational )
19
20 import AbsCSyn          ( node, tagreg, 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 SMRep            ( fixedHdrSize, arrHdrSize )
28 import UniqSupply       ( returnUs, thenUs, getUniqueUs, UniqSM )
29 import Outputable
30 \end{code}
31
32 Here is the tag at the nodes of our @StixTree@.  Notice its
33 relationship with @PrimOp@ in prelude/PrimOp.
34
35 \begin{code}
36 data StixTree
37   = -- Segment (text or data)
38
39     StSegment CodeSegment
40
41     -- We can tag the leaves with constants/immediates.
42
43   | StInt       Integer     -- ** add Kind at some point
44   | StDouble    Rational
45   | StString    FAST_STRING
46   | StLitLbl    SDoc    -- literal labels
47                             -- (will be _-prefixed on some machines)
48   | StLitLit    FAST_STRING -- innards from CLitLit
49   | StCLbl      CLabel      -- labels that we might index into
50
51     -- Abstract registers of various kinds
52
53   | StReg StixReg
54
55     -- A typed offset from a base location
56
57   | StIndex PrimRep StixTree StixTree -- kind, base, offset
58
59     -- An indirection from an address to its contents.
60
61   | StInd PrimRep StixTree
62
63     -- Assignment is typed to determine size and register placement
64
65   | StAssign PrimRep StixTree StixTree -- dst, src
66
67     -- A simple assembly label that we might jump to.
68
69   | StLabel CLabel
70
71     -- A function header and footer
72
73   | StFunBegin CLabel
74   | StFunEnd CLabel
75
76     -- An unconditional jump. This instruction is terminal.
77     -- Dynamic targets are allowed
78
79   | StJump StixTree
80
81     -- A fall-through, from slow to fast
82
83   | StFallThrough CLabel
84
85     -- A conditional jump. This instruction can be non-terminal :-)
86     -- Only static, local, forward labels are allowed
87
88   | StCondJump CLabel StixTree
89
90     -- Raw data (as in an info table).
91
92   | StData PrimRep [StixTree]
93
94     -- Primitive Operations
95
96   | StPrim PrimOp [StixTree]
97
98     -- Calls to C functions
99
100   | StCall FAST_STRING CallConv PrimRep [StixTree]
101
102     -- Assembly-language comments
103
104   | StComment FAST_STRING
105
106 sStLitLbl :: FAST_STRING -> StixTree
107 sStLitLbl s = StLitLbl (ptext s)
108 \end{code}
109
110 Stix registers can have two forms.  They {\em may} or {\em may not}
111 map to real, machine-level registers.
112
113 \begin{code}
114 data StixReg
115   = StixMagicId MagicId -- Regs which are part of the abstract machine model
116
117   | StixTemp Unique PrimRep -- "Regs" which model local variables (CTemps) in
118                                         -- the abstract C.
119 \end{code}
120
121 We hope that every machine supports the idea of data segment and text
122 segment (or that it has no segments at all, and we can lump these
123 together).
124
125 \begin{code}
126 data CodeSegment = DataSegment | TextSegment deriving Eq
127
128 type StixTreeList = [StixTree] -> [StixTree]
129 \end{code}
130
131 Stix Trees for STG registers:
132 \begin{code}
133 stgBaseReg, stgNode, stgSp, stgSu, stgSpLim, stgHp, stgHpLim 
134         :: StixTree
135
136 stgBaseReg          = StReg (StixMagicId BaseReg)
137 stgNode             = StReg (StixMagicId node)
138 stgTagReg           = StReg (StixMagicId tagreg)
139 stgSp               = StReg (StixMagicId Sp)
140 stgSu               = StReg (StixMagicId Su)
141 stgSpLim            = StReg (StixMagicId SpLim)
142 stgHp               = StReg (StixMagicId Hp)
143 stgHpLim            = StReg (StixMagicId HpLim)
144
145 getUniqLabelNCG :: UniqSM CLabel
146 getUniqLabelNCG
147   = getUniqueUs       `thenUs` \ u ->
148     returnUs (mkAsmTempLabel u)
149
150 fixedHS = StInt (toInteger fixedHdrSize)
151 arrHS   = StInt (toInteger arrHdrSize)
152 \end{code}