[project @ 2000-12-08 12:32:15 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / DriverState.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverState.hs,v 1.19 2000/12/08 12:32:15 simonpj Exp $
3 --
4 -- Settings for the driver
5 --
6 -- (c) The University of Glasgow 2000
7 --
8 -----------------------------------------------------------------------------
9
10 module DriverState where
11
12 #include "HsVersions.h"
13
14 import CmStaticInfo
15 import CmdLineOpts
16 import DriverUtil
17 import Util
18 import Config
19 import Exception
20 import IOExts
21 #ifdef mingw32_TARGET_OS
22 import TmpFiles ( newTempName )
23 import Directory ( removeFile )
24 #endif
25
26 import List
27 import Char  
28 import Monad
29
30 -----------------------------------------------------------------------------
31 -- Driver state
32
33 -- certain flags can be specified on a per-file basis, in an OPTIONS
34 -- pragma at the beginning of the source file.  This means that when
35 -- compiling mulitple files, we have to restore the global option
36 -- settings before compiling a new file.  
37 --
38 -- The DriverState record contains the per-file-mutable state.
39
40 data DriverState = DriverState {
41
42         -- are we runing cpp on this file?
43         cpp_flag                :: Bool,
44
45         -- misc
46         stolen_x86_regs         :: Int,
47         cmdline_hc_includes     :: [String],
48
49         -- options for a particular phase
50         opt_L                   :: [String],
51         opt_P                   :: [String],
52         opt_c                   :: [String],
53         opt_a                   :: [String],
54         opt_m                   :: [String]
55    }
56
57 initDriverState = DriverState {
58         cpp_flag                = False,
59         stolen_x86_regs         = 4,
60         cmdline_hc_includes     = [],
61         opt_L                   = [],
62         opt_P                   = [],
63         opt_c                   = [],
64         opt_a                   = [],
65         opt_m                   = [],
66    }
67         
68 -- The driver state is first initialized from the command line options,
69 -- and then reset to this initial state before each compilation.
70 -- v_InitDriverState contains the saved initial state, and v_DriverState
71 -- contains the current state (modified by any OPTIONS pragmas, for example).
72 --
73 -- v_InitDriverState may also be modified from the GHCi prompt, using :set.
74 --
75 GLOBAL_VAR(v_InitDriverState, initDriverState, DriverState)
76 GLOBAL_VAR(v_Driver_state,    initDriverState, DriverState)
77
78 readState :: (DriverState -> a) -> IO a
79 readState f = readIORef v_Driver_state >>= return . f
80
81 updateState :: (DriverState -> DriverState) -> IO ()
82 updateState f = readIORef v_Driver_state >>= writeIORef v_Driver_state . f
83
84 addOpt_L     a = updateState (\s -> s{opt_L =  a : opt_L s})
85 addOpt_P     a = updateState (\s -> s{opt_P =  a : opt_P s})
86 addOpt_c     a = updateState (\s -> s{opt_c =  a : opt_c s})
87 addOpt_a     a = updateState (\s -> s{opt_a =  a : opt_a s})
88 addOpt_m     a = updateState (\s -> s{opt_m =  a : opt_m s})
89
90 addCmdlineHCInclude a = 
91    updateState (\s -> s{cmdline_hc_includes =  a : cmdline_hc_includes s})
92
93         -- we add to the options from the front, so we need to reverse the list
94 getOpts :: (DriverState -> [a]) -> IO [a]
95 getOpts opts = readState opts >>= return . reverse
96
97 -----------------------------------------------------------------------------
98 -- non-configured things
99
100 cHaskell1Version = "5" -- i.e., Haskell 98
101
102 -----------------------------------------------------------------------------
103 -- Global compilation flags
104
105 -- location of compiler-related files
106 GLOBAL_VAR(v_TopDir,  clibdir, String)
107
108 -- Cpp-related flags
109 v_Hs_source_cpp_opts = global
110         [ "-D__HASKELL1__="++cHaskell1Version
111         , "-D__GLASGOW_HASKELL__="++cProjectVersionInt                          
112         , "-D__HASKELL98__"
113         , "-D__CONCURRENT_HASKELL__"
114         ]
115 {-# NOINLINE v_Hs_source_cpp_opts #-}
116
117 -- Keep output from intermediate phases
118 GLOBAL_VAR(v_Keep_hi_diffs,             False,          Bool)
119 GLOBAL_VAR(v_Keep_hc_files,             False,          Bool)
120 GLOBAL_VAR(v_Keep_s_files,              False,          Bool)
121 GLOBAL_VAR(v_Keep_raw_s_files,          False,          Bool)
122 GLOBAL_VAR(v_Keep_tmp_files,            False,          Bool)
123
124 -- Misc
125 GLOBAL_VAR(v_Scale_sizes_by,            1.0,            Double)
126 GLOBAL_VAR(v_Dry_run,                   False,          Bool)
127 #if !defined(HAVE_WIN32_DLL_SUPPORT) || defined(DONT_WANT_WIN32_DLL_SUPPORT)
128 GLOBAL_VAR(v_Static,                    True,           Bool)
129 #else
130 GLOBAL_VAR(v_Static,                    False,          Bool)
131 #endif
132 GLOBAL_VAR(v_NoHsMain,                  False,          Bool)
133 GLOBAL_VAR(v_Recomp,                    True,           Bool)
134 GLOBAL_VAR(v_Collect_ghc_timing,        False,          Bool)
135 GLOBAL_VAR(v_Do_asm_mangling,           True,           Bool)
136 GLOBAL_VAR(v_Excess_precision,          False,          Bool)
137
138 -----------------------------------------------------------------------------
139 -- Splitting object files (for libraries)
140
141 GLOBAL_VAR(v_Split_object_files,        False,          Bool)
142 GLOBAL_VAR(v_Split_prefix,              "",             String)
143 GLOBAL_VAR(v_N_split_files,             0,              Int)
144         
145 can_split :: Bool
146 can_split =  prefixMatch "i386"    cTARGETPLATFORM
147           || prefixMatch "alpha"   cTARGETPLATFORM
148           || prefixMatch "hppa"    cTARGETPLATFORM
149           || prefixMatch "m68k"    cTARGETPLATFORM
150           || prefixMatch "mips"    cTARGETPLATFORM
151           || prefixMatch "powerpc" cTARGETPLATFORM
152           || prefixMatch "rs6000"  cTARGETPLATFORM
153           || prefixMatch "sparc"   cTARGETPLATFORM
154
155 -----------------------------------------------------------------------------
156 -- Compiler output options
157
158 defaultHscLang
159   | cGhcWithNativeCodeGen == "YES" && 
160         (prefixMatch "i386" cTARGETPLATFORM ||
161          prefixMatch "sparc" cTARGETPLATFORM)   =  HscAsm
162   | otherwise                                   =  HscC
163
164 GLOBAL_VAR(v_Output_dir,  Nothing, Maybe String)
165 GLOBAL_VAR(v_Object_suf,  Nothing, Maybe String)
166 GLOBAL_VAR(v_Output_file, Nothing, Maybe String)
167 GLOBAL_VAR(v_Output_hi,   Nothing, Maybe String)
168
169 GLOBAL_VAR(v_Ld_inputs, [],      [String])
170
171 odir_ify :: String -> IO String
172 odir_ify f = do
173   odir_opt <- readIORef v_Output_dir
174   case odir_opt of
175         Nothing -> return f
176         Just d  -> return (newdir d f)
177
178 osuf_ify :: String -> IO String
179 osuf_ify f = do
180   osuf_opt <- readIORef v_Object_suf
181   case osuf_opt of
182         Nothing -> return f
183         Just s  -> return (newsuf s f)
184
185 -----------------------------------------------------------------------------
186 -- Hi Files
187
188 GLOBAL_VAR(v_ProduceHi,         True,   Bool)
189 GLOBAL_VAR(v_Hi_on_stdout,      False,  Bool)
190 GLOBAL_VAR(v_Hi_suf,            "hi",   String)
191
192 -----------------------------------------------------------------------------
193 -- Warnings & sanity checking
194
195 -- Warning packages that are controlled by -W and -Wall.  The 'standard'
196 -- warnings that you get all the time are
197 --         
198 --         -fwarn-overlapping-patterns
199 --         -fwarn-missing-methods
200 --         -fwarn-missing-fields
201 --         -fwarn-deprecations
202 --         -fwarn-duplicate-exports
203 -- 
204 -- these are turned off by -Wnot.
205
206
207 standardWarnings  = [ "-fwarn-overlapping-patterns"
208                     , "-fwarn-missing-methods"
209                     , "-fwarn-missing-fields"
210                     , "-fwarn-deprecations"
211                     , "-fwarn-duplicate-exports"
212                     ]
213 minusWOpts        = standardWarnings ++ 
214                     [ "-fwarn-unused-binds"
215                     , "-fwarn-unused-matches"
216                     , "-fwarn-incomplete-patterns"
217                     , "-fwarn-unused-imports"
218                     ]
219 minusWallOpts     = minusWOpts ++
220                     [ "-fwarn-type-defaults"
221                     , "-fwarn-name-shadowing"
222                     , "-fwarn-missing-signatures"
223                     , "-fwarn-hi-shadowing"
224                     ]
225
226 data WarningState = W_default | W_ | W_all | W_not
227 GLOBAL_VAR(v_Warning_opt, W_default, WarningState)
228
229 -----------------------------------------------------------------------------
230 -- Compiler optimisation options
231
232 GLOBAL_VAR(v_OptLevel, 0, Int)
233
234 setOptLevel :: String -> IO ()
235 setOptLevel ""              = do { writeIORef v_OptLevel 1 }
236 setOptLevel "not"           = writeIORef v_OptLevel 0
237 setOptLevel [c] | isDigit c = do
238    let level = ord c - ord '0'
239    writeIORef v_OptLevel level
240 setOptLevel s = unknownFlagErr ("-O"++s)
241
242 GLOBAL_VAR(v_minus_o2_for_C,            False, Bool)
243 GLOBAL_VAR(v_MaxSimplifierIterations,   4,     Int)
244 GLOBAL_VAR(v_StgStats,                  False, Bool)
245 GLOBAL_VAR(v_UsageSPInf,                False, Bool)  -- Off by default
246 GLOBAL_VAR(v_Strictness,                True,  Bool)
247 GLOBAL_VAR(v_CPR,                       True,  Bool)
248 GLOBAL_VAR(v_CSE,                       True,  Bool)
249
250 hsc_minusO2_flags = hsc_minusO_flags    -- for now
251
252 hsc_minusNoO_flags =
253        [ 
254         "-fignore-interface-pragmas",
255         "-fomit-interface-pragmas"
256         ]
257
258 hsc_minusO_flags =
259   [ 
260         "-ffoldr-build-on",
261         "-fdo-eta-reduction",
262         "-fdo-lambda-eta-expansion",
263         "-fcase-of-case",
264         "-fcase-merge",
265         "-flet-to-case"
266    ]
267
268 getStaticOptimisationFlags 0 = hsc_minusNoO_flags
269 getStaticOptimisationFlags 1 = hsc_minusO_flags
270 getStaticOptimisationFlags n = hsc_minusO2_flags
271
272 buildCoreToDo :: IO [CoreToDo]
273 buildCoreToDo = do
274    opt_level  <- readIORef v_OptLevel
275    max_iter   <- readIORef v_MaxSimplifierIterations
276    usageSP    <- readIORef v_UsageSPInf
277    strictness <- readIORef v_Strictness
278    cpr        <- readIORef v_CPR
279    cse        <- readIORef v_CSE
280
281    if opt_level == 0 then return
282       [
283         CoreDoSimplify (isAmongSimpl [
284             MaxSimplifierIterations max_iter
285         ])
286       ]
287
288     else {- opt_level >= 1 -} return [ 
289
290         -- initial simplify: mk specialiser happy: minimum effort please
291         CoreDoSimplify (isAmongSimpl [
292             SimplInlinePhase 0,
293                         -- Don't inline anything till full laziness has bitten
294                         -- In particular, inlining wrappers inhibits floating
295                         -- e.g. ...(case f x of ...)...
296                         --  ==> ...(case (case x of I# x# -> fw x#) of ...)...
297                         --  ==> ...(case x of I# x# -> case fw x# of ...)...
298                         -- and now the redex (f x) isn't floatable any more
299             DontApplyRules,
300                         -- Similarly, don't apply any rules until after full 
301                         -- laziness.  Notably, list fusion can prevent floating.
302             NoCaseOfCase,
303                         -- Don't do case-of-case transformations.
304                         -- This makes full laziness work better
305             MaxSimplifierIterations max_iter
306         ]),
307
308         -- Specialisation is best done before full laziness
309         -- so that overloaded functions have all their dictionary lambdas manifest
310         CoreDoSpecialising,
311
312         CoreDoFloatOutwards False{-not full-},
313         CoreDoFloatInwards,
314
315         CoreDoSimplify (isAmongSimpl [
316            SimplInlinePhase 1,
317                 -- Want to run with inline phase 1 after the specialiser to give
318                 -- maximum chance for fusion to work before we inline build/augment
319                 -- in phase 2.  This made a difference in 'ansi' where an 
320                 -- overloaded function wasn't inlined till too late.
321            MaxSimplifierIterations max_iter
322         ]),
323
324         -- infer usage information here in case we need it later.
325         -- (add more of these where you need them --KSW 1999-04)
326         if usageSP then CoreDoUSPInf else CoreDoNothing,
327
328         CoreDoSimplify (isAmongSimpl [
329                 -- Need inline-phase2 here so that build/augment get 
330                 -- inlined.  I found that spectral/hartel/genfft lost some useful
331                 -- strictness in the function sumcode' if augment is not inlined
332                 -- before strictness analysis runs
333            SimplInlinePhase 2,
334            MaxSimplifierIterations max_iter
335         ]),
336
337         CoreDoSimplify (isAmongSimpl [
338            MaxSimplifierIterations 2
339                 -- No -finline-phase: allow all Ids to be inlined now
340                 -- This gets foldr inlined before strictness analysis
341         ]),
342
343         if strictness then CoreDoStrictness else CoreDoNothing,
344         if cpr        then CoreDoCPResult   else CoreDoNothing,
345         CoreDoWorkerWrapper,
346         CoreDoGlomBinds,
347
348         CoreDoSimplify (isAmongSimpl [
349            MaxSimplifierIterations max_iter
350                 -- No -finline-phase: allow all Ids to be inlined now
351         ]),
352
353         CoreDoFloatOutwards False{-not full-},
354                 -- nofib/spectral/hartel/wang doubles in speed if you
355                 -- do full laziness late in the day.  It only happens
356                 -- after fusion and other stuff, so the early pass doesn't
357                 -- catch it.  For the record, the redex is 
358                 --        f_el22 (f_el21 r_midblock)
359
360
361 -- Leave out lambda lifting for now
362 --        "-fsimplify", -- Tidy up results of full laziness
363 --          "[", 
364 --                "-fmax-simplifier-iterations2",
365 --          "]",
366 --        "-ffloat-outwards-full",      
367
368         -- We want CSE to follow the final full-laziness pass, because it may
369         -- succeed in commoning up things floated out by full laziness.
370         -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
371
372         if cse then CoreCSE else CoreDoNothing,
373
374         CoreDoFloatInwards,
375
376 -- Case-liberation for -O2.  This should be after
377 -- strictness analysis and the simplification which follows it.
378
379         if opt_level >= 2 then
380            CoreLiberateCase
381         else
382            CoreDoNothing,
383
384         -- Final clean-up simplification:
385         CoreDoSimplify (isAmongSimpl [
386           MaxSimplifierIterations max_iter
387                 -- No -finline-phase: allow all Ids to be inlined now
388         ])
389      ]
390
391 buildStgToDo :: IO [ StgToDo ]
392 buildStgToDo = do
393   stg_stats <- readIORef v_StgStats
394   let flags1 | stg_stats = [ D_stg_stats ]
395              | otherwise = [ ]
396
397         -- STG passes
398   ways_ <- readIORef v_Ways
399   let flags2 | WayProf `elem` ways_ = StgDoMassageForProfiling : flags1
400              | otherwise            = flags1
401
402   return flags2
403
404 -----------------------------------------------------------------------------
405 -- Paths & Libraries
406
407 split_marker = ':'   -- not configurable (ToDo)
408
409 v_Import_paths, v_Include_paths, v_Library_paths :: IORef [String]
410 GLOBAL_VAR(v_Import_paths,  ["."], [String])
411 GLOBAL_VAR(v_Include_paths, ["."], [String])
412 GLOBAL_VAR(v_Library_paths, [],  [String])
413
414 GLOBAL_VAR(v_Cmdline_libraries,   [], [String])
415
416 addToDirList :: IORef [String] -> String -> IO ()
417 addToDirList ref path
418   = do paths <- readIORef ref
419        writeIORef ref (paths ++ split split_marker path)
420
421 -----------------------------------------------------------------------------
422 -- Packages
423
424 GLOBAL_VAR(v_Path_package_config, error "path_package_config", String)
425
426 -- package list is maintained in dependency order
427 GLOBAL_VAR(v_Packages, ("std":"rts":"gmp":[]), [String])
428
429 addPackage :: String -> IO ()
430 addPackage package
431   = do pkg_details <- readIORef v_Package_details
432        case lookupPkg package pkg_details of
433           Nothing -> throwDyn (OtherError ("unknown package name: " ++ package))
434           Just details -> do
435             ps <- readIORef v_Packages
436             unless (package `elem` ps) $ do
437                 mapM_ addPackage (package_deps details)
438                 ps <- readIORef v_Packages
439                 writeIORef v_Packages (package:ps)
440
441 getPackageImportPath   :: IO [String]
442 getPackageImportPath = do
443   ps <- getPackageInfo
444   return (nub (concat (map import_dirs ps)))
445
446 getPackageIncludePath   :: IO [String]
447 getPackageIncludePath = do
448   ps <- getPackageInfo
449   return (nub (filter (not.null) (concatMap include_dirs ps)))
450
451         -- includes are in reverse dependency order (i.e. rts first)
452 getPackageCIncludes   :: IO [String]
453 getPackageCIncludes = do
454   ps <- getPackageInfo
455   return (reverse (nub (filter (not.null) (concatMap c_includes ps))))
456
457 getPackageLibraryPath  :: IO [String]
458 getPackageLibraryPath = do
459   ps <- getPackageInfo
460   return (nub (concat (map library_dirs ps)))
461
462 getPackageLibraries    :: IO [String]
463 getPackageLibraries = do
464   ps <- getPackageInfo
465   tag <- readIORef v_Build_tag
466   let suffix = if null tag then "" else '_':tag
467   return (concat (
468         map (\p -> map (++suffix) (hs_libraries p) ++ extra_libraries p) ps
469      ))
470
471 getPackageExtraGhcOpts :: IO [String]
472 getPackageExtraGhcOpts = do
473   ps <- getPackageInfo
474   return (concatMap extra_ghc_opts ps)
475
476 getPackageExtraCcOpts  :: IO [String]
477 getPackageExtraCcOpts = do
478   ps <- getPackageInfo
479   return (concatMap extra_cc_opts ps)
480
481 getPackageExtraLdOpts  :: IO [String]
482 getPackageExtraLdOpts = do
483   ps <- getPackageInfo
484   return (concatMap extra_ld_opts ps)
485
486 getPackageInfo :: IO [Package]
487 getPackageInfo = do
488   ps <- readIORef v_Packages
489   getPackageDetails ps
490
491 getPackageDetails :: [String] -> IO [Package]
492 getPackageDetails ps = do
493   pkg_details <- readIORef v_Package_details
494   return [ pkg | p <- ps, Just pkg <- [ lookupPkg p pkg_details ] ]
495
496 GLOBAL_VAR(v_Package_details, (error "package_details"), [Package])
497
498 lookupPkg :: String -> [Package] -> Maybe Package
499 lookupPkg nm ps
500    = case [p | p <- ps, name p == nm] of
501         []    -> Nothing
502         (p:_) -> Just p
503 -----------------------------------------------------------------------------
504 -- Ways
505
506 -- The central concept of a "way" is that all objects in a given
507 -- program must be compiled in the same "way".  Certain options change
508 -- parameters of the virtual machine, eg. profiling adds an extra word
509 -- to the object header, so profiling objects cannot be linked with
510 -- non-profiling objects.
511
512 -- After parsing the command-line options, we determine which "way" we
513 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
514
515 -- We then find the "build-tag" associated with this way, and this
516 -- becomes the suffix used to find .hi files and libraries used in
517 -- this compilation.
518
519 GLOBAL_VAR(v_Build_tag, "", String)
520
521 data WayName
522   = WayProf
523   | WayUnreg
524   | WayTicky
525   | WayPar
526   | WayGran
527   | WaySMP
528   | WayDebug
529   | WayUser_a
530   | WayUser_b
531   | WayUser_c
532   | WayUser_d
533   | WayUser_e
534   | WayUser_f
535   | WayUser_g
536   | WayUser_h
537   | WayUser_i
538   | WayUser_j
539   | WayUser_k
540   | WayUser_l
541   | WayUser_m
542   | WayUser_n
543   | WayUser_o
544   | WayUser_A
545   | WayUser_B
546   deriving (Eq,Ord)
547
548 GLOBAL_VAR(v_Ways, [] ,[WayName])
549
550 allowed_combination way = way `elem` combs
551   where  -- the sub-lists must be ordered according to WayName, 
552          -- because findBuildTag sorts them
553     combs                = [ [WayProf,WayUnreg], [WayProf,WaySMP] ]
554
555 findBuildTag :: IO [String]  -- new options
556 findBuildTag = do
557   way_names <- readIORef v_Ways
558   case sort way_names of
559      []  -> do  writeIORef v_Build_tag ""
560                 return []
561
562      [w] -> do let details = lkupWay w
563                writeIORef v_Build_tag (wayTag details)
564                return (wayOpts details)
565
566      ws  -> if not (allowed_combination ws)
567                 then throwDyn (OtherError $
568                                 "combination not supported: "  ++
569                                 foldr1 (\a b -> a ++ '/':b) 
570                                 (map (wayName . lkupWay) ws))
571                 else let stuff = map lkupWay ws
572                          tag   = concat (map wayTag stuff)
573                          flags = map wayOpts stuff
574                      in do
575                      writeIORef v_Build_tag tag
576                      return (concat flags)
577
578 lkupWay w = 
579    case lookup w way_details of
580         Nothing -> error "findBuildTag"
581         Just details -> details
582
583 data Way = Way {
584   wayTag   :: String,
585   wayName  :: String,
586   wayOpts  :: [String]
587   }
588
589 way_details :: [ (WayName, Way) ]
590 way_details =
591   [ (WayProf, Way  "p" "Profiling"  
592         [ "-fscc-profiling"
593         , "-DPROFILING"
594         , "-optc-DPROFILING"
595         , "-fvia-C" ]),
596
597     (WayTicky, Way  "t" "Ticky-ticky Profiling"  
598         [ "-fticky-ticky"
599         , "-DTICKY_TICKY"
600         , "-optc-DTICKY_TICKY"
601         , "-fvia-C" ]),
602
603     (WayUnreg, Way  "u" "Unregisterised" 
604         [ "-optc-DNO_REGS"
605         , "-optc-DUSE_MINIINTERPRETER"
606         , "-fno-asm-mangling"
607         , "-funregisterised"
608         , "-fvia-C" ]),
609
610     (WayPar, Way  "mp" "Parallel" 
611         [ "-fparallel"
612         , "-D__PARALLEL_HASKELL__"
613         , "-optc-DPAR"
614         , "-package concurrent"
615         , "-fvia-C" ]),
616
617     (WayGran, Way  "mg" "Gransim" 
618         [ "-fgransim"
619         , "-D__GRANSIM__"
620         , "-optc-DGRAN"
621         , "-package concurrent"
622         , "-fvia-C" ]),
623
624     (WaySMP, Way  "s" "SMP"
625         [ "-fsmp"
626         , "-optc-pthread"
627         , "-optl-pthread"
628         , "-optc-DSMP"
629         , "-fvia-C" ]),
630
631     (WayUser_a,  Way  "a"  "User way 'a'"  ["$WAY_a_REAL_OPTS"]),       
632     (WayUser_b,  Way  "b"  "User way 'b'"  ["$WAY_b_REAL_OPTS"]),       
633     (WayUser_c,  Way  "c"  "User way 'c'"  ["$WAY_c_REAL_OPTS"]),       
634     (WayUser_d,  Way  "d"  "User way 'd'"  ["$WAY_d_REAL_OPTS"]),       
635     (WayUser_e,  Way  "e"  "User way 'e'"  ["$WAY_e_REAL_OPTS"]),       
636     (WayUser_f,  Way  "f"  "User way 'f'"  ["$WAY_f_REAL_OPTS"]),       
637     (WayUser_g,  Way  "g"  "User way 'g'"  ["$WAY_g_REAL_OPTS"]),       
638     (WayUser_h,  Way  "h"  "User way 'h'"  ["$WAY_h_REAL_OPTS"]),       
639     (WayUser_i,  Way  "i"  "User way 'i'"  ["$WAY_i_REAL_OPTS"]),       
640     (WayUser_j,  Way  "j"  "User way 'j'"  ["$WAY_j_REAL_OPTS"]),       
641     (WayUser_k,  Way  "k"  "User way 'k'"  ["$WAY_k_REAL_OPTS"]),       
642     (WayUser_l,  Way  "l"  "User way 'l'"  ["$WAY_l_REAL_OPTS"]),       
643     (WayUser_m,  Way  "m"  "User way 'm'"  ["$WAY_m_REAL_OPTS"]),       
644     (WayUser_n,  Way  "n"  "User way 'n'"  ["$WAY_n_REAL_OPTS"]),       
645     (WayUser_o,  Way  "o"  "User way 'o'"  ["$WAY_o_REAL_OPTS"]),       
646     (WayUser_A,  Way  "A"  "User way 'A'"  ["$WAY_A_REAL_OPTS"]),       
647     (WayUser_B,  Way  "B"  "User way 'B'"  ["$WAY_B_REAL_OPTS"]) 
648   ]
649
650 -----------------------------------------------------------------------------
651 -- Programs for particular phases
652
653 GLOBAL_VAR(v_Pgm_L,   error "pgm_L", String)
654 GLOBAL_VAR(v_Pgm_P,   cRAWCPP,       String)
655 GLOBAL_VAR(v_Pgm_c,   cGCC,          String)
656 GLOBAL_VAR(v_Pgm_m,   error "pgm_m", String)
657 GLOBAL_VAR(v_Pgm_s,   error "pgm_s", String)
658 GLOBAL_VAR(v_Pgm_a,   cGCC,          String)
659 GLOBAL_VAR(v_Pgm_l,   cGCC,          String)
660
661 GLOBAL_VAR(v_Opt_dep,    [], [String])
662 GLOBAL_VAR(v_Anti_opt_C, [], [String])
663 GLOBAL_VAR(v_Opt_C,      [], [String])
664 GLOBAL_VAR(v_Opt_l,      [], [String])
665 GLOBAL_VAR(v_Opt_dll,    [], [String])
666
667 getStaticOpts :: IORef [String] -> IO [String]
668 getStaticOpts ref = readIORef ref >>= return . reverse
669
670 -----------------------------------------------------------------------------
671 -- Via-C compilation stuff
672
673 -- flags returned are: ( all C compilations
674 --                     , registerised HC compilations
675 --                     )
676
677 machdepCCOpts 
678    | prefixMatch "alpha"   cTARGETPLATFORM  
679         = return ( ["-static"], [] )
680
681    | prefixMatch "hppa"    cTARGETPLATFORM  
682         -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
683         -- (very nice, but too bad the HP /usr/include files don't agree.)
684         = return ( ["-static", "-D_HPUX_SOURCE"], [] )
685
686    | prefixMatch "m68k"    cTARGETPLATFORM
687       -- -fno-defer-pop : for the .hc files, we want all the pushing/
688       --    popping of args to routines to be explicit; if we let things
689       --    be deferred 'til after an STGJUMP, imminent death is certain!
690       --
691       -- -fomit-frame-pointer : *don't*
692       --     It's better to have a6 completely tied up being a frame pointer
693       --     rather than let GCC pick random things to do with it.
694       --     (If we want to steal a6, then we would try to do things
695       --     as on iX86, where we *do* steal the frame pointer [%ebp].)
696         = return ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
697
698    | prefixMatch "i386"    cTARGETPLATFORM  
699       -- -fno-defer-pop : basically the same game as for m68k
700       --
701       -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
702       --   the fp (%ebp) for our register maps.
703         = do n_regs <- readState stolen_x86_regs
704              sta    <- readIORef v_Static
705              return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else "",
706                         if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else "" ],
707                       [ "-fno-defer-pop", "-fomit-frame-pointer",
708                         "-DSTOLEN_X86_REGS="++show n_regs ]
709                     )
710
711    | prefixMatch "mips"    cTARGETPLATFORM
712         = return ( ["static"], [] )
713
714    | prefixMatch "powerpc" cTARGETPLATFORM || prefixMatch "rs6000" cTARGETPLATFORM
715         = return ( ["static"], ["-finhibit-size-directive"] )
716
717    | otherwise
718         = return ( [], [] )