1 {-# OPTIONS -fno-cse #-}
2 -- -fno-cse is needed for GLOBAL_VAR's to behave properly
4 -----------------------------------------------------------------------------
8 -- Static flags can only be set once, on the command-line. Inside GHC,
9 -- each static flag corresponds to a top-level value, usually of type Bool.
11 -- (c) The University of Glasgow 2005
13 -----------------------------------------------------------------------------
20 WayName(..), Way(..), v_Ways, isRTSWay, mkBuildTag,
22 -- Output style options
25 opt_SuppressCoercions,
37 opt_IrrefutableTuples,
43 opt_SimpleListLiterals,
45 opt_SimplNoPreInlining,
46 opt_SimplExcessPrecision,
50 opt_UF_CreationThreshold,
52 opt_UF_FunAppDiscount,
57 -- Optimization fuel controls
78 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
81 #include "HsVersions.h"
86 import Maybes ( firstJust )
89 import Data.Maybe ( listToMaybe )
91 import System.IO.Unsafe ( unsafePerformIO )
94 -----------------------------------------------------------------------------
97 initStaticOpts :: IO ()
98 initStaticOpts = writeIORef v_opt_C_ready True
100 addOpt :: String -> IO ()
101 addOpt = consIORef v_opt_C
103 addWay :: WayName -> IO ()
104 addWay = consIORef v_Ways . lkupWay
106 removeOpt :: String -> IO ()
108 fs <- readIORef v_opt_C
109 writeIORef v_opt_C $! filter (/= f) fs
111 lookUp :: FastString -> Bool
112 lookup_def_int :: String -> Int -> Int
113 lookup_def_float :: String -> Float -> Float
114 lookup_str :: String -> Maybe String
116 -- holds the static opts while they're being collected, before
117 -- being unsafely read by unpacked_static_opts below.
118 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
119 GLOBAL_VAR(v_opt_C_ready, False, Bool)
121 staticFlags :: [String]
122 staticFlags = unsafePerformIO $ do
123 ready <- readIORef v_opt_C_ready
125 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
126 else readIORef v_opt_C
128 -- -static is the default
129 defaultStaticOpts :: [String]
130 defaultStaticOpts = ["-static"]
132 packed_static_opts :: [FastString]
133 packed_static_opts = map mkFastString staticFlags
135 lookUp sw = sw `elem` packed_static_opts
137 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
138 -- and returns the string X
140 = case firstJust (map (stripPrefix sw) staticFlags) of
141 Just ('=' : str) -> Just str
145 lookup_def_int sw def = case (lookup_str sw) of
146 Nothing -> def -- Use default
147 Just xx -> try_read sw xx
149 lookup_def_float sw def = case (lookup_str sw) of
150 Nothing -> def -- Use default
151 Just xx -> try_read sw xx
154 try_read :: Read a => String -> String -> a
155 -- (try_read sw str) tries to read s; if it fails, it
156 -- bleats about flag sw
159 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
160 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
161 -- ToDo: hack alert. We should really parse the arugments
162 -- and announce errors in a more civilised way.
166 Putting the compiler options into temporary at-files
167 may turn out to be necessary later on if we turn hsc into
168 a pure Win32 application where I think there's a command-line
169 length limit of 255. unpacked_opts understands the @ option.
171 unpacked_opts :: [String]
175 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
177 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
181 opt_IgnoreDotGhci :: Bool
182 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
185 opt_SuppressUniques :: Bool
186 opt_SuppressUniques = lookUp (fsLit "-dsuppress-uniques")
187 opt_SuppressCoercions :: Bool
188 opt_SuppressCoercions = lookUp (fsLit "-dsuppress-coercions")
189 opt_PprStyle_Debug :: Bool
190 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
191 opt_PprUserLength :: Int
192 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
194 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
195 opt_NoDebugOutput :: Bool
196 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
200 opt_SccProfilingOn :: Bool
201 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
205 opt_Hpc = lookUp (fsLit "-fhpc")
208 opt_DictsStrict :: Bool
209 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
210 opt_IrrefutableTuples :: Bool
211 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
213 opt_Parallel = lookUp (fsLit "-fparallel")
216 opt_DsMultiTyVar :: Bool
217 opt_DsMultiTyVar = not (lookUp (fsLit "-fno-ds-multi-tyvar"))
220 opt_SimpleListLiterals :: Bool
221 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
223 opt_NoStateHack :: Bool
224 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
227 opt_CprOff = lookUp (fsLit "-fcpr-off")
228 -- Switch off CPR analysis in the new demand analyser
229 opt_MaxWorkerArgs :: Int
230 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
232 opt_GranMacros :: Bool
233 opt_GranMacros = lookUp (fsLit "-fgransim")
234 opt_HiVersion :: Integer
235 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
236 opt_HistorySize :: Int
237 opt_HistorySize = lookup_def_int "-fhistory-size" 20
238 opt_OmitBlackHoling :: Bool
239 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
240 opt_StubDeadValues :: Bool
241 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
243 -- Simplifier switches
244 opt_SimplNoPreInlining :: Bool
245 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
246 -- NoPreInlining is there just to see how bad things
247 -- get if you don't do it!
248 opt_SimplExcessPrecision :: Bool
249 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
252 -- See Note [Discounts and thresholds] in CoreUnfold
254 opt_UF_CreationThreshold, opt_UF_UseThreshold :: Int
255 opt_UF_DearOp, opt_UF_FunAppDiscount, opt_UF_DictDiscount :: Int
256 opt_UF_KeenessFactor :: Float
258 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
259 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int)
260 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int)
261 opt_UF_DictDiscount = lookup_def_int "-funfolding-dict-discount" (1::Int)
262 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
263 opt_UF_DearOp = ( 4 :: Int)
266 -- Related to linking
268 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
270 #elif darwin_TARGET_OS
271 opt_PIC = lookUp (fsLit "-fPIC") || not opt_Static
273 opt_PIC = lookUp (fsLit "-fPIC")
276 opt_Static = lookUp (fsLit "-static")
277 opt_Unregisterised :: Bool
278 opt_Unregisterised = lookUp (fsLit "-funregisterised")
280 -- Derived, not a real option. Determines whether we will be compiling
281 -- info tables that reside just before the entry code, or with an
282 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
283 -- includes/rts/storage/InfoTables.h.
284 tablesNextToCode :: Bool
285 tablesNextToCode = not opt_Unregisterised
286 && cGhcEnableTablesNextToCode == "YES"
288 -- Include full span info in error messages, instead of just the start position.
289 opt_ErrorSpans :: Bool
290 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
293 opt_Ticky = lookUp (fsLit "-ticky")
295 -- object files and libraries to be linked in are collected here.
296 -- ToDo: perhaps this could be done without a global, it wasn't obvious
297 -- how to do it though --SDM.
298 GLOBAL_VAR(v_Ld_inputs, [], [String])
300 -----------------------------------------------------------------------------
303 -- The central concept of a "way" is that all objects in a given
304 -- program must be compiled in the same "way". Certain options change
305 -- parameters of the virtual machine, eg. profiling adds an extra word
306 -- to the object header, so profiling objects cannot be linked with
307 -- non-profiling objects.
309 -- After parsing the command-line options, we determine which "way" we
310 -- are building - this might be a combination way, eg. profiling+threaded.
312 -- We then find the "build-tag" associated with this way, and this
313 -- becomes the suffix used to find .hi files and libraries used in
327 GLOBAL_VAR(v_Ways, [] ,[Way])
329 allowed_combination :: [WayName] -> Bool
330 allowed_combination way = and [ x `allowedWith` y
331 | x <- way, y <- way, x < y ]
333 -- Note ordering in these tests: the left argument is
334 -- <= the right argument, according to the Ord instance
337 -- dyn is allowed with everything
338 _ `allowedWith` WayDyn = True
339 WayDyn `allowedWith` _ = True
341 -- debug is allowed with everything
342 _ `allowedWith` WayDebug = True
343 WayDebug `allowedWith` _ = True
345 WayProf `allowedWith` WayNDP = True
346 WayThreaded `allowedWith` WayProf = True
347 WayThreaded `allowedWith` WayEventLog = True
348 _ `allowedWith` _ = False
351 getWayFlags :: IO [String] -- new options
353 unsorted <- readIORef v_Ways
354 let ways = sortBy (compare `on` wayName) $
355 nubBy ((==) `on` wayName) $ unsorted
356 writeIORef v_Ways ways
358 if not (allowed_combination (map wayName ways))
359 then ghcError (CmdLineError $
360 "combination not supported: " ++
361 foldr1 (\a b -> a ++ '/':b)
364 return (concatMap wayOpts ways)
366 mkBuildTag :: [Way] -> String
367 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
369 lkupWay :: WayName -> Way
371 case listToMaybe (filter ((==) w . wayName) way_details) of
372 Nothing -> error "findBuildTag"
373 Just details -> details
375 isRTSWay :: WayName -> Bool
376 isRTSWay = wayRTSOnly . lkupWay
386 way_details :: [ Way ]
388 [ Way WayThreaded "thr" True "Threaded" [
389 #if defined(freebsd_TARGET_OS)
392 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
393 -- which GHC has some problems with. It's currently not clear whether
394 -- the problems are our fault or theirs, but it seems that using the
395 -- alternative 1:1 threading library libthr works around it:
397 #elif defined(solaris2_TARGET_OS)
402 Way WayDebug "debug" True "Debug" [],
404 Way WayDyn "dyn" False "Dynamic"
407 #if defined(mingw32_TARGET_OS)
408 -- On Windows, code that is to be linked into a dynamic library must be compiled
409 -- with -fPIC. Labels not in the current package are assumed to be in a DLL
410 -- different from the current one.
415 Way WayProf "p" False "Profiling"
418 , "-optc-DPROFILING" ],
420 Way WayEventLog "l" True "RTS Event Logging"
422 , "-optc-DTRACING" ],
424 Way WayPar "mp" False "Parallel"
426 , "-D__PARALLEL_HASKELL__"
428 , "-package concurrent"
430 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
434 -- at the moment we only change the RTS and could share compiler and libs!
435 Way WayPar "mt" False "Parallel ticky profiling"
437 , "-D__PARALLEL_HASKELL__"
440 , "-package concurrent"
442 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
446 Way WayPar "md" False "Distributed"
448 , "-D__PARALLEL_HASKELL__"
449 , "-D__DISTRIBUTED_HASKELL__"
452 , "-package concurrent"
454 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
458 Way WayGran "mg" False "GranSim"
462 , "-package concurrent" ],
464 Way WayNDP "ndp" False "Nested data parallelism"