-- | Llvm code generator configuration
module GHC.CmmToLlvm.Config
  ( LlvmCgConfig(..)
  , LlvmVersion(..)
  )
where

import GHC.Prelude
import GHC.Platform

import GHC.Utils.Outputable
import GHC.Driver.Session

import qualified Data.List.NonEmpty as NE

newtype LlvmVersion = LlvmVersion { LlvmVersion -> NonEmpty Int
llvmVersionNE :: NE.NonEmpty Int }
  deriving (LlvmVersion -> LlvmVersion -> Bool
(LlvmVersion -> LlvmVersion -> Bool)
-> (LlvmVersion -> LlvmVersion -> Bool) -> Eq LlvmVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LlvmVersion -> LlvmVersion -> Bool
== :: LlvmVersion -> LlvmVersion -> Bool
$c/= :: LlvmVersion -> LlvmVersion -> Bool
/= :: LlvmVersion -> LlvmVersion -> Bool
Eq, Eq LlvmVersion
Eq LlvmVersion
-> (LlvmVersion -> LlvmVersion -> Ordering)
-> (LlvmVersion -> LlvmVersion -> Bool)
-> (LlvmVersion -> LlvmVersion -> Bool)
-> (LlvmVersion -> LlvmVersion -> Bool)
-> (LlvmVersion -> LlvmVersion -> Bool)
-> (LlvmVersion -> LlvmVersion -> LlvmVersion)
-> (LlvmVersion -> LlvmVersion -> LlvmVersion)
-> Ord LlvmVersion
LlvmVersion -> LlvmVersion -> Bool
LlvmVersion -> LlvmVersion -> Ordering
LlvmVersion -> LlvmVersion -> LlvmVersion
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
$ccompare :: LlvmVersion -> LlvmVersion -> Ordering
compare :: LlvmVersion -> LlvmVersion -> Ordering
$c< :: LlvmVersion -> LlvmVersion -> Bool
< :: LlvmVersion -> LlvmVersion -> Bool
$c<= :: LlvmVersion -> LlvmVersion -> Bool
<= :: LlvmVersion -> LlvmVersion -> Bool
$c> :: LlvmVersion -> LlvmVersion -> Bool
> :: LlvmVersion -> LlvmVersion -> Bool
$c>= :: LlvmVersion -> LlvmVersion -> Bool
>= :: LlvmVersion -> LlvmVersion -> Bool
$cmax :: LlvmVersion -> LlvmVersion -> LlvmVersion
max :: LlvmVersion -> LlvmVersion -> LlvmVersion
$cmin :: LlvmVersion -> LlvmVersion -> LlvmVersion
min :: LlvmVersion -> LlvmVersion -> LlvmVersion
Ord)

data LlvmCgConfig = LlvmCgConfig
  { LlvmCgConfig -> Platform
llvmCgPlatform          :: !Platform     -- ^ Target platform
  , LlvmCgConfig -> SDocContext
llvmCgContext           :: !SDocContext  -- ^ Context for LLVM code generation
  , LlvmCgConfig -> Bool
llvmCgFillUndefWithGarbage :: !Bool      -- ^ Fill undefined literals with garbage values
  , LlvmCgConfig -> Bool
llvmCgSplitSection      :: !Bool         -- ^ Split sections
  , LlvmCgConfig -> Maybe BmiVersion
llvmCgBmiVersion        :: Maybe BmiVersion  -- ^ (x86) BMI instructions
  , LlvmCgConfig -> Maybe LlvmVersion
llvmCgLlvmVersion       :: Maybe LlvmVersion -- ^ version of Llvm we're using
  , LlvmCgConfig -> Bool
llvmCgDoWarn            :: !Bool         -- ^ True ==> warn unsupported Llvm version
  , LlvmCgConfig -> String
llvmCgLlvmTarget        :: !String       -- ^ target triple passed to LLVM
  , LlvmCgConfig -> LlvmConfig
llvmCgLlvmConfig        :: !LlvmConfig   -- ^ mirror DynFlags LlvmConfig.
    -- see Note [LLVM configuration] in "GHC.SysTools". This can be strict since
    -- GHC.Driver.Config.CmmToLlvm.initLlvmCgConfig verifies the files are present.
  }