Revert "Remove ArchUnknown"
[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 = ArchUnknown
40 | ArchX86
41 | ArchX86_64
42 | ArchPPC
43 | ArchPPC_64
44 | ArchSPARC
45 | ArchARM
46 { armISA :: ArmISA
47 , armISAExt :: [ArmISAExt] }
48 deriving (Show, Eq)
49
50
51 -- | Operating systems that we know about.
52 data OS
53 = OSLinux
54 | OSDarwin
55 | OSSolaris2
56 | OSMinGW32
57 | OSFreeBSD
58 | OSOpenBSD
59 deriving (Show, Eq)
60
61 -- | ARM Instruction Set Architecture and Extensions
62 --
63 data ArmISA
64 = ARMv5
65 | ARMv6
66 | ARMv7
67 deriving (Show, Eq)
68
69 data ArmISAExt
70 = VFPv2
71 | VFPv3
72 | VFPv3D16
73 | NEON
74 | IWMMX2
75 deriving (Show, Eq)
76
77
78 target32Bit :: Platform -> Bool
79 target32Bit p = case platformArch p of
80 ArchUnknown -> panic "Don't know if ArchUnknown is 32bit"
81 ArchX86 -> True
82 ArchX86_64 -> False
83 ArchPPC -> True
84 ArchPPC_64 -> False
85 ArchSPARC -> True
86 ArchARM _ _ -> True
87
88
89 -- | This predicates tells us whether the OS supports ELF-like shared libraries.
90 osElfTarget :: OS -> Bool
91 osElfTarget OSLinux = True
92 osElfTarget OSFreeBSD = True
93 osElfTarget OSOpenBSD = True
94 osElfTarget OSSolaris2 = True
95 osElfTarget OSDarwin = False
96 osElfTarget OSMinGW32 = False
97
98
99 -- | This is the target platform as far as the #ifdefs are concerned.
100 -- These are set in includes/ghcplatform.h by the autoconf scripts
101 defaultTargetPlatform :: Platform
102 defaultTargetPlatform
103 = Platform defaultTargetArch defaultTargetOS
104
105
106 -- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
107 defaultTargetArch :: Arch
108 #if i386_TARGET_ARCH
109 defaultTargetArch = ArchX86
110 #elif x86_64_TARGET_ARCH
111 defaultTargetArch = ArchX86_64
112 #elif powerpc_TARGET_ARCH
113 defaultTargetArch = ArchPPC
114 #elif powerpc64_TARGET_ARCH
115 defaultTargetArch = ArchPPC_64
116 #elif sparc_TARGET_ARCH
117 defaultTargetArch = ArchSPARC
118 #elif arm_TARGET_ARCH
119 defaultTargetArch = ArchARM defaultTargetArmISA defaultTargetArmISAExt
120 #else
121 defaultTargetArch = ArchUnknown
122 #endif
123
124
125 -- | Move the evil TARGET_OS #ifdefs into Haskell land.
126 defaultTargetOS :: OS
127 #if linux_TARGET_OS
128 defaultTargetOS = OSLinux
129 #elif darwin_TARGET_OS
130 defaultTargetOS = OSDarwin
131 #elif solaris2_TARGET_OS
132 defaultTargetOS = OSSolaris2
133 #elif mingw32_TARGET_OS
134 defaultTargetOS = OSMinGW32
135 #elif freebsd_TARGET_OS
136 defaultTargetOS = OSFreeBSD
137 #elif kfreebsdgnu_TARGET_OS
138 defaultTargetOS = OSFreeBSD
139 #elif openbsd_TARGET_OS
140 defaultTargetOS = OSOpenBSD
141 #else
142 #error Unknown OS
143 #endif
144
145 #if arm_TARGET_ARCH
146 defaultTargetArmISA :: ArmISA
147 #if defined(arm_HOST_ARCH_PRE_ARMv6)
148 defaultTargetArmISA = ARMv5
149 #elif defined(arm_HOST_ARCH_PRE_ARMv7)
150 defaultTargetArmISA = ARMv6
151 #else
152 defaultTargetArmISA = ARMv7
153 #endif
154
155 defaultTargetArmISAExt :: [ArmISAExt]
156 #if defined(arm_TARGET_ARCH) && !defined(arm_HOST_ARCH_PRE_ARMv7)
157 /* wild guess really, in case of ARMv7 we assume both VFPv3 and NEON presented
158 however this is not true for SoCs like NVidia Tegra2 and Marvell Dove */
159 defaultTargetArmISAExt = [VFPv3, NEON]
160 #else
161 defaultTargetArmISAExt = []
162 #endif
163 #endif /* arm_TARGET_ARCH */