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,
44 opt_SpecInlineJoinPoints,
46 opt_SimplNoPreInlining,
47 opt_SimplExcessPrecision,
51 opt_UF_CreationThreshold,
53 opt_UF_FunAppDiscount,
57 -- Optimization fuel controls
77 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
80 #include "HsVersions.h"
85 import Maybes ( firstJust )
88 import Data.Maybe ( listToMaybe )
90 import System.IO.Unsafe ( unsafePerformIO )
93 -----------------------------------------------------------------------------
96 initStaticOpts :: IO ()
97 initStaticOpts = writeIORef v_opt_C_ready True
99 addOpt :: String -> IO ()
100 addOpt = consIORef v_opt_C
102 addWay :: WayName -> IO ()
103 addWay = consIORef v_Ways . lkupWay
105 removeOpt :: String -> IO ()
107 fs <- readIORef v_opt_C
108 writeIORef v_opt_C $! filter (/= f) fs
110 lookUp :: FastString -> Bool
111 lookup_def_int :: String -> Int -> Int
112 lookup_def_float :: String -> Float -> Float
113 lookup_str :: String -> Maybe String
115 -- holds the static opts while they're being collected, before
116 -- being unsafely read by unpacked_static_opts below.
117 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
118 GLOBAL_VAR(v_opt_C_ready, False, Bool)
120 staticFlags :: [String]
121 staticFlags = unsafePerformIO $ do
122 ready <- readIORef v_opt_C_ready
124 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
125 else readIORef v_opt_C
127 -- -static is the default
128 defaultStaticOpts :: [String]
129 defaultStaticOpts = ["-static"]
131 packed_static_opts :: [FastString]
132 packed_static_opts = map mkFastString staticFlags
134 lookUp sw = sw `elem` packed_static_opts
136 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
137 -- and returns the string X
139 = case firstJust (map (stripPrefix sw) staticFlags) of
140 Just ('=' : str) -> Just str
144 lookup_def_int sw def = case (lookup_str sw) of
145 Nothing -> def -- Use default
146 Just xx -> try_read sw xx
148 lookup_def_float sw def = case (lookup_str sw) of
149 Nothing -> def -- Use default
150 Just xx -> try_read sw xx
153 try_read :: Read a => String -> String -> a
154 -- (try_read sw str) tries to read s; if it fails, it
155 -- bleats about flag sw
158 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
159 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
160 -- ToDo: hack alert. We should really parse the arugments
161 -- and announce errors in a more civilised way.
165 Putting the compiler options into temporary at-files
166 may turn out to be necessary later on if we turn hsc into
167 a pure Win32 application where I think there's a command-line
168 length limit of 255. unpacked_opts understands the @ option.
170 unpacked_opts :: [String]
174 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
176 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
180 opt_IgnoreDotGhci :: Bool
181 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
184 opt_SuppressUniques :: Bool
185 opt_SuppressUniques = lookUp (fsLit "-dsuppress-uniques")
186 opt_SuppressCoercions :: Bool
187 opt_SuppressCoercions = lookUp (fsLit "-dsuppress-coercions")
188 opt_PprStyle_Debug :: Bool
189 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
190 opt_PprUserLength :: Int
191 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
193 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
194 opt_NoDebugOutput :: Bool
195 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
199 opt_SccProfilingOn :: Bool
200 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
204 opt_Hpc = lookUp (fsLit "-fhpc")
207 opt_DictsStrict :: Bool
208 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
209 opt_IrrefutableTuples :: Bool
210 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
212 opt_Parallel = lookUp (fsLit "-fparallel")
215 opt_DsMultiTyVar :: Bool
216 opt_DsMultiTyVar = not (lookUp (fsLit "-fno-ds-multi-tyvar"))
219 opt_SpecInlineJoinPoints :: Bool
220 opt_SpecInlineJoinPoints = lookUp (fsLit "-fspec-inline-join-points")
222 opt_SimpleListLiterals :: Bool
223 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
225 opt_NoStateHack :: Bool
226 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
229 opt_CprOff = lookUp (fsLit "-fcpr-off")
230 -- Switch off CPR analysis in the new demand analyser
231 opt_MaxWorkerArgs :: Int
232 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
234 opt_GranMacros :: Bool
235 opt_GranMacros = lookUp (fsLit "-fgransim")
236 opt_HiVersion :: Integer
237 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
238 opt_HistorySize :: Int
239 opt_HistorySize = lookup_def_int "-fhistory-size" 20
240 opt_OmitBlackHoling :: Bool
241 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
242 opt_StubDeadValues :: Bool
243 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
245 -- Simplifier switches
246 opt_SimplNoPreInlining :: Bool
247 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
248 -- NoPreInlining is there just to see how bad things
249 -- get if you don't do it!
250 opt_SimplExcessPrecision :: Bool
251 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
254 opt_UF_CreationThreshold :: Int
255 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
256 opt_UF_UseThreshold :: Int
257 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int) -- Discounts can be big
258 opt_UF_FunAppDiscount :: Int
259 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int) -- It's great to inline a fn
260 opt_UF_KeenessFactor :: Float
261 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
264 opt_UF_DearOp = ( 4 :: Int)
267 -- Related to linking
269 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
272 opt_PIC = lookUp (fsLit "-fPIC")
275 opt_Static = lookUp (fsLit "-static")
276 opt_Unregisterised :: Bool
277 opt_Unregisterised = lookUp (fsLit "-funregisterised")
279 -- Derived, not a real option. Determines whether we will be compiling
280 -- info tables that reside just before the entry code, or with an
281 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
282 -- includes/rts/storage/InfoTables.h.
283 tablesNextToCode :: Bool
284 tablesNextToCode = not opt_Unregisterised
285 && cGhcEnableTablesNextToCode == "YES"
287 -- Include full span info in error messages, instead of just the start position.
288 opt_ErrorSpans :: Bool
289 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
292 -- object files and libraries to be linked in are collected here.
293 -- ToDo: perhaps this could be done without a global, it wasn't obvious
294 -- how to do it though --SDM.
295 GLOBAL_VAR(v_Ld_inputs, [], [String])
297 -----------------------------------------------------------------------------
300 -- The central concept of a "way" is that all objects in a given
301 -- program must be compiled in the same "way". Certain options change
302 -- parameters of the virtual machine, eg. profiling adds an extra word
303 -- to the object header, so profiling objects cannot be linked with
304 -- non-profiling objects.
306 -- After parsing the command-line options, we determine which "way" we
307 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
309 -- We then find the "build-tag" associated with this way, and this
310 -- becomes the suffix used to find .hi files and libraries used in
325 GLOBAL_VAR(v_Ways, [] ,[Way])
327 allowed_combination :: [WayName] -> Bool
328 allowed_combination way = and [ x `allowedWith` y
329 | x <- way, y <- way, x < y ]
331 -- Note ordering in these tests: the left argument is
332 -- <= the right argument, according to the Ord instance
335 -- dyn is allowed with everything
336 _ `allowedWith` WayDyn = True
337 WayDyn `allowedWith` _ = True
339 -- debug is allowed with everything
340 _ `allowedWith` WayDebug = True
341 WayDebug `allowedWith` _ = True
343 WayProf `allowedWith` WayNDP = True
344 WayThreaded `allowedWith` WayProf = True
345 WayThreaded `allowedWith` WayEventLog = True
346 _ `allowedWith` _ = False
349 getWayFlags :: IO [String] -- new options
351 unsorted <- readIORef v_Ways
352 let ways = sortBy (compare `on` wayName) $
353 nubBy ((==) `on` wayName) $ unsorted
354 writeIORef v_Ways ways
356 if not (allowed_combination (map wayName ways))
357 then ghcError (CmdLineError $
358 "combination not supported: " ++
359 foldr1 (\a b -> a ++ '/':b)
362 return (concatMap wayOpts ways)
364 mkBuildTag :: [Way] -> String
365 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
367 lkupWay :: WayName -> Way
369 case listToMaybe (filter ((==) w . wayName) way_details) of
370 Nothing -> error "findBuildTag"
371 Just details -> details
373 isRTSWay :: WayName -> Bool
374 isRTSWay = wayRTSOnly . lkupWay
384 way_details :: [ Way ]
386 [ Way WayThreaded "thr" True "Threaded" [
387 #if defined(freebsd_TARGET_OS)
390 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
391 -- which GHC has some problems with. It's currently not clear whether
392 -- the problems are our fault or theirs, but it seems that using the
393 -- alternative 1:1 threading library libthr works around it:
395 #elif defined(solaris2_TARGET_OS)
400 Way WayDebug "debug" True "Debug" [],
402 Way WayDyn "dyn" False "Dynamic"
404 , "-optc-DDYNAMIC" ],
406 Way WayProf "p" False "Profiling"
409 , "-optc-DPROFILING" ],
411 Way WayEventLog "l" True "RTS Event Logging"
413 , "-optc-DTRACING" ],
415 Way WayTicky "t" True "Ticky-ticky Profiling"
417 , "-optc-DTICKY_TICKY" ],
419 Way WayPar "mp" False "Parallel"
421 , "-D__PARALLEL_HASKELL__"
423 , "-package concurrent"
425 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
429 -- at the moment we only change the RTS and could share compiler and libs!
430 Way WayPar "mt" False "Parallel ticky profiling"
432 , "-D__PARALLEL_HASKELL__"
435 , "-package concurrent"
437 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
441 Way WayPar "md" False "Distributed"
443 , "-D__PARALLEL_HASKELL__"
444 , "-D__DISTRIBUTED_HASKELL__"
447 , "-package concurrent"
449 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
453 Way WayGran "mg" False "GranSim"
457 , "-package concurrent" ],
459 Way WayNDP "ndp" False "Nested data parallelism"