summaryrefslogtreecommitdiff
path: root/libraries/ghc-boot
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-05-30 20:06:24 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-06-19 22:16:16 -0400
commitbff2f24ba9104275c665b6a0cf30a8dd18407392 (patch)
treeec8f3bc21dfc3e8bb09ec69d82ac499d12489093 /libraries/ghc-boot
parent3ae23992786c7ea3211ab6f13e1d61a5edfe5952 (diff)
downloadhaskell-bff2f24ba9104275c665b6a0cf30a8dd18407392.tar.gz
Move 'Platform' to ghc-boot
ghc-pkg needs to be aware of platforms so it can figure out which subdire within the user package db to use. This is admittedly roundabout, but maybe Cabal could use the same notion of a platform as GHC to good affect too.
Diffstat (limited to 'libraries/ghc-boot')
-rw-r--r--libraries/ghc-boot/GHC/Platform.hs190
-rw-r--r--libraries/ghc-boot/ghc-boot.cabal.in1
2 files changed, 191 insertions, 0 deletions
diff --git a/libraries/ghc-boot/GHC/Platform.hs b/libraries/ghc-boot/GHC/Platform.hs
new file mode 100644
index 0000000000..8344778ea9
--- /dev/null
+++ b/libraries/ghc-boot/GHC/Platform.hs
@@ -0,0 +1,190 @@
+
+-- | A description of the platform we're compiling for.
+--
+module GHC.Platform (
+ Platform(..),
+ Arch(..),
+ OS(..),
+ ArmISA(..),
+ ArmISAExt(..),
+ ArmABI(..),
+ PPC_64ABI(..),
+
+ target32Bit,
+ isARM,
+ osElfTarget,
+ osMachOTarget,
+ osSubsectionsViaSymbols,
+ platformUsesFrameworks,
+
+ PlatformMisc(..),
+ IntegerLibrary(..),
+)
+
+where
+
+import Prelude -- See Note [Why do we import Prelude here?]
+
+-- | Contains enough information for the native code generator to emit
+-- code for this platform.
+data Platform
+ = Platform {
+ platformArch :: Arch,
+ platformOS :: OS,
+ -- Word size in bytes (i.e. normally 4 or 8,
+ -- for 32bit and 64bit platforms respectively)
+ platformWordSize :: {-# UNPACK #-} !Int,
+ platformUnregisterised :: Bool,
+ platformHasGnuNonexecStack :: Bool,
+ platformHasIdentDirective :: Bool,
+ platformHasSubsectionsViaSymbols :: Bool,
+ platformIsCrossCompiling :: Bool
+ }
+ deriving (Read, Show, Eq)
+
+
+-- | Architectures that the native code generator knows about.
+-- TODO: It might be nice to extend these constructors with information
+-- about what instruction set extensions an architecture might support.
+--
+data Arch
+ = ArchUnknown
+ | ArchX86
+ | ArchX86_64
+ | ArchPPC
+ | ArchPPC_64
+ { ppc_64ABI :: PPC_64ABI
+ }
+ | ArchSPARC
+ | ArchSPARC64
+ | ArchARM
+ { armISA :: ArmISA
+ , armISAExt :: [ArmISAExt]
+ , armABI :: ArmABI
+ }
+ | ArchARM64
+ | ArchAlpha
+ | ArchMipseb
+ | ArchMipsel
+ | ArchJavaScript
+ deriving (Read, Show, Eq)
+
+isARM :: Arch -> Bool
+isARM (ArchARM {}) = True
+isARM ArchARM64 = True
+isARM _ = False
+
+-- | Operating systems that the native code generator knows about.
+-- Having OSUnknown should produce a sensible default, but no promises.
+data OS
+ = OSUnknown
+ | OSLinux
+ | OSDarwin
+ | OSSolaris2
+ | OSMinGW32
+ | OSFreeBSD
+ | OSDragonFly
+ | OSOpenBSD
+ | OSNetBSD
+ | OSKFreeBSD
+ | OSHaiku
+ | OSQNXNTO
+ | OSAIX
+ | OSHurd
+ deriving (Read, Show, Eq)
+
+-- | ARM Instruction Set Architecture, Extensions and ABI
+--
+data ArmISA
+ = ARMv5
+ | ARMv6
+ | ARMv7
+ deriving (Read, Show, Eq)
+
+data ArmISAExt
+ = VFPv2
+ | VFPv3
+ | VFPv3D16
+ | NEON
+ | IWMMX2
+ deriving (Read, Show, Eq)
+
+data ArmABI
+ = SOFT
+ | SOFTFP
+ | HARD
+ deriving (Read, Show, Eq)
+
+-- | PowerPC 64-bit ABI
+--
+data PPC_64ABI
+ = ELF_V1
+ | ELF_V2
+ deriving (Read, Show, Eq)
+
+-- | This predicate tells us whether the platform is 32-bit.
+target32Bit :: Platform -> Bool
+target32Bit p = platformWordSize p == 4
+
+-- | This predicate tells us whether the OS supports ELF-like shared libraries.
+osElfTarget :: OS -> Bool
+osElfTarget OSLinux = True
+osElfTarget OSFreeBSD = True
+osElfTarget OSDragonFly = True
+osElfTarget OSOpenBSD = True
+osElfTarget OSNetBSD = True
+osElfTarget OSSolaris2 = True
+osElfTarget OSDarwin = False
+osElfTarget OSMinGW32 = False
+osElfTarget OSKFreeBSD = True
+osElfTarget OSHaiku = True
+osElfTarget OSQNXNTO = False
+osElfTarget OSAIX = False
+osElfTarget OSHurd = True
+osElfTarget OSUnknown = False
+ -- Defaulting to False is safe; it means don't rely on any
+ -- ELF-specific functionality. It is important to have a default for
+ -- portability, otherwise we have to answer this question for every
+ -- new platform we compile on (even unreg).
+
+-- | This predicate tells us whether the OS support Mach-O shared libraries.
+osMachOTarget :: OS -> Bool
+osMachOTarget OSDarwin = True
+osMachOTarget _ = False
+
+osUsesFrameworks :: OS -> Bool
+osUsesFrameworks OSDarwin = True
+osUsesFrameworks _ = False
+
+platformUsesFrameworks :: Platform -> Bool
+platformUsesFrameworks = osUsesFrameworks . platformOS
+
+osSubsectionsViaSymbols :: OS -> Bool
+osSubsectionsViaSymbols OSDarwin = True
+osSubsectionsViaSymbols _ = False
+
+-- | Platform-specific settings formerly hard-coded in Config.hs.
+--
+-- These should probably be all be triaged whether they can be computed from
+-- other settings or belong in another another place (like 'Platform' above).
+data PlatformMisc = PlatformMisc
+ { -- TODO Recalculate string from richer info?
+ platformMisc_targetPlatformString :: String
+ , platformMisc_integerLibrary :: String
+ , platformMisc_integerLibraryType :: IntegerLibrary
+ , platformMisc_ghcWithInterpreter :: Bool
+ , platformMisc_ghcWithNativeCodeGen :: Bool
+ , platformMisc_ghcWithSMP :: Bool
+ , platformMisc_ghcRTSWays :: String
+ , platformMisc_tablesNextToCode :: Bool
+ , platformMisc_leadingUnderscore :: Bool
+ , platformMisc_libFFI :: Bool
+ , platformMisc_ghcThreaded :: Bool
+ , platformMisc_ghcDebugged :: Bool
+ , platformMisc_ghcRtsWithLibdw :: Bool
+ }
+
+data IntegerLibrary
+ = IntegerGMP
+ | IntegerSimple
+ deriving (Read, Show, Eq)
diff --git a/libraries/ghc-boot/ghc-boot.cabal.in b/libraries/ghc-boot/ghc-boot.cabal.in
index 97872c15f7..15721b1489 100644
--- a/libraries/ghc-boot/ghc-boot.cabal.in
+++ b/libraries/ghc-boot/ghc-boot.cabal.in
@@ -43,6 +43,7 @@ Library
GHC.Serialized
GHC.ForeignSrcLang
GHC.HandleEncoding
+ GHC.Platform
build-depends: base >= 4.7 && < 4.14,
binary == 0.8.*,