|
18 | 18 | -} |
19 | 19 |
|
20 | 20 | import Compile |
| 21 | +import Control.Applicative (optional) |
21 | 22 | import Control.Monad (join) |
22 | 23 | import Data.Monoid ((<>)) |
23 | 24 | import Options.Applicative |
24 | 25 | import System.Environment |
25 | 26 | import System.Directory |
26 | 27 | import System.IO |
27 | 28 |
|
28 | | -data Options = Options { source :: String, |
29 | | - output :: String, |
30 | | - err :: String, |
31 | | - mode :: String |
| 29 | +data Options = Options { source :: String, |
| 30 | + output :: String, |
| 31 | + err :: String, |
| 32 | + mode :: String, |
| 33 | + baseModule :: Maybe String, |
| 34 | + baseSymbols :: Maybe String |
32 | 35 | } deriving (Show) |
33 | 36 |
|
34 | 37 | main = execParser opts >>= runWithOptions |
35 | 38 | where |
36 | | - parser = Options <$> argument str ( metavar "SourceFile" |
37 | | - <> help "Location of source file" ) |
38 | | - <*> strOption ( long "output" |
39 | | - <> short 'o' |
40 | | - <> metavar "OutputFile" |
41 | | - <> help "Location of output file" ) |
42 | | - <*> strOption ( long "error" |
43 | | - <> short 'e' |
44 | | - <> metavar "ErrorFile" |
45 | | - <> help "Location of error file" ) |
46 | | - <*> strOption ( long "mode" |
47 | | - <> short 'm' |
48 | | - <> metavar "BuildMode" |
49 | | - <> help "Enter the mode of compilation" ) |
| 39 | + parser = Options <$> argument str ( metavar "SourceFile" |
| 40 | + <> help "Location of source file" ) |
| 41 | + <*> strOption ( long "output" |
| 42 | + <> short 'o' |
| 43 | + <> metavar "OutputFile" |
| 44 | + <> help "Location of output file" ) |
| 45 | + <*> strOption ( long "error" |
| 46 | + <> short 'e' |
| 47 | + <> metavar "ErrorFile" |
| 48 | + <> help "Location of error file" ) |
| 49 | + <*> strOption ( long "mode" |
| 50 | + <> short 'm' |
| 51 | + <> metavar "BuildMode" |
| 52 | + <> help "Enter the mode of compilation" ) |
| 53 | + <*> optional (strOption ( long "base-module" |
| 54 | + <> short 'b' |
| 55 | + <> metavar "BaseModule" |
| 56 | + <> help "Base module to build dependencies" )) |
| 57 | + <*> optional (strOption ( long "base-syms" |
| 58 | + <> short 's' |
| 59 | + <> metavar "BaseSyms" |
| 60 | + <> help "Location of base symbol file" )) |
50 | 61 | opts = info parser mempty |
51 | 62 |
|
| 63 | +optionsToStage :: Options -> Stage |
| 64 | +optionsToStage Options{..} = case (baseModule, baseSymbols) of |
| 65 | + (Just mod, Just syms) -> GenBase mod syms |
| 66 | + (Nothing, Just syms) -> UseBase syms |
| 67 | + (Nothing, Nothing) -> FullBuild |
| 68 | + _ -> error "--base-module must be used with --base-syms" |
| 69 | + |
52 | 70 | runWithOptions :: Options -> IO () |
53 | | -runWithOptions Options{..} = do |
| 71 | +runWithOptions opts@Options{..} = do |
54 | 72 | fileExists <- doesFileExist source |
55 | 73 | if fileExists |
56 | 74 | then do |
57 | | - compileOutput <- extractSource source output err mode |
| 75 | + compileOutput <- extractSource (optionsToStage opts) source output err mode |
58 | 76 | return () |
59 | 77 | else |
60 | 78 | putStrLn $ "File not found:" ++ (show source) |
61 | 79 |
|
62 | | -extractSource :: String -> String -> String -> String -> IO Bool |
63 | | -extractSource source out err mode = do |
64 | | - res <- compileSource source out err mode |
65 | | - case res of |
| 80 | +extractSource :: Stage -> String -> String -> String -> String -> IO Bool |
| 81 | +extractSource stage source out err mode = do |
| 82 | + res <- compileSource stage source out err mode |
| 83 | + case res of |
66 | 84 | True -> return True |
67 | 85 | False -> do |
68 | 86 | errMsg <- readFile err |
|
0 commit comments