module Options (Architecture(..),Action(..),Settings(..),Format(..),helpMsg,getSettings) where import Specialize.Architecture import System.Console.GetOpt import Data.Maybe import My.Data.List data Flag = Help | Version | SourceDir FilePath | Program FilePath | LanguageDir FilePath | Architecture Architecture | Format Format deriving Show data Action = PrintHelp | PrintVersion | Compile deriving Show data Format = Elf64 | Raw Int deriving Show data Settings = Settings { action :: Action, sourceDirs :: [FilePath], languageDir :: FilePath, programs :: [(String,String)], outputArch :: Architecture, outputFmt :: Format } deriving Show splitArg s = case break (==':') s of (a,':':b) -> a:splitArg b ("","") -> [] (a,"") -> [a] options = [Option ['h','?'] ["help"] (NoArg Help) "prints usage information" ,Option ['v'] ["version"] (NoArg Version) "prints Alpha's version information" ,sep ,Option ['S'] ["source-dir"] (ReqArg SourceDir "") "adds to the list of directories searched for source files" ,Option ['L'] ["language-dir"] (ReqArg LanguageDir "") "writes and seeks all language files in (defaults to the current directory)" ,sep ,Option ['a'] ["architecture"] (ReqArg (Architecture . str2arch) "") $ "specializes for instead of the host architecture ( can be one of "++foldr glue "" (tails archNames)++")" ,Option ['f'] ["format"] (ReqArg (Format . str2fmt) "") $ "writes the output programs in the specified format ( can be one of elf64 or \n" ++"raw: where is the start address)" ] where str2arch s = fromMaybe (error $ "Invalid architecture name "++s) $ lookup s $ zip archNames architectures str2fmt s = case splitArg s of ["elf64"] -> Elf64 ["raw",n] -> Raw (read n) _ -> error ("Invalid format argument "++show s) archNames = map archName architectures glue [a] _ = a glue [a,_] t = a++" or "++t glue (a:_) t = a++", "++t sep = Option [] [] undefined "-----------------" helpMsg = usageInfo "Usage: alpha (