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
24 opt_PprStyle_Debug, opt_TraceLevel,
27 -- Suppressing boring aspects of core dumps
30 opt_SuppressCoercions,
31 opt_SuppressModulePrefixes,
32 opt_SuppressTypeApplications,
34 opt_SuppressTypeSignatures,
44 opt_IrrefutableTuples,
49 opt_SimpleListLiterals,
51 opt_SimplNoPreInlining,
52 opt_SimplExcessPrecision,
56 opt_UF_CreationThreshold,
58 opt_UF_FunAppDiscount,
63 -- Optimization fuel controls
84 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
87 #include "HsVersions.h"
92 import Maybes ( firstJusts )
95 import Data.Maybe ( listToMaybe )
97 import System.IO.Unsafe ( unsafePerformIO )
100 -----------------------------------------------------------------------------
103 initStaticOpts :: IO ()
104 initStaticOpts = writeIORef v_opt_C_ready True
106 addOpt :: String -> IO ()
107 addOpt = consIORef v_opt_C
109 addWay :: WayName -> IO ()
110 addWay = consIORef v_Ways . lkupWay
112 removeOpt :: String -> IO ()
114 fs <- readIORef v_opt_C
115 writeIORef v_opt_C $! filter (/= f) fs
117 lookUp :: FastString -> Bool
118 lookup_def_int :: String -> Int -> Int
119 lookup_def_float :: String -> Float -> Float
120 lookup_str :: String -> Maybe String
122 -- holds the static opts while they're being collected, before
123 -- being unsafely read by unpacked_static_opts below.
124 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
125 GLOBAL_VAR(v_opt_C_ready, False, Bool)
127 staticFlags :: [String]
128 staticFlags = unsafePerformIO $ do
129 ready <- readIORef v_opt_C_ready
131 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
132 else readIORef v_opt_C
134 -- -static is the default
135 defaultStaticOpts :: [String]
136 defaultStaticOpts = ["-static"]
138 packed_static_opts :: [FastString]
139 packed_static_opts = map mkFastString staticFlags
141 lookUp sw = sw `elem` packed_static_opts
143 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
144 -- and returns the string X
146 = case firstJusts (map (stripPrefix sw) staticFlags) of
147 Just ('=' : str) -> Just str
151 lookup_def_int sw def = case (lookup_str sw) of
152 Nothing -> def -- Use default
153 Just xx -> try_read sw xx
155 lookup_def_float sw def = case (lookup_str sw) of
156 Nothing -> def -- Use default
157 Just xx -> try_read sw xx
160 try_read :: Read a => String -> String -> a
161 -- (try_read sw str) tries to read s; if it fails, it
162 -- bleats about flag sw
165 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
166 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
167 -- ToDo: hack alert. We should really parse the arugments
168 -- and announce errors in a more civilised way.
172 Putting the compiler options into temporary at-files
173 may turn out to be necessary later on if we turn hsc into
174 a pure Win32 application where I think there's a command-line
175 length limit of 255. unpacked_opts understands the @ option.
177 unpacked_opts :: [String]
181 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
183 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
187 opt_IgnoreDotGhci :: Bool
188 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
191 -- | Suppress all that is suppressable in core dumps.
192 opt_SuppressAll :: Bool
194 = lookUp (fsLit "-dsuppress-all")
196 -- | Suppress unique ids on variables.
197 opt_SuppressUniques :: Bool
199 = lookUp (fsLit "-dsuppress-all")
200 || lookUp (fsLit "-dsuppress-uniques")
202 -- | Suppress all coercions, them replacing with '...'
203 opt_SuppressCoercions :: Bool
204 opt_SuppressCoercions
205 = lookUp (fsLit "-dsuppress-all")
206 || lookUp (fsLit "-dsuppress-coercions")
208 -- | Suppress module id prefixes on variables.
209 opt_SuppressModulePrefixes :: Bool
210 opt_SuppressModulePrefixes
211 = lookUp (fsLit "-dsuppress-all")
212 || lookUp (fsLit "-dsuppress-module-prefixes")
214 -- | Suppress type applications.
215 opt_SuppressTypeApplications :: Bool
216 opt_SuppressTypeApplications
217 = lookUp (fsLit "-dsuppress-all")
218 || lookUp (fsLit "-dsuppress-type-applications")
220 -- | Suppress info such as arity and unfoldings on identifiers.
221 opt_SuppressIdInfo :: Bool
223 = lookUp (fsLit "-dsuppress-all")
224 || lookUp (fsLit "-dsuppress-idinfo")
226 -- | Suppress seprate type signatures in core, but leave types on lambda bound vars
227 opt_SuppressTypeSignatures :: Bool
228 opt_SuppressTypeSignatures
229 = lookUp (fsLit "-dsuppress-all")
230 || lookUp (fsLit "-dsuppress-type-signatures")
233 opt_PprStyle_Debug :: Bool
234 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
236 opt_TraceLevel :: Int
237 opt_TraceLevel = lookup_def_int "-dtrace-level" 1 -- Standard level is 1
240 opt_PprUserLength :: Int
241 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
244 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
246 opt_NoDebugOutput :: Bool
247 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
251 opt_SccProfilingOn :: Bool
252 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
256 opt_Hpc = lookUp (fsLit "-fhpc")
259 opt_DictsStrict :: Bool
260 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
262 opt_IrrefutableTuples :: Bool
263 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
266 opt_Parallel = lookUp (fsLit "-fparallel")
268 opt_SimpleListLiterals :: Bool
269 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
271 opt_NoStateHack :: Bool
272 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
275 opt_CprOff = lookUp (fsLit "-fcpr-off")
276 -- Switch off CPR analysis in the new demand analyser
277 opt_MaxWorkerArgs :: Int
278 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
280 opt_GranMacros :: Bool
281 opt_GranMacros = lookUp (fsLit "-fgransim")
283 opt_HiVersion :: Integer
284 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
286 opt_HistorySize :: Int
287 opt_HistorySize = lookup_def_int "-fhistory-size" 20
289 opt_OmitBlackHoling :: Bool
290 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
292 opt_StubDeadValues :: Bool
293 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
295 -- Simplifier switches
296 opt_SimplNoPreInlining :: Bool
297 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
298 -- NoPreInlining is there just to see how bad things
299 -- get if you don't do it!
300 opt_SimplExcessPrecision :: Bool
301 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
304 -- See Note [Discounts and thresholds] in CoreUnfold
306 opt_UF_CreationThreshold, opt_UF_UseThreshold :: Int
307 opt_UF_DearOp, opt_UF_FunAppDiscount, opt_UF_DictDiscount :: Int
308 opt_UF_KeenessFactor :: Float
310 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
311 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int)
312 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int)
314 opt_UF_DictDiscount = lookup_def_int "-funfolding-dict-discount" (3::Int)
315 -- Be fairly keen to inline a fuction if that means
316 -- we'll be able to pick the right method from a dictionary
318 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
319 opt_UF_DearOp = ( 4 :: Int)
322 -- Related to linking
324 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
326 #elif darwin_TARGET_OS
327 opt_PIC = lookUp (fsLit "-fPIC") || not opt_Static
329 opt_PIC = lookUp (fsLit "-fPIC")
332 opt_Static = lookUp (fsLit "-static")
333 opt_Unregisterised :: Bool
334 opt_Unregisterised = lookUp (fsLit "-funregisterised")
336 -- Derived, not a real option. Determines whether we will be compiling
337 -- info tables that reside just before the entry code, or with an
338 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
339 -- includes/rts/storage/InfoTables.h.
340 tablesNextToCode :: Bool
341 tablesNextToCode = not opt_Unregisterised
342 && cGhcEnableTablesNextToCode == "YES"
344 -- Include full span info in error messages, instead of just the start position.
345 opt_ErrorSpans :: Bool
346 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
349 opt_Ticky = lookUp (fsLit "-ticky")
351 -- object files and libraries to be linked in are collected here.
352 -- ToDo: perhaps this could be done without a global, it wasn't obvious
353 -- how to do it though --SDM.
354 GLOBAL_VAR(v_Ld_inputs, [], [String])
356 -----------------------------------------------------------------------------
359 -- The central concept of a "way" is that all objects in a given
360 -- program must be compiled in the same "way". Certain options change
361 -- parameters of the virtual machine, eg. profiling adds an extra word
362 -- to the object header, so profiling objects cannot be linked with
363 -- non-profiling objects.
365 -- After parsing the command-line options, we determine which "way" we
366 -- are building - this might be a combination way, eg. profiling+threaded.
368 -- We then find the "build-tag" associated with this way, and this
369 -- becomes the suffix used to find .hi files and libraries used in
383 GLOBAL_VAR(v_Ways, [] ,[Way])
385 allowed_combination :: [WayName] -> Bool
386 allowed_combination way = and [ x `allowedWith` y
387 | x <- way, y <- way, x < y ]
389 -- Note ordering in these tests: the left argument is
390 -- <= the right argument, according to the Ord instance
393 -- dyn is allowed with everything
394 _ `allowedWith` WayDyn = True
395 WayDyn `allowedWith` _ = True
397 -- debug is allowed with everything
398 _ `allowedWith` WayDebug = True
399 WayDebug `allowedWith` _ = True
401 WayProf `allowedWith` WayNDP = True
402 WayThreaded `allowedWith` WayProf = True
403 WayThreaded `allowedWith` WayEventLog = True
404 _ `allowedWith` _ = False
407 getWayFlags :: IO [String] -- new options
409 unsorted <- readIORef v_Ways
410 let ways = sortBy (compare `on` wayName) $
411 nubBy ((==) `on` wayName) $ unsorted
412 writeIORef v_Ways ways
414 if not (allowed_combination (map wayName ways))
415 then ghcError (CmdLineError $
416 "combination not supported: " ++
417 foldr1 (\a b -> a ++ '/':b)
420 return (concatMap wayOpts ways)
422 mkBuildTag :: [Way] -> String
423 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
425 lkupWay :: WayName -> Way
427 case listToMaybe (filter ((==) w . wayName) way_details) of
428 Nothing -> error "findBuildTag"
429 Just details -> details
431 isRTSWay :: WayName -> Bool
432 isRTSWay = wayRTSOnly . lkupWay
442 way_details :: [ Way ]
444 [ Way WayThreaded "thr" True "Threaded" [
445 #if defined(freebsd_TARGET_OS)
448 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
449 -- which GHC has some problems with. It's currently not clear whether
450 -- the problems are our fault or theirs, but it seems that using the
451 -- alternative 1:1 threading library libthr works around it:
453 #elif defined(openbsd_TARGET_OS)
456 #elif defined(solaris2_TARGET_OS)
461 Way WayDebug "debug" True "Debug" [],
463 Way WayDyn "dyn" False "Dynamic"
466 #if defined(mingw32_TARGET_OS)
467 -- On Windows, code that is to be linked into a dynamic library must be compiled
468 -- with -fPIC. Labels not in the current package are assumed to be in a DLL
469 -- different from the current one.
471 #elif defined(openbsd_TARGET_OS)
472 -- Without this, linking the shared libHSffi fails because
473 -- it uses pthread mutexes.
478 Way WayProf "p" False "Profiling"
481 , "-optc-DPROFILING" ],
483 Way WayEventLog "l" True "RTS Event Logging"
485 , "-optc-DTRACING" ],
487 Way WayPar "mp" False "Parallel"
489 , "-D__PARALLEL_HASKELL__"
491 , "-package concurrent"
493 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
497 -- at the moment we only change the RTS and could share compiler and libs!
498 Way WayPar "mt" False "Parallel ticky profiling"
500 , "-D__PARALLEL_HASKELL__"
503 , "-package concurrent"
505 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
509 Way WayPar "md" False "Distributed"
511 , "-D__PARALLEL_HASKELL__"
512 , "-D__DISTRIBUTED_HASKELL__"
515 , "-package concurrent"
517 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
521 Way WayGran "mg" False "GranSim"
525 , "-package concurrent" ],
527 Way WayNDP "ndp" False "Nested data parallelism"