on ea65347 help sign in
51 lines 1.5 kB history raw
1module Main where
3import Idris.AbsSyntax
4import Idris.Core.TT
5import Idris.ElabDecls
6import Idris.Main
7import IRTS.CodegenC
8import IRTS.Compiler
10import Util.System
12import Paths_idris
14import Control.Monad
15import System.Environment
16import System.Exit
20data Opts = Opts { inputs :: [FilePath],
21 interface :: Bool,
22 output :: FilePath }
24showUsage = do putStrLn "A code generator which is intended to be called by the compiler, not by a user."
25 putStrLn "Usage: idris-codegen-c <ibc-files> [-o <output-file>]"
26 exitWith ExitSuccess
28getOpts :: IO Opts
29getOpts = do xs <- getArgs
30 return $ process (Opts [] False "a.out") xs
31 where
32 process opts ("-o":o:xs) = process (opts { output = o }) xs
33 process opts ("--interface":xs) = process (opts { interface = True }) xs
34 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
35 process opts [] = opts
37c_main :: Opts -> Idris ()
38c_main opts = do runIO setupBundledCC
39 elabPrims
40 loadInputs (inputs opts) Nothing
41 mainProg <- if interface opts
42 then liftM Just elabMain
43 else return Nothing
44 ir <- compile (Via IBCFormat "c") (output opts) mainProg
45 runIO $ codegenC ir
47main :: IO ()
48main = do opts <- getOpts
49 if (null (inputs opts))
50 then showUsage
51 else runMain (c_main opts)