2d0718b3eebd75091db05fb7f7c112a877f8965d
[ghc-hetmet.git] / ghc / compiler / main / CmdLineOpts.lhs
1
2 % (c) The University of Glasgow, 1996-2000
3 %
4 \section[CmdLineOpts]{Things to do with command-line options}
5
6 \begin{code}
7
8 module CmdLineOpts (
9         CoreToDo(..), StgToDo(..),
10         SimplifierSwitch(..), 
11         SimplifierMode(..), FloatOutSwitches(..),
12
13         HscLang(..),
14         DynFlag(..),    -- needed non-abstractly by DriverFlags
15         DynFlags(..),
16
17         v_Static_hsc_opts,
18
19         isStaticHscFlag,
20
21         -- Manipulating DynFlags
22         defaultDynFlags,                -- DynFlags
23         defaultHscLang,                 -- HscLang
24         dopt,                           -- DynFlag -> DynFlags -> Bool
25         dopt_set, dopt_unset,           -- DynFlags -> DynFlag -> DynFlags
26         dopt_CoreToDo,                  -- DynFlags -> [CoreToDo]
27         dopt_StgToDo,                   -- DynFlags -> [StgToDo]
28         dopt_HscLang,                   -- DynFlags -> HscLang
29         dopt_OutName,                   -- DynFlags -> String
30         getOpts,                        -- (DynFlags -> [a]) -> IO [a]
31         setLang,
32         getVerbFlag,
33
34         -- Manipulating the DynFlags state
35         getDynFlags,                    -- IO DynFlags
36         setDynFlags,                    -- DynFlags -> IO ()
37         updDynFlags,                    -- (DynFlags -> DynFlags) -> IO ()
38         dynFlag,                        -- (DynFlags -> a) -> IO a
39         setDynFlag, unSetDynFlag,       -- DynFlag -> IO ()
40         saveDynFlags,                   -- IO ()
41         restoreDynFlags,                -- IO DynFlags
42
43         -- sets of warning opts
44         standardWarnings,
45         minusWOpts,
46         minusWallOpts,
47
48         -- Output style options
49         opt_PprStyle_NoPrags,
50         opt_PprStyle_RawTypes,
51         opt_PprUserLength,
52         opt_PprStyle_Debug,
53
54         -- profiling opts
55         opt_AutoSccsOnAllToplevs,
56         opt_AutoSccsOnExportedToplevs,
57         opt_AutoSccsOnIndividualCafs,
58         opt_AutoSccsOnDicts,
59         opt_SccProfilingOn,
60         opt_DoTickyProfiling,
61
62         -- language opts
63         opt_AllStrict,
64         opt_DictsStrict,
65         opt_MaxContextReductionDepth,
66         opt_IrrefutableTuples,
67         opt_NumbersStrict,
68         opt_Parallel,
69         opt_SMP,
70         opt_RuntimeTypes,
71         opt_Flatten,
72
73         -- optimisation opts
74         opt_NoMethodSharing,
75         opt_DoSemiTagging,
76         opt_LiberateCaseThreshold,
77         opt_StgDoLetNoEscapes,
78         opt_UnfoldCasms,
79         opt_CprOff,
80         opt_RulesOff,
81         opt_UnboxStrictFields,
82         opt_SimplNoPreInlining,
83         opt_SimplDoEtaReduction,
84         opt_SimplDoLambdaEtaExpansion,
85         opt_SimplCaseMerge,
86         opt_SimplExcessPrecision,
87         opt_MaxWorkerArgs,
88
89         -- Unfolding control
90         opt_UF_CreationThreshold,
91         opt_UF_UseThreshold,
92         opt_UF_FunAppDiscount,
93         opt_UF_KeenessFactor,
94         opt_UF_UpdateInPlace,
95         opt_UF_CheapOp,
96         opt_UF_DearOp,
97
98         -- misc opts
99         opt_InPackage,
100         opt_EmitCExternDecls,
101         opt_EnsureSplittableC,
102         opt_GranMacros,
103         opt_HiVersion,
104         opt_HistorySize,
105         opt_IgnoreAsserts,
106         opt_IgnoreIfacePragmas,
107         opt_NoHiCheck,
108         opt_OmitBlackHoling,
109         opt_OmitInterfacePragmas,
110         opt_NoPruneDecls,
111         opt_Static,
112         opt_Unregisterised,
113         opt_EmitExternalCore
114     ) where
115
116 #include "HsVersions.h"
117
118 import Constants        -- Default values for some flags
119 import Util
120 import FastString       ( FastString, mkFastString )
121 import Config
122 import Maybes           ( firstJust )
123
124 import GLAEXTS
125 import DATA_IOREF       ( IORef, readIORef, writeIORef )
126 import UNSAFE_IO        ( unsafePerformIO )
127 \end{code}
128
129 %************************************************************************
130 %*                                                                      *
131 \subsection{Command-line options}
132 %*                                                                      *
133 %************************************************************************
134
135 The hsc command-line options are split into two categories:
136
137   - static flags
138   - dynamic flags
139
140 Static flags are represented by top-level values of type Bool or Int,
141 for example.  They therefore have the same value throughout the
142 invocation of hsc.
143
144 Dynamic flags are represented by an abstract type, DynFlags, which is
145 passed into hsc by the compilation manager for every compilation.
146 Dynamic flags are those that change on a per-compilation basis,
147 perhaps because they may be present in the OPTIONS pragma at the top
148 of a module.
149
150 Other flag-related blurb:
151
152 A list of {\em ToDo}s is things to be done in a particular part of
153 processing.  A (fictitious) example for the Core-to-Core simplifier
154 might be: run the simplifier, then run the strictness analyser, then
155 run the simplifier again (three ``todos'').
156
157 There are three ``to-do processing centers'' at the moment.  In the
158 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
159 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
160 (\tr{simplStg/SimplStg.lhs}).
161
162 %************************************************************************
163 %*                                                                      *
164 \subsection{Datatypes associated with command-line options}
165 %*                                                                      *
166 %************************************************************************
167
168 \begin{code}
169 data CoreToDo           -- These are diff core-to-core passes,
170                         -- which may be invoked in any order,
171                         -- as many times as you like.
172
173   = CoreDoSimplify      -- The core-to-core simplifier.
174         SimplifierMode
175         [SimplifierSwitch]
176                         -- Each run of the simplifier can take a different
177                         -- set of simplifier-specific flags.
178   | CoreDoFloatInwards
179   | CoreDoFloatOutwards FloatOutSwitches
180   | CoreLiberateCase
181   | CoreDoPrintCore
182   | CoreDoStaticArgs
183   | CoreDoStrictness
184   | CoreDoWorkerWrapper
185   | CoreDoSpecialising
186   | CoreDoSpecConstr
187   | CoreDoOldStrictness
188   | CoreDoGlomBinds
189   | CoreCSE
190   | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules 
191                                                 -- matching this string
192
193   | CoreDoNothing        -- useful when building up lists of these things
194 \end{code}
195
196 \begin{code}
197 data StgToDo
198   = StgDoMassageForProfiling  -- should be (next to) last
199   -- There's also setStgVarInfo, but its absolute "lastness"
200   -- is so critical that it is hardwired in (no flag).
201   | D_stg_stats
202 \end{code}
203
204 \begin{code}
205 data SimplifierMode             -- See comments in SimplMonad
206   = SimplGently
207   | SimplPhase Int
208
209 data SimplifierSwitch
210   = MaxSimplifierIterations Int
211   | NoCaseOfCase
212
213 data FloatOutSwitches
214   = FloatOutSw  Bool    -- True <=> float lambdas to top level
215                 Bool    -- True <=> float constants to top level,
216                         --          even if they do not escape a lambda
217 \end{code}
218
219 %************************************************************************
220 %*                                                                      *
221 \subsection{Dynamic command-line options}
222 %*                                                                      *
223 %************************************************************************
224
225 \begin{code}
226 data DynFlag
227
228    -- debugging flags
229    = Opt_D_dump_absC
230    | Opt_D_dump_asm
231    | Opt_D_dump_cpranal
232    | Opt_D_dump_deriv
233    | Opt_D_dump_ds
234    | Opt_D_dump_flatC
235    | Opt_D_dump_foreign
236    | Opt_D_dump_inlinings
237    | Opt_D_dump_occur_anal
238    | Opt_D_dump_parsed
239    | Opt_D_dump_realC
240    | Opt_D_dump_rn
241    | Opt_D_dump_simpl
242    | Opt_D_dump_simpl_iterations
243    | Opt_D_dump_spec
244    | Opt_D_dump_prep
245    | Opt_D_dump_stg
246    | Opt_D_dump_stranal
247    | Opt_D_dump_tc
248    | Opt_D_dump_types
249    | Opt_D_dump_rules
250    | Opt_D_dump_cse
251    | Opt_D_dump_worker_wrapper
252    | Opt_D_dump_rn_trace
253    | Opt_D_dump_rn_stats
254    | Opt_D_dump_stix
255    | Opt_D_dump_simpl_stats
256    | Opt_D_dump_tc_trace
257    | Opt_D_dump_splices
258    | Opt_D_dump_BCOs
259    | Opt_D_dump_vect
260    | Opt_D_source_stats
261    | Opt_D_verbose_core2core
262    | Opt_D_verbose_stg2stg
263    | Opt_D_dump_hi
264    | Opt_D_dump_hi_diffs
265    | Opt_D_dump_minimal_imports
266    | Opt_DoCoreLinting
267    | Opt_DoStgLinting
268
269    | Opt_WarnIsError            -- -Werror; makes warnings fatal
270    | Opt_WarnDuplicateExports
271    | Opt_WarnHiShadows
272    | Opt_WarnIncompletePatterns
273    | Opt_WarnMissingFields
274    | Opt_WarnMissingMethods
275    | Opt_WarnMissingSigs
276    | Opt_WarnNameShadowing
277    | Opt_WarnOverlappingPatterns
278    | Opt_WarnSimplePatterns
279    | Opt_WarnTypeDefaults
280    | Opt_WarnUnusedBinds
281    | Opt_WarnUnusedImports
282    | Opt_WarnUnusedMatches
283    | Opt_WarnDeprecations
284    | Opt_WarnMisc
285
286    -- language opts
287    | Opt_AllowOverlappingInstances
288    | Opt_AllowUndecidableInstances
289    | Opt_AllowIncoherentInstances
290    | Opt_NoMonomorphismRestriction
291    | Opt_GlasgowExts
292    | Opt_FFI
293    | Opt_PArr                          -- syntactic support for parallel arrays
294    | Opt_With                          -- deprecated keyword for implicit parms
295    | Opt_Arrows                        -- Arrow-notation syntax
296    | Opt_TH
297    | Opt_ImplicitParams
298    | Opt_Generics
299    | Opt_NoImplicitPrelude 
300
301    deriving (Eq)
302
303 data DynFlags = DynFlags {
304   coreToDo              :: [CoreToDo],
305   stgToDo               :: [StgToDo],
306   hscLang               :: HscLang,
307   hscOutName            :: String,      -- name of the output file
308   hscStubHOutName       :: String,      -- name of the .stub_h output file
309   hscStubCOutName       :: String,      -- name of the .stub_c output file
310   extCoreName           :: String,      -- name of the .core output file
311   verbosity             :: Int,         -- verbosity level
312   cppFlag               :: Bool,        -- preprocess with cpp?
313   ppFlag                :: Bool,        -- preprocess with a Haskell Pp?
314   stolen_x86_regs       :: Int,         
315   cmdlineHcIncludes     :: [String],    -- -#includes
316
317   -- options for particular phases
318   opt_L                 :: [String],
319   opt_P                 :: [String],
320   opt_F                 :: [String],
321   opt_c                 :: [String],
322   opt_a                 :: [String],
323   opt_m                 :: [String],
324 #ifdef ILX                         
325   opt_I                 :: [String],
326   opt_i                 :: [String],
327 #endif
328
329   -- hsc dynamic flags
330   flags                 :: [DynFlag]
331  }
332
333 data HscLang
334   = HscC
335   | HscAsm
336   | HscJava
337   | HscILX
338   | HscInterpreted
339   | HscNothing
340     deriving (Eq, Show)
341
342 defaultHscLang
343   | cGhcWithNativeCodeGen == "YES" && 
344         (prefixMatch "i386" cTARGETPLATFORM ||
345          prefixMatch "sparc" cTARGETPLATFORM ||
346          prefixMatch "powerpc" cTARGETPLATFORM)   =  HscAsm
347   | otherwise                                   =  HscC
348
349 defaultDynFlags = DynFlags {
350   coreToDo = [], stgToDo = [], 
351   hscLang = defaultHscLang, 
352   hscOutName = "", 
353   hscStubHOutName = "", hscStubCOutName = "",
354   extCoreName = "",
355   verbosity = 0, 
356   cppFlag               = False,
357   ppFlag                = False,
358   stolen_x86_regs       = 4,
359   cmdlineHcIncludes     = [],
360   opt_L                 = [],
361   opt_P                 = [],
362   opt_F                 = [],
363   opt_c                 = [],
364   opt_a                 = [],
365   opt_m                 = [],
366 #ifdef ILX
367   opt_I                 = [],
368   opt_i                 = [],
369 #endif
370   flags = [Opt_Generics] ++ standardWarnings,
371         -- Generating the helper-functions for
372         -- generics is now on by default
373   }
374
375 {- 
376     Verbosity levels:
377         
378     0   |   print errors & warnings only
379     1   |   minimal verbosity: print "compiling M ... done." for each module.
380     2   |   equivalent to -dshow-passes
381     3   |   equivalent to existing "ghc -v"
382     4   |   "ghc -v -ddump-most"
383     5   |   "ghc -v -ddump-all"
384 -}
385
386 dopt :: DynFlag -> DynFlags -> Bool
387 dopt f dflags  = f `elem` (flags dflags)
388
389 dopt_CoreToDo :: DynFlags -> [CoreToDo]
390 dopt_CoreToDo = coreToDo
391
392 dopt_StgToDo :: DynFlags -> [StgToDo]
393 dopt_StgToDo = stgToDo
394
395 dopt_OutName :: DynFlags -> String
396 dopt_OutName = hscOutName
397
398 dopt_HscLang :: DynFlags -> HscLang
399 dopt_HscLang = hscLang
400
401 dopt_set :: DynFlags -> DynFlag -> DynFlags
402 dopt_set dfs f = dfs{ flags = f : flags dfs }
403
404 dopt_unset :: DynFlags -> DynFlag -> DynFlags
405 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
406
407 getOpts :: (DynFlags -> [a]) -> IO [a]
408         -- We add to the options from the front, so we need to reverse the list
409 getOpts opts = dynFlag opts >>= return . reverse
410
411 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags 
412 -- (-fvia-C, -fasm, -filx respectively).
413 setLang l = updDynFlags (\ dfs -> case hscLang dfs of
414                                         HscC   -> dfs{ hscLang = l }
415                                         HscAsm -> dfs{ hscLang = l }
416                                         HscILX -> dfs{ hscLang = l }
417                                         _      -> dfs)
418
419 getVerbFlag = do
420    verb <- dynFlag verbosity
421    if verb >= 3  then return  "-v" else return ""
422 \end{code}
423
424 -----------------------------------------------------------------------------
425 -- Mess about with the mutable variables holding the dynamic arguments
426
427 -- v_InitDynFlags 
428 --      is the "baseline" dynamic flags, initialised from
429 --      the defaults and command line options, and updated by the
430 --      ':s' command in GHCi.
431 --
432 -- v_DynFlags
433 --      is the dynamic flags for the current compilation.  It is reset
434 --      to the value of v_InitDynFlags before each compilation, then
435 --      updated by reading any OPTIONS pragma in the current module.
436
437 \begin{code}
438 GLOBAL_VAR(v_InitDynFlags, defaultDynFlags, DynFlags)
439 GLOBAL_VAR(v_DynFlags,     defaultDynFlags, DynFlags)
440
441 setDynFlags :: DynFlags -> IO ()
442 setDynFlags dfs = writeIORef v_DynFlags dfs
443
444 saveDynFlags :: IO ()
445 saveDynFlags = do dfs <- readIORef v_DynFlags
446                   writeIORef v_InitDynFlags dfs
447
448 restoreDynFlags :: IO DynFlags
449 restoreDynFlags = do dfs <- readIORef v_InitDynFlags
450                      writeIORef v_DynFlags dfs
451                      return dfs
452
453 getDynFlags :: IO DynFlags
454 getDynFlags = readIORef v_DynFlags
455
456 updDynFlags :: (DynFlags -> DynFlags) -> IO ()
457 updDynFlags f = do dfs <- readIORef v_DynFlags
458                    writeIORef v_DynFlags (f dfs)
459
460 dynFlag :: (DynFlags -> a) -> IO a
461 dynFlag f = do dflags <- readIORef v_DynFlags; return (f dflags)
462
463 setDynFlag, unSetDynFlag :: DynFlag -> IO ()
464 setDynFlag f   = updDynFlags (\dfs -> dopt_set dfs f)
465 unSetDynFlag f = updDynFlags (\dfs -> dopt_unset dfs f)
466 \end{code}
467
468
469 %************************************************************************
470 %*                                                                      *
471 \subsection{Warnings}
472 %*                                                                      *
473 %************************************************************************
474
475 \begin{code}
476 standardWarnings
477     = [ Opt_WarnDeprecations,
478         Opt_WarnOverlappingPatterns,
479         Opt_WarnMissingFields,
480         Opt_WarnMissingMethods,
481         Opt_WarnDuplicateExports
482       ]
483
484 minusWOpts
485     = standardWarnings ++ 
486       [ Opt_WarnUnusedBinds,
487         Opt_WarnUnusedMatches,
488         Opt_WarnUnusedImports,
489         Opt_WarnIncompletePatterns,
490         Opt_WarnMisc
491       ]
492
493 minusWallOpts
494     = minusWOpts ++
495       [ Opt_WarnTypeDefaults,
496         Opt_WarnNameShadowing,
497         Opt_WarnMissingSigs,
498         Opt_WarnHiShadows
499       ]
500 \end{code}
501
502 %************************************************************************
503 %*                                                                      *
504 \subsection{Classifying command-line options}
505 %*                                                                      *
506 %************************************************************************
507
508 \begin{code}
509 -- v_Statis_hsc_opts is here to avoid a circular dependency with
510 -- main/DriverState.
511 GLOBAL_VAR(v_Static_hsc_opts, [], [String])
512
513 lookUp           :: FastString -> Bool
514 lookup_int       :: String -> Maybe Int
515 lookup_def_int   :: String -> Int -> Int
516 lookup_def_float :: String -> Float -> Float
517 lookup_str       :: String -> Maybe String
518
519 unpacked_static_opts = unsafePerformIO (readIORef v_Static_hsc_opts)
520 packed_static_opts   = map mkFastString unpacked_static_opts
521
522 lookUp     sw = sw `elem` packed_static_opts
523         
524 lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts)
525
526 lookup_int sw = case (lookup_str sw) of
527                   Nothing -> Nothing
528                   Just xx -> Just (read xx)
529
530 lookup_def_int sw def = case (lookup_str sw) of
531                             Nothing -> def              -- Use default
532                             Just xx -> read xx
533
534 lookup_def_float sw def = case (lookup_str sw) of
535                             Nothing -> def              -- Use default
536                             Just xx -> read xx
537
538
539 {-
540  Putting the compiler options into temporary at-files
541  may turn out to be necessary later on if we turn hsc into
542  a pure Win32 application where I think there's a command-line
543  length limit of 255. unpacked_opts understands the @ option.
544
545 unpacked_opts :: [String]
546 unpacked_opts =
547   concat $
548   map (expandAts) $
549   map unpackFS argv  -- NOT ARGV any more: v_Static_hsc_opts
550   where
551    expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
552    expandAts l = [l]
553 -}
554 \end{code}
555
556 %************************************************************************
557 %*                                                                      *
558 \subsection{Static options}
559 %*                                                                      *
560 %************************************************************************
561
562 \begin{code}
563 -- debugging opts
564 opt_PprStyle_NoPrags            = lookUp  FSLIT("-dppr-noprags")
565 opt_PprStyle_Debug              = lookUp  FSLIT("-dppr-debug")
566 opt_PprStyle_RawTypes           = lookUp  FSLIT("-dppr-rawtypes")
567 opt_PprUserLength               = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
568
569 -- profiling opts
570 opt_AutoSccsOnAllToplevs        = lookUp  FSLIT("-fauto-sccs-on-all-toplevs")
571 opt_AutoSccsOnExportedToplevs   = lookUp  FSLIT("-fauto-sccs-on-exported-toplevs")
572 opt_AutoSccsOnIndividualCafs    = lookUp  FSLIT("-fauto-sccs-on-individual-cafs")
573 opt_AutoSccsOnDicts             = lookUp  FSLIT("-fauto-sccs-on-dicts")
574 opt_SccProfilingOn              = lookUp  FSLIT("-fscc-profiling")
575 opt_DoTickyProfiling            = lookUp  FSLIT("-fticky-ticky")
576
577 -- language opts
578 opt_AllStrict                   = lookUp  FSLIT("-fall-strict")
579 opt_DictsStrict                 = lookUp  FSLIT("-fdicts-strict")
580 opt_IrrefutableTuples           = lookUp  FSLIT("-firrefutable-tuples")
581 opt_MaxContextReductionDepth    = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
582 opt_NumbersStrict               = lookUp  FSLIT("-fnumbers-strict")
583 opt_Parallel                    = lookUp  FSLIT("-fparallel")
584 opt_SMP                         = lookUp  FSLIT("-fsmp")
585 opt_Flatten                     = lookUp  FSLIT("-fflatten")
586
587 -- optimisation opts
588 opt_NoMethodSharing             = lookUp  FSLIT("-fno-method-sharing")
589 opt_DoSemiTagging               = lookUp  FSLIT("-fsemi-tagging")
590 opt_CprOff                      = lookUp  FSLIT("-fcpr-off")
591 opt_RulesOff                    = lookUp  FSLIT("-frules-off")
592         -- Switch off CPR analysis in the new demand analyser
593 opt_LiberateCaseThreshold       = lookup_def_int "-fliberate-case-threshold" (10::Int)
594 opt_StgDoLetNoEscapes           = lookUp  FSLIT("-flet-no-escape")
595 opt_UnfoldCasms                 = lookUp  FSLIT("-funfold-casms-in-hi-file")
596 opt_UnboxStrictFields           = lookUp  FSLIT("-funbox-strict-fields")
597 opt_MaxWorkerArgs               = lookup_def_int "-fmax-worker-args" (10::Int)
598
599 {-
600    The optional '-inpackage=P' flag tells what package
601    we are compiling this module for.
602    The Prelude, for example is compiled with '-inpackage std'
603 -}
604 opt_InPackage                   = case lookup_str "-inpackage=" of
605                                     Just p  -> mkFastString p
606                                     Nothing -> FSLIT("Main")    -- The package name if none is specified
607
608 opt_EmitCExternDecls            = lookUp  FSLIT("-femit-extern-decls")
609 opt_EnsureSplittableC           = lookUp  FSLIT("-fglobalise-toplev-names")
610 opt_GranMacros                  = lookUp  FSLIT("-fgransim")
611 opt_HiVersion                   = read (cProjectVersionInt ++ cProjectPatchLevel) :: Int
612 opt_HistorySize                 = lookup_def_int "-fhistory-size" 20
613 opt_IgnoreAsserts               = lookUp  FSLIT("-fignore-asserts")
614 opt_IgnoreIfacePragmas          = lookUp  FSLIT("-fignore-interface-pragmas")
615 opt_NoHiCheck                   = lookUp  FSLIT("-fno-hi-version-check")
616 opt_OmitBlackHoling             = lookUp  FSLIT("-dno-black-holing")
617 opt_OmitInterfacePragmas        = lookUp  FSLIT("-fomit-interface-pragmas")
618 opt_RuntimeTypes                = lookUp  FSLIT("-fruntime-types")
619
620 -- Simplifier switches
621 opt_SimplNoPreInlining          = lookUp  FSLIT("-fno-pre-inlining")
622         -- NoPreInlining is there just to see how bad things
623         -- get if you don't do it!
624 opt_SimplDoEtaReduction         = lookUp  FSLIT("-fdo-eta-reduction")
625 opt_SimplDoLambdaEtaExpansion   = lookUp  FSLIT("-fdo-lambda-eta-expansion")
626 opt_SimplCaseMerge              = lookUp  FSLIT("-fcase-merge")
627 opt_SimplExcessPrecision        = lookUp  FSLIT("-fexcess-precision")
628
629 -- Unfolding control
630 opt_UF_CreationThreshold        = lookup_def_int "-funfolding-creation-threshold"  (45::Int)
631 opt_UF_UseThreshold             = lookup_def_int "-funfolding-use-threshold"       (8::Int)     -- Discounts can be big
632 opt_UF_FunAppDiscount           = lookup_def_int "-funfolding-fun-discount"        (6::Int)     -- It's great to inline a fn
633 opt_UF_KeenessFactor            = lookup_def_float "-funfolding-keeness-factor"    (1.5::Float)
634 opt_UF_UpdateInPlace            = lookUp  FSLIT("-funfolding-update-in-place")
635
636 opt_UF_CheapOp  = ( 1 :: Int)   -- Only one instruction; and the args are charged for
637 opt_UF_DearOp   = ( 4 :: Int)
638                         
639 opt_NoPruneDecls                = lookUp  FSLIT("-fno-prune-decls")
640 opt_Static                      = lookUp  FSLIT("-static")
641 opt_Unregisterised              = lookUp  FSLIT("-funregisterised")
642 opt_EmitExternalCore            = lookUp  FSLIT("-fext-core")
643 \end{code}
644
645 %************************************************************************
646 %*                                                                      *
647 \subsection{List of static hsc flags}
648 %*                                                                      *
649 %************************************************************************
650
651 \begin{code}
652 isStaticHscFlag f =
653   f `elem` [
654         "fauto-sccs-on-all-toplevs",
655         "fauto-sccs-on-exported-toplevs",
656         "fauto-sccs-on-individual-cafs",
657         "fauto-sccs-on-dicts",
658         "fscc-profiling",
659         "fticky-ticky",
660         "fall-strict",
661         "fdicts-strict",
662         "firrefutable-tuples",
663         "fnumbers-strict",
664         "fparallel",
665         "fsmp",
666         "fflatten",
667         "fsemi-tagging",
668         "flet-no-escape",
669         "funfold-casms-in-hi-file",
670         "funbox-strict-fields",
671         "femit-extern-decls",
672         "fglobalise-toplev-names",
673         "fgransim",
674         "fignore-asserts",
675         "fignore-interface-pragmas",
676         "fno-hi-version-check",
677         "dno-black-holing",
678         "fno-method-sharing",
679         "fomit-interface-pragmas",
680         "fruntime-types",
681         "fno-pre-inlining",
682         "fdo-eta-reduction",
683         "fdo-lambda-eta-expansion",
684         "fcase-merge",
685         "fexcess-precision",
686         "funfolding-update-in-place",
687         "fno-prune-decls",
688         "static",
689         "funregisterised",
690         "fext-core",
691         "frule-check",
692         "frules-off",
693         "fcpr-off"
694         ]
695   || any (flip prefixMatch f) [
696         "fcontext-stack",
697         "fliberate-case-threshold",
698         "fmax-worker-args",
699         "fhistory-size",
700         "funfolding-creation-threshold",
701         "funfolding-use-threshold",
702         "funfolding-fun-discount",
703         "funfolding-keeness-factor"
704      ]
705 \end{code}
706
707 %************************************************************************
708 %*                                                                      *
709 \subsection{Misc functions for command-line options}
710 %*                                                                      *
711 %************************************************************************
712
713
714
715 \begin{code}
716 startsWith :: String -> String -> Maybe String
717 -- startsWith pfx (pfx++rest) = Just rest
718
719 startsWith []     str = Just str
720 startsWith (c:cs) (s:ss)
721   = if c /= s then Nothing else startsWith cs ss
722 startsWith  _     []  = Nothing
723
724 endsWith  :: String -> String -> Maybe String
725 endsWith cs ss
726   = case (startsWith (reverse cs) (reverse ss)) of
727       Nothing -> Nothing
728       Just rs -> Just (reverse rs)
729 \end{code}