Platform.hs 3.86 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
20
21
22
23
)

where

#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
        deriving (Show, Eq)
30
31
32


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

47

Ian Lynagh's avatar
Ian Lynagh committed
48
-- | Operating systems that we know about.
49
data OS
Ian Lynagh's avatar
Ian Lynagh committed
50
        = OSLinux
51
52
53
54
55
56
        | OSDarwin
        | OSSolaris2
        | OSMinGW32
        | OSFreeBSD
        | OSOpenBSD
        deriving (Show, Eq)
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- | ARM Instruction Set Architecture and Extensions
--
data ArmISA
    = ARMv5
    | ARMv6
    | ARMv7
    deriving (Show, Eq)

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

74

75
76
77
78
79
80
81
target32Bit :: Platform -> Bool
target32Bit p = case platformArch p of
                ArchX86     -> True
                ArchX86_64  -> False
                ArchPPC     -> True
                ArchPPC_64  -> False
                ArchSPARC   -> True
82
                ArchARM _ _ -> True
83
84


85
86
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
87
88
89
osElfTarget OSLinux    = True
osElfTarget OSFreeBSD  = True
osElfTarget OSOpenBSD  = True
90
osElfTarget OSSolaris2 = True
91
92
93
osElfTarget OSDarwin   = False
osElfTarget OSMinGW32  = False

94

95
-- | This is the target platform as far as the #ifdefs are concerned.
96
--      These are set in includes/ghcplatform.h by the autoconf scripts
97
98
defaultTargetPlatform :: Platform
defaultTargetPlatform
99
        = Platform defaultTargetArch defaultTargetOS
100
101
102
103


-- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
defaultTargetArch :: Arch
104
#if i386_TARGET_ARCH
105
defaultTargetArch       = ArchX86
106
#elif x86_64_TARGET_ARCH
107
defaultTargetArch       = ArchX86_64
108
#elif powerpc_TARGET_ARCH
109
defaultTargetArch       = ArchPPC
110
#elif powerpc64_TARGET_ARCH
111
defaultTargetArch       = ArchPPC_64
112
#elif sparc_TARGET_ARCH
113
defaultTargetArch       = ArchSPARC
114
#elif arm_TARGET_ARCH
115
defaultTargetArch       = ArchARM defaultTargetArmISA defaultTargetArmISAExt
116
#else
Ian Lynagh's avatar
Ian Lynagh committed
117
#error Unknown Arch
118
119
120
121
122
123
#endif


-- | Move the evil TARGET_OS #ifdefs into Haskell land.
defaultTargetOS :: OS
#if   linux_TARGET_OS
124
defaultTargetOS = OSLinux
125
#elif darwin_TARGET_OS
126
defaultTargetOS = OSDarwin
kgardas's avatar
kgardas committed
127
#elif solaris2_TARGET_OS
128
defaultTargetOS = OSSolaris2
129
#elif mingw32_TARGET_OS
130
defaultTargetOS = OSMinGW32
131
#elif freebsd_TARGET_OS
132
defaultTargetOS = OSFreeBSD
133
134
#elif kfreebsdgnu_TARGET_OS
defaultTargetOS = OSFreeBSD
kili's avatar
kili committed
135
#elif openbsd_TARGET_OS
136
defaultTargetOS = OSOpenBSD
137
#else
Ian Lynagh's avatar
Ian Lynagh committed
138
#error Unknown OS
139
140
#endif

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#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 */