[project @ 1997-01-06 21:08:42 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / CmdLineOpts.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1996
3 %
4 \section[CmdLineOpts]{Things to do with command-line options}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module CmdLineOpts (
10         CoreToDo(..),
11         SimplifierSwitch(..),
12         StgToDo(..),
13         SwitchResult(..),
14         classifyOpts,
15
16         intSwitchSet,
17         switchIsOn,
18
19         maybe_CompilingGhcInternals,
20         opt_AllDemanded,
21         opt_AllStrict,
22         opt_AutoSccsOnAllToplevs,
23         opt_AutoSccsOnExportedToplevs,
24         opt_AutoSccsOnIndividualCafs,
25         opt_CompilingGhcInternals,
26         opt_D_dump_absC,
27         opt_D_dump_asm,
28         opt_D_dump_deforest,
29         opt_D_dump_deriv,
30         opt_D_dump_ds,
31         opt_D_dump_flatC,
32         opt_D_dump_occur_anal,
33         opt_D_dump_rdr,
34         opt_D_dump_realC,
35         opt_D_dump_rn,
36         opt_D_dump_simpl,
37         opt_D_dump_spec,
38         opt_D_dump_stg,
39         opt_D_dump_stranal,
40         opt_D_dump_tc,
41         opt_D_show_passes,
42         opt_D_show_rn_trace,
43         opt_D_simplifier_stats,
44         opt_D_source_stats,
45         opt_D_verbose_core2core,
46         opt_D_verbose_stg2stg,
47         opt_DoCoreLinting,
48         opt_DoSemiTagging,
49         opt_DoEtaReduction,
50         opt_DoTickyProfiling,
51         opt_EnsureSplittableC,
52         opt_FoldrBuildOn,
53         opt_FoldrBuildTrace,
54         opt_ForConcurrent,
55         opt_GlasgowExts,
56         opt_GranMacros,
57         opt_Haskell_1_3,
58         opt_HiMap,
59         opt_IgnoreIfacePragmas,
60         opt_IgnoreStrictnessPragmas,
61         opt_IrrefutableEverything,
62         opt_IrrefutableTuples,
63         opt_LiberateCaseThreshold,
64         opt_NoImplicitPrelude,
65         opt_NumbersStrict,
66         opt_OmitBlackHoling,
67         opt_OmitDefaultInstanceMethods,
68         opt_OmitInterfacePragmas,
69         opt_PprStyle_All,
70         opt_PprStyle_Debug,
71         opt_PprStyle_User,
72         opt_ProduceC,
73         opt_ProduceHi,
74         opt_ProduceS,
75         opt_ReportWhyUnfoldingsDisallowed,
76         opt_ReturnInRegsThreshold,
77         opt_SccGroup,
78         opt_SccProfilingOn,
79         opt_ShowImportSpecs,
80         opt_ShowPragmaNameErrs,
81         opt_SigsRequired,
82         opt_SourceUnchanged,
83         opt_SpecialiseAll,
84         opt_SpecialiseImports,
85         opt_SpecialiseOverloaded,
86         opt_SpecialiseTrace,
87         opt_SpecialiseUnboxed,
88         opt_StgDoLetNoEscapes,
89
90         opt_InterfaceUnfoldThreshold,
91         opt_UnfoldingCreationThreshold,
92         opt_UnfoldingConDiscount,
93         opt_UnfoldingUseThreshold,
94
95         opt_Verbose,
96         opt_WarnNameShadowing
97     ) where
98
99 IMPORT_1_3(Array(array, (//)))
100 import PreludeGlaST     -- bad bad bad boy, Will (_Array internals)
101 import Argv
102
103 CHK_Ubiq() -- debugging consistency check
104
105 import Constants        -- Default values for some flags
106
107 import Maybes           ( assocMaybe, firstJust, maybeToBool )
108 import Util             ( startsWith, panic, panic#, assertPanic )
109 \end{code}
110
111 A command-line {\em switch} is (generally) either on or off; e.g., the
112 ``verbose'' (-v) switch is either on or off.  (The \tr{-G<group>}
113 switch is an exception; it's set to a string, or nothing.)
114
115 A list of {\em ToDo}s is things to be done in a particular part of
116 processing.  A (fictitious) example for the Core-to-Core simplifier
117 might be: run the simplifier, then run the strictness analyser, then
118 run the simplifier again (three ``todos'').
119
120 There are three ``to-do processing centers'' at the moment.  In the
121 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
122 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
123 (\tr{simplStg/SimplStg.lhs}).
124
125 %************************************************************************
126 %*                                                                      *
127 \subsection{Datatypes associated with command-line options}
128 %*                                                                      *
129 %************************************************************************
130
131 \begin{code}
132 data SwitchResult
133   = SwBool      Bool            -- on/off
134   | SwString    FAST_STRING     -- nothing or a String
135   | SwInt       Int             -- nothing or an Int
136 \end{code}
137
138 \begin{code}
139 data CoreToDo           -- These are diff core-to-core passes,
140                         -- which may be invoked in any order,
141                         -- as many times as you like.
142
143   = CoreDoSimplify      -- The core-to-core simplifier.
144         (SimplifierSwitch -> SwitchResult)
145                         -- Each run of the simplifier can take a different
146                         -- set of simplifier-specific flags.
147   | CoreDoCalcInlinings1
148   | CoreDoCalcInlinings2
149   | CoreDoFloatInwards
150   | CoreDoFullLaziness
151   | CoreLiberateCase
152   | CoreDoPrintCore
153   | CoreDoStaticArgs
154   | CoreDoStrictness
155   | CoreDoSpecialising
156   | CoreDoDeforest
157   | CoreDoFoldrBuildWorkerWrapper
158   | CoreDoFoldrBuildWWAnal
159 \end{code}
160
161 \begin{code}
162 data StgToDo
163   = StgDoStaticArgs
164   | StgDoUpdateAnalysis
165   | StgDoLambdaLift
166   | StgDoMassageForProfiling  -- should be (next to) last
167   -- There's also setStgVarInfo, but its absolute "lastness"
168   -- is so critical that it is hardwired in (no flag).
169   | D_stg_stats
170 \end{code}
171
172 \begin{code}
173 data SimplifierSwitch
174   = SimplOkToDupCode
175   | SimplFloatLetsExposingWHNF
176   | SimplOkToFloatPrimOps
177   | SimplAlwaysFloatLetsFromLets
178   | SimplDoCaseElim
179   | SimplReuseCon
180   | SimplCaseOfCase
181   | SimplLetToCase
182   | SimplMayDeleteConjurableIds
183   | SimplPedanticBottoms -- see Simplifier for an explanation
184   | SimplDoArityExpand   -- expand arity of bindings
185   | SimplDoFoldrBuild    -- This is the per-simplification flag;
186                          -- see also FoldrBuildOn, used elsewhere
187                          -- in the compiler.
188   | SimplDoInlineFoldrBuild
189                          -- inline foldr/build (*after* f/b rule is used)
190
191   | IgnoreINLINEPragma
192   | SimplDoLambdaEtaExpansion
193
194   | EssentialUnfoldingsOnly -- never mind the thresholds, only
195                             -- do unfoldings that *must* be done
196                             -- (to saturate constructors and primitives)
197
198   | ShowSimplifierProgress  -- report counts on every interation
199
200   | MaxSimplifierIterations Int
201
202   | KeepSpecPragmaIds       -- We normally *toss* Ids we can do without
203   | KeepUnusedBindings
204
205   | SimplNoLetFromCase      -- used when turning off floating entirely
206   | SimplNoLetFromApp       -- (for experimentation only) WDP 95/10
207   | SimplNoLetFromStrictLet
208
209   | SimplDontFoldBackAppend
210                         -- we fold `foldr (:)' back into flip (++),
211                         -- but we *don't* want to do it when compiling
212                         -- List.hs, otherwise
213                         -- xs ++ ys = foldr (:) ys xs
214                         -- {- via our loopback -}
215                         -- xs ++ ys = xs ++ ys
216                         -- Oops!
217                         -- So only use this flag inside List.hs
218                         -- (Sigh, what a HACK, Andy.  WDP 96/01)
219
220   | SimplCaseMerge
221 \end{code}
222
223 %************************************************************************
224 %*                                                                      *
225 \subsection{Classifying command-line options}
226 %*                                                                      *
227 %************************************************************************
228
229 \begin{code}
230 lookUp         :: FAST_STRING -> Bool
231 lookup_int     :: String -> Maybe Int
232 lookup_def_int :: String -> Int -> Int
233 lookup_str     :: String -> Maybe String
234
235 lookUp     sw = maybeToBool (assoc_opts sw)
236         
237 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
238
239 lookup_int sw = case (lookup_str sw) of
240                   Nothing -> Nothing
241                   Just xx -> Just (read xx)
242
243 lookup_def_int sw def = case (lookup_str sw) of
244                             Nothing -> def              -- Use default
245                             Just xx -> read xx
246
247 assoc_opts    = assocMaybe [ (a, True) | a <- argv ]
248 unpacked_opts = map _UNPK_ argv
249 \end{code}
250
251 \begin{code}
252 opt_AllDemanded                 = lookUp  SLIT("-fall-demanded")
253 opt_AllStrict                   = lookUp  SLIT("-fall-strict")
254 opt_AutoSccsOnAllToplevs        = lookUp  SLIT("-fauto-sccs-on-all-toplevs")
255 opt_AutoSccsOnExportedToplevs   = lookUp  SLIT("-fauto-sccs-on-exported-toplevs")
256 opt_AutoSccsOnIndividualCafs    = lookUp  SLIT("-fauto-sccs-on-individual-cafs")
257 opt_CompilingGhcInternals       = maybeToBool maybe_CompilingGhcInternals
258 maybe_CompilingGhcInternals     = lookup_str "-fcompiling-ghc-internals="
259 opt_D_dump_absC                 = lookUp  SLIT("-ddump-absC")
260 opt_D_dump_asm                  = lookUp  SLIT("-ddump-asm")
261 opt_D_dump_deforest             = lookUp  SLIT("-ddump-deforest")
262 opt_D_dump_deriv                = lookUp  SLIT("-ddump-deriv")
263 opt_D_dump_ds                   = lookUp  SLIT("-ddump-ds")
264 opt_D_dump_flatC                = lookUp  SLIT("-ddump-flatC")
265 opt_D_dump_occur_anal           = lookUp  SLIT("-ddump-occur-anal")
266 opt_D_dump_rdr                  = lookUp  SLIT("-ddump-rdr")
267 opt_D_dump_realC                = lookUp  SLIT("-ddump-realC")
268 opt_D_dump_rn                   = lookUp  SLIT("-ddump-rn")
269 opt_D_dump_simpl                = lookUp  SLIT("-ddump-simpl")
270 opt_D_dump_spec                 = lookUp  SLIT("-ddump-spec")
271 opt_D_dump_stg                  = lookUp  SLIT("-ddump-stg")
272 opt_D_dump_stranal              = lookUp  SLIT("-ddump-stranal")
273 opt_D_dump_tc                   = lookUp  SLIT("-ddump-tc")
274 opt_D_show_passes               = lookUp  SLIT("-dshow-passes")
275 opt_D_show_rn_trace             = lookUp  SLIT("-dshow-rn-trace")
276 opt_D_simplifier_stats          = lookUp  SLIT("-dsimplifier-stats")
277 opt_D_source_stats              = lookUp  SLIT("-dsource-stats")
278 opt_D_verbose_core2core         = lookUp  SLIT("-dverbose-simpl")
279 opt_D_verbose_stg2stg           = lookUp  SLIT("-dverbose-stg")
280 opt_DoCoreLinting               = lookUp  SLIT("-dcore-lint")
281 opt_DoSemiTagging               = lookUp  SLIT("-fsemi-tagging")
282 opt_DoTickyProfiling            = lookUp  SLIT("-fticky-ticky")
283 opt_DoEtaReduction              = lookUp  SLIT("-fdo-eta-reduction")
284 opt_EnsureSplittableC           = lookUp  SLIT("-fglobalise-toplev-names")
285 opt_FoldrBuildOn                = lookUp  SLIT("-ffoldr-build-on")
286 opt_FoldrBuildTrace             = lookUp  SLIT("-ffoldr-build-trace")
287 opt_ForConcurrent               = lookUp  SLIT("-fconcurrent")
288 opt_GranMacros                  = lookUp  SLIT("-fgransim")
289 opt_GlasgowExts                 = lookUp  SLIT("-fglasgow-exts")
290 opt_Haskell_1_3                 = lookUp  SLIT("-fhaskell-1.3")
291 opt_HiMap                       = lookup_str "-himap="  -- file saying where to look for .hi files
292 opt_IgnoreIfacePragmas          = lookUp  SLIT("-fignore-interface-pragmas")
293 opt_IgnoreStrictnessPragmas     = lookUp  SLIT("-fignore-strictness-pragmas")
294 opt_IrrefutableEverything       = lookUp  SLIT("-firrefutable-everything")
295 opt_IrrefutableTuples           = lookUp  SLIT("-firrefutable-tuples")
296 opt_NoImplicitPrelude           = lookUp  SLIT("-fno-implicit-prelude")
297 opt_NumbersStrict               = lookUp  SLIT("-fnumbers-strict")
298 opt_OmitBlackHoling             = lookUp  SLIT("-dno-black-holing")
299 opt_OmitDefaultInstanceMethods  = lookUp  SLIT("-fomit-default-instance-methods")
300 opt_OmitInterfacePragmas        = lookUp  SLIT("-fomit-interface-pragmas")
301 opt_PprStyle_All                = lookUp  SLIT("-dppr-all")
302 opt_PprStyle_Debug              = lookUp  SLIT("-dppr-debug")
303 opt_PprStyle_User               = lookUp  SLIT("-dppr-user")
304 opt_ProduceC                    = lookup_str "-C="
305 opt_ProduceS                    = lookup_str "-S="
306 opt_ProduceHi                   = lookup_str "-hifile=" -- the one to produce this time 
307 opt_ReportWhyUnfoldingsDisallowed= lookUp SLIT("-freport-disallowed-unfoldings")
308 opt_SccProfilingOn              = lookUp  SLIT("-fscc-profiling")
309 opt_ShowImportSpecs             = lookUp  SLIT("-fshow-import-specs")
310 opt_ShowPragmaNameErrs          = lookUp  SLIT("-fshow-pragma-name-errs")
311 opt_SigsRequired                = lookUp  SLIT("-fsignatures-required")
312 opt_SourceUnchanged             = lookUp  SLIT("-fsource-unchanged")
313 opt_SpecialiseAll               = lookUp  SLIT("-fspecialise-all")
314 opt_SpecialiseImports           = lookUp  SLIT("-fspecialise-imports")
315 opt_SpecialiseOverloaded        = lookUp  SLIT("-fspecialise-overloaded")
316 opt_SpecialiseTrace             = lookUp  SLIT("-ftrace-specialisation")
317 opt_SpecialiseUnboxed           = lookUp  SLIT("-fspecialise-unboxed")
318 opt_StgDoLetNoEscapes           = lookUp  SLIT("-flet-no-escape")
319 opt_ReturnInRegsThreshold       = lookup_int "-freturn-in-regs-threshold"
320 opt_SccGroup                    = lookup_str "-G="
321 opt_Verbose                     = lookUp  SLIT("-v")
322
323 opt_InterfaceUnfoldThreshold    = lookup_def_int "-funfolding-interface-threshold" iNTERFACE_UNFOLD_THRESHOLD
324 opt_UnfoldingCreationThreshold  = lookup_def_int "-funfolding-creation-threshold"  uNFOLDING_CREATION_THRESHOLD
325 opt_UnfoldingUseThreshold       = lookup_def_int "-funfolding-use-threshold"       uNFOLDING_USE_THRESHOLD
326 opt_UnfoldingConDiscount        = lookup_def_int "-funfolding-con-discount"        uNFOLDING_CON_DISCOUNT_WEIGHT
327                         
328 opt_LiberateCaseThreshold       = lookup_def_int "-fliberate-case-threshold"       lIBERATE_CASE_THRESHOLD
329 opt_WarnNameShadowing           = lookUp  SLIT("-fwarn-name-shadowing")
330
331 -- opt_UnfoldingUseThreshold    = lookup_int "-funfolding-use-threshold"
332 -- opt_UnfoldingOverrideThreshold       = lookup_int "-funfolding-override-threshold"
333 \end{code}
334
335 \begin{code}
336 classifyOpts :: ([CoreToDo],    -- Core-to-Core processing spec
337                  [StgToDo])     -- STG-to-STG   processing spec
338
339 classifyOpts = sep argv [] [] -- accumulators...
340   where
341     sep :: [FAST_STRING]                         -- cmd-line opts (input)
342         -> [CoreToDo] -> [StgToDo]       -- to_do accumulators
343         -> ([CoreToDo], [StgToDo])       -- result
344
345     sep [] core_td stg_td -- all done!
346       = (reverse core_td, reverse stg_td)
347
348 #       define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
349 #       define STG_TD(to_do)  sep opts core_td (to_do:stg_td)
350 #       define IGNORE_ARG()   sep opts core_td stg_td
351
352     sep (opt1:opts) core_td stg_td
353       =
354         case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
355
356           ',' : _       -> IGNORE_ARG() -- it is for the parser
357
358           "-fsimplify"  -> -- gather up SimplifierSwitches specially...
359                            simpl_sep opts defaultSimplSwitches core_td stg_td
360
361           "-fcalc-inlinings1"-> CORE_TD(CoreDoCalcInlinings1)
362           "-fcalc-inlinings2"-> CORE_TD(CoreDoCalcInlinings2)
363           "-ffloat-inwards"  -> CORE_TD(CoreDoFloatInwards)
364           "-ffull-laziness"  -> CORE_TD(CoreDoFullLaziness)
365           "-fliberate-case"  -> CORE_TD(CoreLiberateCase)
366           "-fprint-core"     -> CORE_TD(CoreDoPrintCore)
367           "-fstatic-args"    -> CORE_TD(CoreDoStaticArgs)
368           "-fstrictness"     -> CORE_TD(CoreDoStrictness)
369           "-fspecialise"     -> CORE_TD(CoreDoSpecialising)
370           "-fdeforest"       -> CORE_TD(CoreDoDeforest)
371           "-ffoldr-build-worker-wrapper"  -> CORE_TD(CoreDoFoldrBuildWorkerWrapper)
372           "-ffoldr-build-ww-anal"  -> CORE_TD(CoreDoFoldrBuildWWAnal)
373
374           "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
375           "-fupdate-analysis" -> STG_TD(StgDoUpdateAnalysis)
376           "-dstg-stats"       -> STG_TD(D_stg_stats)
377           "-flambda-lift"     -> STG_TD(StgDoLambdaLift)
378           "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
379
380           _ -> -- NB: the driver is really supposed to handle bad options
381                IGNORE_ARG()
382
383     ----------------
384
385     simpl_sep :: [FAST_STRING]      -- cmd-line opts (input)
386         -> [SimplifierSwitch]       -- simplifier-switch accumulator
387         -> [CoreToDo] -> [StgToDo]  -- to_do accumulators
388         -> ([CoreToDo], [StgToDo])  -- result
389
390         -- "simpl_sep" tailcalls "sep" once it's seen one set
391         -- of SimplifierSwitches for a CoreDoSimplify.
392
393 #ifdef DEBUG
394     simpl_sep input@[] simpl_sw core_td stg_td
395       = panic "simpl_sep []"
396 #endif
397
398         -- The SimplifierSwitches should be delimited by "(" and ")".
399
400     simpl_sep (opt1:opts) simpl_sw core_td stg_td
401       = case (_UNPK_ opt1) of
402           "(" -> simpl_sep opts simpl_sw core_td stg_td
403           ")" -> let
404                     this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
405                  in
406                  sep opts (this_simpl : core_td) stg_td
407
408 #         define SIMPL_SW(sw) simpl_sep opts (sw:simpl_sw) core_td stg_td
409
410           -- the non-"just match a string" options are at the end...
411           "-fshow-simplifier-progress"      -> SIMPL_SW(ShowSimplifierProgress)
412           "-fcode-duplication-ok"           -> SIMPL_SW(SimplOkToDupCode)
413           "-ffloat-lets-exposing-whnf"      -> SIMPL_SW(SimplFloatLetsExposingWHNF)
414           "-ffloat-primops-ok"              -> SIMPL_SW(SimplOkToFloatPrimOps)
415           "-falways-float-lets-from-lets"   -> SIMPL_SW(SimplAlwaysFloatLetsFromLets)
416           "-fdo-case-elim"                  -> SIMPL_SW(SimplDoCaseElim)
417           "-fdo-lambda-eta-expansion"       -> SIMPL_SW(SimplDoLambdaEtaExpansion)
418           "-fdo-foldr-build"                -> SIMPL_SW(SimplDoFoldrBuild)
419           "-fdo-not-fold-back-append"       -> SIMPL_SW(SimplDontFoldBackAppend)
420           "-fdo-arity-expand"               -> SIMPL_SW(SimplDoArityExpand)
421           "-fdo-inline-foldr-build"         -> SIMPL_SW(SimplDoInlineFoldrBuild)
422           "-freuse-con"                     -> SIMPL_SW(SimplReuseCon)
423           "-fcase-of-case"                  -> SIMPL_SW(SimplCaseOfCase)
424           "-fcase-merge"                    -> SIMPL_SW(SimplCaseMerge)
425           "-flet-to-case"                   -> SIMPL_SW(SimplLetToCase)
426           "-fpedantic-bottoms"              -> SIMPL_SW(SimplPedanticBottoms)
427           "-fkeep-spec-pragma-ids"          -> SIMPL_SW(KeepSpecPragmaIds)
428           "-fkeep-unused-bindings"          -> SIMPL_SW(KeepUnusedBindings)
429           "-fmay-delete-conjurable-ids"     -> SIMPL_SW(SimplMayDeleteConjurableIds)
430           "-fessential-unfoldings-only"     -> SIMPL_SW(EssentialUnfoldingsOnly)
431           "-fignore-inline-pragma"          -> SIMPL_SW(IgnoreINLINEPragma)
432           "-fno-let-from-case"              -> SIMPL_SW(SimplNoLetFromCase)
433           "-fno-let-from-app"               -> SIMPL_SW(SimplNoLetFromApp)
434           "-fno-let-from-strict-let"        -> SIMPL_SW(SimplNoLetFromStrictLet)
435
436           o | starts_with_msi  -> SIMPL_SW(MaxSimplifierIterations (read after_msi))
437            where
438             maybe_msi           = startsWith "-fmax-simplifier-iterations"   o
439             starts_with_msi     = maybeToBool maybe_msi
440             (Just after_msi)    = maybe_msi
441
442           _ -> -- NB: the driver is really supposed to handle bad options
443                simpl_sep opts simpl_sw core_td stg_td
444 \end{code}
445
446 %************************************************************************
447 %*                                                                      *
448 \subsection{Switch ordering}
449 %*                                                                      *
450 %************************************************************************
451
452 In spite of the @Produce*@ and @SccGroup@ constructors, these things
453 behave just like enumeration types.
454
455 \begin{code}
456 instance Eq SimplifierSwitch where
457     a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
458
459 instance Ord SimplifierSwitch where
460     a <  b  = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
461     a <= b  = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
462
463 tagOf_SimplSwitch SimplOkToDupCode              =(ILIT(0) :: FAST_INT)
464 tagOf_SimplSwitch SimplFloatLetsExposingWHNF    = ILIT(1)
465 tagOf_SimplSwitch SimplOkToFloatPrimOps         = ILIT(2)
466 tagOf_SimplSwitch SimplAlwaysFloatLetsFromLets  = ILIT(3)
467 tagOf_SimplSwitch SimplDoCaseElim               = ILIT(4)
468 tagOf_SimplSwitch SimplReuseCon                 = ILIT(5)
469 tagOf_SimplSwitch SimplCaseOfCase               = ILIT(6)
470 tagOf_SimplSwitch SimplLetToCase                = ILIT(7)
471 tagOf_SimplSwitch SimplMayDeleteConjurableIds   = ILIT(9)
472 tagOf_SimplSwitch SimplPedanticBottoms          = ILIT(10)
473 tagOf_SimplSwitch SimplDoArityExpand            = ILIT(11)
474 tagOf_SimplSwitch SimplDoFoldrBuild             = ILIT(12)
475 tagOf_SimplSwitch SimplDoInlineFoldrBuild       = ILIT(14)
476 tagOf_SimplSwitch IgnoreINLINEPragma            = ILIT(15)
477 tagOf_SimplSwitch SimplDoLambdaEtaExpansion     = ILIT(16)
478 tagOf_SimplSwitch EssentialUnfoldingsOnly       = ILIT(19)
479 tagOf_SimplSwitch ShowSimplifierProgress        = ILIT(20)
480 tagOf_SimplSwitch (MaxSimplifierIterations _)   = ILIT(21)
481 tagOf_SimplSwitch KeepSpecPragmaIds             = ILIT(25)
482 tagOf_SimplSwitch KeepUnusedBindings            = ILIT(26)
483 tagOf_SimplSwitch SimplNoLetFromCase            = ILIT(27)
484 tagOf_SimplSwitch SimplNoLetFromApp             = ILIT(28)
485 tagOf_SimplSwitch SimplNoLetFromStrictLet       = ILIT(29)
486 tagOf_SimplSwitch SimplDontFoldBackAppend       = ILIT(30)
487 tagOf_SimplSwitch SimplCaseMerge                = ILIT(31)
488 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
489
490 tagOf_SimplSwitch _ = panic# "tagOf_SimplSwitch"
491
492 lAST_SIMPL_SWITCH_TAG = IBOX(tagOf_SimplSwitch SimplCaseMerge)
493 \end{code}
494
495 %************************************************************************
496 %*                                                                      *
497 \subsection{Switch lookup}
498 %*                                                                      *
499 %************************************************************************
500
501 \begin{code}
502 #if __GLASGOW_HASKELL__ >= 200
503 # define ARRAY      Array
504 # define LIFT       GHCbase.Lift
505 # define SET_TO     =:
506 (=:) a b = (a,b)
507 #else
508 # define ARRAY      _Array
509 # define LIFT       _Lift
510 # define SET_TO     :=
511 #endif
512
513 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
514
515 isAmongSimpl on_switches                -- Switches mentioned later occur *earlier*
516                                         -- in the list; defaults right at the end.
517   = let
518         tidied_on_switches = foldl rm_dups [] on_switches
519                 -- The fold*l* ensures that we keep the latest switches;
520                 -- ie the ones that occur earliest in the list.
521
522         sw_tbl :: Array Int SwitchResult
523
524         sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
525                         all_undefined)
526                  // defined_elems
527
528         all_undefined = [ i SET_TO SwBool False | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
529
530         defined_elems = map mk_assoc_elem tidied_on_switches
531     in
532     -- (avoid some unboxing, bounds checking, and other horrible things:)
533     case sw_tbl of { ARRAY bounds_who_needs_'em stuff ->
534     \ switch ->
535         case (indexArray# stuff (tagOf_SimplSwitch switch)) of
536           LIFT v -> v
537     }
538   where
539     mk_assoc_elem k@(MaxSimplifierIterations lvl)       = IBOX(tagOf_SimplSwitch k) SET_TO SwInt lvl
540
541     mk_assoc_elem k = IBOX(tagOf_SimplSwitch k) SET_TO SwBool   True -- I'm here, Mom!
542
543     -- cannot have duplicates if we are going to use the array thing
544     rm_dups switches_so_far switch
545       = if switch `is_elem` switches_so_far
546         then switches_so_far
547         else switch : switches_so_far
548       where
549         sw `is_elem` []     = False
550         sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
551                             || sw `is_elem` ss
552 \end{code}
553
554 Default settings for simplifier switches
555
556 \begin{code}
557 defaultSimplSwitches = [MaxSimplifierIterations         1
558                        ]
559 \end{code}
560
561 %************************************************************************
562 %*                                                                      *
563 \subsection{Misc functions for command-line options}
564 %*                                                                      *
565 %************************************************************************
566
567
568 \begin{code}
569 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
570
571 switchIsOn lookup_fn switch
572   = case (lookup_fn switch) of
573       SwBool False -> False
574       _            -> True
575
576 stringSwitchSet :: (switch -> SwitchResult)
577                 -> (FAST_STRING -> switch)
578                 -> Maybe FAST_STRING
579
580 stringSwitchSet lookup_fn switch
581   = case (lookup_fn (switch (panic "stringSwitchSet"))) of
582       SwString str -> Just str
583       _            -> Nothing
584
585 intSwitchSet :: (switch -> SwitchResult)
586              -> (Int -> switch)
587              -> Maybe Int
588
589 intSwitchSet lookup_fn switch
590   = case (lookup_fn (switch (panic "intSwitchSet"))) of
591       SwInt int -> Just int
592       _         -> Nothing
593 \end{code}