[project @ 2001-10-24 15:11:28 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / Literal.lhs
index 03101e3..2167ba0 100644 (file)
@@ -13,6 +13,7 @@ module Literal
        , hashLiteral
 
        , inIntRange, inWordRange, tARGET_MAX_INT, inCharRange
+       , isZeroLit,
 
        , word2IntLit, int2WordLit
        , narrow8IntLit, narrow16IntLit, narrow32IntLit
@@ -146,10 +147,16 @@ instance Ord Literal where
 \begin{code}
 mkMachInt, mkMachWord, mkMachInt64, mkMachWord64 :: Integer -> Literal
 
-mkMachInt  x   = ASSERT2( inIntRange x,  integer x ) MachInt x
-mkMachWord x   = ASSERT2( inWordRange x, integer x ) MachWord x
-mkMachInt64  x = MachInt64 x   -- Assertions?
-mkMachWord64 x = MachWord64 x  -- Ditto?
+mkMachInt  x   = -- ASSERT2( inIntRange x,  integer x ) 
+                -- 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
+mkMachInt64  x = MachInt64 x
+mkMachWord64 x = MachWord64 x
 
 inIntRange, inWordRange :: Integer -> Bool
 inIntRange  x = x >= tARGET_MIN_INT && x <= tARGET_MAX_INT
@@ -157,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