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
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, getWayFlags, v_opt_C_ready
79 #include "HsVersions.h"
84 import Maybes ( firstJust )
87 import Data.Maybe ( listToMaybe )
89 import System.IO.Unsafe ( unsafePerformIO )
92 -----------------------------------------------------------------------------
95 initStaticOpts :: IO ()
96 initStaticOpts = writeIORef v_opt_C_ready True
98 addOpt :: String -> IO ()
99 addOpt = consIORef v_opt_C
101 addWay :: WayName -> IO ()
102 addWay = consIORef v_Ways . lkupWay
104 removeOpt :: String -> IO ()
106 fs <- readIORef v_opt_C
107 writeIORef v_opt_C $! filter (/= f) fs
109 lookUp :: FastString -> Bool
110 lookup_def_int :: String -> Int -> Int
111 lookup_def_float :: String -> Float -> Float
112 lookup_str :: String -> Maybe String
114 -- holds the static opts while they're being collected, before
115 -- being unsafely read by unpacked_static_opts below.
116 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
117 GLOBAL_VAR(v_opt_C_ready, False, Bool)
119 staticFlags :: [String]
120 staticFlags = unsafePerformIO $ do
121 ready <- readIORef v_opt_C_ready
123 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
124 else readIORef v_opt_C
126 -- -static is the default
127 defaultStaticOpts :: [String]
128 defaultStaticOpts = ["-static"]
130 packed_static_opts :: [FastString]
131 packed_static_opts = map mkFastString staticFlags
133 lookUp sw = sw `elem` packed_static_opts
135 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
136 -- and returns the string X
138 = case firstJust (map (stripPrefix sw) staticFlags) of
139 Just ('=' : str) -> Just str
143 lookup_def_int sw def = case (lookup_str sw) of
144 Nothing -> def -- Use default
145 Just xx -> try_read sw xx
147 lookup_def_float sw def = case (lookup_str sw) of
148 Nothing -> def -- Use default
149 Just xx -> try_read sw xx
152 try_read :: Read a => String -> String -> a
153 -- (try_read sw str) tries to read s; if it fails, it
154 -- bleats about flag sw
157 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
158 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
159 -- ToDo: hack alert. We should really parse the arugments
160 -- and announce errors in a more civilised way.
164 Putting the compiler options into temporary at-files
165 may turn out to be necessary later on if we turn hsc into
166 a pure Win32 application where I think there's a command-line
167 length limit of 255. unpacked_opts understands the @ option.
169 unpacked_opts :: [String]
173 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
175 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
179 opt_IgnoreDotGhci :: Bool
180 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
183 opt_SuppressUniques :: Bool
184 opt_SuppressUniques = lookUp (fsLit "-dsuppress-uniques")
185 opt_PprStyle_Debug :: Bool
186 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
187 opt_PprUserLength :: Int
188 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
190 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
191 opt_NoDebugOutput :: Bool
192 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
196 opt_SccProfilingOn :: Bool
197 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
201 opt_Hpc = lookUp (fsLit "-fhpc")
204 opt_DictsStrict :: Bool
205 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
206 opt_IrrefutableTuples :: Bool
207 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
209 opt_Parallel = lookUp (fsLit "-fparallel")
212 opt_DsMultiTyVar :: Bool
213 opt_DsMultiTyVar = not (lookUp (fsLit "-fno-ds-multi-tyvar"))
216 opt_SpecInlineJoinPoints :: Bool
217 opt_SpecInlineJoinPoints = lookUp (fsLit "-fspec-inline-join-points")
219 opt_SimpleListLiterals :: Bool
220 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
222 opt_NoStateHack :: Bool
223 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
226 opt_CprOff = lookUp (fsLit "-fcpr-off")
227 -- Switch off CPR analysis in the new demand analyser
228 opt_MaxWorkerArgs :: Int
229 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
231 opt_GranMacros :: Bool
232 opt_GranMacros = lookUp (fsLit "-fgransim")
233 opt_HiVersion :: Integer
234 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
235 opt_HistorySize :: Int
236 opt_HistorySize = lookup_def_int "-fhistory-size" 20
237 opt_OmitBlackHoling :: Bool
238 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
239 opt_StubDeadValues :: Bool
240 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
242 -- Simplifier switches
243 opt_SimplNoPreInlining :: Bool
244 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
245 -- NoPreInlining is there just to see how bad things
246 -- get if you don't do it!
247 opt_SimplExcessPrecision :: Bool
248 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
251 opt_UF_CreationThreshold :: Int
252 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
253 opt_UF_UseThreshold :: Int
254 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int) -- Discounts can be big
255 opt_UF_FunAppDiscount :: Int
256 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int) -- It's great to inline a fn
257 opt_UF_KeenessFactor :: Float
258 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
261 opt_UF_DearOp = ( 4 :: Int)
264 -- Related to linking
266 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
269 opt_PIC = lookUp (fsLit "-fPIC")
272 opt_Static = lookUp (fsLit "-static")
273 opt_Unregisterised :: Bool
274 opt_Unregisterised = lookUp (fsLit "-funregisterised")
276 -- Derived, not a real option. Determines whether we will be compiling
277 -- info tables that reside just before the entry code, or with an
278 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
279 -- includes/rts/storage/InfoTables.h.
280 tablesNextToCode :: Bool
281 tablesNextToCode = not opt_Unregisterised
282 && cGhcEnableTablesNextToCode == "YES"
284 -- Include full span info in error messages, instead of just the start position.
285 opt_ErrorSpans :: Bool
286 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
289 -- object files and libraries to be linked in are collected here.
290 -- ToDo: perhaps this could be done without a global, it wasn't obvious
291 -- how to do it though --SDM.
292 GLOBAL_VAR(v_Ld_inputs, [], [String])
294 -----------------------------------------------------------------------------
297 -- The central concept of a "way" is that all objects in a given
298 -- program must be compiled in the same "way". Certain options change
299 -- parameters of the virtual machine, eg. profiling adds an extra word
300 -- to the object header, so profiling objects cannot be linked with
301 -- non-profiling objects.
303 -- After parsing the command-line options, we determine which "way" we
304 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
306 -- We then find the "build-tag" associated with this way, and this
307 -- becomes the suffix used to find .hi files and libraries used in
322 GLOBAL_VAR(v_Ways, [] ,[Way])
324 allowed_combination :: [WayName] -> Bool
325 allowed_combination way = and [ x `allowedWith` y
326 | x <- way, y <- way, x < y ]
328 -- Note ordering in these tests: the left argument is
329 -- <= the right argument, according to the Ord instance
332 -- dyn is allowed with everything
333 _ `allowedWith` WayDyn = True
334 WayDyn `allowedWith` _ = True
336 -- debug is allowed with everything
337 _ `allowedWith` WayDebug = True
338 WayDebug `allowedWith` _ = True
340 WayProf `allowedWith` WayNDP = True
341 WayThreaded `allowedWith` WayProf = True
342 WayThreaded `allowedWith` WayEventLog = True
343 _ `allowedWith` _ = False
346 getWayFlags :: IO [String] -- new options
348 unsorted <- readIORef v_Ways
349 let ways = sortBy (compare `on` wayName) $
350 nubBy ((==) `on` wayName) $ unsorted
351 writeIORef v_Ways ways
353 if not (allowed_combination (map wayName ways))
354 then ghcError (CmdLineError $
355 "combination not supported: " ++
356 foldr1 (\a b -> a ++ '/':b)
359 return (concatMap wayOpts ways)
361 mkBuildTag :: [Way] -> String
362 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
364 lkupWay :: WayName -> Way
366 case listToMaybe (filter ((==) w . wayName) way_details) of
367 Nothing -> error "findBuildTag"
368 Just details -> details
370 isRTSWay :: WayName -> Bool
371 isRTSWay = wayRTSOnly . lkupWay
381 way_details :: [ Way ]
383 [ Way WayThreaded "thr" True "Threaded" [
384 #if defined(freebsd_TARGET_OS)
387 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
388 -- which GHC has some problems with. It's currently not clear whether
389 -- the problems are our fault or theirs, but it seems that using the
390 -- alternative 1:1 threading library libthr works around it:
392 #elif defined(solaris2_TARGET_OS)
397 Way WayDebug "debug" True "Debug" [],
399 Way WayDyn "dyn" False "Dynamic"
401 , "-optc-DDYNAMIC" ],
403 Way WayProf "p" False "Profiling"
406 , "-optc-DPROFILING" ],
408 Way WayEventLog "l" True "RTS Event Logging"
410 , "-optc-DEVENTLOG" ],
412 Way WayTicky "t" True "Ticky-ticky Profiling"
414 , "-optc-DTICKY_TICKY" ],
416 Way WayPar "mp" False "Parallel"
418 , "-D__PARALLEL_HASKELL__"
420 , "-package concurrent"
422 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
426 -- at the moment we only change the RTS and could share compiler and libs!
427 Way WayPar "mt" False "Parallel ticky profiling"
429 , "-D__PARALLEL_HASKELL__"
432 , "-package concurrent"
434 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
438 Way WayPar "md" False "Distributed"
440 , "-D__PARALLEL_HASKELL__"
441 , "-D__DISTRIBUTED_HASKELL__"
444 , "-package concurrent"
446 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
450 Way WayGran "mg" False "GranSim"
454 , "-package concurrent" ],
456 Way WayNDP "ndp" False "Nested data parallelism"