Commit 7ba3efd7 authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

Compiler option handling refactored

parent 46b35559
...@@ -12,9 +12,10 @@ Description: The Curry Frontend consists of the executable program "cymake". ...@@ -12,9 +12,10 @@ Description: The Curry Frontend consists of the executable program "cymake".
Category: Language Category: Language
License: OtherLicense License: OtherLicense
License-File: LICENSE License-File: LICENSE
Author: Wolfgang Lux, Martin Engelke, Bernd Brassel, Holger Siegel Author: Wolfgang Lux, Martin Engelke, Bernd Brassel, Holger Siegel,
Maintainer: Holger Siegel Bjoern Peemoeller
Bug-Reports: mailto:hsi@informatik.uni-kiel.de Maintainer: Bjoern Peemoeller
Bug-Reports: mailto:bjp@informatik.uni-kiel.de
Homepage: http://curry-language.org Homepage: http://curry-language.org
Build-Type: Simple Build-Type: Simple
Stability: experimental Stability: experimental
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
May 2011 , refinements by Björn Peemöller (bjp@informatik.uni-kiel.de) May 2011 , refinements by Björn Peemöller (bjp@informatik.uni-kiel.de)
-} -}
module CurryCompilerOpts module CurryCompilerOpts
(Options (..), Dump (..), parseOpts, printUsage, printVersion, defaultOptions) where (Options (..), Dump (..), defaultOptions, compilerOpts, usage) where
import Data.List (nub) import Data.List (nub)
import Data.Maybe (isJust)
import System.Console.GetOpt import System.Console.GetOpt
import System.Environment (getArgs, getProgName)
import Curry.Files.Filenames (currySubdir) import Curry.Files.Filenames (currySubdir)
import Files.CymakePath (cymakeGreeting)
-- |Data type for recording compiler options -- |Data type for recording compiler options
data Options = Options data Options = Options
...@@ -167,12 +168,22 @@ parseOpts :: [String] -> (Options, [String], [String]) ...@@ -167,12 +168,22 @@ parseOpts :: [String] -> (Options, [String], [String])
parseOpts args = (foldl (flip ($)) defaultOptions opts, files, errs) where parseOpts args = (foldl (flip ($)) defaultOptions opts, files, errs) where
(opts, files, errs) = getOpt Permute options args (opts, files, errs) = getOpt Permute options args
-- |Check options and files and return a list of error messages
checkOpts :: Options -> [String] -> [String]
checkOpts opts files
| isJust (output opts) && length files > 1
= ["cannot specify -o with multiple targets"]
| otherwise
= []
-- |Print the usage information of the command line tool. -- |Print the usage information of the command line tool.
printUsage :: String -> IO () usage :: String -> String
printUsage prog = putStrLn $ usageInfo header options usage prog = usageInfo header options
where header = "usage: " ++ prog ++ " [OPTION] ... MODULE ..." where header = "usage: " ++ prog ++ " [OPTION] ... MODULE ..."
-- |Print the program greeting compilerOpts :: IO (String, Options, [String], [String])
printVersion :: IO () compilerOpts = do
printVersion = putStrLn cymakeGreeting args <- getArgs
prog <- getProgName
let (opts, files, errs) = parseOpts args
return (prog, opts, files, errs ++ checkOpts opts files)
...@@ -25,7 +25,7 @@ import Base (ModuleEnv, TCEnv, ValueEnv, TypeInfo (..), ValueInfo (..) ...@@ -25,7 +25,7 @@ import Base (ModuleEnv, TCEnv, ValueEnv, TypeInfo (..), ValueInfo (..)
, lookupValue, qualLookupTC, qualLookupValue, ArityEnv, ArityInfo (..) , lookupValue, qualLookupTC, qualLookupValue, ArityEnv, ArityInfo (..)
, lookupArity, qualLookupArity) , lookupArity, qualLookupArity)
import CurryCompilerOpts import CurryCompilerOpts (Options (..))
import qualified CurryToIL as IL import qualified CurryToIL as IL
import Env.TopEnv (topEnvMap) import Env.TopEnv (topEnvMap)
import Env.CurryEnv (CurryEnv) import Env.CurryEnv (CurryEnv)
......
...@@ -8,49 +8,43 @@ ...@@ -8,49 +8,43 @@
-} -}
module Main (main) where module Main (main) where
import Data.Maybe (isJust)
import System.Environment (getArgs, getProgName)
import CurryBuilder (buildCurry) import CurryBuilder (buildCurry)
import CurryCompilerOpts (Options (..), parseOpts, printUsage, printVersion) import CurryCompilerOpts (Options (..), compilerOpts, usage)
import Files.CymakePath (cymakeGreeting) import Files.CymakePath (cymakeGreeting)
import Html.CurryHtml (source2html) import Html.CurryHtml (source2html)
import Messages (info, putErrsLn, abortWith) import Messages (putErrsLn, abortWith)
-- |The command line tool cymake -- |The command line tool cymake
main :: IO () main :: IO ()
main = do main = compilerOpts >>= cymake
prog <- getProgName
args <- getArgs
cymake prog (parseOpts args)
-- |Check the command line arguments and invoke the curry builder -- |Check the command line arguments and invoke the curry builder
cymake :: String -> (Options, [String], [String]) -> IO () cymake :: (String, Options, [String], [String]) -> IO ()
cymake prog (opts, files, errs) cymake (prog, opts, files, errs)
| help opts = printUsage prog | help opts = printUsage prog
| version opts = printVersion | version opts = printVersion
| null files = printUsage prog | null files = printUsage prog
| not (null errs') = badUsage prog errs' | not (null errs) = badUsage prog errs
| html opts = mapM_ (source2html opts) files | html opts = mapM_ (source2html opts) files
| otherwise = info opts cymakeGreeting | otherwise = mapM_ (buildCurry opts') files
>> mapM_ (buildCurry opts') files
where where
opts' = if or [ flat opts, flatXml opts, abstract opts opts' = if or [ flat opts, flatXml opts, abstract opts
, untypedAbstract opts, parseOnly opts] , untypedAbstract opts, parseOnly opts]
then opts then opts
else opts { flat = True } else opts { flat = True }
errs' = errs ++ check opts' files
-- ---------------------------------------------------------------------------
-- |Print the program greeting
printVersion :: IO ()
printVersion = putStrLn cymakeGreeting
-- |Print errors -- |Print the usage information of the command line tool.
printUsage :: String -> IO ()
printUsage prog = putStrLn $ usage prog
-- |Print errors and abort execution
badUsage :: String -> [String] -> IO () badUsage :: String -> [String] -> IO ()
badUsage prog errs = do badUsage prog errs = do
putErrsLn $ map (\ err -> prog ++ ": " ++ err) errs putErrsLn $ map (\ err -> prog ++ ": " ++ err) errs
abortWith ["Try '" ++ prog ++ " --help' for more information"] abortWith ["Try '" ++ prog ++ " --help' for more information"]
-- |Check options and files and return a list of error messages
check :: Options -> [String] -> [String]
check opts files
| isJust (output opts) && length files > 1
= ["cannot specify -o with multiple targets"]
| otherwise
= []
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment