[project @ 1996-03-26 17:10:41 by simonm]
[ghc-hetmet.git] / ghc / compiler / nativeGen / MachDesc.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-1995
3 %
4
5 Machine- and flag- specific bits that the abstract code generator has
6 to know about.
7
8 No doubt there will be more...
9
10 \begin{code}
11 #include "HsVersions.h"
12
13 module MachDesc (
14         Target(..){-(..) for target_STRICT only-}, mkTarget, RegLoc(..),
15
16         saveLoc,
17
18         fixedHeaderSize, varHeaderSize, stgReg,
19         sizeof, volatileSaves, volatileRestores, hpRel,
20         amodeToStix, amodeToStix', charLikeClosureSize,
21         intLikeClosureSize, mutHS, dataHS, primToStix, macroCode,
22         heapCheck
23
24         -- and, for self-sufficiency...
25     ) where
26
27 import AbsCSyn
28 import CmdLineOpts  ( GlobalSwitch(..), stringSwitchSet, switchIsOn, SwitchResult(..) )
29 import Outputable
30 import OrdList      ( OrdList )
31 import SMRep        ( SMRep )
32 import Stix
33 import UniqSupply
34 import Unique
35 import Unpretty     ( PprStyle, CSeq )
36 import Util
37
38 data RegLoc = Save StixTree | Always StixTree
39 \end{code}
40
41 Think of this as a big runtime class dictionary:
42 \begin{code}
43 data Target = Target
44     Int                                 -- fixedHeaderSize
45     (SMRep -> Int)                      -- varHeaderSize
46     (MagicId -> RegLoc)                 -- stgReg
47     (PrimRep -> Int)                    -- sizeof
48     (HeapOffset -> Int)                 -- hpRel
49     (CAddrMode -> StixTree)             -- amodeToStix
50     (CAddrMode -> StixTree)             -- amodeToStix'
51     (
52     ([MagicId] -> [StixTree]),          -- volatileSaves
53     ([MagicId] -> [StixTree]),          -- volatileRestores
54     Int,                                -- charLikeClosureSize
55     Int,                                -- intLikeClosureSize
56     StixTree,                           -- mutHS
57     StixTree,                           -- dataHS
58     ([CAddrMode] -> PrimOp -> [CAddrMode] -> UniqSM StixTreeList),
59                                         -- primToStix
60     (CStmtMacro -> [CAddrMode] -> UniqSM StixTreeList),
61                                         -- macroCode
62     (StixTree -> StixTree -> StixTree -> UniqSM StixTreeList)
63                                         -- heapCheck
64     )
65
66 mkTarget = Target
67
68 fixedHeaderSize (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) = fhs
69 varHeaderSize (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = vhs x
70 stgReg (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = reg x
71 sizeof (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = size x
72 -- used only for wrapper-hungry PrimOps:
73 hpRel (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = hprel x
74 amodeToStix (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = am x
75 amodeToStix' (Target fhs vhs reg size hprel am am' ~(vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = am' x
76
77 volatileSaves (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = vsave x
78 -- used only for wrapper-hungry PrimOps:
79 volatileRestores (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x = vrest x
80 charLikeClosureSize (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) = csz
81 intLikeClosureSize (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) = isz
82 mutHS (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) = mhs
83 dataHS (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) = dhs
84 primToStix (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x y z = ps x y z
85 macroCode (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x y = mc x y
86 heapCheck (Target fhs vhs reg size hprel am am' (vsave, vrest, csz, isz, mhs, dhs, ps, mc, hc) ) x y z = hc x y z
87 \end{code}
88
89 Trees for register save locations
90 \begin{code}
91 saveLoc :: Target -> MagicId -> StixTree
92
93 saveLoc target reg = case stgReg target reg of {Always loc -> loc; Save loc -> loc}
94 \end{code}
95