Platform.hs 2.46 KB
Newer Older
1
2
3
4

-- | A description of the platform we're compiling for.
--
module Platform (
5
6
7
        Platform(..),
        Arch(..),
        OS(..),
8
9
        ArmISA(..),
        ArmISAExt(..),
10

11
        target32Bit,
12
        osElfTarget
13
14
15
16
)

where

17
18
import Panic

19
-- | Contains enough information for the native code generator to emit
20
--      code for this platform.
21
data Platform
22
23
24
        = Platform {
              platformArch                     :: Arch,
              platformOS                       :: OS,
25
              platformHasGnuNonexecStack       :: Bool,
26
              platformHasIdentDirective        :: Bool,
27
28
              platformHasSubsectionsViaSymbols :: Bool
          }
29
        deriving (Read, Show, Eq)
30
31
32


-- | Architectures that the native code generator knows about.
33
34
--      TODO: It might be nice to extend these constructors with information
--      about what instruction set extensions an architecture might support.
35
36
--
data Arch
Ian Lynagh's avatar
Ian Lynagh committed
37
38
        = ArchUnknown
        | ArchX86
39
40
41
42
        | ArchX86_64
        | ArchPPC
        | ArchPPC_64
        | ArchSPARC
43
        | ArchARM
44
45
          { armISA    :: ArmISA
          , armISAExt :: [ArmISAExt] }
46
        deriving (Read, Show, Eq)
47

48

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

62
63
64
65
66
67
-- | ARM Instruction Set Architecture and Extensions
--
data ArmISA
    = ARMv5
    | ARMv6
    | ARMv7
68
    deriving (Read, Show, Eq)
69
70
71
72
73
74
75

data ArmISAExt
    = VFPv2
    | VFPv3
    | VFPv3D16
    | NEON
    | IWMMX2
76
    deriving (Read, Show, Eq)
77

78

79
80
target32Bit :: Platform -> Bool
target32Bit p = case platformArch p of
Ian Lynagh's avatar
Ian Lynagh committed
81
                ArchUnknown -> panic "Don't know if ArchUnknown is 32bit"
82
83
84
85
86
                ArchX86     -> True
                ArchX86_64  -> False
                ArchPPC     -> True
                ArchPPC_64  -> False
                ArchSPARC   -> True
87
                ArchARM _ _ -> True
88
89


90
91
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
92
93
94
osElfTarget OSLinux    = True
osElfTarget OSFreeBSD  = True
osElfTarget OSOpenBSD  = True
Ian Lynagh's avatar
Ian Lynagh committed
95
osElfTarget OSNetBSD   = True
96
osElfTarget OSSolaris2 = True
97
98
osElfTarget OSDarwin   = False
osElfTarget OSMinGW32  = False
Ian Lynagh's avatar
Ian Lynagh committed
99
osElfTarget OSUnknown  = panic "Don't know if OSUnknown is elf"
100