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(..), v_Ways, v_Build_tag, v_RTS_Build_tag, isRTSWay,
22 -- Output style options
36 opt_IrrefutableTuples,
42 opt_SimpleListLiterals,
43 opt_SpecInlineJoinPoints,
45 opt_SimplNoPreInlining,
46 opt_SimplExcessPrecision,
50 opt_UF_CreationThreshold,
52 opt_UF_FunAppDiscount,
56 -- Optimization fuel controls
76 addOpt, removeOpt, addWay, findBuildTag, v_opt_C_ready
79 #include "HsVersions.h"
84 import Maybes ( firstJust )
88 import System.IO.Unsafe ( unsafePerformIO )
91 -----------------------------------------------------------------------------
94 initStaticOpts :: IO ()
95 initStaticOpts = writeIORef v_opt_C_ready True
97 addOpt :: String -> IO ()
98 addOpt = consIORef v_opt_C
100 addWay :: WayName -> IO ()
101 addWay = consIORef v_Ways
103 removeOpt :: String -> IO ()
105 fs <- readIORef v_opt_C
106 writeIORef v_opt_C $! filter (/= f) fs
108 lookUp :: FastString -> Bool
109 lookup_def_int :: String -> Int -> Int
110 lookup_def_float :: String -> Float -> Float
111 lookup_str :: String -> Maybe String
113 -- holds the static opts while they're being collected, before
114 -- being unsafely read by unpacked_static_opts below.
115 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
116 GLOBAL_VAR(v_opt_C_ready, False, Bool)
118 staticFlags :: [String]
119 staticFlags = unsafePerformIO $ do
120 ready <- readIORef v_opt_C_ready
122 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
123 else readIORef v_opt_C
125 -- -static is the default
126 defaultStaticOpts :: [String]
127 defaultStaticOpts = ["-static"]
129 packed_static_opts :: [FastString]
130 packed_static_opts = map mkFastString staticFlags
132 lookUp sw = sw `elem` packed_static_opts
134 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
135 -- and returns the string X
137 = case firstJust (map (stripPrefix sw) staticFlags) of
138 Just ('=' : str) -> Just str
142 lookup_def_int sw def = case (lookup_str sw) of
143 Nothing -> def -- Use default
144 Just xx -> try_read sw xx
146 lookup_def_float sw def = case (lookup_str sw) of
147 Nothing -> def -- Use default
148 Just xx -> try_read sw xx
151 try_read :: Read a => String -> String -> a
152 -- (try_read sw str) tries to read s; if it fails, it
153 -- bleats about flag sw
156 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
157 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
158 -- ToDo: hack alert. We should really parse the arugments
159 -- and announce errors in a more civilised way.
163 Putting the compiler options into temporary at-files
164 may turn out to be necessary later on if we turn hsc into
165 a pure Win32 application where I think there's a command-line
166 length limit of 255. unpacked_opts understands the @ option.
168 unpacked_opts :: [String]
172 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
174 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
178 opt_IgnoreDotGhci :: Bool
179 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
182 opt_SuppressUniques :: Bool
183 opt_SuppressUniques = lookUp (fsLit "-dsuppress-uniques")
184 opt_PprStyle_Debug :: Bool
185 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
186 opt_PprUserLength :: Int
187 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
189 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
190 opt_NoDebugOutput :: Bool
191 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
195 opt_SccProfilingOn :: Bool
196 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
200 opt_Hpc = lookUp (fsLit "-fhpc")
203 opt_DictsStrict :: Bool
204 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
205 opt_IrrefutableTuples :: Bool
206 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
208 opt_Parallel = lookUp (fsLit "-fparallel")
211 opt_DsMultiTyVar :: Bool
212 opt_DsMultiTyVar = not (lookUp (fsLit "-fno-ds-multi-tyvar"))
215 opt_SpecInlineJoinPoints :: Bool
216 opt_SpecInlineJoinPoints = lookUp (fsLit "-fspec-inline-join-points")
218 opt_SimpleListLiterals :: Bool
219 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
221 opt_NoStateHack :: Bool
222 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
225 opt_CprOff = lookUp (fsLit "-fcpr-off")
226 -- Switch off CPR analysis in the new demand analyser
227 opt_MaxWorkerArgs :: Int
228 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
230 opt_GranMacros :: Bool
231 opt_GranMacros = lookUp (fsLit "-fgransim")
232 opt_HiVersion :: Integer
233 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
234 opt_HistorySize :: Int
235 opt_HistorySize = lookup_def_int "-fhistory-size" 20
236 opt_OmitBlackHoling :: Bool
237 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
238 opt_StubDeadValues :: Bool
239 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
241 -- Simplifier switches
242 opt_SimplNoPreInlining :: Bool
243 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
244 -- NoPreInlining is there just to see how bad things
245 -- get if you don't do it!
246 opt_SimplExcessPrecision :: Bool
247 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
250 opt_UF_CreationThreshold :: Int
251 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
252 opt_UF_UseThreshold :: Int
253 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int) -- Discounts can be big
254 opt_UF_FunAppDiscount :: Int
255 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int) -- It's great to inline a fn
256 opt_UF_KeenessFactor :: Float
257 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
260 opt_UF_DearOp = ( 4 :: Int)
263 -- Related to linking
265 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
268 opt_PIC = lookUp (fsLit "-fPIC")
271 opt_Static = lookUp (fsLit "-static")
272 opt_Unregisterised :: Bool
273 opt_Unregisterised = lookUp (fsLit "-funregisterised")
275 -- Derived, not a real option. Determines whether we will be compiling
276 -- info tables that reside just before the entry code, or with an
277 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
278 -- includes/InfoTables.h.
279 tablesNextToCode :: Bool
280 tablesNextToCode = not opt_Unregisterised
281 && cGhcEnableTablesNextToCode == "YES"
283 -- Include full span info in error messages, instead of just the start position.
284 opt_ErrorSpans :: Bool
285 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
288 -- object files and libraries to be linked in are collected here.
289 -- ToDo: perhaps this could be done without a global, it wasn't obvious
290 -- how to do it though --SDM.
291 GLOBAL_VAR(v_Ld_inputs, [], [String])
293 -----------------------------------------------------------------------------
296 -- The central concept of a "way" is that all objects in a given
297 -- program must be compiled in the same "way". Certain options change
298 -- parameters of the virtual machine, eg. profiling adds an extra word
299 -- to the object header, so profiling objects cannot be linked with
300 -- non-profiling objects.
302 -- After parsing the command-line options, we determine which "way" we
303 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
305 -- We then find the "build-tag" associated with this way, and this
306 -- becomes the suffix used to find .hi files and libraries used in
309 GLOBAL_VAR(v_Build_tag, "", String)
311 -- The RTS has its own build tag, because there are some ways that
312 -- affect the RTS only.
313 GLOBAL_VAR(v_RTS_Build_tag, "", String)
343 GLOBAL_VAR(v_Ways, [] ,[WayName])
345 allowed_combination :: [WayName] -> Bool
346 allowed_combination way = and [ x `allowedWith` y
347 | x <- way, y <- way, x < y ]
349 -- Note ordering in these tests: the left argument is
350 -- <= the right argument, according to the Ord instance
353 -- debug is allowed with everything
354 _ `allowedWith` WayDebug = True
355 WayDebug `allowedWith` _ = True
357 WayProf `allowedWith` WayNDP = True
358 WayThreaded `allowedWith` WayProf = True
359 WayThreaded `allowedWith` WayEventLog = True
360 _ `allowedWith` _ = False
363 findBuildTag :: IO [String] -- new options
365 way_names <- readIORef v_Ways
366 let ws = sort (nub way_names)
368 if not (allowed_combination ws)
369 then ghcError (CmdLineError $
370 "combination not supported: " ++
371 foldr1 (\a b -> a ++ '/':b)
372 (map (wayName . lkupWay) ws))
373 else let ways = map lkupWay ws
374 tag = mkBuildTag (filter (not.wayRTSOnly) ways)
375 rts_tag = mkBuildTag ways
376 flags = map wayOpts ways
378 writeIORef v_Build_tag tag
379 writeIORef v_RTS_Build_tag rts_tag
380 return (concat flags)
384 mkBuildTag :: [Way] -> String
385 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
387 lkupWay :: WayName -> Way
389 case lookup w way_details of
390 Nothing -> error "findBuildTag"
391 Just details -> details
393 isRTSWay :: WayName -> Bool
394 isRTSWay = wayRTSOnly . lkupWay
403 way_details :: [ (WayName, Way) ]
405 [ (WayThreaded, Way "thr" True "Threaded" [
406 #if defined(freebsd_TARGET_OS)
409 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
410 -- which GHC has some problems with. It's currently not clear whether
411 -- the problems are our fault or theirs, but it seems that using the
412 -- alternative 1:1 threading library libthr works around it:
414 #elif defined(solaris2_TARGET_OS)
419 (WayDebug, Way "debug" True "Debug" [] ),
421 (WayProf, Way "p" False "Profiling"
424 , "-optc-DPROFILING" ]),
426 (WayEventLog, Way "l" True "RTS Event Logging"
428 , "-optc-DEVENTLOG" ]),
430 (WayTicky, Way "t" True "Ticky-ticky Profiling"
432 , "-optc-DTICKY_TICKY" ]),
434 -- optl's below to tell linker where to find the PVM library -- HWL
435 (WayPar, Way "mp" False "Parallel"
437 , "-D__PARALLEL_HASKELL__"
439 , "-package concurrent"
441 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
445 -- at the moment we only change the RTS and could share compiler and libs!
446 (WayPar, Way "mt" False "Parallel ticky profiling"
448 , "-D__PARALLEL_HASKELL__"
451 , "-package concurrent"
453 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
457 (WayPar, Way "md" False "Distributed"
459 , "-D__PARALLEL_HASKELL__"
460 , "-D__DISTRIBUTED_HASKELL__"
463 , "-package concurrent"
465 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
469 (WayGran, Way "mg" False "GranSim"
473 , "-package concurrent" ]),
475 (WayNDP, Way "ndp" False "Nested data parallelism"
479 (WayUser_a, Way "a" False "User way 'a'" ["$WAY_a_REAL_OPTS"]),
480 (WayUser_b, Way "b" False "User way 'b'" ["$WAY_b_REAL_OPTS"]),
481 (WayUser_c, Way "c" False "User way 'c'" ["$WAY_c_REAL_OPTS"]),
482 (WayUser_d, Way "d" False "User way 'd'" ["$WAY_d_REAL_OPTS"]),
483 (WayUser_e, Way "e" False "User way 'e'" ["$WAY_e_REAL_OPTS"]),
484 (WayUser_f, Way "f" False "User way 'f'" ["$WAY_f_REAL_OPTS"]),
485 (WayUser_g, Way "g" False "User way 'g'" ["$WAY_g_REAL_OPTS"]),
486 (WayUser_h, Way "h" False "User way 'h'" ["$WAY_h_REAL_OPTS"]),
487 (WayUser_i, Way "i" False "User way 'i'" ["$WAY_i_REAL_OPTS"]),
488 (WayUser_j, Way "j" False "User way 'j'" ["$WAY_j_REAL_OPTS"]),
489 (WayUser_k, Way "k" False "User way 'k'" ["$WAY_k_REAL_OPTS"]),
490 (WayUser_l, Way "l" False "User way 'l'" ["$WAY_l_REAL_OPTS"]),
491 (WayUser_m, Way "m" False "User way 'm'" ["$WAY_m_REAL_OPTS"]),
492 (WayUser_n, Way "n" False "User way 'n'" ["$WAY_n_REAL_OPTS"]),
493 (WayUser_o, Way "o" False "User way 'o'" ["$WAY_o_REAL_OPTS"]),
494 (WayUser_A, Way "A" False "User way 'A'" ["$WAY_A_REAL_OPTS"]),
495 (WayUser_B, Way "B" False "User way 'B'" ["$WAY_B_REAL_OPTS"])