Fill out the osElfTarget definition
[ghc-hetmet.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
11         defaultTargetPlatform,
12         target32Bit,
13         osElfTarget
14 )
15
16 where
17
18 import Panic
19
20 #include "HsVersions.h"
21
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
30
31 -- | Architectures that the native code generator knows about.
32 --      TODO: It might be nice to extend these constructors with information
33 --      about what instruction set extensions an architecture might support.
34 --
35 data Arch
36         = ArchUnknown
37         | ArchX86
38         | ArchX86_64
39         | ArchPPC
40         | ArchPPC_64
41         | ArchSPARC
42         deriving (Show, Eq)
43
44
45 -- | Operating systems that the native code generator knows about.
46 --      Having OSUnknown should produce a sensible default, but no promises.
47 data OS
48         = OSUnknown
49         | OSLinux
50         | OSDarwin
51         | OSSolaris2
52         | OSMinGW32
53         | OSFreeBSD
54         | OSOpenBSD
55         deriving (Show, Eq)
56
57
58 target32Bit :: Platform -> Bool
59 target32Bit p = case platformArch p of
60                 ArchUnknown -> panic "Don't know if ArchUnknown is 32bit"
61                 ArchX86     -> True
62                 ArchX86_64  -> False
63                 ArchPPC     -> True
64                 ArchPPC_64  -> False
65                 ArchSPARC   -> True
66
67
68 -- | This predicates tells us whether the OS supports ELF-like shared libraries.
69 osElfTarget :: OS -> Bool
70 osElfTarget OSLinux    = True
71 osElfTarget OSFreeBSD  = True
72 osElfTarget OSOpenBSD  = True
73 osElfTarget OSSolaris2 = True
74 osElfTarget OSDarwin   = False
75 osElfTarget OSMinGW32  = False
76 osElfTarget OSUnknown  = panic "Don't know if OSUnknown is elf"
77
78
79 -- | This is the target platform as far as the #ifdefs are concerned.
80 --      These are set in includes/ghcplatform.h by the autoconf scripts
81 defaultTargetPlatform :: Platform
82 defaultTargetPlatform
83         = Platform defaultTargetArch defaultTargetOS
84
85
86 -- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
87 defaultTargetArch :: Arch
88 #if i386_TARGET_ARCH
89 defaultTargetArch       = ArchX86
90 #elif x86_64_TARGET_ARCH
91 defaultTargetArch       = ArchX86_64
92 #elif powerpc_TARGET_ARCH
93 defaultTargetArch       = ArchPPC
94 #elif powerpc64_TARGET_ARCH
95 defaultTargetArch       = ArchPPC_64
96 #elif sparc_TARGET_ARCH
97 defaultTargetArch       = ArchSPARC
98 #else
99 defaultTargetArch       = ArchUnknown
100 #endif
101
102
103 -- | Move the evil TARGET_OS #ifdefs into Haskell land.
104 defaultTargetOS :: OS
105 #if   linux_TARGET_OS
106 defaultTargetOS = OSLinux
107 #elif darwin_TARGET_OS
108 defaultTargetOS = OSDarwin
109 #elif solaris2_TARGET_OS
110 defaultTargetOS = OSSolaris2
111 #elif mingw32_TARGET_OS
112 defaultTargetOS = OSMinGW32
113 #elif freebsd_TARGET_OS
114 defaultTargetOS = OSFreeBSD
115 #elif openbsd_TARGET_OS
116 defaultTargetOS = OSOpenBSD
117 #else
118 defaultTargetOS = OSUnknown
119 #endif
120