Platform.hs 2.44 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 17
)

where

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


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

47

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

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

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

77

78
target32Bit :: Platform -> Bool
79
target32Bit p = platformWordSize p == 4
80

81 82
-- | This predicates tells us whether the OS supports ELF-like shared libraries.
osElfTarget :: OS -> Bool
83 84 85
osElfTarget OSLinux    = True
osElfTarget OSFreeBSD  = True
osElfTarget OSOpenBSD  = True
Ian Lynagh's avatar
Ian Lynagh committed
86
osElfTarget OSNetBSD   = True
87
osElfTarget OSSolaris2 = True
88 89
osElfTarget OSDarwin   = False
osElfTarget OSMinGW32  = False
90 91 92 93 94
osElfTarget OSUnknown  = False
 -- Defaulting to False is safe; it means don't rely on any
 -- ELF-specific functionality.  It is important to have a default for
 -- portability, otherwise we have to answer this question for every
 -- new platform we compile on (even unreg).