Platform.hs 4.17 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
        ArmISA(..),
        ArmISAExt(..),
12

13
        defaultTargetPlatform,
14
        target32Bit,
15
        osElfTarget
16
17
18
19
)

where

20
21
import Panic

22
23
24
25
#include "HsVersions.h"


-- | Contains enough information for the native code generator to emit
26
--      code for this platform.
27
data Platform
28
29
30
        = Platform
        { platformArch  :: Arch
        , platformOS    :: OS }
31
        deriving (Show, Eq)
32
33
34


-- | Architectures that the native code generator knows about.
35
36
--      TODO: It might be nice to extend these constructors with information
--      about what instruction set extensions an architecture might support.
37
38
--
data Arch
39
40
41
42
43
44
        = ArchUnknown
        | ArchX86
        | ArchX86_64
        | ArchPPC
        | ArchPPC_64
        | ArchSPARC
45
        | ArchARM
46
47
          { armISA    :: ArmISA
          , armISAExt :: [ArmISAExt] }
48
49
        deriving (Show, Eq)

50
51

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

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- | ARM Instruction Set Architecture and Extensions
--
data ArmISA
    = ARMv5
    | ARMv6
    | ARMv7
    deriving (Show, Eq)

data ArmISAExt
    = VFPv2
    | VFPv3
    | VFPv3D16
    | NEON
    | IWMMX2
    deriving (Show, Eq)

79

80
81
82
83
84
85
86
87
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
88
                ArchARM _ _ -> True
89
90


91
92
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
93
94
95
osElfTarget OSLinux    = True
osElfTarget OSFreeBSD  = True
osElfTarget OSOpenBSD  = True
96
osElfTarget OSSolaris2 = True
97
98
99
100
osElfTarget OSDarwin   = False
osElfTarget OSMinGW32  = False
osElfTarget OSUnknown  = panic "Don't know if OSUnknown is elf"

101

102
-- | This is the target platform as far as the #ifdefs are concerned.
103
--      These are set in includes/ghcplatform.h by the autoconf scripts
104
105
defaultTargetPlatform :: Platform
defaultTargetPlatform
106
        = Platform defaultTargetArch defaultTargetOS
107
108
109
110


-- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
defaultTargetArch :: Arch
111
#if i386_TARGET_ARCH
112
defaultTargetArch       = ArchX86
113
#elif x86_64_TARGET_ARCH
114
defaultTargetArch       = ArchX86_64
115
#elif powerpc_TARGET_ARCH
116
defaultTargetArch       = ArchPPC
117
#elif powerpc64_TARGET_ARCH
118
defaultTargetArch       = ArchPPC_64
119
#elif sparc_TARGET_ARCH
120
defaultTargetArch       = ArchSPARC
121
#elif arm_TARGET_ARCH
122
defaultTargetArch       = ArchARM defaultTargetArmISA defaultTargetArmISAExt
123
#else
124
defaultTargetArch       = ArchUnknown
125
126
127
128
129
130
#endif


-- | Move the evil TARGET_OS #ifdefs into Haskell land.
defaultTargetOS :: OS
#if   linux_TARGET_OS
131
defaultTargetOS = OSLinux
132
#elif darwin_TARGET_OS
133
defaultTargetOS = OSDarwin
kgardas's avatar
kgardas committed
134
#elif solaris2_TARGET_OS
135
defaultTargetOS = OSSolaris2
136
#elif mingw32_TARGET_OS
137
defaultTargetOS = OSMinGW32
138
#elif freebsd_TARGET_OS
139
defaultTargetOS = OSFreeBSD
140
141
#elif kfreebsdgnu_TARGET_OS
defaultTargetOS = OSFreeBSD
kili's avatar
kili committed
142
#elif openbsd_TARGET_OS
143
defaultTargetOS = OSOpenBSD
144
#else
145
defaultTargetOS = OSUnknown
146
147
#endif

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#if arm_TARGET_ARCH
defaultTargetArmISA :: ArmISA
#if defined(arm_HOST_ARCH_PRE_ARMv6)
defaultTargetArmISA = ARMv5
#elif defined(arm_HOST_ARCH_PRE_ARMv7)
defaultTargetArmISA = ARMv6
#else
defaultTargetArmISA = ARMv7
#endif

defaultTargetArmISAExt :: [ArmISAExt]
#if defined(arm_TARGET_ARCH) && !defined(arm_HOST_ARCH_PRE_ARMv7)
/* wild guess really, in case of ARMv7 we assume both VFPv3 and NEON presented
   however this is not true for SoCs like NVidia Tegra2 and Marvell Dove */
defaultTargetArmISAExt = [VFPv3, NEON]
#else
defaultTargetArmISAExt = []
#endif
#endif /* arm_TARGET_ARCH */