Platform.hs 2.57 KB
Newer Older
1
2

-- | A description of the platform we're compiling for.
3
4
--      In the future, this module should be the only one that references
--      the evil #defines for each TARGET_ARCH and TARGET_OS
5
6
--
module Platform (
7
8
9
        Platform(..),
        Arch(..),
        OS(..),
10

11
12
        defaultTargetPlatform,
        osElfTarget
13
14
15
16
17
18
19
20
)

where

#include "HsVersions.h"


-- | Contains enough information for the native code generator to emit
21
--      code for this platform.
22
data Platform
23
24
25
        = Platform
        { platformArch  :: Arch
        , platformOS    :: OS }
26
27
28


-- | Architectures that the native code generator knows about.
29
30
--      TODO: It might be nice to extend these constructors with information
--      about what instruction set extensions an architecture might support.
31
32
--
data Arch
33
34
35
36
37
38
39
40
        = ArchUnknown
        | ArchX86
        | ArchX86_64
        | ArchPPC
        | ArchPPC_64
        | ArchSPARC
        deriving (Show, Eq)

41
42

-- | Operating systems that the native code generator knows about.
43
--      Having OSUnknown should produce a sensible default, but no promises.
44
data OS
45
46
47
48
49
50
51
52
        = OSUnknown
        | OSLinux
        | OSDarwin
        | OSSolaris2
        | OSMinGW32
        | OSFreeBSD
        | OSOpenBSD
        deriving (Show, Eq)
53
54


55
56
57
58
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
osElfTarget OSLinux   = True
osElfTarget OSFreeBSD = True
kili's avatar
kili committed
59
osElfTarget OSOpenBSD = True
60
osElfTarget OSSolaris2 = True
61
62
osElfTarget _         = False

63
-- | This is the target platform as far as the #ifdefs are concerned.
64
--      These are set in includes/ghcplatform.h by the autoconf scripts
65
66
defaultTargetPlatform :: Platform
defaultTargetPlatform
67
        = Platform defaultTargetArch defaultTargetOS
68
69
70
71


-- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
defaultTargetArch :: Arch
72
#if i386_TARGET_ARCH
73
defaultTargetArch       = ArchX86
74
#elif x86_64_TARGET_ARCH
75
defaultTargetArch       = ArchX86_64
76
#elif powerpc_TARGET_ARCH
77
defaultTargetArch       = ArchPPC
78
#elif powerpc64_TARGET_ARCH
79
defaultTargetArch       = ArchPPC_64
80
#elif sparc_TARGET_ARCH
81
defaultTargetArch       = ArchSPARC
82
#else
83
defaultTargetArch       = ArchUnknown
84
85
86
87
88
89
#endif


-- | Move the evil TARGET_OS #ifdefs into Haskell land.
defaultTargetOS :: OS
#if   linux_TARGET_OS
90
defaultTargetOS = OSLinux
91
#elif darwin_TARGET_OS
92
defaultTargetOS = OSDarwin
kgardas's avatar
kgardas committed
93
#elif solaris2_TARGET_OS
94
defaultTargetOS = OSSolaris2
95
#elif mingw32_TARGET_OS
96
defaultTargetOS = OSMinGW32
97
#elif freebsd_TARGET_OS
98
defaultTargetOS = OSFreeBSD
kili's avatar
kili committed
99
#elif openbsd_TARGET_OS
100
defaultTargetOS = OSOpenBSD
101
#else
102
defaultTargetOS = OSUnknown
103
104
#endif