NCG: Split up the native code generator into arch specific modules
[ghc-hetmet.git] / compiler / nativeGen / Platform.hs
1
2 -- | A description of the platform we're compiling for.
3 --      Used by the native code generator.
4 --      In the future, this module should be the only one that references
5 --      the evil #defines for each TARGET_ARCH and TARGET_OS
6 --
7 module Platform (
8         Platform(..),
9         Arch(..),
10         OS(..),
11
12         defaultTargetPlatform
13 )
14
15 where
16
17 #include "HsVersions.h"
18
19
20 -- | Contains enough information for the native code generator to emit
21 --      code for this platform.
22 data Platform
23         = Platform 
24         { platformArch  :: Arch
25         , platformOS    :: OS }
26
27
28 -- | Architectures that the native code generator knows about.
29 --      TODO: It might be nice to extend these constructors with information
30 --      about what instruction set extensions an architecture might support.
31 --
32 data Arch
33         = ArchAlpha
34         | ArchX86
35         | ArchX86_64
36         | ArchPPC
37         | ArchPPC_64
38         | ArchSPARC
39         deriving (Show, Eq)
40         
41
42 -- | Operating systems that the native code generator knows about.
43 --      Having OSUnknown should produce a sensible default, but no promises.
44 data OS
45         = OSUnknown
46         | OSLinux
47         | OSDarwin
48         | OSSolaris
49         | OSMinGW32
50         deriving (Show, Eq)
51
52
53 -- | This is the target platform as far as the #ifdefs are concerned.
54 --      These are set in includes/ghcplatform.h by the autoconf scripts
55 defaultTargetPlatform :: Platform
56 defaultTargetPlatform
57         = Platform defaultTargetArch defaultTargetOS
58
59
60 -- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
61 defaultTargetArch :: Arch
62 #if   alpha_TARGET_ARCH
63 defaultTargetArch       = ArchAlpha
64 #elif i386_TARGET_ARCH
65 defaultTargetArch       = ArchX86
66 #elif x86_64_TARGET_ARCH
67 defaultTargetArch       = ArchX86_64
68 #elif powerpc_TARGET_ARCH
69 defaultTargetArch       = ArchPPC
70 #elif powerpc64_TARGET_ARCH
71 defaultTargetArch       = ArchPPC_64
72 #elif sparc_TARGET_ARCH
73 defaultTargetArch       = ArchSPARC
74 #else
75 #error  "Platform.buildArch: undefined"
76 #endif
77
78
79 -- | Move the evil TARGET_OS #ifdefs into Haskell land.
80 defaultTargetOS :: OS
81 #if   linux_TARGET_OS
82 defaultTargetOS = OSLinux
83 #elif darwin_TARGET_OS
84 defaultTargetOS = OSDarwin
85 #elif solaris_TARGET_OS
86 defaultTargetOS = OSSolaris
87 #elif mingw32_TARGET_OS
88 defaultTargetOS = OSMinGW32
89 #else
90 defaultTargetOS = OSUnknown
91 #endif
92