[project @ 2003-12-28 13:02:46 by panne]
[ghc-hetmet.git] / ghc / compiler / main / DriverState.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverState.hs,v 1.97 2003/09/23 14:33:00 simonmar Exp $
3 --
4 -- Settings for the driver
5 --
6 -- (c) The University of Glasgow 2002
7 --
8 -----------------------------------------------------------------------------
9
10 module DriverState where
11
12 #include "../includes/config.h"
13 #include "HsVersions.h"
14
15 import ParsePkgConf     ( loadPackageConfig )
16 import SysTools         ( getTopDir )
17 import Packages
18 import CmdLineOpts
19 import DriverPhases
20 import DriverUtil
21 import UniqFM           ( eltsUFM )
22 import Util
23 import Config
24 import Panic
25
26 import DATA_IOREF       ( IORef, readIORef, writeIORef )
27 import EXCEPTION
28
29 import List
30 import Char  
31 import Monad
32 import Maybe            ( fromJust, isJust )
33 import Directory        ( doesDirectoryExist )
34
35 -----------------------------------------------------------------------------
36 -- non-configured things
37
38 cHaskell1Version = "5" -- i.e., Haskell 98
39
40 -----------------------------------------------------------------------------
41 -- GHC modes of operation
42
43 data GhcMode
44   = DoMkDependHS                        -- ghc -M
45   | DoMkDLL                             -- ghc --mk-dll
46   | StopBefore Phase                    -- ghc -E | -C | -S | -c
47   | DoMake                              -- ghc --make
48   | DoInteractive                       -- ghc --interactive
49   | DoLink                              -- [ the default ]
50   | DoEval String                       -- ghc -e
51   deriving (Eq,Show)
52
53 GLOBAL_VAR(v_GhcMode,     DoLink, GhcMode)
54 GLOBAL_VAR(v_GhcModeFlag, "",     String)
55
56 setMode :: GhcMode -> String -> IO ()
57 setMode m flag = do
58   old_mode <- readIORef v_GhcMode
59   old_flag <- readIORef v_GhcModeFlag
60   when (notNull old_flag && flag /= old_flag) $
61       throwDyn (UsageError 
62           ("cannot use `" ++ old_flag ++ "' with `" ++ flag ++ "'"))
63   writeIORef v_GhcMode m
64   writeIORef v_GhcModeFlag flag
65
66 isCompManagerMode DoMake        = True
67 isCompManagerMode DoInteractive = True
68 isCompManagerMode _             = False
69
70 -----------------------------------------------------------------------------
71 -- Global compilation flags
72
73 -- Cpp-related flags
74 v_Hs_source_cpp_opts = global
75         [ "-D__HASKELL1__="++cHaskell1Version
76         , "-D__GLASGOW_HASKELL__="++cProjectVersionInt                          
77         , "-D__HASKELL98__"
78         , "-D__CONCURRENT_HASKELL__"
79         ]
80 {-# NOINLINE v_Hs_source_cpp_opts #-}
81
82
83 -- Keep output from intermediate phases
84 GLOBAL_VAR(v_Keep_hi_diffs,             False,          Bool)
85 GLOBAL_VAR(v_Keep_hc_files,             False,          Bool)
86 GLOBAL_VAR(v_Keep_s_files,              False,          Bool)
87 GLOBAL_VAR(v_Keep_raw_s_files,          False,          Bool)
88 GLOBAL_VAR(v_Keep_tmp_files,            False,          Bool)
89 #ifdef ILX
90 GLOBAL_VAR(v_Keep_il_files,             False,          Bool)
91 GLOBAL_VAR(v_Keep_ilx_files,            False,          Bool)
92 #endif
93
94 -- Misc
95 GLOBAL_VAR(v_Scale_sizes_by,            1.0,            Double)
96 GLOBAL_VAR(v_Static,                    True,           Bool)
97 GLOBAL_VAR(v_NoLink,                    False,          Bool)
98 GLOBAL_VAR(v_NoHsMain,                  False,          Bool)
99 GLOBAL_VAR(v_MainModIs,                 Nothing,        Maybe String)
100 GLOBAL_VAR(v_MainFunIs,                 Nothing,        Maybe String)
101 GLOBAL_VAR(v_Recomp,                    True,           Bool)
102 GLOBAL_VAR(v_Collect_ghc_timing,        False,          Bool)
103 GLOBAL_VAR(v_Do_asm_mangling,           True,           Bool)
104 GLOBAL_VAR(v_Excess_precision,          False,          Bool)
105 GLOBAL_VAR(v_Read_DotGHCi,              True,           Bool)
106
107 -- Preprocessor flags
108 GLOBAL_VAR(v_Hs_source_pp_opts, [], [String])
109
110 -----------------------------------------------------------------------------
111 -- Splitting object files (for libraries)
112
113 GLOBAL_VAR(v_Split_object_files,        False,          Bool)
114 GLOBAL_VAR(v_Split_info,                ("",0),         (String,Int))
115         -- The split prefix and number of files
116
117         
118 can_split :: Bool
119 can_split =  prefixMatch "i386"    cTARGETPLATFORM
120           || prefixMatch "alpha"   cTARGETPLATFORM
121           || prefixMatch "hppa"    cTARGETPLATFORM
122           || prefixMatch "m68k"    cTARGETPLATFORM
123           || prefixMatch "mips"    cTARGETPLATFORM
124           || prefixMatch "powerpc" cTARGETPLATFORM
125           || prefixMatch "rs6000"  cTARGETPLATFORM
126           || prefixMatch "sparc"   cTARGETPLATFORM
127
128 -----------------------------------------------------------------------------
129 -- Compiler output options
130
131 GLOBAL_VAR(v_Output_dir,  Nothing, Maybe String)
132 GLOBAL_VAR(v_Output_file, Nothing, Maybe String)
133 GLOBAL_VAR(v_Output_hi,   Nothing, Maybe String)
134
135 -- called to verify that the output files & directories
136 -- point somewhere valid. 
137 --
138 -- The assumption is that the directory portion of these output
139 -- options will have to exist by the time 'verifyOutputFiles'
140 -- is invoked.
141 -- 
142 verifyOutputFiles :: IO ()
143 verifyOutputFiles = do
144   odir <- readIORef v_Output_dir
145   when (isJust odir) $ do
146      let dir = fromJust odir
147      flg <- doesDirectoryExist dir
148      when (not flg) (nonExistentDir "-odir" dir)
149   ofile <- readIORef v_Output_file
150   when (isJust ofile) $ do
151      let fn = fromJust ofile
152      flg <- doesDirNameExist fn
153      when (not flg) (nonExistentDir "-o" fn)
154   ohi <- readIORef v_Output_hi
155   when (isJust ohi) $ do
156      let hi = fromJust ohi
157      flg <- doesDirNameExist hi
158      when (not flg) (nonExistentDir "-ohi" hi)
159  where
160    nonExistentDir flg dir = 
161      throwDyn (CmdLineError ("error: directory portion of " ++ 
162                              show dir ++ " does not exist (used with " ++ 
163                              show flg ++ " option.)"))
164
165 GLOBAL_VAR(v_Object_suf,  phaseInputExt Ln, String)
166 GLOBAL_VAR(v_HC_suf,      Nothing, Maybe String)
167 GLOBAL_VAR(v_Hi_dir,      Nothing, Maybe String)
168 GLOBAL_VAR(v_Hi_suf,      "hi",    String)
169
170 GLOBAL_VAR(v_Ld_inputs, [],      [String])
171
172 odir_ify :: String -> IO String
173 odir_ify f = do
174   odir_opt <- readIORef v_Output_dir
175   case odir_opt of
176         Nothing -> return f
177         Just d  -> return (replaceFilenameDirectory f d)
178
179 osuf_ify :: String -> IO String
180 osuf_ify f = do
181   osuf <- readIORef v_Object_suf
182   return (replaceFilenameSuffix f osuf)
183
184 GLOBAL_VAR(v_StgStats,                  False, Bool)
185
186 buildStgToDo :: IO [ StgToDo ]
187 buildStgToDo = do
188   stg_stats <- readIORef v_StgStats
189   let flags1 | stg_stats = [ D_stg_stats ]
190              | otherwise = [ ]
191
192         -- STG passes
193   ways_ <- readIORef v_Ways
194   let flags2 | WayProf `elem` ways_ = StgDoMassageForProfiling : flags1
195              | otherwise            = flags1
196
197   return flags2
198
199 -----------------------------------------------------------------------------
200 -- Paths & Libraries
201
202 split_marker = ':'   -- not configurable (ToDo)
203
204 v_Import_paths, v_Include_paths, v_Library_paths :: IORef [String]
205 GLOBAL_VAR(v_Import_paths,  ["."], [String])
206 GLOBAL_VAR(v_Include_paths, ["."], [String])
207 GLOBAL_VAR(v_Library_paths, [],  [String])
208
209 #ifdef darwin_TARGET_OS
210 GLOBAL_VAR(v_Framework_paths, [], [String])
211 GLOBAL_VAR(v_Cmdline_frameworks, [], [String])
212 #endif
213
214 addToDirList :: IORef [String] -> String -> IO ()
215 addToDirList ref path
216   = do paths           <- readIORef ref
217        shiny_new_ones  <- splitUp path
218        writeIORef ref (paths ++ filter notNull shiny_new_ones)
219                 -- empty paths are ignored: there might be a trailing
220                 -- ':' in the initial list, for example.  Empty paths can
221                 -- cause confusion when they are translated into -I options
222                 -- for passing to gcc.
223   where
224     splitUp ::String -> IO [String]
225 #ifdef mingw32_TARGET_OS
226      -- 'hybrid' support for DOS-style paths in directory lists.
227      -- 
228      -- That is, if "foo:bar:baz" is used, this interpreted as
229      -- consisting of three entries, 'foo', 'bar', 'baz'.
230      -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
231      -- as four elts, "c:/foo", "c:\\foo", "x", and "/bar" --
232      -- *provided* c:/foo exists and x:/bar doesn't.
233      --
234      -- Notice that no attempt is made to fully replace the 'standard'
235      -- split marker ':' with the Windows / DOS one, ';'. The reason being
236      -- that this will cause too much breakage for users & ':' will
237      -- work fine even with DOS paths, if you're not insisting on being silly.
238      -- So, use either.
239     splitUp []         = return []
240     splitUp (x:':':div:xs) 
241       | div `elem` dir_markers = do
242           let (p,rs) = findNextPath xs
243           ps  <- splitUp rs
244            {-
245              Consult the file system to check the interpretation
246              of (x:':':div:p) -- this is arguably excessive, we
247              could skip this test & just say that it is a valid
248              dir path.
249            -}
250           flg <- doesDirectoryExist (x:':':div:p)
251           if flg then
252              return ((x:':':div:p):ps)
253            else
254              return ([x]:(div:p):ps)
255     splitUp xs = do
256       let (p,rs) = findNextPath xs
257       ps <- splitUp rs
258       return (cons p ps)
259     
260     cons "" xs = xs
261     cons x  xs = x:xs
262
263     -- will be called either when we've consumed nought or the "<Drive>:/" part of
264     -- a DOS path, so splitting is just a Q of finding the next split marker.
265     findNextPath xs = 
266         case break (`elem` split_markers) xs of
267            (p, d:ds) -> (p, ds)
268            (p, xs)   -> (p, xs)
269
270     split_markers :: [Char]
271     split_markers = [':', ';']
272
273     dir_markers :: [Char]
274     dir_markers = ['/', '\\']
275
276 #else
277     splitUp xs = return (split split_marker xs)
278 #endif
279
280 -- ----------------------------------------------------------------------------
281 -- Loading the package config file
282
283 readPackageConf :: String -> IO ()
284 readPackageConf conf_file = do
285   proto_pkg_configs <- loadPackageConfig conf_file
286   top_dir           <- getTopDir
287   let pkg_configs = mungePackagePaths top_dir proto_pkg_configs
288   extendPackageConfigMap pkg_configs
289
290 mungePackagePaths :: String -> [PackageConfig] -> [PackageConfig]
291 -- Replace the string "$libdir" at the beginning of a path
292 -- with the current libdir (obtained from the -B option).
293 mungePackagePaths top_dir ps = map munge_pkg ps
294  where 
295   munge_pkg p = p{ import_dirs  = munge_paths (import_dirs p),
296                    include_dirs = munge_paths (include_dirs p),
297                    library_dirs = munge_paths (library_dirs p),
298                    framework_dirs = munge_paths (framework_dirs p) }
299
300   munge_paths = map munge_path
301
302   munge_path p 
303           | Just p' <- maybePrefixMatch "$libdir" p = top_dir ++ p'
304           | otherwise                               = p
305
306
307 -- -----------------------------------------------------------------------------
308 -- The list of packages requested on the command line
309
310 -- The package list reflects what packages were given as command-line options,
311 -- plus their dependent packages.  It is maintained in dependency order;
312 -- earlier packages may depend on later ones, but not vice versa
313 GLOBAL_VAR(v_ExplicitPackages, initPackageList, [PackageName])
314
315 initPackageList = [basePackage, rtsPackage]
316         -- basePackage is part of this list entirely because of 
317         -- wired-in names in GHCi.  See the notes on wired-in names in
318         -- Linker.linkExpr.  By putting the base backage in initPackageList
319         -- we make sure that it'll always by linked.
320
321
322 -- add a package requested from the command-line
323 addPackage :: String -> IO ()
324 addPackage package = do
325   pkg_details <- getPackageConfigMap
326   ps  <- readIORef v_ExplicitPackages
327   ps' <- add_package pkg_details ps (mkPackageName package)
328                 -- Throws an exception if it fails
329   writeIORef v_ExplicitPackages ps'
330
331 -- internal helper
332 add_package :: PackageConfigMap -> [PackageName]
333             -> PackageName -> IO [PackageName]
334 add_package pkg_details ps p    
335   | p `elem` ps -- Check if we've already added this package
336   = return ps
337   | Just details <- lookupPkg pkg_details p
338   -- Add the package's dependents also
339   = do ps' <- foldM (add_package pkg_details) ps (packageDependents details)
340        return (p : ps')
341   | otherwise
342   = throwDyn (CmdLineError ("unknown package name: " ++ packageNameString p))
343
344
345 -- -----------------------------------------------------------------------------
346 -- Extracting information from the packages in scope
347
348 -- Many of these functions take a list of packages: in those cases,
349 -- the list is expected to contain the "dependent packages",
350 -- i.e. those packages that were found to be depended on by the
351 -- current module/program.  These can be auto or non-auto packages, it
352 -- doesn't really matter.  The list is always combined with the list
353 -- of explicit (command-line) packages to determine which packages to
354 -- use.
355
356 getPackageImportPath :: IO [String]
357 getPackageImportPath = do
358   ps <- getExplicitAndAutoPackageConfigs
359                   -- import dirs are always derived from the 'auto' 
360                   -- packages as well as the explicit ones
361   return (nub (filter notNull (concatMap import_dirs ps)))
362
363 getPackageIncludePath :: [PackageName] -> IO [String]
364 getPackageIncludePath pkgs = do
365   ps <- getExplicitPackagesAnd pkgs
366   return (nub (filter notNull (concatMap include_dirs ps)))
367
368         -- includes are in reverse dependency order (i.e. rts first)
369 getPackageCIncludes :: [PackageConfig] -> IO [String]
370 getPackageCIncludes pkg_configs = do
371   return (reverse (nub (filter notNull (concatMap c_includes pkg_configs))))
372
373 getPackageLibraryPath :: [PackageName] -> IO [String]
374 getPackageLibraryPath pkgs = do 
375   ps <- getExplicitPackagesAnd pkgs
376   return (nub (filter notNull (concatMap library_dirs ps)))
377
378 getPackageLinkOpts :: [PackageName] -> IO [String]
379 getPackageLinkOpts pkgs = do
380   ps <- getExplicitPackagesAnd pkgs
381   tag <- readIORef v_Build_tag
382   static <- readIORef v_Static
383   let 
384         imp        = if static then "" else "_imp"
385         suffix     = if null tag then "" else '_':tag
386         libs p     = map (++suffix) (hACK (hs_libraries p)) ++ extra_libraries p
387         imp_libs p = map (++imp) (libs p)
388         all_opts p = map ("-l" ++) (imp_libs p) ++ extra_ld_opts p
389
390   return (concat (map all_opts ps))
391   where
392      -- This is a totally horrible (temporary) hack, for Win32.  Problem is
393      -- that package.conf for Win32 says that the main prelude lib is 
394      -- split into HSbase1, HSbase2 and HSbase3, which is needed due to a bug
395      -- in the GNU linker (PEi386 backend). However, we still only
396      -- have HSbase.a for static linking, not HSbase{1,2,3}.a
397      -- getPackageLibraries is called to find the .a's to add to the static
398      -- link line.  On Win32, this hACK detects HSbase{1,2,3} and 
399      -- replaces them with HSbase, so static linking still works.
400      -- Libraries needed for dynamic (GHCi) linking are discovered via
401      -- different route (in InteractiveUI.linkPackage).
402      -- See driver/PackageSrc.hs for the HSbase1/HSbase2 split definition.
403      -- THIS IS A STRICTLY TEMPORARY HACK (famous last words ...)
404      -- JRS 04 Sept 01: Same appalling hack for HSwin32[1,2]
405      -- KAA 29 Mar  02: Same appalling hack for HSobjectio[1,2,3,4]
406      hACK libs
407 #      if !defined(mingw32_TARGET_OS) && !defined(cygwin32_TARGET_OS)
408        = libs
409 #      else
410        = if   "HSbase1" `elem` libs && "HSbase2" `elem` libs && "HSbase3" `elem` libs
411          then "HSbase" : filter (not.(isPrefixOf "HSbase")) libs
412          else
413          if   "HSwin321" `elem` libs && "HSwin322" `elem` libs
414          then "HSwin32" : filter (not.(isPrefixOf "HSwin32")) libs
415          else 
416          if   "HSobjectio1" `elem` libs && "HSobjectio2" `elem` libs && "HSobjectio3" `elem` libs && "HSobjectio4" `elem` libs
417          then "HSobjectio" : filter (not.(isPrefixOf "HSobjectio")) libs
418          else 
419          libs
420 #      endif
421
422 getPackageExtraGhcOpts :: IO [String]
423 getPackageExtraGhcOpts = do
424   ps <- getExplicitAndAutoPackageConfigs
425   return (concatMap extra_ghc_opts ps)
426
427 getPackageExtraCcOpts :: [PackageName] -> IO [String]
428 getPackageExtraCcOpts pkgs = do
429   ps <- getExplicitPackagesAnd pkgs
430   return (concatMap extra_cc_opts ps)
431
432 #ifdef darwin_TARGET_OS
433 getPackageFrameworkPath  :: [PackageName] -> IO [String]
434 getPackageFrameworkPath pkgs = do
435   ps <- getExplicitPackagesAnd pkgs
436   return (nub (filter notNull (concatMap framework_dirs ps)))
437
438 getPackageFrameworks  :: [PackageName] -> IO [String]
439 getPackageFrameworks pkgs = do
440   ps <- getExplicitPackagesAnd pkgs
441   return (concatMap extra_frameworks ps)
442 #endif
443
444 -- -----------------------------------------------------------------------------
445 -- Package Utils
446
447 getExplicitPackagesAnd :: [PackageName] -> IO [PackageConfig]
448 getExplicitPackagesAnd pkg_names = do
449   pkg_map <- getPackageConfigMap
450   expl <- readIORef v_ExplicitPackages
451   all_pkgs <- foldM (add_package pkg_map) expl pkg_names
452   getPackageDetails all_pkgs
453
454 -- return all packages, including both the auto packages and the explicit ones
455 getExplicitAndAutoPackageConfigs :: IO [PackageConfig]
456 getExplicitAndAutoPackageConfigs = do
457   pkg_map <- getPackageConfigMap
458   let auto_packages = [ mkPackageName (name p) | p <- eltsUFM pkg_map, auto p ]
459   getExplicitPackagesAnd auto_packages
460
461 -----------------------------------------------------------------------------
462 -- Ways
463
464 -- The central concept of a "way" is that all objects in a given
465 -- program must be compiled in the same "way".  Certain options change
466 -- parameters of the virtual machine, eg. profiling adds an extra word
467 -- to the object header, so profiling objects cannot be linked with
468 -- non-profiling objects.
469
470 -- After parsing the command-line options, we determine which "way" we
471 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
472
473 -- We then find the "build-tag" associated with this way, and this
474 -- becomes the suffix used to find .hi files and libraries used in
475 -- this compilation.
476
477 GLOBAL_VAR(v_Build_tag, "", String)
478
479 data WayName
480   = WayProf
481   | WayUnreg
482   | WayTicky
483   | WayPar
484   | WayGran
485   | WaySMP
486   | WayNDP
487   | WayDebug
488   | WayUser_a
489   | WayUser_b
490   | WayUser_c
491   | WayUser_d
492   | WayUser_e
493   | WayUser_f
494   | WayUser_g
495   | WayUser_h
496   | WayUser_i
497   | WayUser_j
498   | WayUser_k
499   | WayUser_l
500   | WayUser_m
501   | WayUser_n
502   | WayUser_o
503   | WayUser_A
504   | WayUser_B
505   deriving (Eq,Ord)
506
507 GLOBAL_VAR(v_Ways, [] ,[WayName])
508
509 allowed_combination way = way `elem` combs
510   where  -- the sub-lists must be ordered according to WayName, 
511          -- because findBuildTag sorts them
512     combs                = [ [WayProf, WayUnreg], 
513                              [WayProf, WaySMP]  ,
514                              [WayProf, WayNDP]  ]
515
516 findBuildTag :: IO [String]  -- new options
517 findBuildTag = do
518   way_names <- readIORef v_Ways
519   case sort way_names of
520      []  -> do  -- writeIORef v_Build_tag ""
521                 return []
522
523      [w] -> do let details = lkupWay w
524                writeIORef v_Build_tag (wayTag details)
525                return (wayOpts details)
526
527      ws  -> if not (allowed_combination ws)
528                 then throwDyn (CmdLineError $
529                                 "combination not supported: "  ++
530                                 foldr1 (\a b -> a ++ '/':b) 
531                                 (map (wayName . lkupWay) ws))
532                 else let stuff = map lkupWay ws
533                          tag   = concat (map wayTag stuff)
534                          flags = map wayOpts stuff
535                      in do
536                      writeIORef v_Build_tag tag
537                      return (concat flags)
538
539 lkupWay w = 
540    case lookup w way_details of
541         Nothing -> error "findBuildTag"
542         Just details -> details
543
544 data Way = Way {
545   wayTag   :: String,
546   wayName  :: String,
547   wayOpts  :: [String]
548   }
549
550 way_details :: [ (WayName, Way) ]
551 way_details =
552   [ (WayProf, Way  "p" "Profiling"  
553         [ "-fscc-profiling"
554         , "-DPROFILING"
555         , "-optc-DPROFILING"
556         , "-fvia-C" ]),
557
558     (WayTicky, Way  "t" "Ticky-ticky Profiling"  
559         [ "-fticky-ticky"
560         , "-DTICKY_TICKY"
561         , "-optc-DTICKY_TICKY"
562         , "-fvia-C" ]),
563
564     (WayUnreg, Way  "u" "Unregisterised" 
565         unregFlags ),
566
567     -- optl's below to tell linker where to find the PVM library -- HWL
568     (WayPar, Way  "mp" "Parallel" 
569         [ "-fparallel"
570         , "-D__PARALLEL_HASKELL__"
571         , "-optc-DPAR"
572         , "-package concurrent"
573         , "-optc-w"
574         , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
575         , "-optl-lpvm3"
576         , "-optl-lgpvm3"
577         , "-fvia-C" ]),
578
579     -- at the moment we only change the RTS and could share compiler and libs!
580     (WayPar, Way  "mt" "Parallel ticky profiling" 
581         [ "-fparallel"
582         , "-D__PARALLEL_HASKELL__"
583         , "-optc-DPAR"
584         , "-optc-DPAR_TICKY"
585         , "-package concurrent"
586         , "-optc-w"
587         , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
588         , "-optl-lpvm3"
589         , "-optl-lgpvm3"
590         , "-fvia-C" ]),
591
592     (WayPar, Way  "md" "Distributed" 
593         [ "-fparallel"
594         , "-D__PARALLEL_HASKELL__"
595         , "-D__DISTRIBUTED_HASKELL__"
596         , "-optc-DPAR"
597         , "-optc-DDIST"
598         , "-package concurrent"
599         , "-optc-w"
600         , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
601         , "-optl-lpvm3"
602         , "-optl-lgpvm3"
603         , "-fvia-C" ]),
604
605     (WayGran, Way  "mg" "GranSim" 
606         [ "-fgransim"
607         , "-D__GRANSIM__"
608         , "-optc-DGRAN"
609         , "-package concurrent"
610         , "-fvia-C" ]),
611
612     (WaySMP, Way  "s" "SMP"
613         [ "-fsmp"
614         , "-optc-pthread"
615 #ifndef freebsd_TARGET_OS
616         , "-optl-pthread"
617 #endif
618         , "-optc-DSMP"
619         , "-fvia-C" ]),
620
621     (WayNDP, Way  "ndp" "Nested data parallelism"
622         [ "-fparr"
623         , "-fflatten"]),
624
625     (WayUser_a,  Way  "a"  "User way 'a'"  ["$WAY_a_REAL_OPTS"]),       
626     (WayUser_b,  Way  "b"  "User way 'b'"  ["$WAY_b_REAL_OPTS"]),       
627     (WayUser_c,  Way  "c"  "User way 'c'"  ["$WAY_c_REAL_OPTS"]),       
628     (WayUser_d,  Way  "d"  "User way 'd'"  ["$WAY_d_REAL_OPTS"]),       
629     (WayUser_e,  Way  "e"  "User way 'e'"  ["$WAY_e_REAL_OPTS"]),       
630     (WayUser_f,  Way  "f"  "User way 'f'"  ["$WAY_f_REAL_OPTS"]),       
631     (WayUser_g,  Way  "g"  "User way 'g'"  ["$WAY_g_REAL_OPTS"]),       
632     (WayUser_h,  Way  "h"  "User way 'h'"  ["$WAY_h_REAL_OPTS"]),       
633     (WayUser_i,  Way  "i"  "User way 'i'"  ["$WAY_i_REAL_OPTS"]),       
634     (WayUser_j,  Way  "j"  "User way 'j'"  ["$WAY_j_REAL_OPTS"]),       
635     (WayUser_k,  Way  "k"  "User way 'k'"  ["$WAY_k_REAL_OPTS"]),       
636     (WayUser_l,  Way  "l"  "User way 'l'"  ["$WAY_l_REAL_OPTS"]),       
637     (WayUser_m,  Way  "m"  "User way 'm'"  ["$WAY_m_REAL_OPTS"]),       
638     (WayUser_n,  Way  "n"  "User way 'n'"  ["$WAY_n_REAL_OPTS"]),       
639     (WayUser_o,  Way  "o"  "User way 'o'"  ["$WAY_o_REAL_OPTS"]),       
640     (WayUser_A,  Way  "A"  "User way 'A'"  ["$WAY_A_REAL_OPTS"]),       
641     (WayUser_B,  Way  "B"  "User way 'B'"  ["$WAY_B_REAL_OPTS"]) 
642   ]
643
644 unregFlags = 
645    [ "-optc-DNO_REGS"
646    , "-optc-DUSE_MINIINTERPRETER"
647    , "-fno-asm-mangling"
648    , "-funregisterised"
649    , "-fvia-C" ]
650
651 -----------------------------------------------------------------------------
652 -- Options for particular phases
653
654 GLOBAL_VAR(v_Opt_dep,    [], [String])
655 GLOBAL_VAR(v_Anti_opt_C, [], [String])
656 GLOBAL_VAR(v_Opt_C,      [], [String])
657 GLOBAL_VAR(v_Opt_l,      [], [String])
658 GLOBAL_VAR(v_Opt_dll,    [], [String])
659
660 getStaticOpts :: IORef [String] -> IO [String]
661 getStaticOpts ref = readIORef ref >>= return . reverse