Merge in new code generator branch.
[ghc-hetmet.git] / compiler / nativeGen / Size.hs
1 -- | Sizes on this architecture
2 --      A Size is a combination of width and class
3 -- 
4 --      TODO:   Rename this to "Format" instead of "Size" to reflect
5 --              the fact that it represents floating point vs integer.
6 --
7 --      TODO:   Signed vs unsigned?
8 --
9 --      TODO:   This module is currenly shared by all architectures because
10 --              NCGMonad need to know about it to make a VReg. It would be better
11 --              to have architecture specific formats, and do the overloading
12 --              properly. eg SPARC doesn't care about FF80.
13 --
14 module Size (
15         Size(..),
16         intSize,
17         floatSize,
18         isFloatSize,
19         cmmTypeSize,
20         sizeToWidth
21 )
22
23 where
24
25 import OldCmm
26 import Outputable
27
28 -- It looks very like the old MachRep, but it's now of purely local
29 -- significance, here in the native code generator.  You can change it
30 -- without global consequences.
31 --
32 -- A major use is as an opcode qualifier; thus the opcode 
33 --      mov.l a b
34 -- might be encoded 
35 --      MOV II32 a b
36 -- where the Size field encodes the ".l" part.
37
38 -- ToDo: it's not clear to me that we need separate signed-vs-unsigned sizes
39 --        here.  I've removed them from the x86 version, we'll see what happens --SDM
40
41 -- ToDo: quite a few occurrences of Size could usefully be replaced by Width
42
43 data Size
44         = II8 
45         | II16 
46         | II32 
47         | II64 
48         | FF32 
49         | FF64 
50         | FF80
51         deriving (Show, Eq)
52
53
54 -- | Get the integer size of this width.
55 intSize :: Width -> Size
56 intSize width
57  = case width of
58         W8      -> II8
59         W16     -> II16
60         W32     -> II32
61         W64     -> II64
62         other   -> pprPanic "Size.intSize" (ppr other)
63
64
65 -- | Get the float size of this width.
66 floatSize :: Width -> Size
67 floatSize width
68  = case width of
69         W32     -> FF32
70         W64     -> FF64
71         other   -> pprPanic "Size.floatSize" (ppr other)
72
73
74 -- | Check if a size represents a floating point value.
75 isFloatSize :: Size -> Bool
76 isFloatSize size
77  = case size of
78         FF32    -> True
79         FF64    -> True
80         FF80    -> True
81         _       -> False
82
83
84 -- | Convert a Cmm type to a Size.
85 cmmTypeSize :: CmmType -> Size
86 cmmTypeSize ty 
87         | isFloatType ty        = floatSize (typeWidth ty)
88         | otherwise             = intSize (typeWidth ty)
89
90
91 -- | Get the Width of a Size.
92 sizeToWidth :: Size -> Width
93 sizeToWidth size
94  = case size of
95         II8             -> W8
96         II16            -> W16
97         II32            -> W32
98         II64            -> W64
99         FF32            -> W32
100         FF64            -> W64
101         FF80            -> W80
102         
103