on 2b258db help sign in
52 lines 1.4 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
17import Util.System
19data Opts = Opts { inputs :: [FilePath],
20 interface :: Bool,
21 output :: FilePath }
23showUsage = do putStrLn "Usage: idris-c <ibc-files> [-o <output-file>]"
24 exitWith ExitSuccess
26getOpts :: IO Opts
27getOpts = do xs <- getArgs
28 return $ process (Opts [] False "a.out") xs
29 where
30 process opts ("-o":o:xs) = process (opts { output = o }) xs
31 process opts ("--interface":xs) = process (opts { interface = True }) xs
32 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
33 process opts [] = opts
35c_main :: Opts -> Idris ()
36c_main opts = do runIO setupBundledCC
37 elabPrims
38 loadInputs (inputs opts) Nothing
39 mainProg <- if interface opts
40 then liftM Just elabMain
41 else return Nothing
42 ir <- compile (Via "c") (output opts) mainProg
43 runIO $ codegenC ir
45main :: IO ()
46main = do opts <- getOpts
47 if (null (inputs opts))
48 then showUsage
49 else runMain (c_main opts)