-instance Outputable Literal where
- ppr sty (MachChar ch)
- = let
- char_encoding
- = case sty of
- PprForC -> charToC ch
- PprForAsm _ _ -> charToC ch
- PprUnfolding -> charToEasyHaskell ch
- _ -> [ch]
- in
- ppBeside (ppBesides [ppCast sty SLIT("(C_)"), ppChar '\'', ppStr char_encoding, ppChar '\''])
- (if_ubxd sty)
-
- ppr sty (MachStr s)
- = ppBeside (if codeStyle sty
- then ppBesides [ppChar '"', ppStr (stringToC (_UNPK_ s)), ppChar '"']
- else ppStr (show (_UNPK_ s)))
- (if_ubxd sty)
-
- ppr sty (MachAddr p) = ppBesides [ppCast sty SLIT("(void*)"), ppInteger p, if_ubxd sty]
- ppr sty (MachInt i signed)
- | codeStyle sty
- && ((signed && (i >= toInteger minInt && i <= toInteger maxInt))
- || (not signed && (i >= toInteger 0 && i <= toInteger maxInt)))
- -- ToDo: Think about these ranges!
- = ppBesides [ppInteger i, if_ubxd sty]
-
- | not (codeStyle sty) -- we'd prefer the code to the error message
- = ppBesides [ppInteger i, if_ubxd sty]
-
- | otherwise
- = error ("ERROR: Int " ++ show i ++ " out of range [" ++
- show range_min ++ " .. " ++ show maxInt ++ "]\n")
- where
- range_min = if signed then minInt else 0
-
- ppr sty (MachFloat f) = ppBesides [ppCast sty SLIT("(StgFloat)"), ppRational f, if_ubxd sty]
- ppr sty (MachDouble d) = ppBesides [ppRational d, if_ubxd sty, if_ubxd sty]
-
- ppr sty (NoRepInteger i _)
- | codeStyle sty = ppInteger i
- | ufStyle sty = ppCat [ppStr "_NOREP_I_", ppInteger i]
- | otherwise = ppBesides [ppInteger i, ppChar 'I']
-
- ppr sty (NoRepRational r _)
- | ufStyle sty = ppCat [ppStr "_NOREP_R_", ppInteger (numerator r), ppInteger (denominator r)]
- | codeStyle sty = panic "ppr.ForC.NoRepRational"
- | otherwise = ppBesides [ppRational r, ppChar 'R']
-
- ppr sty (NoRepStr s)
- | codeStyle sty = ppBesides [ppStr (show (_UNPK_ s))]
- | ufStyle sty = ppCat [ppStr "_NOREP_S_", ppStr (show (_UNPK_ s))]
- | otherwise = ppBesides [ppStr (show (_UNPK_ s)), ppChar 'S']
-
- ppr sty (MachLitLit s k)
- | codeStyle sty = ppPStr s
- | ufStyle sty = ppBesides [ppStr "``", ppPStr s, ppStr "'' _K_ ", ppr sty k]
- | otherwise = ppBesides [ppStr "``", ppPStr s, ppStr "''"]
-
-ufStyle PprUnfolding = True
-ufStyle _ = False
-
-if_ubxd sty = if codeStyle sty then ppNil else ppChar '#'
-
-showLiteral :: PprStyle -> Literal -> String
-
-showLiteral sty lit = ppShow 80 (ppr sty lit)
+
+%************************************************************************
+%* *
+\subsection{Hashing}
+%* *
+%************************************************************************
+
+Hash values should be zero or a positive integer. No negatives please.
+(They mess up the UniqFM for some reason.)
+
+\begin{code}
+hashLiteral :: Literal -> Int
+hashLiteral (MachChar c) = ord c + 1000 -- Keep it out of range of common ints
+hashLiteral (MachStr s) = hashFS s
+hashLiteral (MachNullAddr) = 0
+hashLiteral (MachInt i) = hashInteger i
+hashLiteral (MachInt64 i) = hashInteger i
+hashLiteral (MachWord i) = hashInteger i
+hashLiteral (MachWord64 i) = hashInteger i
+hashLiteral (MachFloat r) = hashRational r
+hashLiteral (MachDouble r) = hashRational r
+hashLiteral (MachLabel s _) = hashFS s
+
+hashRational :: Rational -> Int
+hashRational r = hashInteger (numerator r)
+
+hashInteger :: Integer -> Int
+hashInteger i = 1 + abs (fromInteger (i `rem` 10000))
+ -- The 1+ is to avoid zero, which is a Bad Number
+ -- since we use * to combine hash values
+
+hashFS :: FastString -> Int
+hashFS s = iBox (uniqueOfFS s)