@@ -8,57 +8,55 @@ exiting with status code, etc.
8
8
module Main where
9
9
10
10
import qualified Codegen
11
- import Common.Compiler ( passIO )
12
- import Common.Default ( Default (.. ) )
11
+ import Common.Compiler ( passIO )
12
+ import Common.Default ( Default (.. ))
13
13
import qualified Front
14
14
import qualified IR
15
15
16
- import Control.Monad ( unless
17
- , when
18
- )
19
- import System.Console.GetOpt ( ArgDescr (.. )
20
- , ArgOrder (.. )
21
- , OptDescr (.. )
22
- , getOpt
23
- , getOpt'
24
- , usageInfo
25
- )
26
- import System.Environment ( getArgs
27
- , getProgName
28
- )
29
- import System.Exit ( exitFailure
30
- , exitSuccess
31
- )
32
- import System.IO ( hPutStr
33
- , hPutStrLn
34
- , stderr
35
- )
16
+ import System.Console.GetOpt (
17
+ ArgDescr (.. ),
18
+ ArgOrder (.. ),
19
+ OptDescr (.. ),
20
+ getOpt ,
21
+ getOpt' ,
22
+ usageInfo ,
23
+ )
24
+ import System.Environment (getArgs , getProgName )
25
+ import System.Exit (exitFailure , exitSuccess )
26
+ import System.IO (hPutStr , hPutStrLn , stderr )
27
+
28
+ import Control.Monad (unless , when )
29
+
36
30
37
31
-- | Print the usage message, collating options from each compiler stage.
38
32
usageMessage :: IO ()
39
33
usageMessage = do
40
34
prg <- getProgName
41
35
let header = " Usage: " ++ prg ++ " [options] <filename>"
42
- hPutStr stderr $ unlines
43
- [ header
44
- , " "
45
- , " When `-' is specified as the filename, input is read from stdin."
46
- , usageInfo " " options
47
- , usageInfo " " Front. options
48
- , usageInfo " " IR. options
49
- , usageInfo " " Codegen. options
50
- ]
36
+ hPutStr stderr $
37
+ unlines
38
+ [ header
39
+ , " "
40
+ , " When `-' is specified as the filename, input is read from stdin."
41
+ , usageInfo " " options
42
+ , usageInfo " " Front. options
43
+ , usageInfo " " IR. options
44
+ , usageInfo " " Codegen. options
45
+ ]
46
+
51
47
52
48
-- | CLI options.
53
49
options :: [OptDescr (IO () )]
54
50
options =
55
51
[Option " h" [" help" ] (NoArg $ usageMessage >> exitSuccess) " Print help" ]
56
52
53
+
57
54
-- | Read input from file or stdin.
58
55
readInput :: String -> IO String
59
- readInput " -" = getContents
56
+ readInput " -" = getContents
60
57
readInput filename = readFile filename
61
58
59
+
62
60
-- | Compiler executable entry point.
63
61
main :: IO ()
64
62
main = do
@@ -72,9 +70,9 @@ main = do
72
70
getOpt' RequireOrder IR. options $ iArgs' ++ iArgs
73
71
(cOpts, filenames, cErr) =
74
72
getOpt RequireOrder Codegen. options $ cArgs' ++ cArgs
75
- errors = cliErrors ++ fErr ++ iErr ++ cErr
76
- frontOpts = foldr ($) def fOpts
77
- irOpts = foldr ($) def iOpts
73
+ errors = cliErrors ++ fErr ++ iErr ++ cErr
74
+ frontOpts = foldr ($) def fOpts
75
+ irOpts = foldr ($) def iOpts
78
76
codegenOpts = foldr ($) def cOpts
79
77
80
78
mapM_ return cliActions
@@ -94,12 +92,12 @@ main = do
94
92
usageMessage
95
93
exitFailure
96
94
97
- input <- readInput $ head filenames
95
+ input <- readInput $ head filenames
98
96
(cStr, warnings) <-
99
- passIO
100
- $ Front. run frontOpts input
101
- >>= IR. run irOpts
102
- >>= Codegen. run codegenOpts
97
+ passIO $
98
+ Front. run frontOpts input
99
+ >>= IR. run irOpts
100
+ >>= Codegen. run codegenOpts
103
101
unless (null warnings) $ do
104
102
hPutStr stderr " Encountered warnings:"
105
103
hPutStr stderr $ show warnings
0 commit comments