[commit: ghc] master: LLVM: Figure out llvm version we are calling (5fb59c0)
David Terei
davidterei at gmail.com
Tue May 31 10:10:21 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/5fb59c02d3829cdd88cb2180237aba4ea4a2f66a
>---------------------------------------------------------------
commit 5fb59c02d3829cdd88cb2180237aba4ea4a2f66a
Author: David Terei <davidterei at gmail.com>
Date: Mon May 9 02:29:21 2011 -0700
LLVM: Figure out llvm version we are calling
>---------------------------------------------------------------
compiler/main/SysTools.lhs | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 9c086cc..3f69995 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -21,6 +21,7 @@ module SysTools (
runWindres,
runLlvmOpt,
runLlvmLlc,
+ figureLlvmVersion,
readElfSection,
touch, -- String -> String -> IO ()
@@ -58,6 +59,7 @@ import System.IO
import System.IO.Error as IO
import System.Directory
import Data.Char
+import Data.Maybe ( isNothing )
import Data.List
import qualified Data.Map as Map
import Text.ParserCombinators.ReadP hiding (char)
@@ -416,16 +418,54 @@ runAs dflags args = do
mb_env <- getGccEnv args1
runSomethingFiltered dflags id "Assembler" p args1 mb_env
+-- | Run the LLVM Optimiser
runLlvmOpt :: DynFlags -> [Option] -> IO ()
runLlvmOpt dflags args = do
let (p,args0) = pgm_lo dflags
runSomething dflags "LLVM Optimiser" p (args0++args)
+-- | Run the LLVM Compiler
runLlvmLlc :: DynFlags -> [Option] -> IO ()
runLlvmLlc dflags args = do
let (p,args0) = pgm_lc dflags
runSomething dflags "LLVM Compiler" p (args0++args)
+-- | Figure out which version of LLVM we are running this session
+figureLlvmVersion :: DynFlags -> IO (Maybe Int)
+figureLlvmVersion dflags = do
+ let (pgm,opts) = pgm_lc dflags
+ args = filter notNull (map showOpt opts)
+ -- we grab the args even though they should be useless just in
+ -- case the user is using a customised 'llc' that requires some
+ -- of the options they've specified. llc doesn't care what other
+ -- options are specified when '-version' is used.
+ args' = args ++ ["-version"]
+ ver <- catchIO (do
+ (pin, pout, perr, _) <- runInteractiveProcess pgm args'
+ Nothing Nothing
+ {- $ llc -version
+ Low Level Virtual Machine (http://llvm.org/):
+ llvm version 2.8 (Ubuntu 2.8-0Ubuntu1)
+ ...
+ -}
+ hSetBinaryMode pout False
+ _ <- hGetLine pout
+ vline <- hGetLine pout
+ v <- case filter isDigit vline of
+ [] -> fail "no digits!"
+ [x] -> fail $ "only 1 digit! (" ++ show x ++ ")"
+ (x:y:_) -> return ((read [x,y]) :: Int)
+ hClose pin
+ hClose pout
+ hClose perr
+ return $ Just v
+ )
+ (\err -> do
+ putMsg dflags $ text $ "Warning: " ++ show err
+ return Nothing)
+ return ver
+
+
runLink :: DynFlags -> [Option] -> IO ()
runLink dflags args = do
let (p,args0) = pgm_l dflags
More information about the Cvs-ghc
mailing list