b4eb7aad81a979bf980cef5cdf247c1219be9d32
[ghc.git] / compiler / utils / Platform.hs
1
2 -- | A description of the platform we're compiling for.
3 -- In the future, this module should be the only one that references
4 -- the evil #defines for each TARGET_ARCH and TARGET_OS
5 --
6 module Platform (
7 Platform(..),
8 Arch(..),
9 OS(..),
10 ArmISA(..),
11 ArmISAExt(..),
12
13 defaultTargetPlatform,
14 target32Bit,
15 osElfTarget
16 )
17
18 where
19
20 import Panic
21
22 #include "HsVersions.h"
23
24
25 -- | Contains enough information for the native code generator to emit
26 -- code for this platform.
27 data Platform
28 = Platform
29 { platformArch :: Arch
30 , platformOS :: OS }
31 deriving (Show, Eq)
32
33
34 -- | Architectures that the native code generator knows about.
35 -- TODO: It might be nice to extend these constructors with information
36 -- about what instruction set extensions an architecture might support.
37 --
38 data Arch
39 = ArchX86
40 | ArchX86_64
41 | ArchPPC
42 | ArchPPC_64
43 | ArchSPARC
44 | ArchARM
45 { armISA :: ArmISA
46 , armISAExt :: [ArmISAExt] }
47 deriving (Show, Eq)
48
49
50 -- | Operating systems that we know about.
51 data OS
52 = OSLinux
53 | OSDarwin
54 | OSSolaris2
55 | OSMinGW32
56 | OSFreeBSD
57 | OSOpenBSD
58 deriving (Show, Eq)
59
60 -- | ARM Instruction Set Architecture and Extensions
61 --
62 data ArmISA
63 = ARMv5
64 | ARMv6
65 | ARMv7
66 deriving (Show, Eq)
67
68 data ArmISAExt
69 = VFPv2
70 | VFPv3
71 | VFPv3D16
72 | NEON
73 | IWMMX2
74 deriving (Show, Eq)
75
76
77 target32Bit :: Platform -> Bool
78 target32Bit p = case platformArch p of
79 ArchX86 -> True
80 ArchX86_64 -> False
81 ArchPPC -> True
82 ArchPPC_64 -> False
83 ArchSPARC -> True
84 ArchARM _ _ -> True
85
86
87 -- | This predicates tells us whether the OS supports ELF-like shared libraries.
88 osElfTarget :: OS -> Bool
89 osElfTarget OSLinux = True
90 osElfTarget OSFreeBSD = True
91 osElfTarget OSOpenBSD = True
92 osElfTarget OSSolaris2 = True
93 osElfTarget OSDarwin = False
94 osElfTarget OSMinGW32 = False
95
96
97 -- | This is the target platform as far as the #ifdefs are concerned.
98 -- These are set in includes/ghcplatform.h by the autoconf scripts
99 defaultTargetPlatform :: Platform
100 defaultTargetPlatform
101 = Platform defaultTargetArch defaultTargetOS
102
103
104 -- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
105 defaultTargetArch :: Arch
106 #if i386_TARGET_ARCH
107 defaultTargetArch = ArchX86
108 #elif x86_64_TARGET_ARCH
109 defaultTargetArch = ArchX86_64
110 #elif powerpc_TARGET_ARCH
111 defaultTargetArch = ArchPPC
112 #elif powerpc64_TARGET_ARCH
113 defaultTargetArch = ArchPPC_64
114 #elif sparc_TARGET_ARCH
115 defaultTargetArch = ArchSPARC
116 #elif arm_TARGET_ARCH
117 defaultTargetArch = ArchARM defaultTargetArmISA defaultTargetArmISAExt
118 #else
119 #error Unknown Arch
120 #endif
121
122
123 -- | Move the evil TARGET_OS #ifdefs into Haskell land.
124 defaultTargetOS :: OS
125 #if linux_TARGET_OS
126 defaultTargetOS = OSLinux
127 #elif darwin_TARGET_OS
128 defaultTargetOS = OSDarwin
129 #elif solaris2_TARGET_OS
130 defaultTargetOS = OSSolaris2
131 #elif mingw32_TARGET_OS
132 defaultTargetOS = OSMinGW32
133 #elif freebsd_TARGET_OS
134 defaultTargetOS = OSFreeBSD
135 #elif kfreebsdgnu_TARGET_OS
136 defaultTargetOS = OSFreeBSD
137 #elif openbsd_TARGET_OS
138 defaultTargetOS = OSOpenBSD
139 #else
140 #error Unknown OS
141 #endif
142
143 #if arm_TARGET_ARCH
144 defaultTargetArmISA :: ArmISA
145 #if defined(arm_HOST_ARCH_PRE_ARMv6)
146 defaultTargetArmISA = ARMv5
147 #elif defined(arm_HOST_ARCH_PRE_ARMv7)
148 defaultTargetArmISA = ARMv6
149 #else
150 defaultTargetArmISA = ARMv7
151 #endif
152
153 defaultTargetArmISAExt :: [ArmISAExt]
154 #if defined(arm_TARGET_ARCH) && !defined(arm_HOST_ARCH_PRE_ARMv7)
155 /* wild guess really, in case of ARMv7 we assume both VFPv3 and NEON presented
156 however this is not true for SoCs like NVidia Tegra2 and Marvell Dove */
157 defaultTargetArmISAExt = [VFPv3, NEON]
158 #else
159 defaultTargetArmISAExt = []
160 #endif
161 #endif /* arm_TARGET_ARCH */