Platform.hs 2.19 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
        deriving (Read, Show, Eq)
26
27
28


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

44

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

57
58
59
60
61
62
-- | ARM Instruction Set Architecture and Extensions
--
data ArmISA
    = ARMv5
    | ARMv6
    | ARMv7
63
    deriving (Read, Show, Eq)
64
65
66
67
68
69
70

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

73

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


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