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
26 opt_SuppressCoercions,
27 opt_SuppressModulePrefixes,
28 opt_SuppressTypeApplications,
30 opt_PprStyle_Debug, opt_TraceLevel,
41 opt_IrrefutableTuples,
46 opt_SimpleListLiterals,
48 opt_SimplNoPreInlining,
49 opt_SimplExcessPrecision,
53 opt_UF_CreationThreshold,
55 opt_UF_FunAppDiscount,
60 -- Optimization fuel controls
81 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
84 #include "HsVersions.h"
89 import Maybes ( firstJusts )
92 import Data.Maybe ( listToMaybe )
94 import System.IO.Unsafe ( unsafePerformIO )
97 -----------------------------------------------------------------------------
100 initStaticOpts :: IO ()
101 initStaticOpts = writeIORef v_opt_C_ready True
103 addOpt :: String -> IO ()
104 addOpt = consIORef v_opt_C
106 addWay :: WayName -> IO ()
107 addWay = consIORef v_Ways . lkupWay
109 removeOpt :: String -> IO ()
111 fs <- readIORef v_opt_C
112 writeIORef v_opt_C $! filter (/= f) fs
114 lookUp :: FastString -> Bool
115 lookup_def_int :: String -> Int -> Int
116 lookup_def_float :: String -> Float -> Float
117 lookup_str :: String -> Maybe String
119 -- holds the static opts while they're being collected, before
120 -- being unsafely read by unpacked_static_opts below.
121 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
122 GLOBAL_VAR(v_opt_C_ready, False, Bool)
124 staticFlags :: [String]
125 staticFlags = unsafePerformIO $ do
126 ready <- readIORef v_opt_C_ready
128 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
129 else readIORef v_opt_C
131 -- -static is the default
132 defaultStaticOpts :: [String]
133 defaultStaticOpts = ["-static"]
135 packed_static_opts :: [FastString]
136 packed_static_opts = map mkFastString staticFlags
138 lookUp sw = sw `elem` packed_static_opts
140 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
141 -- and returns the string X
143 = case firstJusts (map (stripPrefix sw) staticFlags) of
144 Just ('=' : str) -> Just str
148 lookup_def_int sw def = case (lookup_str sw) of
149 Nothing -> def -- Use default
150 Just xx -> try_read sw xx
152 lookup_def_float sw def = case (lookup_str sw) of
153 Nothing -> def -- Use default
154 Just xx -> try_read sw xx
157 try_read :: Read a => String -> String -> a
158 -- (try_read sw str) tries to read s; if it fails, it
159 -- bleats about flag sw
162 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
163 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
164 -- ToDo: hack alert. We should really parse the arugments
165 -- and announce errors in a more civilised way.
169 Putting the compiler options into temporary at-files
170 may turn out to be necessary later on if we turn hsc into
171 a pure Win32 application where I think there's a command-line
172 length limit of 255. unpacked_opts understands the @ option.
174 unpacked_opts :: [String]
178 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
180 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
184 opt_IgnoreDotGhci :: Bool
185 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
188 -- | Suppress all that is suppressable in core dumps.
189 opt_SuppressAll :: Bool
191 = lookUp (fsLit "-dsuppress-all")
193 -- | Suppress unique ids on variables.
194 opt_SuppressUniques :: Bool
196 = lookUp (fsLit "-dsuppress-all")
197 || lookUp (fsLit "-dsuppress-uniques")
199 -- | Suppress all coercions, them replacing with '...'
200 opt_SuppressCoercions :: Bool
201 opt_SuppressCoercions
202 = lookUp (fsLit "-dsuppress-all")
203 || lookUp (fsLit "-dsuppress-coercions")
205 -- | Suppress module id prefixes on variables.
206 opt_SuppressModulePrefixes :: Bool
207 opt_SuppressModulePrefixes
208 = lookUp (fsLit "-dsuppress-all")
209 || lookUp (fsLit "-dsuppress-module-prefixes")
211 -- | Suppress type applications.
212 opt_SuppressTypeApplications :: Bool
213 opt_SuppressTypeApplications
214 = lookUp (fsLit "-dsuppress-all")
215 || lookUp (fsLit "-dsuppress-type-applications")
217 -- | Suppress info such as arity and unfoldings on identifiers.
218 opt_SuppressIdInfo :: Bool
220 = lookUp (fsLit "-dsuppress-all")
221 || lookUp (fsLit "-dsuppress-idinfo")
224 opt_PprStyle_Debug :: Bool
225 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
227 opt_TraceLevel :: Int
228 opt_TraceLevel = lookup_def_int "-dtrace-level" 1 -- Standard level is 1
231 opt_PprUserLength :: Int
232 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
235 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
237 opt_NoDebugOutput :: Bool
238 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
242 opt_SccProfilingOn :: Bool
243 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
247 opt_Hpc = lookUp (fsLit "-fhpc")
250 opt_DictsStrict :: Bool
251 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
253 opt_IrrefutableTuples :: Bool
254 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
257 opt_Parallel = lookUp (fsLit "-fparallel")
259 opt_SimpleListLiterals :: Bool
260 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
262 opt_NoStateHack :: Bool
263 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
266 opt_CprOff = lookUp (fsLit "-fcpr-off")
267 -- Switch off CPR analysis in the new demand analyser
268 opt_MaxWorkerArgs :: Int
269 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
271 opt_GranMacros :: Bool
272 opt_GranMacros = lookUp (fsLit "-fgransim")
274 opt_HiVersion :: Integer
275 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
277 opt_HistorySize :: Int
278 opt_HistorySize = lookup_def_int "-fhistory-size" 20
280 opt_OmitBlackHoling :: Bool
281 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
283 opt_StubDeadValues :: Bool
284 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
286 -- Simplifier switches
287 opt_SimplNoPreInlining :: Bool
288 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
289 -- NoPreInlining is there just to see how bad things
290 -- get if you don't do it!
291 opt_SimplExcessPrecision :: Bool
292 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
295 -- See Note [Discounts and thresholds] in CoreUnfold
297 opt_UF_CreationThreshold, opt_UF_UseThreshold :: Int
298 opt_UF_DearOp, opt_UF_FunAppDiscount, opt_UF_DictDiscount :: Int
299 opt_UF_KeenessFactor :: Float
301 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
302 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int)
303 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int)
305 opt_UF_DictDiscount = lookup_def_int "-funfolding-dict-discount" (3::Int)
306 -- Be fairly keen to inline a fuction if that means
307 -- we'll be able to pick the right method from a dictionary
309 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
310 opt_UF_DearOp = ( 4 :: Int)
313 -- Related to linking
315 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
317 #elif darwin_TARGET_OS
318 opt_PIC = lookUp (fsLit "-fPIC") || not opt_Static
320 opt_PIC = lookUp (fsLit "-fPIC")
323 opt_Static = lookUp (fsLit "-static")
324 opt_Unregisterised :: Bool
325 opt_Unregisterised = lookUp (fsLit "-funregisterised")
327 -- Derived, not a real option. Determines whether we will be compiling
328 -- info tables that reside just before the entry code, or with an
329 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
330 -- includes/rts/storage/InfoTables.h.
331 tablesNextToCode :: Bool
332 tablesNextToCode = not opt_Unregisterised
333 && cGhcEnableTablesNextToCode == "YES"
335 -- Include full span info in error messages, instead of just the start position.
336 opt_ErrorSpans :: Bool
337 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
340 opt_Ticky = lookUp (fsLit "-ticky")
342 -- object files and libraries to be linked in are collected here.
343 -- ToDo: perhaps this could be done without a global, it wasn't obvious
344 -- how to do it though --SDM.
345 GLOBAL_VAR(v_Ld_inputs, [], [String])
347 -----------------------------------------------------------------------------
350 -- The central concept of a "way" is that all objects in a given
351 -- program must be compiled in the same "way". Certain options change
352 -- parameters of the virtual machine, eg. profiling adds an extra word
353 -- to the object header, so profiling objects cannot be linked with
354 -- non-profiling objects.
356 -- After parsing the command-line options, we determine which "way" we
357 -- are building - this might be a combination way, eg. profiling+threaded.
359 -- We then find the "build-tag" associated with this way, and this
360 -- becomes the suffix used to find .hi files and libraries used in
374 GLOBAL_VAR(v_Ways, [] ,[Way])
376 allowed_combination :: [WayName] -> Bool
377 allowed_combination way = and [ x `allowedWith` y
378 | x <- way, y <- way, x < y ]
380 -- Note ordering in these tests: the left argument is
381 -- <= the right argument, according to the Ord instance
384 -- dyn is allowed with everything
385 _ `allowedWith` WayDyn = True
386 WayDyn `allowedWith` _ = True
388 -- debug is allowed with everything
389 _ `allowedWith` WayDebug = True
390 WayDebug `allowedWith` _ = True
392 WayProf `allowedWith` WayNDP = True
393 WayThreaded `allowedWith` WayProf = True
394 WayThreaded `allowedWith` WayEventLog = True
395 _ `allowedWith` _ = False
398 getWayFlags :: IO [String] -- new options
400 unsorted <- readIORef v_Ways
401 let ways = sortBy (compare `on` wayName) $
402 nubBy ((==) `on` wayName) $ unsorted
403 writeIORef v_Ways ways
405 if not (allowed_combination (map wayName ways))
406 then ghcError (CmdLineError $
407 "combination not supported: " ++
408 foldr1 (\a b -> a ++ '/':b)
411 return (concatMap wayOpts ways)
413 mkBuildTag :: [Way] -> String
414 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
416 lkupWay :: WayName -> Way
418 case listToMaybe (filter ((==) w . wayName) way_details) of
419 Nothing -> error "findBuildTag"
420 Just details -> details
422 isRTSWay :: WayName -> Bool
423 isRTSWay = wayRTSOnly . lkupWay
433 way_details :: [ Way ]
435 [ Way WayThreaded "thr" True "Threaded" [
436 #if defined(freebsd_TARGET_OS)
439 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
440 -- which GHC has some problems with. It's currently not clear whether
441 -- the problems are our fault or theirs, but it seems that using the
442 -- alternative 1:1 threading library libthr works around it:
444 #elif defined(openbsd_TARGET_OS)
447 #elif defined(solaris2_TARGET_OS)
452 Way WayDebug "debug" True "Debug" [],
454 Way WayDyn "dyn" False "Dynamic"
457 #if defined(mingw32_TARGET_OS)
458 -- On Windows, code that is to be linked into a dynamic library must be compiled
459 -- with -fPIC. Labels not in the current package are assumed to be in a DLL
460 -- different from the current one.
462 #elif defined(openbsd_TARGET_OS)
463 -- Without this, linking the shared libHSffi fails because
464 -- it uses pthread mutexes.
469 Way WayProf "p" False "Profiling"
472 , "-optc-DPROFILING" ],
474 Way WayEventLog "l" True "RTS Event Logging"
476 , "-optc-DTRACING" ],
478 Way WayPar "mp" False "Parallel"
480 , "-D__PARALLEL_HASKELL__"
482 , "-package concurrent"
484 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
488 -- at the moment we only change the RTS and could share compiler and libs!
489 Way WayPar "mt" False "Parallel ticky profiling"
491 , "-D__PARALLEL_HASKELL__"
494 , "-package concurrent"
496 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
500 Way WayPar "md" False "Distributed"
502 , "-D__PARALLEL_HASKELL__"
503 , "-D__DISTRIBUTED_HASKELL__"
506 , "-package concurrent"
508 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
512 Way WayGran "mg" False "GranSim"
516 , "-package concurrent" ],
518 Way WayNDP "ndp" False "Nested data parallelism"