[project @ 2001-10-24 15:11:28 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / Literal.lhs
index 3555d31..2167ba0 100644 (file)
@@ -13,6 +13,7 @@ module Literal
        , hashLiteral
 
        , inIntRange, inWordRange, tARGET_MAX_INT, inCharRange
+       , isZeroLit,
 
        , word2IntLit, int2WordLit
        , narrow8IntLit, narrow16IntLit, narrow32IntLit
@@ -147,7 +148,10 @@ instance Ord Literal where
 mkMachInt, mkMachWord, mkMachInt64, mkMachWord64 :: Integer -> Literal
 
 mkMachInt  x   = -- ASSERT2( inIntRange x,  integer x ) 
-                -- not true: you can write out of range Int# literals
+                -- Not true: you can write out of range Int# literals
+                -- For example, one can write (intToWord# 0xffff0000) to
+                -- get a particular Word bit-pattern, and there's no other
+                -- convenient way to write such literals, which is why we allow it.
                 MachInt x
 mkMachWord x   = -- ASSERT2( inWordRange x, integer x ) 
                 MachWord x
@@ -160,6 +164,15 @@ inWordRange x = x >= 0                 && x <= tARGET_MAX_WORD
 
 inCharRange :: Int -> Bool
 inCharRange c =  c >= 0 && c <= tARGET_MAX_CHAR
+
+isZeroLit :: Literal -> Bool
+isZeroLit (MachInt    0) = True
+isZeroLit (MachInt64  0) = True
+isZeroLit (MachWord   0) = True
+isZeroLit (MachWord64 0) = True
+isZeroLit (MachFloat  0) = True
+isZeroLit (MachDouble 0) = True
+isZeroLit other                 = False
 \end{code}
 
        Coercions