Scrap DEC OSF/1 support
[ghc.git] / compiler / utils / Platform.hs
1
2 -- | A description of the platform we're compiling for.
3 --
4 module Platform (
5 Platform(..),
6 Arch(..),
7 OS(..),
8 ArmISA(..),
9 ArmISAExt(..),
10 ArmABI(..),
11 PPC_64ABI(..),
12
13 target32Bit,
14 isARM,
15 osElfTarget,
16 osMachOTarget,
17 platformUsesFrameworks,
18 platformBinariesAreStaticLibs,
19 )
20
21 where
22
23 -- | Contains enough information for the native code generator to emit
24 -- code for this platform.
25 data Platform
26 = Platform {
27 platformArch :: Arch,
28 platformOS :: OS,
29 -- Word size in bytes (i.e. normally 4 or 8,
30 -- for 32bit and 64bit platforms respectively)
31 platformWordSize :: {-# UNPACK #-} !Int,
32 platformUnregisterised :: Bool,
33 platformHasGnuNonexecStack :: Bool,
34 platformHasIdentDirective :: Bool,
35 platformHasSubsectionsViaSymbols :: Bool,
36 platformIsCrossCompiling :: Bool
37 }
38 deriving (Read, Show, Eq)
39
40
41 -- | Architectures that the native code generator knows about.
42 -- TODO: It might be nice to extend these constructors with information
43 -- about what instruction set extensions an architecture might support.
44 --
45 data Arch
46 = ArchUnknown
47 | ArchX86
48 | ArchX86_64
49 | ArchPPC
50 | ArchPPC_64
51 { ppc_64ABI :: PPC_64ABI
52 }
53 | ArchSPARC
54 | ArchSPARC64
55 | ArchARM
56 { armISA :: ArmISA
57 , armISAExt :: [ArmISAExt]
58 , armABI :: ArmABI
59 }
60 | ArchARM64
61 | ArchAlpha
62 | ArchMipseb
63 | ArchMipsel
64 | ArchJavaScript
65 deriving (Read, Show, Eq)
66
67 isARM :: Arch -> Bool
68 isARM (ArchARM {}) = True
69 isARM ArchARM64 = True
70 isARM _ = False
71
72 -- | Operating systems that the native code generator knows about.
73 -- Having OSUnknown should produce a sensible default, but no promises.
74 data OS
75 = OSUnknown
76 | OSLinux
77 | OSDarwin
78 | OSiOS
79 | OSSolaris2
80 | OSMinGW32
81 | OSFreeBSD
82 | OSDragonFly
83 | OSOpenBSD
84 | OSNetBSD
85 | OSKFreeBSD
86 | OSHaiku
87 | OSQNXNTO
88 | OSAndroid
89 | OSAIX
90 deriving (Read, Show, Eq)
91
92 -- | ARM Instruction Set Architecture, Extensions and ABI
93 --
94 data ArmISA
95 = ARMv5
96 | ARMv6
97 | ARMv7
98 deriving (Read, Show, Eq)
99
100 data ArmISAExt
101 = VFPv2
102 | VFPv3
103 | VFPv3D16
104 | NEON
105 | IWMMX2
106 deriving (Read, Show, Eq)
107
108 data ArmABI
109 = SOFT
110 | SOFTFP
111 | HARD
112 deriving (Read, Show, Eq)
113
114 -- | PowerPC 64-bit ABI
115 --
116 data PPC_64ABI
117 = ELF_V1
118 | ELF_V2
119 deriving (Read, Show, Eq)
120
121 -- | This predicate tells us whether the platform is 32-bit.
122 target32Bit :: Platform -> Bool
123 target32Bit p = platformWordSize p == 4
124
125 -- | This predicate tells us whether the OS supports ELF-like shared libraries.
126 osElfTarget :: OS -> Bool
127 osElfTarget OSLinux = True
128 osElfTarget OSFreeBSD = True
129 osElfTarget OSDragonFly = True
130 osElfTarget OSOpenBSD = True
131 osElfTarget OSNetBSD = True
132 osElfTarget OSSolaris2 = True
133 osElfTarget OSDarwin = False
134 osElfTarget OSiOS = False
135 osElfTarget OSMinGW32 = False
136 osElfTarget OSKFreeBSD = True
137 osElfTarget OSHaiku = True
138 osElfTarget OSQNXNTO = False
139 osElfTarget OSAndroid = True
140 osElfTarget OSAIX = False
141 osElfTarget OSUnknown = False
142 -- Defaulting to False is safe; it means don't rely on any
143 -- ELF-specific functionality. It is important to have a default for
144 -- portability, otherwise we have to answer this question for every
145 -- new platform we compile on (even unreg).
146
147 -- | This predicate tells us whether the OS support Mach-O shared libraries.
148 osMachOTarget :: OS -> Bool
149 osMachOTarget OSDarwin = True
150 osMachOTarget _ = False
151
152 osUsesFrameworks :: OS -> Bool
153 osUsesFrameworks OSDarwin = True
154 osUsesFrameworks OSiOS = True
155 osUsesFrameworks _ = False
156
157 platformUsesFrameworks :: Platform -> Bool
158 platformUsesFrameworks = osUsesFrameworks . platformOS
159
160 osBinariesAreStaticLibs :: OS -> Bool
161 osBinariesAreStaticLibs OSiOS = True
162 osBinariesAreStaticLibs _ = False
163
164 platformBinariesAreStaticLibs :: Platform -> Bool
165 platformBinariesAreStaticLibs = osBinariesAreStaticLibs . platformOS
166