Platform.hs 2.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11

-- | A description of the platform we're compiling for.
--	Used by the native code generator.
--	In the future, this module should be the only one that references
--	the evil #defines for each TARGET_ARCH and TARGET_OS
--
module Platform (
	Platform(..),
	Arch(..),
	OS(..),

12
13
	defaultTargetPlatform,
	osElfTarget
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
)

where

#include "HsVersions.h"


-- | Contains enough information for the native code generator to emit
--	code for this platform.
data Platform
	= Platform 
	{ platformArch	:: Arch
	, platformOS	:: OS }


-- | Architectures that the native code generator knows about.
--	TODO: It might be nice to extend these constructors with information
--	about what instruction set extensions an architecture might support.
--
data Arch
34
35
	= ArchUnknown
	| ArchX86
36
37
38
39
40
41
42
43
44
45
46
47
48
	| ArchX86_64
	| ArchPPC
	| ArchPPC_64
	| ArchSPARC
	deriving (Show, Eq)
	

-- | Operating systems that the native code generator knows about.
--	Having OSUnknown should produce a sensible default, but no promises.
data OS
	= OSUnknown
	| OSLinux
	| OSDarwin
kgardas's avatar
kgardas committed
49
	| OSSolaris2
50
	| OSMinGW32
51
	| OSFreeBSD
kili's avatar
kili committed
52
	| OSOpenBSD
53
54
55
	deriving (Show, Eq)


56
57
58
59
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
osElfTarget OSLinux   = True
osElfTarget OSFreeBSD = True
kili's avatar
kili committed
60
osElfTarget OSOpenBSD = True
61
osElfTarget OSSolaris2 = True
62
63
osElfTarget _         = False

64
65
66
67
68
69
70
71
72
-- | This is the target platform as far as the #ifdefs are concerned.
--	These are set in includes/ghcplatform.h by the autoconf scripts
defaultTargetPlatform :: Platform
defaultTargetPlatform
	= Platform defaultTargetArch defaultTargetOS


-- | Move the evil TARGET_ARCH #ifdefs into Haskell land.
defaultTargetArch :: Arch
73
#if i386_TARGET_ARCH
74
75
76
77
78
79
80
81
82
83
defaultTargetArch	= ArchX86
#elif x86_64_TARGET_ARCH
defaultTargetArch	= ArchX86_64
#elif powerpc_TARGET_ARCH
defaultTargetArch	= ArchPPC
#elif powerpc64_TARGET_ARCH
defaultTargetArch	= ArchPPC_64
#elif sparc_TARGET_ARCH
defaultTargetArch	= ArchSPARC
#else
84
defaultTargetArch	= ArchUnknown
85
86
87
88
89
90
91
92
93
#endif


-- | Move the evil TARGET_OS #ifdefs into Haskell land.
defaultTargetOS :: OS
#if   linux_TARGET_OS
defaultTargetOS	= OSLinux
#elif darwin_TARGET_OS
defaultTargetOS	= OSDarwin
kgardas's avatar
kgardas committed
94
95
#elif solaris2_TARGET_OS
defaultTargetOS	= OSSolaris2
96
97
#elif mingw32_TARGET_OS
defaultTargetOS	= OSMinGW32
98
99
#elif freebsd_TARGET_OS
defaultTargetOS	= OSFreeBSD
kili's avatar
kili committed
100
101
#elif openbsd_TARGET_OS
defaultTargetOS	= OSOpenBSD
102
103
104
105
#else
defaultTargetOS	= OSUnknown
#endif