on d773edd help sign in
49 lines 1.5 kB history raw
1module Main where
3import Idris.AbsSyntax
4import Idris.ElabDecls
5import Idris.Main
6import Idris.Options
7import IRTS.CodegenC
8import IRTS.Compiler
10import Util.System
12import Control.Monad
13import System.Environment
14import System.Exit
18data Opts = Opts { inputs :: [FilePath],
19 interface :: Bool,
20 output :: FilePath }
22showUsage = do putStrLn "A code generator which is intended to be called by the compiler, not by a user."
23 putStrLn "Usage: idris-codegen-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 IBCFormat "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)