From 24c0c8c2040e7050fd5306afc85378eb94a06bd2 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sun, 1 May 2011 17:00:26 +0100 Subject: [PATCH] Remove some ifdefs in favour of Haskell tests --- compiler/ghci/ByteCodeAsm.lhs | 2 + compiler/main/DriverPipeline.hs | 94 ++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 51 deletions(-) diff --git a/compiler/ghci/ByteCodeAsm.lhs b/compiler/ghci/ByteCodeAsm.lhs index e3c57b5..2c7473b 100644 --- a/compiler/ghci/ByteCodeAsm.lhs +++ b/compiler/ghci/ByteCodeAsm.lhs @@ -31,6 +31,7 @@ import Constants import FastString import SMRep import Outputable +import Config import Control.Monad ( foldM ) import Control.Monad.ST ( runST ) @@ -44,6 +45,7 @@ import Data.Char ( ord ) import Data.List import Data.Map (Map) import qualified Data.Map as Map +import Distribution.System import GHC.Base ( ByteArray#, MutableByteArray#, RealWorld ) diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index 70d99d4..03e3cf6 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -55,6 +55,7 @@ import MonadUtils -- import Data.Either import Exception import Data.IORef ( readIORef ) +import Distribution.System -- import GHC.Exts ( Int(..) ) import System.Directory import System.FilePath @@ -269,11 +270,11 @@ link :: GhcLink -- interactive or batch -- exports main, i.e., we have good reason to believe that linking -- will succeed. -#ifdef GHCI link LinkInMemory _ _ _ - = do -- Not Linking...(demand linker will do the job) - return Succeeded -#endif + = if cGhcWithInterpreter == "YES" + then -- Not Linking...(demand linker will do the job) + return Succeeded + else panicBadLink LinkInMemory link NoLink _ _ _ = return Succeeded @@ -284,11 +285,6 @@ link LinkBinary dflags batch_attempt_linking hpt link LinkDynLib dflags batch_attempt_linking hpt = link' dflags batch_attempt_linking hpt -#ifndef GHCI --- warning suppression -link other _ _ _ = panicBadLink other -#endif - panicBadLink :: GhcLink -> a panicBadLink other = panic ("link: GHC not built to link this way: " ++ show other) @@ -1061,15 +1057,14 @@ runPhase cc_phase input_fn dflags let more_hcc_opts = -#if i386_TARGET_ARCH -- on x86 the floating point regs have greater precision -- than a double, which leads to unpredictable results. -- By default, we turn this off with -ffloat-store unless -- the user specified -fexcess-precision. - (if dopt Opt_ExcessPrecision dflags - then [] - else [ "-ffloat-store" ]) ++ -#endif + (if cTargetArch == I386 && + not (dopt Opt_ExcessPrecision dflags) + then [ "-ffloat-store" ] + else []) ++ -- gcc's -fstrict-aliasing allows two accesses to memory -- to be considered non-aliasing if they have different types. @@ -1093,26 +1088,26 @@ runPhase cc_phase input_fn dflags ++ map SysTools.Option ( pic_c_flags -#if defined(mingw32_TARGET_OS) -- Stub files generated for foreign exports references the runIO_closure -- and runNonIO_closure symbols, which are defined in the base package. -- These symbols are imported into the stub.c file via RtsAPI.h, and the -- way we do the import depends on whether we're currently compiling -- the base package or not. - ++ (if thisPackage dflags == basePackageId + ++ (if cTargetOS == Windows && + thisPackage dflags == basePackageId then [ "-DCOMPILING_BASE_PACKAGE" ] else []) -#endif -#ifdef sparc_TARGET_ARCH -- We only support SparcV9 and better because V8 lacks an atomic CAS -- instruction. Note that the user can still override this -- (e.g., -mcpu=ultrasparc) as GCC picks the "best" -mcpu flag -- regardless of the ordering. -- -- This is a temporary hack. - ++ ["-mcpu=v9"] -#endif + ++ (if cTargetArch == Sparc + then ["-mcpu=v9"] + else []) + ++ (if hcc then gcc_extra_viac_flags ++ more_hcc_opts else []) @@ -1179,7 +1174,7 @@ runPhase As input_fn dflags io $ SysTools.runAs dflags (map SysTools.Option as_opts ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ] -#ifdef sparc_TARGET_ARCH + -- We only support SparcV9 and better because V8 lacks an atomic CAS -- instruction so we have to make sure that the assembler accepts the -- instruction set. Note that the user can still override this @@ -1187,8 +1182,10 @@ runPhase As input_fn dflags -- regardless of the ordering. -- -- This is a temporary hack. - ++ [ SysTools.Option "-mcpu=v9" ] -#endif + ++ (if cTargetArch == Sparc + then [SysTools.Option "-mcpu=v9"] + else []) + ++ [ SysTools.Option "-c" , SysTools.FileOption "" input_fn , SysTools.Option "-o" @@ -1232,7 +1229,7 @@ runPhase SplitAs _input_fn dflags let assemble_file n = SysTools.runAs dflags (map SysTools.Option as_opts ++ -#ifdef sparc_TARGET_ARCH + -- We only support SparcV9 and better because V8 lacks an atomic CAS -- instruction so we have to make sure that the assembler accepts the -- instruction set. Note that the user can still override this @@ -1240,8 +1237,10 @@ runPhase SplitAs _input_fn dflags -- regardless of the ordering. -- -- This is a temporary hack. - [ SysTools.Option "-mcpu=v9" ] ++ -#endif + (if cTargetArch == Sparc + then [SysTools.Option "-mcpu=v9"] + else []) ++ + [ SysTools.Option "-c" , SysTools.Option "-o" , SysTools.FileOption "" (split_obj n) @@ -1316,11 +1315,9 @@ runPhase LlvmLlc input_fn dflags = do let lc_opts = getOpts dflags opt_lc let opt_lvl = max 0 (min 2 $ optLevel dflags) -#if darwin_TARGET_OS - let nphase = LlvmMangle -#else - let nphase = As -#endif + let nphase = if cTargetOS == OSX + then LlvmMangle + else As let rmodel | opt_PIC = "pic" | not opt_Static = "dynamic-no-pic" | otherwise = "static" @@ -1336,11 +1333,9 @@ runPhase LlvmLlc input_fn dflags return (nphase, output_fn) where -#if darwin_TARGET_OS - llvmOpts = ["-O1", "-O2", "-O2"] -#else - llvmOpts = ["-O1", "-O2", "-O3"] -#endif + llvmOpts = if cTargetOS == OSX + then ["-O1", "-O2", "-O2"] + else ["-O1", "-O2", "-O3"] ----------------------------------------------------------------------------- @@ -1654,11 +1649,12 @@ linkBinary dflags o_files dep_packages = do ++ map SysTools.Option ( [] -#ifdef mingw32_TARGET_OS -- Permit the linker to auto link _symbol to _imp_symbol. -- This lets us link against DLLs without needing an "import library". - ++ ["-Wl,--enable-auto-import"] -#endif + ++ (if cTargetOS == Windows + then ["-Wl,--enable-auto-import"] + else []) + ++ o_files ++ extra_ld_inputs ++ lib_path_opts @@ -1689,19 +1685,15 @@ linkBinary dflags o_files dep_packages = do exeFileName :: DynFlags -> FilePath exeFileName dflags | Just s <- outputFile dflags = -#if defined(mingw32_HOST_OS) - if null (takeExtension s) - then s <.> "exe" - else s -#else - s -#endif + if cTargetOS == Windows + then if null (takeExtension s) + then s <.> "exe" + else s + else s | otherwise = -#if defined(mingw32_HOST_OS) - "main.exe" -#else - "a.out" -#endif + if cTargetOS == Windows + then "main.exe" + else "a.out" maybeCreateManifest :: DynFlags -- 1.7.10.4