Platform.hs 4.5 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
        ArmABI(..),
11
        PPC_64ABI(..),
12

13
        target32Bit,
mad.one@gmail.com's avatar
mad.one@gmail.com committed
14
        isARM,
15
        osElfTarget,
16
        osMachOTarget,
17
        osSubsectionsViaSymbols,
18
        platformUsesFrameworks,
19
        platformBinariesAreStaticLibs,
20 21 22 23 24
)

where

-- | Contains enough information for the native code generator to emit
25
--      code for this platform.
26
data Platform
27 28 29
        = Platform {
              platformArch                     :: Arch,
              platformOS                       :: OS,
30 31
              -- Word size in bytes (i.e. normally 4 or 8,
              -- for 32bit and 64bit platforms respectively)
32
              platformWordSize                 :: {-# UNPACK #-} !Int,
33
              platformUnregisterised           :: Bool,
34
              platformHasGnuNonexecStack       :: Bool,
35
              platformHasIdentDirective        :: Bool,
36 37
              platformHasSubsectionsViaSymbols :: Bool,
              platformIsCrossCompiling         :: Bool
38
          }
39
        deriving (Read, Show, Eq)
40 41 42


-- | Architectures that the native code generator knows about.
43 44
--      TODO: It might be nice to extend these constructors with information
--      about what instruction set extensions an architecture might support.
45 46
--
data Arch
Ian Lynagh's avatar
Ian Lynagh committed
47 48
        = ArchUnknown
        | ArchX86
49 50 51
        | ArchX86_64
        | ArchPPC
        | ArchPPC_64
52 53
          { ppc_64ABI :: PPC_64ABI
          }
54
        | ArchSPARC
55
        | ArchSPARC64
56
        | ArchARM
57
          { armISA    :: ArmISA
58 59 60
          , armISAExt :: [ArmISAExt]
          , armABI    :: ArmABI
          }
Colin Watson's avatar
Colin Watson committed
61
        | ArchARM64
62 63 64
        | ArchAlpha
        | ArchMipseb
        | ArchMipsel
thoughtpolice's avatar
thoughtpolice committed
65
        | ArchJavaScript
66
        deriving (Read, Show, Eq)
67

mad.one@gmail.com's avatar
mad.one@gmail.com committed
68 69
isARM :: Arch -> Bool
isARM (ArchARM {}) = True
70
isARM ArchARM64    = True
mad.one@gmail.com's avatar
mad.one@gmail.com committed
71
isARM _ = False
72

Ian Lynagh's avatar
Ian Lynagh committed
73 74
-- | Operating systems that the native code generator knows about.
--      Having OSUnknown should produce a sensible default, but no promises.
75
data OS
Ian Lynagh's avatar
Ian Lynagh committed
76 77
        = OSUnknown
        | OSLinux
78
        | OSDarwin
79
        | OSiOS
80 81 82
        | OSSolaris2
        | OSMinGW32
        | OSFreeBSD
83
        | OSDragonFly
84
        | OSOpenBSD
Ian Lynagh's avatar
Ian Lynagh committed
85
        | OSNetBSD
86
        | OSKFreeBSD
pcapriotti's avatar
pcapriotti committed
87
        | OSHaiku
88
        | OSQNXNTO
89
        | OSAndroid
90
        | OSAIX
91
        deriving (Read, Show, Eq)
92

93
-- | ARM Instruction Set Architecture, Extensions and ABI
94 95 96 97 98
--
data ArmISA
    = ARMv5
    | ARMv6
    | ARMv7
99
    deriving (Read, Show, Eq)
100 101 102 103 104 105 106

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

109 110 111 112 113
data ArmABI
    = SOFT
    | SOFTFP
    | HARD
    deriving (Read, Show, Eq)
114

115 116 117 118 119 120 121 122
-- | PowerPC 64-bit ABI
--
data PPC_64ABI
    = ELF_V1
    | ELF_V2
    deriving (Read, Show, Eq)

-- | This predicate tells us whether the platform is 32-bit.
123
target32Bit :: Platform -> Bool
124
target32Bit p = platformWordSize p == 4
125

126
-- | This predicate tells us whether the OS supports ELF-like shared libraries.
127
osElfTarget :: OS -> Bool
128 129 130 131 132 133 134
osElfTarget OSLinux     = True
osElfTarget OSFreeBSD   = True
osElfTarget OSDragonFly = True
osElfTarget OSOpenBSD   = True
osElfTarget OSNetBSD    = True
osElfTarget OSSolaris2  = True
osElfTarget OSDarwin    = False
135
osElfTarget OSiOS       = False
136 137
osElfTarget OSMinGW32   = False
osElfTarget OSKFreeBSD  = True
pcapriotti's avatar
pcapriotti committed
138
osElfTarget OSHaiku     = True
139
osElfTarget OSQNXNTO    = False
140
osElfTarget OSAndroid   = True
141
osElfTarget OSAIX       = False
142
osElfTarget OSUnknown   = False
143 144 145 146
 -- 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).
ian@well-typed.com's avatar
ian@well-typed.com committed
147

148 149 150 151 152
-- | This predicate tells us whether the OS support Mach-O shared libraries.
osMachOTarget :: OS -> Bool
osMachOTarget OSDarwin = True
osMachOTarget _ = False

153 154 155 156 157 158 159 160
osUsesFrameworks :: OS -> Bool
osUsesFrameworks OSDarwin = True
osUsesFrameworks OSiOS    = True
osUsesFrameworks _        = False

platformUsesFrameworks :: Platform -> Bool
platformUsesFrameworks = osUsesFrameworks . platformOS

161 162 163 164
osBinariesAreStaticLibs :: OS -> Bool
osBinariesAreStaticLibs OSiOS = True
osBinariesAreStaticLibs _     = False

165 166 167 168 169
osSubsectionsViaSymbols :: OS -> Bool
osSubsectionsViaSymbols OSDarwin = True
osSubsectionsViaSymbols OSiOS    = True
osSubsectionsViaSymbols _        = False

170 171 172
platformBinariesAreStaticLibs :: Platform -> Bool
platformBinariesAreStaticLibs = osBinariesAreStaticLibs . platformOS