@@ -16,17 +16,21 @@ import Paths_idris
17import Util.System
17import Util.System
19+data Opts = Opts { really :: Bool,
19−data Opts = Opts { inputs :: [FilePath],
20+ inputs :: [FilePath],
20 interface :: Bool,
21 interface :: Bool,
21 output :: FilePath }
22 output :: FilePath }
24+showUsage = do putStrLn "A code generator which is intended to be called by the compiler, not by a user."
25+ putStrLn "To call the code generator manually, pass the --yes-really option.\n"
23−showUsage = do putStrLn "Usage: idris-c <ibc-files> [-o <output-file>]"
26+ putStrLn "Usage: idris-codegen-c [--yes-really] <ibc-files> [-o <output-file>]"
24 exitWith ExitSuccess
27 exitWith ExitSuccess
26getOpts :: IO Opts
29getOpts :: IO Opts
27getOpts = do xs <- getArgs
30getOpts = do xs <- getArgs
28− return $ process (Opts [] False "a.out") xs
31+ return $ process (Opts False [] False "a.out") xs
33+ process opts ("--yes-really":xs) = process (opts { really = True }) xs
30 process opts ("-o":o:xs) = process (opts { output = o }) xs
34 process opts ("-o":o:xs) = process (opts { output = o }) xs
31 process opts ("--interface":xs) = process (opts { interface = True }) xs
35 process opts ("--interface":xs) = process (opts { interface = True }) xs
32 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
36 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
@@ -36,7 +40,7 @@ c_main :: Opts -> Idris ()
36c_main opts = do runIO setupBundledCC
40c_main opts = do runIO setupBundledCC
38 loadInputs (inputs opts) Nothing
42 loadInputs (inputs opts) Nothing
39− mainProg <- if interface opts
43+ mainProg <- if interface opts
40 then liftM Just elabMain
44 then liftM Just elabMain
41 else return Nothing
45 else return Nothing
42 ir <- compile (Via "c") (output opts) mainProg
46 ir <- compile (Via "c") (output opts) mainProg
@@ -44,9 +48,10 @@ c_main opts = do runIO setupBundledCC
45main :: IO ()
49main :: IO ()
46main = do opts <- getOpts
50main = do opts <- getOpts
47− if (null (inputs opts))
51+ if (null (inputs opts))
48 then showUsage
52 then showUsage
53+ else if (not $ really opts)
54+ then do putStrLn "This code generator is intended to be called by the Idris compiler. \
55+ \Please pass Idris the '--codegen' flag to choose a backend."
49− else runMain (c_main opts)
57+ else runMain (c_main opts)