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