    {-# LANGUAGE MultiWayIf #-}

    -- | Code generation backends
    module GHC.Driver.Backend
       ( Backend (..)
       , platformDefaultBackend
       , platformNcgSupported
       )
    where

    import GHC.Prelude
    import GHC.Platform

    -- | Backend
    data Backend
       = NCG           -- ^ Native code generator backend
       | LLVM          -- ^ LLVM backend
       | ViaC          -- ^ Via-C backend
       | Interpreter   -- ^ Interpreter
       deriving (Backend -> Backend -> Bool
    (Backend -> Backend -> Bool)
    -> (Backend -> Backend -> Bool) -> Eq Backend
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Backend -> Backend -> Bool
    $c/= :: Backend -> Backend -> Bool
    == :: Backend -> Backend -> Bool
    $c== :: Backend -> Backend -> Bool
    Eq,Eq Backend
    Eq Backend
    -> (Backend -> Backend -> Ordering)
    -> (Backend -> Backend -> Bool)
    -> (Backend -> Backend -> Bool)
    -> (Backend -> Backend -> Bool)
    -> (Backend -> Backend -> Bool)
    -> (Backend -> Backend -> Backend)
    -> (Backend -> Backend -> Backend)
    -> Ord Backend
    Backend -> Backend -> Bool
    Backend -> Backend -> Ordering
    Backend -> Backend -> Backend
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    min :: Backend -> Backend -> Backend
    $cmin :: Backend -> Backend -> Backend
    max :: Backend -> Backend -> Backend
    $cmax :: Backend -> Backend -> Backend
    >= :: Backend -> Backend -> Bool
    $c>= :: Backend -> Backend -> Bool
    > :: Backend -> Backend -> Bool
    $c> :: Backend -> Backend -> Bool
    <= :: Backend -> Backend -> Bool
    $c<= :: Backend -> Backend -> Bool
    < :: Backend -> Backend -> Bool
    $c< :: Backend -> Backend -> Bool
    compare :: Backend -> Backend -> Ordering
    $ccompare :: Backend -> Backend -> Ordering
    Ord,Int -> Backend -> ShowS
    [Backend] -> ShowS
    Backend -> String
    (Int -> Backend -> ShowS)
    -> (Backend -> String) -> ([Backend] -> ShowS) -> Show Backend
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [Backend] -> ShowS
    $cshowList :: [Backend] -> ShowS
    show :: Backend -> String
    $cshow :: Backend -> String
    showsPrec :: Int -> Backend -> ShowS
    $cshowsPrec :: Int -> Backend -> ShowS
    Show,ReadPrec [Backend]
    ReadPrec Backend
    Int -> ReadS Backend
    ReadS [Backend]
    (Int -> ReadS Backend)
    -> ReadS [Backend]
    -> ReadPrec Backend
    -> ReadPrec [Backend]
    -> Read Backend
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [Backend]
    $creadListPrec :: ReadPrec [Backend]
    readPrec :: ReadPrec Backend
    $creadPrec :: ReadPrec Backend
    readList :: ReadS [Backend]
    $creadList :: ReadS [Backend]
    readsPrec :: Int -> ReadS Backend
    $creadsPrec :: Int -> ReadS Backend
    Read)

    -- | Default backend to use for the given platform.
    platformDefaultBackend :: Platform -> Backend
    platformDefaultBackend :: Platform -> Backend
    platformDefaultBackend Platform
    platform = if
          | Platform -> Bool
    platformUnregisterised Platform
    platform -> Backend
    ViaC
          | Platform -> Bool
    platformNcgSupported Platform
    platform   -> Backend
    NCG
          | Bool
    otherwise                       -> Backend
    LLVM

    -- | Is the platform supported by the Native Code Generator?
    platformNcgSupported :: Platform -> Bool
    platformNcgSupported :: Platform -> Bool
    platformNcgSupported Platform
    platform = if
          | Platform -> Bool
    platformUnregisterised Platform
    platform -> Bool
    False -- NCG doesn't support unregisterised ABI
          | Bool
    ncgValidArch                    -> Bool
    True
          | Bool
    otherwise                       -> Bool
    False
       where
          ncgValidArch :: Bool
    ncgValidArch = case Platform -> Arch
    platformArch Platform
    platform of
             Arch
    ArchX86       -> Bool
    True
             Arch
    ArchX86_64    -> Bool
    True
             Arch
    ArchPPC       -> Bool
    True
             ArchPPC_64 {} -> Bool
    True
             Arch
    ArchSPARC     -> Bool
    True
             Arch
    _             -> Bool
    False