on 7d42ba2 help sign in
49 lines 1.3 kB history raw
1module Main where
3import Idris.Core.TT
4import Idris.AbsSyntax
5import Idris.ElabDecls
6import Idris.REPL
8import IRTS.Compiler
9import IRTS.CodegenC
11import System.Environment
12import System.Exit
13import Control.Monad
15import Paths_idris
17data Opts = Opts { inputs :: [FilePath],
18 interface :: Bool,
19 output :: FilePath }
21showUsage = do putStrLn "Usage: idris-c <ibc-files> [-o <output-file>]"
22 exitWith ExitSuccess
24getOpts :: IO Opts
25getOpts = do xs <- getArgs
26 return $ process (Opts [] False "a.out") xs
27 where
28 process opts ("-o":o:xs) = process (opts { output = o }) xs
29 process opts ("--interface":xs) = process (opts { interface = True }) xs
30 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
31 process opts [] = opts
33c_main :: Opts -> Idris ()
34c_main opts = do elabPrims
35 loadInputs (inputs opts) Nothing
36 mainProg <- if interface opts
37 then liftM Just elabMain
38 else return Nothing
39 ir <- compile (Via "c") (output opts) mainProg
40 runIO $ codegenC ir
42main :: IO ()
43main = do opts <- getOpts
44 if (null (inputs opts))
45 then showUsage
46 else runMain (c_main opts)