Platform.hs 3.13 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
        defaultTargetPlatform,
12
        target32Bit,
13
        osElfTarget
14
15
16
17
)

where

18
19
import Panic

20
21
22
23
#include "HsVersions.h"


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


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

45
46

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


59
60
61
62
63
64
65
66
target32Bit :: Platform -> Bool
target32Bit p = case platformArch p of
                ArchUnknown -> panic "Don't know if ArchUnknown is 32bit"
                ArchX86     -> True
                ArchX86_64  -> False
                ArchPPC     -> True
                ArchPPC_64  -> False
                ArchSPARC   -> True
67
                ArchARM     -> True
68
69


70
71
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
72
73
74
osElfTarget OSLinux    = True
osElfTarget OSFreeBSD  = True
osElfTarget OSOpenBSD  = True
75
osElfTarget OSSolaris2 = True
76
77
78
79
osElfTarget OSDarwin   = False
osElfTarget OSMinGW32  = False
osElfTarget OSUnknown  = panic "Don't know if OSUnknown is elf"

80

81
-- | This is the target platform as far as the #ifdefs are concerned.
82
--      These are set in includes/ghcplatform.h by the autoconf scripts
83
84
defaultTargetPlatform :: Platform
defaultTargetPlatform
85
        = Platform defaultTargetArch defaultTargetOS
86
87
88
89


-- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
defaultTargetArch :: Arch
90
#if i386_TARGET_ARCH
91
defaultTargetArch       = ArchX86
92
#elif x86_64_TARGET_ARCH
93
defaultTargetArch       = ArchX86_64
94
#elif powerpc_TARGET_ARCH
95
defaultTargetArch       = ArchPPC
96
#elif powerpc64_TARGET_ARCH
97
defaultTargetArch       = ArchPPC_64
98
#elif sparc_TARGET_ARCH
99
defaultTargetArch       = ArchSPARC
100
101
#elif arm_TARGET_ARCH
defaultTargetArch       = ArchARM
102
#else
103
defaultTargetArch       = ArchUnknown
104
105
106
107
108
109
#endif


-- | Move the evil TARGET_OS #ifdefs into Haskell land.
defaultTargetOS :: OS
#if   linux_TARGET_OS
110
defaultTargetOS = OSLinux
111
#elif darwin_TARGET_OS
112
defaultTargetOS = OSDarwin
kgardas's avatar
kgardas committed
113
#elif solaris2_TARGET_OS
114
defaultTargetOS = OSSolaris2
115
#elif mingw32_TARGET_OS
116
defaultTargetOS = OSMinGW32
117
#elif freebsd_TARGET_OS
118
defaultTargetOS = OSFreeBSD
kili's avatar
kili committed
119
#elif openbsd_TARGET_OS
120
defaultTargetOS = OSOpenBSD
121
#else
122
defaultTargetOS = OSUnknown
123
124
#endif