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,
26 opt_SuppressModulePrefixes,
38 opt_IrrefutableTuples,
44 opt_SimpleListLiterals,
46 opt_SimplNoPreInlining,
47 opt_SimplExcessPrecision,
51 opt_UF_CreationThreshold,
53 opt_UF_FunAppDiscount,
58 -- Optimization fuel controls
79 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
82 #include "HsVersions.h"
87 import Maybes ( firstJust )
90 import Data.Maybe ( listToMaybe )
92 import System.IO.Unsafe ( unsafePerformIO )
95 -----------------------------------------------------------------------------
98 initStaticOpts :: IO ()
99 initStaticOpts = writeIORef v_opt_C_ready True
101 addOpt :: String -> IO ()
102 addOpt = consIORef v_opt_C
104 addWay :: WayName -> IO ()
105 addWay = consIORef v_Ways . lkupWay
107 removeOpt :: String -> IO ()
109 fs <- readIORef v_opt_C
110 writeIORef v_opt_C $! filter (/= f) fs
112 lookUp :: FastString -> Bool
113 lookup_def_int :: String -> Int -> Int
114 lookup_def_float :: String -> Float -> Float
115 lookup_str :: String -> Maybe String
117 -- holds the static opts while they're being collected, before
118 -- being unsafely read by unpacked_static_opts below.
119 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
120 GLOBAL_VAR(v_opt_C_ready, False, Bool)
122 staticFlags :: [String]
123 staticFlags = unsafePerformIO $ do
124 ready <- readIORef v_opt_C_ready
126 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
127 else readIORef v_opt_C
129 -- -static is the default
130 defaultStaticOpts :: [String]
131 defaultStaticOpts = ["-static"]
133 packed_static_opts :: [FastString]
134 packed_static_opts = map mkFastString staticFlags
136 lookUp sw = sw `elem` packed_static_opts
138 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
139 -- and returns the string X
141 = case firstJust (map (stripPrefix sw) staticFlags) of
142 Just ('=' : str) -> Just str
146 lookup_def_int sw def = case (lookup_str sw) of
147 Nothing -> def -- Use default
148 Just xx -> try_read sw xx
150 lookup_def_float sw def = case (lookup_str sw) of
151 Nothing -> def -- Use default
152 Just xx -> try_read sw xx
155 try_read :: Read a => String -> String -> a
156 -- (try_read sw str) tries to read s; if it fails, it
157 -- bleats about flag sw
160 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
161 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
162 -- ToDo: hack alert. We should really parse the arugments
163 -- and announce errors in a more civilised way.
167 Putting the compiler options into temporary at-files
168 may turn out to be necessary later on if we turn hsc into
169 a pure Win32 application where I think there's a command-line
170 length limit of 255. unpacked_opts understands the @ option.
172 unpacked_opts :: [String]
176 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
178 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
182 opt_IgnoreDotGhci :: Bool
183 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
186 opt_SuppressUniques :: Bool
187 opt_SuppressUniques = lookUp (fsLit "-dsuppress-uniques")
189 opt_SuppressCoercions :: Bool
190 opt_SuppressCoercions = lookUp (fsLit "-dsuppress-coercions")
192 opt_SuppressModulePrefixes :: Bool
193 opt_SuppressModulePrefixes = lookUp (fsLit "-dsuppress-module-prefixes")
195 opt_PprStyle_Debug :: Bool
196 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
198 opt_PprUserLength :: Int
199 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
202 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
204 opt_NoDebugOutput :: Bool
205 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
209 opt_SccProfilingOn :: Bool
210 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
214 opt_Hpc = lookUp (fsLit "-fhpc")
217 opt_DictsStrict :: Bool
218 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
220 opt_IrrefutableTuples :: Bool
221 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
224 opt_Parallel = lookUp (fsLit "-fparallel")
227 opt_DsMultiTyVar :: Bool
228 opt_DsMultiTyVar = not (lookUp (fsLit "-fno-ds-multi-tyvar"))
231 opt_SimpleListLiterals :: Bool
232 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
234 opt_NoStateHack :: Bool
235 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
238 opt_CprOff = lookUp (fsLit "-fcpr-off")
239 -- Switch off CPR analysis in the new demand analyser
240 opt_MaxWorkerArgs :: Int
241 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
243 opt_GranMacros :: Bool
244 opt_GranMacros = lookUp (fsLit "-fgransim")
246 opt_HiVersion :: Integer
247 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
249 opt_HistorySize :: Int
250 opt_HistorySize = lookup_def_int "-fhistory-size" 20
252 opt_OmitBlackHoling :: Bool
253 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
255 opt_StubDeadValues :: Bool
256 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
258 -- Simplifier switches
259 opt_SimplNoPreInlining :: Bool
260 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
261 -- NoPreInlining is there just to see how bad things
262 -- get if you don't do it!
263 opt_SimplExcessPrecision :: Bool
264 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
267 -- See Note [Discounts and thresholds] in CoreUnfold
269 opt_UF_CreationThreshold, opt_UF_UseThreshold :: Int
270 opt_UF_DearOp, opt_UF_FunAppDiscount, opt_UF_DictDiscount :: Int
271 opt_UF_KeenessFactor :: Float
273 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
274 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int)
275 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int)
276 opt_UF_DictDiscount = lookup_def_int "-funfolding-dict-discount" (1::Int)
277 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
278 opt_UF_DearOp = ( 4 :: Int)
281 -- Related to linking
283 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
285 #elif darwin_TARGET_OS
286 opt_PIC = lookUp (fsLit "-fPIC") || not opt_Static
288 opt_PIC = lookUp (fsLit "-fPIC")
291 opt_Static = lookUp (fsLit "-static")
292 opt_Unregisterised :: Bool
293 opt_Unregisterised = lookUp (fsLit "-funregisterised")
295 -- Derived, not a real option. Determines whether we will be compiling
296 -- info tables that reside just before the entry code, or with an
297 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
298 -- includes/rts/storage/InfoTables.h.
299 tablesNextToCode :: Bool
300 tablesNextToCode = not opt_Unregisterised
301 && cGhcEnableTablesNextToCode == "YES"
303 -- Include full span info in error messages, instead of just the start position.
304 opt_ErrorSpans :: Bool
305 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
308 opt_Ticky = lookUp (fsLit "-ticky")
310 -- object files and libraries to be linked in are collected here.
311 -- ToDo: perhaps this could be done without a global, it wasn't obvious
312 -- how to do it though --SDM.
313 GLOBAL_VAR(v_Ld_inputs, [], [String])
315 -----------------------------------------------------------------------------
318 -- The central concept of a "way" is that all objects in a given
319 -- program must be compiled in the same "way". Certain options change
320 -- parameters of the virtual machine, eg. profiling adds an extra word
321 -- to the object header, so profiling objects cannot be linked with
322 -- non-profiling objects.
324 -- After parsing the command-line options, we determine which "way" we
325 -- are building - this might be a combination way, eg. profiling+threaded.
327 -- We then find the "build-tag" associated with this way, and this
328 -- becomes the suffix used to find .hi files and libraries used in
342 GLOBAL_VAR(v_Ways, [] ,[Way])
344 allowed_combination :: [WayName] -> Bool
345 allowed_combination way = and [ x `allowedWith` y
346 | x <- way, y <- way, x < y ]
348 -- Note ordering in these tests: the left argument is
349 -- <= the right argument, according to the Ord instance
352 -- dyn is allowed with everything
353 _ `allowedWith` WayDyn = True
354 WayDyn `allowedWith` _ = True
356 -- debug is allowed with everything
357 _ `allowedWith` WayDebug = True
358 WayDebug `allowedWith` _ = True
360 WayProf `allowedWith` WayNDP = True
361 WayThreaded `allowedWith` WayProf = True
362 WayThreaded `allowedWith` WayEventLog = True
363 _ `allowedWith` _ = False
366 getWayFlags :: IO [String] -- new options
368 unsorted <- readIORef v_Ways
369 let ways = sortBy (compare `on` wayName) $
370 nubBy ((==) `on` wayName) $ unsorted
371 writeIORef v_Ways ways
373 if not (allowed_combination (map wayName ways))
374 then ghcError (CmdLineError $
375 "combination not supported: " ++
376 foldr1 (\a b -> a ++ '/':b)
379 return (concatMap wayOpts ways)
381 mkBuildTag :: [Way] -> String
382 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
384 lkupWay :: WayName -> Way
386 case listToMaybe (filter ((==) w . wayName) way_details) of
387 Nothing -> error "findBuildTag"
388 Just details -> details
390 isRTSWay :: WayName -> Bool
391 isRTSWay = wayRTSOnly . lkupWay
401 way_details :: [ Way ]
403 [ Way WayThreaded "thr" True "Threaded" [
404 #if defined(freebsd_TARGET_OS)
407 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
408 -- which GHC has some problems with. It's currently not clear whether
409 -- the problems are our fault or theirs, but it seems that using the
410 -- alternative 1:1 threading library libthr works around it:
412 #elif defined(solaris2_TARGET_OS)
417 Way WayDebug "debug" True "Debug" [],
419 Way WayDyn "dyn" False "Dynamic"
422 #if defined(mingw32_TARGET_OS)
423 -- On Windows, code that is to be linked into a dynamic library must be compiled
424 -- with -fPIC. Labels not in the current package are assumed to be in a DLL
425 -- different from the current one.
430 Way WayProf "p" False "Profiling"
433 , "-optc-DPROFILING" ],
435 Way WayEventLog "l" True "RTS Event Logging"
437 , "-optc-DTRACING" ],
439 Way WayPar "mp" False "Parallel"
441 , "-D__PARALLEL_HASKELL__"
443 , "-package concurrent"
445 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
449 -- at the moment we only change the RTS and could share compiler and libs!
450 Way WayPar "mt" False "Parallel ticky profiling"
452 , "-D__PARALLEL_HASKELL__"
455 , "-package concurrent"
457 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
461 Way WayPar "md" False "Distributed"
463 , "-D__PARALLEL_HASKELL__"
464 , "-D__DISTRIBUTED_HASKELL__"
467 , "-package concurrent"
469 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
473 Way WayGran "mg" False "GranSim"
477 , "-package concurrent" ],
479 Way WayNDP "ndp" False "Nested data parallelism"