Fix missing import in HscMain.
[ghc.git] / compiler / nativeGen / PprBase.hs
1 -----------------------------------------------------------------------------
2 --
3 -- Pretty-printing assembly language
4 --
5 -- (c) The University of Glasgow 1993-2005
6 --
7 -----------------------------------------------------------------------------
8
9 {-# OPTIONS -fno-warn-tabs #-}
10 -- The above warning supression flag is a temporary kludge.
11 -- While working on this module you are encouraged to remove it and
12 -- detab the module (please do the detabbing in a separate patch). See
13 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
14 -- for details
15
16 module PprBase (
17 asmSDoc,
18 pprCLabel_asm,
19 castFloatToWord8Array,
20 castDoubleToWord8Array,
21 floatToBytes,
22 doubleToBytes
23 )
24
25 where
26
27 import qualified Outputable
28 import Platform
29 import CLabel
30 import Pretty
31
32 -- castSTUArray has moved to Data.Array.Unsafe
33 #if __GLASGOW_HASKELL__ >= 703
34 import Data.Array.Unsafe( castSTUArray )
35 import Data.Array.ST hiding( castSTUArray )
36 #else
37 import Data.Array.ST
38 #endif
39
40 import Control.Monad.ST
41
42 import Data.Word
43
44
45
46 asmSDoc :: Outputable.SDoc -> Doc
47 asmSDoc d
48 = Outputable.withPprStyleDoc (Outputable.mkCodeStyle Outputable.AsmStyle) d
49
50
51 pprCLabel_asm :: Platform -> CLabel -> Doc
52 pprCLabel_asm platform l
53 = asmSDoc (pprCLabel platform l)
54
55
56 -- -----------------------------------------------------------------------------
57 -- Converting floating-point literals to integrals for printing
58
59 castFloatToWord8Array :: STUArray s Int Float -> ST s (STUArray s Int Word8)
60 castFloatToWord8Array = castSTUArray
61
62 castDoubleToWord8Array :: STUArray s Int Double -> ST s (STUArray s Int Word8)
63 castDoubleToWord8Array = castSTUArray
64
65 -- floatToBytes and doubleToBytes convert to the host's byte
66 -- order. Providing that we're not cross-compiling for a
67 -- target with the opposite endianness, this should work ok
68 -- on all targets.
69
70 -- ToDo: this stuff is very similar to the shenanigans in PprAbs,
71 -- could they be merged?
72
73 floatToBytes :: Float -> [Int]
74 floatToBytes f
75 = runST (do
76 arr <- newArray_ ((0::Int),3)
77 writeArray arr 0 f
78 arr <- castFloatToWord8Array arr
79 i0 <- readArray arr 0
80 i1 <- readArray arr 1
81 i2 <- readArray arr 2
82 i3 <- readArray arr 3
83 return (map fromIntegral [i0,i1,i2,i3])
84 )
85
86 doubleToBytes :: Double -> [Int]
87 doubleToBytes d
88 = runST (do
89 arr <- newArray_ ((0::Int),7)
90 writeArray arr 0 d
91 arr <- castDoubleToWord8Array arr
92 i0 <- readArray arr 0
93 i1 <- readArray arr 1
94 i2 <- readArray arr 2
95 i3 <- readArray arr 3
96 i4 <- readArray arr 4
97 i5 <- readArray arr 5
98 i6 <- readArray arr 6
99 i7 <- readArray arr 7
100 return (map fromIntegral [i0,i1,i2,i3,i4,i5,i6,i7])
101 )