-- | Refers to an integer constant (i64 42).
= LMIntLit Integer LlvmType
-- | Floating point literal
- | LMFloatLit Rational LlvmType
+ | LMFloatLit Double LlvmType
deriving (Eq)
instance Show LlvmLit where
-- | Print a literal value. No type.
getLit :: LlvmLit -> String
-getLit (LMIntLit i _) = show ((fromInteger i)::Int)
--- In Llvm float literals can be printed in a big-endian hexadecimal format,
--- regardless of underlying architecture.
-getLit (LMFloatLit r LMFloat) = fToStr $ fromRational r
-getLit (LMFloatLit r LMDouble) = dToStr $ fromRational r
-getLit l = error $ "getLit: Usupported LlvmLit type! " ++ show (getLitType l)
+getLit (LMIntLit i _) = show ((fromInteger i)::Int)
+getLit (LMFloatLit r _) = dToStr r
-- | Return the 'LlvmType' of the 'LlvmVar'
getVarType :: LlvmVar -> LlvmType
-- * Floating point conversion
--
--- | Convert a Haskell Float to an LLVM hex encoded floating point form
-fToStr :: Float -> String
-fToStr f = dToStr $ realToFrac f
-
--- | Convert a Haskell Double to an LLVM hex encoded floating point form
+-- | Convert a Haskell Double to an LLVM hex encoded floating point form. In
+-- Llvm float literals can be printed in a big-endian hexadecimal format,
+-- regardless of underlying architecture.
dToStr :: Double -> String
dToStr d
= let bs = doubleToBytes d
str = map toUpper $ concat . fixEndian . (map hex) $ bs
in "0x" ++ str
--- | Reverse or leave byte data alone to fix endianness on this
--- target. LLVM generally wants things in Big-Endian form
--- regardless of target architecture.
+-- | Reverse or leave byte data alone to fix endianness on this target.
fixEndian :: [a] -> [a]
#ifdef WORDS_BIGENDIAN
fixEndian = id
in negate (widthToLlvmInt w) all0 LM_MO_Sub
MO_F_Neg w ->
- let all0 = LMLitVar $ LMFloatLit 0 (widthToLlvmFloat w)
+ let all0 = LMLitVar $ LMFloatLit (-0) (widthToLlvmFloat w)
in negate (widthToLlvmFloat w) all0 LM_MO_Sub
MO_SF_Conv _ w -> fiConv (widthToLlvmFloat w) LM_Sitofp
= return (env, mkIntLit i (LMInt $ widthInBits w), nilOL, [])
genLit env (CmmFloat r w)
- = return (env, LMLitVar $ LMFloatLit r (widthToLlvmFloat w), nilOL, [])
+ = return (env, LMLitVar $ LMFloatLit (fromRational r) (widthToLlvmFloat w),
+ nilOL, [])
genLit env cmm@(CmmLabel l)
= let label = strCLabel_llvm l