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