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