module Format (
Format(..),
intFormat,
floatFormat,
isFloatFormat,
cmmTypeFormat,
formatToWidth,
formatInBytes
)
where
import GhcPrelude
import Cmm
import Outputable
data Format
= II8
| II16
| II32
| II64
| FF32
| FF64
| FF80
deriving (Show, Eq)
intFormat :: Width -> Format
intFormat width
= case width of
W8 -> II8
W16 -> II16
W32 -> II32
W64 -> II64
other -> sorry $ "The native code generator cannot " ++
"produce code for Format.intFormat " ++ show other
++ "\n\tConsider using the llvm backend with -fllvm"
floatFormat :: Width -> Format
floatFormat width
= case width of
W32 -> FF32
W64 -> FF64
W80 -> FF80
other -> pprPanic "Format.floatFormat" (ppr other)
isFloatFormat :: Format -> Bool
isFloatFormat format
= case format of
FF32 -> True
FF64 -> True
FF80 -> True
_ -> False
cmmTypeFormat :: CmmType -> Format
cmmTypeFormat ty
| isFloatType ty = floatFormat (typeWidth ty)
| otherwise = intFormat (typeWidth ty)
formatToWidth :: Format -> Width
formatToWidth format
= case format of
II8 -> W8
II16 -> W16
II32 -> W32
II64 -> W64
FF32 -> W32
FF64 -> W64
FF80 -> W80
formatInBytes :: Format -> Int
formatInBytes = widthInBytes . formatToWidth