Added support for automatically inducing the output file from the input file for full compile mode (filename minus extension)
This commit is contained in:
parent
0eadbd0b11
commit
5e70e70d95
28
Main.hs
28
Main.hs
|
@ -139,11 +139,14 @@ main = do
|
||||||
-- Try to guess the filename from the extension. Since this function is
|
-- Try to guess the filename from the extension. Since this function is
|
||||||
-- applied before the options are applied, it will be overriden by the
|
-- applied before the options are applied, it will be overriden by the
|
||||||
-- --frontend=x command-line option
|
-- --frontend=x command-line option
|
||||||
let frontendGuess = if ".occ" `isSuffixOf` fn
|
let (frontendGuess, fileStem)
|
||||||
then \ps -> ps {csFrontend = FrontendOccam}
|
= if ".occ" `isSuffixOf` fn
|
||||||
|
then (\ps -> ps {csFrontend = FrontendOccam},
|
||||||
|
Just $ take (length fn - length ".occ") fn)
|
||||||
else if ".rain" `isSuffixOf` fn
|
else if ".rain" `isSuffixOf` fn
|
||||||
then \ps -> ps {csFrontend = FrontendRain}
|
then (\ps -> ps {csFrontend = FrontendRain},
|
||||||
else id
|
Just $ take (length fn - length ".rain") fn)
|
||||||
|
else (id, Nothing)
|
||||||
|
|
||||||
initState <- foldl (>>=) (return $ frontendGuess emptyState) opts
|
initState <- foldl (>>=) (return $ frontendGuess emptyState) opts
|
||||||
|
|
||||||
|
@ -153,7 +156,7 @@ main = do
|
||||||
ModeFlowGraph -> useOutputOptions (compile ModeFlowGraph fn)
|
ModeFlowGraph -> useOutputOptions (compile ModeFlowGraph fn)
|
||||||
ModeCompile -> useOutputOptions (compile ModeCompile fn)
|
ModeCompile -> useOutputOptions (compile ModeCompile fn)
|
||||||
ModePostC -> useOutputOptions (postCAnalyse fn)
|
ModePostC -> useOutputOptions (postCAnalyse fn)
|
||||||
ModeFull -> evalStateT (compileFull fn) []
|
ModeFull -> evalStateT (compileFull fn fileStem) []
|
||||||
|
|
||||||
-- Run the compiler.
|
-- Run the compiler.
|
||||||
-- TODO still get the warnings back in future
|
-- TODO still get the warnings back in future
|
||||||
|
@ -184,12 +187,17 @@ instance Die (StateT [FilePath] PassM) where
|
||||||
liftIO $ removeFiles files
|
liftIO $ removeFiles files
|
||||||
lift $ dieReport err
|
lift $ dieReport err
|
||||||
|
|
||||||
compileFull :: String -> StateT [FilePath] PassM ()
|
compileFull :: String -> Maybe String -> StateT [FilePath] PassM ()
|
||||||
compileFull inputFile
|
compileFull inputFile moutputFile
|
||||||
= do optsPS <- lift get
|
= do optsPS <- lift get
|
||||||
outputFile <- case csOutputFile optsPS of
|
outputFile <- case (csOutputFile optsPS, moutputFile) of
|
||||||
"-" -> dieReport (Nothing, "Must specify an output file when using full-compile mode")
|
-- If the user hasn't given an output file, we guess by
|
||||||
file -> return file
|
-- using a stem (input file minus known extension).
|
||||||
|
-- If the extension isn't known, the user must specify
|
||||||
|
-- the output file
|
||||||
|
("-", Just file) -> return file
|
||||||
|
("-", Nothing) -> dieReport (Nothing, "Must specify an output file when using full-compile mode")
|
||||||
|
(file, _) -> return file
|
||||||
|
|
||||||
let extension = case csBackend optsPS of
|
let extension = case csBackend optsPS of
|
||||||
BackendC -> ".c"
|
BackendC -> ".c"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user