-literalType :: Literal -> Type
-
-literalType (MachChar _) = charPrimTy
-literalType (MachStr _) = addrPrimTy
-literalType (MachAddr _) = addrPrimTy
-literalType (MachInt _ signed) = if signed then intPrimTy else wordPrimTy
-literalType (MachFloat _) = floatPrimTy
-literalType (MachDouble _) = doublePrimTy
-literalType (MachLitLit _ k) = case (getPrimRepInfo k) of { (_,t,_) -> t }
-literalType (NoRepInteger _ t) = t
-literalType (NoRepRational _ t) = t
-literalType (NoRepStr _) = stringTy
+word2IntLit, int2WordLit,
+ narrow8IntLit, narrow16IntLit, narrow32IntLit,
+ narrow8WordLit, narrow16WordLit, narrow32WordLit,
+ char2IntLit, int2CharLit,
+ float2IntLit, int2FloatLit, double2IntLit, int2DoubleLit,
+ float2DoubleLit, double2FloatLit
+ :: Literal -> Literal
+
+word2IntLit (MachWord w)
+ | w > tARGET_MAX_INT = MachInt (w - tARGET_MAX_WORD - 1)
+ | otherwise = MachInt w
+
+int2WordLit (MachInt i)
+ | i < 0 = MachWord (1 + tARGET_MAX_WORD + i) -- (-1) ---> tARGET_MAX_WORD
+ | otherwise = MachWord i
+
+narrow8IntLit (MachInt i) = MachInt (toInteger (fromInteger i :: Int8))
+narrow16IntLit (MachInt i) = MachInt (toInteger (fromInteger i :: Int16))
+narrow32IntLit (MachInt i) = MachInt (toInteger (fromInteger i :: Int32))
+narrow8WordLit (MachWord w) = MachWord (toInteger (fromInteger w :: Word8))
+narrow16WordLit (MachWord w) = MachWord (toInteger (fromInteger w :: Word16))
+narrow32WordLit (MachWord w) = MachWord (toInteger (fromInteger w :: Word32))
+
+char2IntLit (MachChar c) = MachInt (toInteger (ord c))
+int2CharLit (MachInt i) = MachChar (chr (fromInteger i))
+
+float2IntLit (MachFloat f) = MachInt (truncate f)
+int2FloatLit (MachInt i) = MachFloat (fromInteger i)
+
+double2IntLit (MachDouble f) = MachInt (truncate f)
+int2DoubleLit (MachInt i) = MachDouble (fromInteger i)
+
+float2DoubleLit (MachFloat f) = MachDouble f
+double2FloatLit (MachDouble d) = MachFloat d
+
+nullAddrLit :: Literal
+nullAddrLit = MachNullAddr