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