Merge branch 'master' of http://darcs.haskell.org/ghc
[ghc-hetmet.git] / compiler / basicTypes / Literal.lhs
index a03e1c1..da8685e 100644 (file)
@@ -27,6 +27,7 @@ module Literal
        -- ** Operations on Literals
        , literalType
        , hashLiteral
+        , absentLiteralOf
 
         -- ** Predicates on Literals and their contents
        , litIsDupable, litIsTrivial
@@ -44,19 +45,21 @@ module Literal
        ) where
 
 import TysPrim
+import PrelNames
 import Type
+import TyCon
 import Outputable
 import FastTypes
 import FastString
 import BasicTypes
 import Binary
 import Constants
-
+import UniqFM
 import Data.Int
 import Data.Ratio
 import Data.Word
 import Data.Char
-import Data.Data
+import Data.Data( Data, Typeable )
 \end{code}
 
 
@@ -326,6 +329,21 @@ literalType (MachWord64  _) = word64PrimTy
 literalType (MachFloat _)   = floatPrimTy
 literalType (MachDouble _)  = doublePrimTy
 literalType (MachLabel _ _ _) = addrPrimTy
+
+absentLiteralOf :: TyCon -> Maybe Literal
+-- Return a literal of the appropriate primtive
+-- TyCon, to use as a placeholder when it doesn't matter
+absentLiteralOf tc = lookupUFM absent_lits (tyConName tc)
+
+absent_lits :: UniqFM Literal
+absent_lits = listToUFM [ (addrPrimTyConKey,    MachNullAddr)
+                       , (charPrimTyConKey,    MachChar 'x')
+                       , (intPrimTyConKey,     MachInt 0)
+                       , (int64PrimTyConKey,   MachInt64 0)
+                       , (floatPrimTyConKey,   MachFloat 0)
+                       , (doublePrimTyConKey,  MachDouble 0)
+                       , (wordPrimTyConKey,    MachWord 0)
+                       , (word64PrimTyConKey,  MachWord64 0) ]
 \end{code}