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