[project @ 2001-01-08 12:31:34 by rrt]
[ghc-hetmet.git] / ghc / compiler / main / DriverState.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverState.hs,v 1.21 2001/01/08 12:31:34 rrt 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 hsc_minusO2_flags = hsc_minusO_flags    -- for now
248
249 hsc_minusNoO_flags =
250        [ 
251         "-fignore-interface-pragmas",
252         "-fomit-interface-pragmas"
253         ]
254
255 hsc_minusO_flags =
256   [ 
257         "-ffoldr-build-on",
258         "-fdo-eta-reduction",
259         "-fdo-lambda-eta-expansion",
260         "-fcase-of-case",
261         "-fcase-merge",
262         "-flet-to-case"
263    ]
264
265 getStaticOptimisationFlags 0 = hsc_minusNoO_flags
266 getStaticOptimisationFlags 1 = hsc_minusO_flags
267 getStaticOptimisationFlags n = hsc_minusO2_flags
268
269 buildCoreToDo :: IO [CoreToDo]
270 buildCoreToDo = do
271    opt_level  <- readIORef v_OptLevel
272    max_iter   <- readIORef v_MaxSimplifierIterations
273    usageSP    <- readIORef v_UsageSPInf
274    strictness <- readIORef v_Strictness
275    cpr        <- readIORef v_CPR
276    cse        <- readIORef v_CSE
277
278    if opt_level == 0 then return
279       [
280         CoreDoSimplify (isAmongSimpl [
281             MaxSimplifierIterations max_iter
282         ])
283       ]
284
285     else {- opt_level >= 1 -} return [ 
286
287         -- initial simplify: mk specialiser happy: minimum effort please
288         CoreDoSimplify (isAmongSimpl [
289             SimplInlinePhase 0,
290                         -- Don't inline anything till full laziness has bitten
291                         -- In particular, inlining wrappers inhibits floating
292                         -- e.g. ...(case f x of ...)...
293                         --  ==> ...(case (case x of I# x# -> fw x#) of ...)...
294                         --  ==> ...(case x of I# x# -> case fw x# of ...)...
295                         -- and now the redex (f x) isn't floatable any more
296             DontApplyRules,
297                         -- Similarly, don't apply any rules until after full 
298                         -- laziness.  Notably, list fusion can prevent floating.
299             NoCaseOfCase,
300                         -- Don't do case-of-case transformations.
301                         -- This makes full laziness work better
302             MaxSimplifierIterations max_iter
303         ]),
304
305         -- Specialisation is best done before full laziness
306         -- so that overloaded functions have all their dictionary lambdas manifest
307         CoreDoSpecialising,
308
309         CoreDoFloatOutwards False{-not full-},
310         CoreDoFloatInwards,
311
312         CoreDoSimplify (isAmongSimpl [
313            SimplInlinePhase 1,
314                 -- Want to run with inline phase 1 after the specialiser to give
315                 -- maximum chance for fusion to work before we inline build/augment
316                 -- in phase 2.  This made a difference in 'ansi' where an 
317                 -- overloaded function wasn't inlined till too late.
318            MaxSimplifierIterations max_iter
319         ]),
320
321         -- infer usage information here in case we need it later.
322         -- (add more of these where you need them --KSW 1999-04)
323         if usageSP then CoreDoUSPInf else CoreDoNothing,
324
325         CoreDoSimplify (isAmongSimpl [
326                 -- Need inline-phase2 here so that build/augment get 
327                 -- inlined.  I found that spectral/hartel/genfft lost some useful
328                 -- strictness in the function sumcode' if augment is not inlined
329                 -- before strictness analysis runs
330            SimplInlinePhase 2,
331            MaxSimplifierIterations max_iter
332         ]),
333
334         CoreDoSimplify (isAmongSimpl [
335            MaxSimplifierIterations 2
336                 -- No -finline-phase: allow all Ids to be inlined now
337                 -- This gets foldr inlined before strictness analysis
338         ]),
339
340         if strictness then CoreDoStrictness else CoreDoNothing,
341         if cpr        then CoreDoCPResult   else CoreDoNothing,
342         CoreDoWorkerWrapper,
343         CoreDoGlomBinds,
344
345         CoreDoSimplify (isAmongSimpl [
346            MaxSimplifierIterations max_iter
347                 -- No -finline-phase: allow all Ids to be inlined now
348         ]),
349
350         CoreDoFloatOutwards False{-not full-},
351                 -- nofib/spectral/hartel/wang doubles in speed if you
352                 -- do full laziness late in the day.  It only happens
353                 -- after fusion and other stuff, so the early pass doesn't
354                 -- catch it.  For the record, the redex is 
355                 --        f_el22 (f_el21 r_midblock)
356
357
358 -- Leave out lambda lifting for now
359 --        "-fsimplify", -- Tidy up results of full laziness
360 --          "[", 
361 --                "-fmax-simplifier-iterations2",
362 --          "]",
363 --        "-ffloat-outwards-full",      
364
365         -- We want CSE to follow the final full-laziness pass, because it may
366         -- succeed in commoning up things floated out by full laziness.
367         -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
368
369         if cse then CoreCSE else CoreDoNothing,
370
371         CoreDoFloatInwards,
372
373 -- Case-liberation for -O2.  This should be after
374 -- strictness analysis and the simplification which follows it.
375
376         if opt_level >= 2 then
377            CoreLiberateCase
378         else
379            CoreDoNothing,
380
381         -- Final clean-up simplification:
382         CoreDoSimplify (isAmongSimpl [
383           MaxSimplifierIterations max_iter
384                 -- No -finline-phase: allow all Ids to be inlined now
385         ])
386      ]
387
388 buildStgToDo :: IO [ StgToDo ]
389 buildStgToDo = do
390   stg_stats <- readIORef v_StgStats
391   let flags1 | stg_stats = [ D_stg_stats ]
392              | otherwise = [ ]
393
394         -- STG passes
395   ways_ <- readIORef v_Ways
396   let flags2 | WayProf `elem` ways_ = StgDoMassageForProfiling : flags1
397              | otherwise            = flags1
398
399   return flags2
400
401 -----------------------------------------------------------------------------
402 -- Paths & Libraries
403
404 split_marker = ':'   -- not configurable (ToDo)
405
406 v_Import_paths, v_Include_paths, v_Library_paths :: IORef [String]
407 GLOBAL_VAR(v_Import_paths,  ["."], [String])
408 GLOBAL_VAR(v_Include_paths, ["."], [String])
409 GLOBAL_VAR(v_Library_paths, [],  [String])
410
411 GLOBAL_VAR(v_Cmdline_libraries,   [], [String])
412
413 addToDirList :: IORef [String] -> String -> IO ()
414 addToDirList ref path
415   = do paths <- readIORef ref
416        writeIORef ref (paths ++ split split_marker path)
417
418 -----------------------------------------------------------------------------
419 -- Packages
420
421 GLOBAL_VAR(v_Path_package_config, error "path_package_config", String)
422
423 -- package list is maintained in dependency order
424 GLOBAL_VAR(v_Packages, ("std":"rts":"gmp":[]), [String])
425
426 addPackage :: String -> IO ()
427 addPackage package
428   = do pkg_details <- readIORef v_Package_details
429        case lookupPkg package pkg_details of
430           Nothing -> throwDyn (OtherError ("unknown package name: " ++ package))
431           Just details -> do
432             ps <- readIORef v_Packages
433             unless (package `elem` ps) $ do
434                 mapM_ addPackage (package_deps details)
435                 ps <- readIORef v_Packages
436                 writeIORef v_Packages (package:ps)
437
438 getPackageImportPath   :: IO [String]
439 getPackageImportPath = do
440   ps <- getPackageInfo
441   return (nub (concat (map import_dirs ps)))
442
443 getPackageIncludePath   :: IO [String]
444 getPackageIncludePath = do
445   ps <- getPackageInfo
446   return (nub (filter (not.null) (concatMap include_dirs ps)))
447
448         -- includes are in reverse dependency order (i.e. rts first)
449 getPackageCIncludes   :: IO [String]
450 getPackageCIncludes = do
451   ps <- getPackageInfo
452   return (reverse (nub (filter (not.null) (concatMap c_includes ps))))
453
454 getPackageLibraryPath  :: IO [String]
455 getPackageLibraryPath = do
456   ps <- getPackageInfo
457   return (nub (concat (map library_dirs ps)))
458
459 getPackageLibraries    :: IO [String]
460 getPackageLibraries = do
461   ps <- getPackageInfo
462   tag <- readIORef v_Build_tag
463   let suffix = if null tag then "" else '_':tag
464   return (concat (
465         map (\p -> map (++suffix) (hs_libraries p) ++ extra_libraries p) ps
466      ))
467
468 getPackageExtraGhcOpts :: IO [String]
469 getPackageExtraGhcOpts = do
470   ps <- getPackageInfo
471   return (concatMap extra_ghc_opts ps)
472
473 getPackageExtraCcOpts  :: IO [String]
474 getPackageExtraCcOpts = do
475   ps <- getPackageInfo
476   return (concatMap extra_cc_opts ps)
477
478 getPackageExtraLdOpts  :: IO [String]
479 getPackageExtraLdOpts = do
480   ps <- getPackageInfo
481   return (concatMap extra_ld_opts ps)
482
483 getPackageInfo :: IO [Package]
484 getPackageInfo = do
485   ps <- readIORef v_Packages
486   getPackageDetails ps
487
488 getPackageDetails :: [String] -> IO [Package]
489 getPackageDetails ps = do
490   pkg_details <- readIORef v_Package_details
491   return [ pkg | p <- ps, Just pkg <- [ lookupPkg p pkg_details ] ]
492
493 GLOBAL_VAR(v_Package_details, (error "package_details"), [Package])
494
495 lookupPkg :: String -> [Package] -> Maybe Package
496 lookupPkg nm ps
497    = case [p | p <- ps, name p == nm] of
498         []    -> Nothing
499         (p:_) -> Just p
500 -----------------------------------------------------------------------------
501 -- Ways
502
503 -- The central concept of a "way" is that all objects in a given
504 -- program must be compiled in the same "way".  Certain options change
505 -- parameters of the virtual machine, eg. profiling adds an extra word
506 -- to the object header, so profiling objects cannot be linked with
507 -- non-profiling objects.
508
509 -- After parsing the command-line options, we determine which "way" we
510 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
511
512 -- We then find the "build-tag" associated with this way, and this
513 -- becomes the suffix used to find .hi files and libraries used in
514 -- this compilation.
515
516 GLOBAL_VAR(v_Build_tag, "", String)
517
518 data WayName
519   = WayProf
520   | WayUnreg
521   | WayTicky
522   | WayPar
523   | WayGran
524   | WaySMP
525   | WayDebug
526   | WayUser_a
527   | WayUser_b
528   | WayUser_c
529   | WayUser_d
530   | WayUser_e
531   | WayUser_f
532   | WayUser_g
533   | WayUser_h
534   | WayUser_i
535   | WayUser_j
536   | WayUser_k
537   | WayUser_l
538   | WayUser_m
539   | WayUser_n
540   | WayUser_o
541   | WayUser_A
542   | WayUser_B
543   deriving (Eq,Ord)
544
545 GLOBAL_VAR(v_Ways, [] ,[WayName])
546
547 allowed_combination way = way `elem` combs
548   where  -- the sub-lists must be ordered according to WayName, 
549          -- because findBuildTag sorts them
550     combs                = [ [WayProf,WayUnreg], [WayProf,WaySMP] ]
551
552 findBuildTag :: IO [String]  -- new options
553 findBuildTag = do
554   way_names <- readIORef v_Ways
555   case sort way_names of
556      []  -> do  writeIORef v_Build_tag ""
557                 return []
558
559      [w] -> do let details = lkupWay w
560                writeIORef v_Build_tag (wayTag details)
561                return (wayOpts details)
562
563      ws  -> if not (allowed_combination ws)
564                 then throwDyn (OtherError $
565                                 "combination not supported: "  ++
566                                 foldr1 (\a b -> a ++ '/':b) 
567                                 (map (wayName . lkupWay) ws))
568                 else let stuff = map lkupWay ws
569                          tag   = concat (map wayTag stuff)
570                          flags = map wayOpts stuff
571                      in do
572                      writeIORef v_Build_tag tag
573                      return (concat flags)
574
575 lkupWay w = 
576    case lookup w way_details of
577         Nothing -> error "findBuildTag"
578         Just details -> details
579
580 data Way = Way {
581   wayTag   :: String,
582   wayName  :: String,
583   wayOpts  :: [String]
584   }
585
586 way_details :: [ (WayName, Way) ]
587 way_details =
588   [ (WayProf, Way  "p" "Profiling"  
589         [ "-fscc-profiling"
590         , "-DPROFILING"
591         , "-optc-DPROFILING"
592         , "-fvia-C" ]),
593
594     (WayTicky, Way  "t" "Ticky-ticky Profiling"  
595         [ "-fticky-ticky"
596         , "-DTICKY_TICKY"
597         , "-optc-DTICKY_TICKY"
598         , "-fvia-C" ]),
599
600     (WayUnreg, Way  "u" "Unregisterised" 
601         [ "-optc-DNO_REGS"
602         , "-optc-DUSE_MINIINTERPRETER"
603         , "-fno-asm-mangling"
604         , "-funregisterised"
605         , "-fvia-C" ]),
606
607     (WayPar, Way  "mp" "Parallel" 
608         [ "-fparallel"
609         , "-D__PARALLEL_HASKELL__"
610         , "-optc-DPAR"
611         , "-package concurrent"
612         , "-fvia-C" ]),
613
614     (WayGran, Way  "mg" "Gransim" 
615         [ "-fgransim"
616         , "-D__GRANSIM__"
617         , "-optc-DGRAN"
618         , "-package concurrent"
619         , "-fvia-C" ]),
620
621     (WaySMP, Way  "s" "SMP"
622         [ "-fsmp"
623         , "-optc-pthread"
624         , "-optl-pthread"
625         , "-optc-DSMP"
626         , "-fvia-C" ]),
627
628     (WayUser_a,  Way  "a"  "User way 'a'"  ["$WAY_a_REAL_OPTS"]),       
629     (WayUser_b,  Way  "b"  "User way 'b'"  ["$WAY_b_REAL_OPTS"]),       
630     (WayUser_c,  Way  "c"  "User way 'c'"  ["$WAY_c_REAL_OPTS"]),       
631     (WayUser_d,  Way  "d"  "User way 'd'"  ["$WAY_d_REAL_OPTS"]),       
632     (WayUser_e,  Way  "e"  "User way 'e'"  ["$WAY_e_REAL_OPTS"]),       
633     (WayUser_f,  Way  "f"  "User way 'f'"  ["$WAY_f_REAL_OPTS"]),       
634     (WayUser_g,  Way  "g"  "User way 'g'"  ["$WAY_g_REAL_OPTS"]),       
635     (WayUser_h,  Way  "h"  "User way 'h'"  ["$WAY_h_REAL_OPTS"]),       
636     (WayUser_i,  Way  "i"  "User way 'i'"  ["$WAY_i_REAL_OPTS"]),       
637     (WayUser_j,  Way  "j"  "User way 'j'"  ["$WAY_j_REAL_OPTS"]),       
638     (WayUser_k,  Way  "k"  "User way 'k'"  ["$WAY_k_REAL_OPTS"]),       
639     (WayUser_l,  Way  "l"  "User way 'l'"  ["$WAY_l_REAL_OPTS"]),       
640     (WayUser_m,  Way  "m"  "User way 'm'"  ["$WAY_m_REAL_OPTS"]),       
641     (WayUser_n,  Way  "n"  "User way 'n'"  ["$WAY_n_REAL_OPTS"]),       
642     (WayUser_o,  Way  "o"  "User way 'o'"  ["$WAY_o_REAL_OPTS"]),       
643     (WayUser_A,  Way  "A"  "User way 'A'"  ["$WAY_A_REAL_OPTS"]),       
644     (WayUser_B,  Way  "B"  "User way 'B'"  ["$WAY_B_REAL_OPTS"]) 
645   ]
646
647 -----------------------------------------------------------------------------
648 -- Programs for particular phases
649
650 GLOBAL_VAR(v_Pgm_L,   error "pgm_L", String)
651 GLOBAL_VAR(v_Pgm_P,   cRAWCPP,       String)
652 GLOBAL_VAR(v_Pgm_c,   cGCC,          String)
653 GLOBAL_VAR(v_Pgm_m,   error "pgm_m", String)
654 GLOBAL_VAR(v_Pgm_s,   error "pgm_s", String)
655 GLOBAL_VAR(v_Pgm_a,   cGCC,          String)
656 GLOBAL_VAR(v_Pgm_l,   cGCC,          String)
657
658 GLOBAL_VAR(v_Opt_dep,    [], [String])
659 GLOBAL_VAR(v_Anti_opt_C, [], [String])
660 GLOBAL_VAR(v_Opt_C,      [], [String])
661 GLOBAL_VAR(v_Opt_l,      [], [String])
662 GLOBAL_VAR(v_Opt_dll,    [], [String])
663
664 getStaticOpts :: IORef [String] -> IO [String]
665 getStaticOpts ref = readIORef ref >>= return . reverse
666
667 -----------------------------------------------------------------------------
668 -- Via-C compilation stuff
669
670 -- flags returned are: ( all C compilations
671 --                     , registerised HC compilations
672 --                     )
673
674 machdepCCOpts 
675    | prefixMatch "alpha"   cTARGETPLATFORM  
676         = return ( ["-static"], [] )
677
678    | prefixMatch "hppa"    cTARGETPLATFORM  
679         -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
680         -- (very nice, but too bad the HP /usr/include files don't agree.)
681         = return ( ["-static", "-D_HPUX_SOURCE"], [] )
682
683    | prefixMatch "m68k"    cTARGETPLATFORM
684       -- -fno-defer-pop : for the .hc files, we want all the pushing/
685       --    popping of args to routines to be explicit; if we let things
686       --    be deferred 'til after an STGJUMP, imminent death is certain!
687       --
688       -- -fomit-frame-pointer : *don't*
689       --     It's better to have a6 completely tied up being a frame pointer
690       --     rather than let GCC pick random things to do with it.
691       --     (If we want to steal a6, then we would try to do things
692       --     as on iX86, where we *do* steal the frame pointer [%ebp].)
693         = return ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
694
695    | prefixMatch "i386"    cTARGETPLATFORM  
696       -- -fno-defer-pop : basically the same game as for m68k
697       --
698       -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
699       --   the fp (%ebp) for our register maps.
700         = do n_regs <- readState stolen_x86_regs
701              sta    <- readIORef v_Static
702              return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else "",
703                         if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else "" ],
704                       [ "-fno-defer-pop", "-fomit-frame-pointer",
705                         "-DSTOLEN_X86_REGS="++show n_regs ]
706                     )
707
708    | prefixMatch "mips"    cTARGETPLATFORM
709         = return ( ["static"], [] )
710
711    | prefixMatch "powerpc" cTARGETPLATFORM || prefixMatch "rs6000" cTARGETPLATFORM
712         = return ( ["static"], ["-finhibit-size-directive"] )
713
714    | otherwise
715         = return ( [], [] )