-- | Native code generator configuration
module GHC.CmmToAsm.Config
   ( NCGConfig(..)
   , ncgWordWidth
   , platformWordWidth
   )
where

import GHC.Prelude
import GHC.Platform
import GHC.Cmm.Type (Width(..))

-- | Native code generator configuration
data NCGConfig = NCGConfig
   { NCGConfig -> Platform
ncgPlatform              :: !Platform        -- ^ Target platform
   , NCGConfig -> Maybe Int
ncgProcAlignment         :: !(Maybe Int)     -- ^ Mandatory proc alignment
   , NCGConfig -> Int
ncgDebugLevel            :: !Int             -- ^ Debug level
   , NCGConfig -> Bool
ncgExternalDynamicRefs   :: !Bool            -- ^ Generate code to link against dynamic libraries
   , NCGConfig -> Bool
ncgPIC                   :: !Bool            -- ^ Enable Position-Independent Code
   , NCGConfig -> Word
ncgInlineThresholdMemcpy :: !Word            -- ^ If inlining `memcpy` produces less than this threshold (in pseudo-instruction unit), do it
   , NCGConfig -> Word
ncgInlineThresholdMemset :: !Word            -- ^ Ditto for `memset`
   , NCGConfig -> Bool
ncgSplitSections         :: !Bool            -- ^ Split sections
   , NCGConfig -> Int
ncgSpillPreallocSize     :: !Int             -- ^ Size in bytes of the pre-allocated spill space on the C stack
   , NCGConfig -> Bool
ncgRegsIterative         :: !Bool
   , NCGConfig -> Bool
ncgAsmLinting            :: !Bool            -- ^ Perform ASM linting pass
   , NCGConfig -> Bool
ncgDoConstantFolding     :: !Bool            -- ^ Perform CMM constant folding
   , NCGConfig -> Maybe SseVersion
ncgSseVersion            :: Maybe SseVersion -- ^ (x86) SSE instructions
   , NCGConfig -> Maybe BmiVersion
ncgBmiVersion            :: Maybe BmiVersion -- ^ (x86) BMI instructions
   , NCGConfig -> Bool
ncgDumpRegAllocStages    :: !Bool
   , NCGConfig -> Bool
ncgDumpAsmStats          :: !Bool
   , NCGConfig -> Bool
ncgDumpAsmConflicts      :: !Bool
   }

-- | Return Word size
ncgWordWidth :: NCGConfig -> Width
ncgWordWidth :: NCGConfig -> Width
ncgWordWidth NCGConfig
config = Platform -> Width
platformWordWidth (NCGConfig -> Platform
ncgPlatform NCGConfig
config)

-- | Return Word size
platformWordWidth :: Platform -> Width
platformWordWidth :: Platform -> Width
platformWordWidth Platform
platform = case Platform -> PlatformWordSize
platformWordSize Platform
platform of
   PlatformWordSize
PW4 -> Width
W32
   PlatformWordSize
PW8 -> Width
W64