diff options
author | Simon Marlow <marlowsd@gmail.com> | 2008-12-09 10:55:15 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2008-12-09 10:55:15 +0000 |
commit | 7fbdd9e0bccec89c958e2a1e36d5ec058fc69a3d (patch) | |
tree | bd64e07efff98b201a7400cb7a76b9c16501b2b8 /compiler/cmm/CmmExpr.hs | |
parent | a3ea8b447cb55279a5767ebe04d861da3b761924 (diff) | |
download | haskell-7fbdd9e0bccec89c958e2a1e36d5ec058fc69a3d.tar.gz |
Fix #2838: we should narrow a CmmInt before converting to ImmInteger
Diffstat (limited to 'compiler/cmm/CmmExpr.hs')
-rw-r--r-- | compiler/cmm/CmmExpr.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/cmm/CmmExpr.hs b/compiler/cmm/CmmExpr.hs index db42564171..8e40654352 100644 --- a/compiler/cmm/CmmExpr.hs +++ b/compiler/cmm/CmmExpr.hs @@ -10,6 +10,7 @@ module CmmExpr , Width(..) , widthInBits, widthInBytes, widthInLog, widthFromBytes , wordWidth, halfWordWidth, cIntWidth, cLongWidth + , narrowU, narrowS , CmmExpr(..), cmmExprType, cmmExprWidth, maybeInvertCmmExpr , CmmReg(..), cmmRegType @@ -55,6 +56,9 @@ import Panic import Unique import UniqSet +import Data.Word +import Data.Int + ----------------------------------------------------------------------------- -- CmmExpr -- An expression. Expressions have no side effects. @@ -636,6 +640,21 @@ widthInLog W64 = 3 widthInLog W128 = 4 widthInLog W80 = panic "widthInLog: F80" +-- widening / narrowing + +narrowU :: Width -> Integer -> Integer +narrowU W8 x = fromIntegral (fromIntegral x :: Word8) +narrowU W16 x = fromIntegral (fromIntegral x :: Word16) +narrowU W32 x = fromIntegral (fromIntegral x :: Word32) +narrowU W64 x = fromIntegral (fromIntegral x :: Word64) +narrowU _ _ = panic "narrowTo" + +narrowS :: Width -> Integer -> Integer +narrowS W8 x = fromIntegral (fromIntegral x :: Int8) +narrowS W16 x = fromIntegral (fromIntegral x :: Int16) +narrowS W32 x = fromIntegral (fromIntegral x :: Int32) +narrowS W64 x = fromIntegral (fromIntegral x :: Int64) +narrowS _ _ = panic "narrowTo" ----------------------------------------------------------------------------- -- MachOp |