2 % (c) The AQUA Project, Glasgow University, 1996-98
4 \section[CmdLineOpts]{Things to do with command-line options}
26 opt_D_dump_occur_anal,
31 opt_D_dump_simpl_iterations,
37 opt_D_dump_worker_wrapper,
39 opt_D_show_rn_imports,
42 opt_D_simplifier_stats,
44 opt_D_verbose_core2core,
45 opt_D_verbose_stg2stg,
54 opt_WarnDuplicateExports,
56 opt_WarnIncompletePatterns,
57 opt_WarnMissingMethods,
59 opt_WarnNameShadowing,
60 opt_WarnOverlappingPatterns,
61 opt_WarnSimplePatterns,
64 opt_WarnUnusedImports,
65 opt_WarnUnusedMatches,
68 opt_AutoSccsOnAllToplevs,
69 opt_AutoSccsOnExportedToplevs,
70 opt_AutoSccsOnIndividualCafs,
79 opt_MaxContextReductionDepth,
80 opt_AllowOverlappingInstances,
81 opt_AllowUndecidableInstances,
83 opt_IrrefutableTuples,
91 opt_InterfaceUnfoldThreshold,
92 opt_LiberateCaseThreshold,
94 opt_StgDoLetNoEscapes,
96 opt_UnfoldingConDiscount,
97 opt_UnfoldingCreationThreshold,
98 opt_UnfoldingKeenessFactor,
99 opt_UnfoldingUseThreshold,
101 opt_UnboxStrictFields,
104 opt_CompilingPrelude,
105 opt_EmitCExternDecls,
106 opt_EnsureSplittableC,
111 opt_IgnoreIfacePragmas,
113 opt_NoImplicitPrelude,
115 opt_OmitInterfacePragmas,
117 opt_ProduceExportCStubs,
118 opt_ProduceExportHStubs,
135 #include "HsVersions.h"
137 import Array ( array, (//) )
140 import Constants -- Default values for some flags
142 import Maybes ( assocMaybe, firstJust, maybeToBool )
143 import Panic ( panic, panic# )
145 #if __GLASGOW_HASKELL__ < 301
146 import ArrBase ( Array(..) )
148 import PrelArr ( Array(..) )
152 A command-line {\em switch} is (generally) either on or off; e.g., the
153 ``verbose'' (-v) switch is either on or off. (The \tr{-G<group>}
154 switch is an exception; it's set to a string, or nothing.)
156 A list of {\em ToDo}s is things to be done in a particular part of
157 processing. A (fictitious) example for the Core-to-Core simplifier
158 might be: run the simplifier, then run the strictness analyser, then
159 run the simplifier again (three ``todos'').
161 There are three ``to-do processing centers'' at the moment. In the
162 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
163 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
164 (\tr{simplStg/SimplStg.lhs}).
166 %************************************************************************
168 \subsection{Datatypes associated with command-line options}
170 %************************************************************************
174 = SwBool Bool -- on/off
175 | SwString FAST_STRING -- nothing or a String
176 | SwInt Int -- nothing or an Int
180 data CoreToDo -- These are diff core-to-core passes,
181 -- which may be invoked in any order,
182 -- as many times as you like.
184 = CoreDoSimplify -- The core-to-core simplifier.
185 (SimplifierSwitch -> SwitchResult)
186 -- Each run of the simplifier can take a different
187 -- set of simplifier-specific flags.
188 | CoreDoCalcInlinings1
189 | CoreDoCalcInlinings2
196 | CoreDoWorkerWrapper
198 | CoreDoFoldrBuildWorkerWrapper
199 | CoreDoFoldrBuildWWAnal
207 | StgDoUpdateAnalysis
209 | StgDoMassageForProfiling -- should be (next to) last
210 -- There's also setStgVarInfo, but its absolute "lastness"
211 -- is so critical that it is hardwired in (no flag).
216 data SimplifierSwitch
218 | SimplFloatLetsExposingWHNF
219 | SimplOkToFloatPrimOps
220 | SimplAlwaysFloatLetsFromLets
224 | SimplMayDeleteConjurableIds
225 | SimplPedanticBottoms -- see Simplifier for an explanation
226 | SimplDoArityExpand -- expand arity of bindings
227 | SimplDoFoldrBuild -- This is the per-simplification flag;
228 -- see also FoldrBuildOn, used elsewhere
230 | SimplDoInlineFoldrBuild
231 -- inline foldr/build (*after* f/b rule is used)
234 | SimplDoLambdaEtaExpansion
236 | EssentialUnfoldingsOnly -- never mind the thresholds, only
237 -- do unfoldings that *must* be done
238 -- (to saturate constructors and primitives)
240 | MaxSimplifierIterations Int
242 | SimplNoLetFromCase -- used when turning off floating entirely
243 | SimplNoLetFromApp -- (for experimentation only) WDP 95/10
244 | SimplNoLetFromStrictLet
250 %************************************************************************
252 \subsection{Classifying command-line options}
254 %************************************************************************
257 lookUp :: FAST_STRING -> Bool
258 lookup_int :: String -> Maybe Int
259 lookup_def_int :: String -> Int -> Int
260 lookup_def_float :: String -> Float -> Float
261 lookup_str :: String -> Maybe String
263 lookUp sw = maybeToBool (assoc_opts sw)
265 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
267 lookup_int sw = case (lookup_str sw) of
269 Just xx -> Just (read xx)
271 lookup_def_int sw def = case (lookup_str sw) of
272 Nothing -> def -- Use default
275 lookup_def_float sw def = case (lookup_str sw) of
276 Nothing -> def -- Use default
279 assoc_opts = assocMaybe [ (a, True) | a <- argv ]
280 unpacked_opts = map _UNPK_ argv
283 Putting the compiler options into temporary at-files
284 may turn out to be necessary later on if we turn hsc into
285 a pure Win32 application where I think there's a command-line
286 length limit of 255. unpacked_opts understands the @ option.
288 assoc_opts = assocMaybe [ (_PK_ a, True) | a <- unpacked_opts ]
290 unpacked_opts :: [String]
296 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
303 opt_D_dump_absC = lookUp SLIT("-ddump-absC")
304 opt_D_dump_asm = lookUp SLIT("-ddump-asm")
305 opt_D_dump_cpranal = lookUp SLIT("-ddump-cpranalyse")
306 opt_D_dump_deriv = lookUp SLIT("-ddump-deriv")
307 opt_D_dump_ds = lookUp SLIT("-ddump-ds")
308 opt_D_dump_flatC = lookUp SLIT("-ddump-flatC")
309 opt_D_dump_foreign = lookUp SLIT("-ddump-foreign-stubs")
310 opt_D_dump_inlinings = lookUp SLIT("-ddump-inlinings")
311 opt_D_dump_occur_anal = lookUp SLIT("-ddump-occur-anal")
312 opt_D_dump_rdr = lookUp SLIT("-ddump-rdr")
313 opt_D_dump_realC = lookUp SLIT("-ddump-realC")
314 opt_D_dump_rn = lookUp SLIT("-ddump-rn")
315 opt_D_dump_simpl = lookUp SLIT("-ddump-simpl")
316 opt_D_dump_simpl_iterations = lookUp SLIT("-ddump-simpl-iterations")
317 opt_D_dump_spec = lookUp SLIT("-ddump-spec")
318 opt_D_dump_stg = lookUp SLIT("-ddump-stg")
319 opt_D_dump_stranal = lookUp SLIT("-ddump-stranal")
320 opt_D_dump_tc = lookUp SLIT("-ddump-tc")
321 opt_D_dump_usagesp = lookUp SLIT("-ddump-usagesp")
322 opt_D_dump_worker_wrapper = lookUp SLIT("-ddump-workwrap")
323 opt_D_show_passes = lookUp SLIT("-dshow-passes")
324 opt_D_show_rn_imports = lookUp SLIT("-dshow-rn-imports")
325 opt_D_show_rn_trace = lookUp SLIT("-dshow-rn-trace")
326 opt_D_show_rn_stats = lookUp SLIT("-dshow-rn-stats")
327 opt_D_simplifier_stats = lookUp SLIT("-dsimplifier-stats")
328 opt_D_source_stats = lookUp SLIT("-dsource-stats")
329 opt_D_verbose_core2core = lookUp SLIT("-dverbose-simpl")
330 opt_D_verbose_stg2stg = lookUp SLIT("-dverbose-stg")
331 opt_DoCoreLinting = lookUp SLIT("-dcore-lint")
332 opt_DoStgLinting = lookUp SLIT("-dstg-lint")
333 opt_DoUSPLinting = lookUp SLIT("-dusagesp-lint")
334 opt_PprStyle_NoPrags = lookUp SLIT("-dppr-noprags")
335 opt_PprStyle_Debug = lookUp SLIT("-dppr-debug")
336 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
339 opt_WarnDuplicateExports = lookUp SLIT("-fwarn-duplicate-exports")
340 opt_WarnHiShadows = lookUp SLIT("-fwarn-hi-shadowing")
341 opt_WarnIncompletePatterns = lookUp SLIT("-fwarn-incomplete-patterns")
342 opt_WarnMissingMethods = lookUp SLIT("-fwarn-missing-methods")
343 opt_WarnMissingSigs = lookUp SLIT("-fwarn-missing-signatures")
344 opt_WarnNameShadowing = lookUp SLIT("-fwarn-name-shadowing")
345 opt_WarnOverlappingPatterns = lookUp SLIT("-fwarn-overlapping-patterns")
346 opt_WarnSimplePatterns = lookUp SLIT("-fwarn-simple-patterns")
347 opt_WarnTypeDefaults = lookUp SLIT("-fwarn-type-defaults")
348 opt_WarnUnusedBinds = lookUp SLIT("-fwarn-unused-binds")
349 opt_WarnUnusedImports = lookUp SLIT("-fwarn-unused-imports")
350 opt_WarnUnusedMatches = lookUp SLIT("-fwarn-unused-matches")
353 opt_AutoSccsOnAllToplevs = lookUp SLIT("-fauto-sccs-on-all-toplevs")
354 opt_AutoSccsOnExportedToplevs = lookUp SLIT("-fauto-sccs-on-exported-toplevs")
355 opt_AutoSccsOnIndividualCafs = lookUp SLIT("-fauto-sccs-on-individual-cafs")
356 opt_AutoSccsOnDicts = lookUp SLIT("-fauto-sccs-on-dicts")
357 opt_SccGroup = lookup_str "-G="
358 opt_SccProfilingOn = lookUp SLIT("-fscc-profiling")
359 opt_DoTickyProfiling = lookUp SLIT("-fticky-ticky")
362 opt_AllStrict = lookUp SLIT("-fall-strict")
363 opt_DictsStrict = lookUp SLIT("-fdicts-strict")
364 opt_AllowOverlappingInstances = lookUp SLIT("-fallow-overlapping-instances")
365 opt_AllowUndecidableInstances = lookUp SLIT("-fallow-undecidable-instances")
366 opt_GlasgowExts = lookUp SLIT("-fglasgow-exts")
367 opt_IrrefutableTuples = lookUp SLIT("-firrefutable-tuples")
368 opt_MaxContextReductionDepth = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
369 opt_NumbersStrict = lookUp SLIT("-fnumbers-strict")
370 opt_Parallel = lookUp SLIT("-fparallel")
373 opt_DoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
374 opt_DoSemiTagging = lookUp SLIT("-fsemi-tagging")
375 opt_FoldrBuildOn = lookUp SLIT("-ffoldr-build-on")
376 opt_InterfaceUnfoldThreshold = lookup_def_int "-funfolding-interface-threshold" iNTERFACE_UNFOLD_THRESHOLD
377 opt_LiberateCaseThreshold = lookup_def_int "-fliberate-case-threshold" lIBERATE_CASE_THRESHOLD
378 opt_NoPreInlining = lookUp SLIT("-fno-pre-inlining")
379 opt_StgDoLetNoEscapes = lookUp SLIT("-flet-no-escape")
380 opt_UnfoldCasms = lookUp SLIT("-funfold-casms-in-hi-file")
381 opt_UnfoldingConDiscount = lookup_def_int "-funfolding-con-discount" uNFOLDING_CON_DISCOUNT_WEIGHT
382 opt_UnfoldingCreationThreshold = lookup_def_int "-funfolding-creation-threshold" uNFOLDING_CREATION_THRESHOLD
383 opt_UnfoldingKeenessFactor = lookup_def_float "-funfolding-keeness-factor" uNFOLDING_KEENESS_FACTOR
384 opt_UnfoldingUseThreshold = lookup_def_int "-funfolding-use-threshold" uNFOLDING_USE_THRESHOLD
385 opt_UsageSPOn = lookUp SLIT("-fusagesp-on")
386 opt_UnboxStrictFields = lookUp SLIT("-funbox-strict-fields")
389 It's a bit unfortunate to have to re-introduce this chap, but on Win32
390 platforms we do need a way of distinguishing between the case when we're
391 compiling a static version of the Prelude and one that's going to be
392 put into a DLL. Why? Because the compiler's wired in modules need to
393 be attributed as either coming from a DLL or not.
395 opt_CompilingPrelude = lookUp SLIT("-fcompiling-prelude")
396 opt_EmitCExternDecls = lookUp SLIT("-femit-extern-decls")
397 opt_EnsureSplittableC = lookUp SLIT("-fglobalise-toplev-names")
398 opt_GranMacros = lookUp SLIT("-fgransim")
399 opt_HiMap = lookup_str "-himap=" -- file saying where to look for .hi files
400 opt_HiVersion = lookup_def_int "-fhi-version=" 0 -- what version we're compiling.
401 opt_IgnoreAsserts = lookUp SLIT("-fignore-asserts")
402 opt_IgnoreIfacePragmas = lookUp SLIT("-fignore-interface-pragmas")
403 opt_NoHiCheck = lookUp SLIT("-fno-hi-version-check")
404 opt_NoImplicitPrelude = lookUp SLIT("-fno-implicit-prelude")
405 opt_OmitBlackHoling = lookUp SLIT("-dno-black-holing")
406 opt_OmitInterfacePragmas = lookUp SLIT("-fomit-interface-pragmas")
407 opt_ProduceC = lookup_str "-C="
408 opt_ProduceExportCStubs = lookup_str "-F="
409 opt_ProduceExportHStubs = lookup_str "-FH="
410 opt_ProduceHi = lookup_str "-hifile=" -- the one to produce this time
411 opt_ProduceS = lookup_str "-S="
412 opt_ReportCompile = lookUp SLIT("-freport-compile")
413 opt_PruneTyDecls = not (lookUp SLIT("-fno-prune-tydecls"))
414 opt_PruneInstDecls = not (lookUp SLIT("-fno-prune-instdecls"))
415 opt_SourceUnchanged = lookUp SLIT("-fsource-unchanged")
416 opt_Static = lookUp SLIT("-static")
417 opt_Unregisterised = lookUp SLIT("-funregisterised")
418 opt_Verbose = lookUp SLIT("-v")
420 opt_UseVanillaRegs | opt_Unregisterised = 0
421 | otherwise = mAX_Real_Vanilla_REG
422 opt_UseFloatRegs | opt_Unregisterised = 0
423 | otherwise = mAX_Real_Float_REG
424 opt_UseDoubleRegs | opt_Unregisterised = 0
425 | otherwise = mAX_Real_Double_REG
426 opt_UseLongRegs | opt_Unregisterised = 0
427 | otherwise = mAX_Real_Long_REG
429 -- opt_UnfoldingOverrideThreshold = lookup_int "-funfolding-override-threshold"
433 classifyOpts :: ([CoreToDo], -- Core-to-Core processing spec
434 [StgToDo]) -- STG-to-STG processing spec
436 classifyOpts = sep argv [] [] -- accumulators...
438 sep :: [FAST_STRING] -- cmd-line opts (input)
439 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
440 -> ([CoreToDo], [StgToDo]) -- result
442 sep [] core_td stg_td -- all done!
443 = (reverse core_td, reverse stg_td)
445 # define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
446 # define STG_TD(to_do) sep opts core_td (to_do:stg_td)
448 sep (opt1:opts) core_td stg_td
449 = case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
450 ',' : _ -> sep opts core_td stg_td -- it is for the parser
452 "-fsimplify" -> -- gather up SimplifierSwitches specially...
453 simpl_sep opts defaultSimplSwitches core_td stg_td
455 "-fcalc-inlinings1"-> CORE_TD(CoreDoCalcInlinings1)
456 "-fcalc-inlinings2"-> CORE_TD(CoreDoCalcInlinings2)
457 "-ffloat-inwards" -> CORE_TD(CoreDoFloatInwards)
458 "-ffull-laziness" -> CORE_TD(CoreDoFullLaziness)
459 "-fliberate-case" -> CORE_TD(CoreLiberateCase)
460 "-fprint-core" -> CORE_TD(CoreDoPrintCore)
461 "-fstatic-args" -> CORE_TD(CoreDoStaticArgs)
462 "-fstrictness" -> CORE_TD(CoreDoStrictness)
463 "-fworker-wrapper" -> CORE_TD(CoreDoWorkerWrapper)
464 "-fspecialise" -> CORE_TD(CoreDoSpecialising)
465 "-ffoldr-build-worker-wrapper" -> CORE_TD(CoreDoFoldrBuildWorkerWrapper)
466 "-ffoldr-build-ww-anal" -> CORE_TD(CoreDoFoldrBuildWWAnal)
467 "-fusagesp" -> CORE_TD(CoreDoUSPInf)
468 "-fcpr-analyse" -> CORE_TD(CoreDoCPResult)
470 "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
471 "-fupdate-analysis" -> STG_TD(StgDoUpdateAnalysis)
472 "-dstg-stats" -> STG_TD(D_stg_stats)
473 "-flambda-lift" -> STG_TD(StgDoLambdaLift)
474 "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
476 _ -> -- NB: the driver is really supposed to handle bad options
477 sep opts core_td stg_td
481 simpl_sep :: [FAST_STRING] -- cmd-line opts (input)
482 -> [SimplifierSwitch] -- simplifier-switch accumulator
483 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
484 -> ([CoreToDo], [StgToDo]) -- result
486 -- "simpl_sep" tailcalls "sep" once it's seen one set
487 -- of SimplifierSwitches for a CoreDoSimplify.
490 simpl_sep input@[] simpl_sw core_td stg_td
491 = panic "simpl_sep []"
494 -- The SimplifierSwitches should be delimited by "[" and "]".
496 simpl_sep (opt1:opts) simpl_sw core_td stg_td
497 = case (_UNPK_ opt1) of
498 "[" -> simpl_sep opts simpl_sw core_td stg_td
500 this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
502 sep opts (this_simpl : core_td) stg_td
504 # define SIMPL_SW(sw) simpl_sep opts (sw:simpl_sw) core_td stg_td
506 -- the non-"just match a string" options are at the end...
507 "-fcode-duplication-ok" -> SIMPL_SW(SimplOkToDupCode)
508 "-ffloat-lets-exposing-whnf" -> SIMPL_SW(SimplFloatLetsExposingWHNF)
509 "-ffloat-primops-ok" -> SIMPL_SW(SimplOkToFloatPrimOps)
510 "-falways-float-lets-from-lets" -> SIMPL_SW(SimplAlwaysFloatLetsFromLets)
511 "-fdo-case-elim" -> SIMPL_SW(SimplDoCaseElim)
512 "-fdo-lambda-eta-expansion" -> SIMPL_SW(SimplDoLambdaEtaExpansion)
513 "-fdo-foldr-build" -> SIMPL_SW(SimplDoFoldrBuild)
514 "-fdo-arity-expand" -> SIMPL_SW(SimplDoArityExpand)
515 "-fdo-inline-foldr-build" -> SIMPL_SW(SimplDoInlineFoldrBuild)
516 "-fcase-of-case" -> SIMPL_SW(SimplCaseOfCase)
517 "-fcase-merge" -> SIMPL_SW(SimplCaseMerge)
518 "-flet-to-case" -> SIMPL_SW(SimplLetToCase)
519 "-fpedantic-bottoms" -> SIMPL_SW(SimplPedanticBottoms)
520 "-fmay-delete-conjurable-ids" -> SIMPL_SW(SimplMayDeleteConjurableIds)
521 "-fessential-unfoldings-only" -> SIMPL_SW(EssentialUnfoldingsOnly)
522 "-fignore-inline-pragma" -> SIMPL_SW(IgnoreINLINEPragma)
523 "-fno-let-from-case" -> SIMPL_SW(SimplNoLetFromCase)
524 "-fno-let-from-app" -> SIMPL_SW(SimplNoLetFromApp)
525 "-fno-let-from-strict-let" -> SIMPL_SW(SimplNoLetFromStrictLet)
526 "-fclone-binds" -> SIMPL_SW(SimplPleaseClone)
528 o | starts_with_msi -> SIMPL_SW(MaxSimplifierIterations (read after_msi))
530 maybe_msi = startsWith "-fmax-simplifier-iterations" o
531 starts_with_msi = maybeToBool maybe_msi
532 (Just after_msi) = maybe_msi
534 _ -> -- NB: the driver is really supposed to handle bad options
535 simpl_sep opts simpl_sw core_td stg_td
538 %************************************************************************
540 \subsection{Switch ordering}
542 %************************************************************************
544 In spite of the @Produce*@ and @SccGroup@ constructors, these things
545 behave just like enumeration types.
548 instance Eq SimplifierSwitch where
549 a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
551 instance Ord SimplifierSwitch where
552 a < b = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
553 a <= b = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
555 tagOf_SimplSwitch SimplOkToDupCode =(ILIT(0) :: FAST_INT)
556 tagOf_SimplSwitch SimplFloatLetsExposingWHNF = ILIT(1)
557 tagOf_SimplSwitch SimplOkToFloatPrimOps = ILIT(2)
558 tagOf_SimplSwitch SimplAlwaysFloatLetsFromLets = ILIT(3)
559 tagOf_SimplSwitch SimplDoCaseElim = ILIT(4)
560 tagOf_SimplSwitch SimplCaseOfCase = ILIT(6)
561 tagOf_SimplSwitch SimplLetToCase = ILIT(7)
562 tagOf_SimplSwitch SimplMayDeleteConjurableIds = ILIT(9)
563 tagOf_SimplSwitch SimplPedanticBottoms = ILIT(10)
564 tagOf_SimplSwitch SimplDoArityExpand = ILIT(11)
565 tagOf_SimplSwitch SimplDoFoldrBuild = ILIT(12)
566 tagOf_SimplSwitch SimplDoInlineFoldrBuild = ILIT(14)
567 tagOf_SimplSwitch IgnoreINLINEPragma = ILIT(15)
568 tagOf_SimplSwitch SimplDoLambdaEtaExpansion = ILIT(16)
569 tagOf_SimplSwitch EssentialUnfoldingsOnly = ILIT(19)
570 tagOf_SimplSwitch (MaxSimplifierIterations _) = ILIT(21)
571 tagOf_SimplSwitch SimplNoLetFromCase = ILIT(27)
572 tagOf_SimplSwitch SimplNoLetFromApp = ILIT(28)
573 tagOf_SimplSwitch SimplNoLetFromStrictLet = ILIT(29)
574 tagOf_SimplSwitch SimplCaseMerge = ILIT(31)
575 tagOf_SimplSwitch SimplPleaseClone = ILIT(32)
577 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
579 tagOf_SimplSwitch _ = panic# "tagOf_SimplSwitch"
581 lAST_SIMPL_SWITCH_TAG = IBOX(tagOf_SimplSwitch SimplPleaseClone)
584 %************************************************************************
586 \subsection{Switch lookup}
588 %************************************************************************
591 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
593 isAmongSimpl on_switches -- Switches mentioned later occur *earlier*
594 -- in the list; defaults right at the end.
596 tidied_on_switches = foldl rm_dups [] on_switches
597 -- The fold*l* ensures that we keep the latest switches;
598 -- ie the ones that occur earliest in the list.
600 sw_tbl :: Array Int SwitchResult
602 sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
606 all_undefined = [ (i, SwBool False) | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
608 defined_elems = map mk_assoc_elem tidied_on_switches
610 -- (avoid some unboxing, bounds checking, and other horrible things:)
611 case sw_tbl of { Array bounds_who_needs_'em stuff ->
613 case (indexArray# stuff (tagOf_SimplSwitch switch)) of
614 #if __GLASGOW_HASKELL__ < 400
616 #elif __GLASGOW_HASKELL__ < 403
623 mk_assoc_elem k@(MaxSimplifierIterations lvl) = (IBOX(tagOf_SimplSwitch k), SwInt lvl)
625 mk_assoc_elem k = (IBOX(tagOf_SimplSwitch k), SwBool True) -- I'm here, Mom!
627 -- cannot have duplicates if we are going to use the array thing
628 rm_dups switches_so_far switch
629 = if switch `is_elem` switches_so_far
631 else switch : switches_so_far
633 sw `is_elem` [] = False
634 sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
638 Default settings for simplifier switches
641 defaultSimplSwitches = [MaxSimplifierIterations 1
645 %************************************************************************
647 \subsection{Misc functions for command-line options}
649 %************************************************************************
653 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
655 switchIsOn lookup_fn switch
656 = case (lookup_fn switch) of
657 SwBool False -> False
660 intSwitchSet :: (switch -> SwitchResult)
664 intSwitchSet lookup_fn switch
665 = case (lookup_fn (switch (panic "intSwitchSet"))) of
666 SwInt int -> Just int
671 startsWith, endsWith :: String -> String -> Maybe String
673 startsWith [] str = Just str
674 startsWith (c:cs) (s:ss)
675 = if c /= s then Nothing else startsWith cs ss
676 startsWith _ [] = Nothing
679 = case (startsWith (reverse cs) (reverse ss)) of
681 Just rs -> Just (reverse rs)