on master help sign in
Merge pull request #2579 from suhr/explit-codegen

Avoid confusion between the compiler and codegens

commit5d6a5c41ebe099834e7216ace3e6066d86f10d0b authorNiklas Larsson <metaniklas@gmail.com> dateSun 6 Sep 2015, 19:42 (11 years ago) parent5be9e7cc382799
5 files changed+46−25
codegen/idris-c/Main.hs → codegen/idris-codegen-c/Main.hs+14−9 codegen/idris-javascript/Main.hs → codegen/idris-codegen-javascript/Main.hs+12−4 codegen/idris-node/Main.hs → codegen/idris-codegen-node/Main.hs+12−4 idris.cabal+6−6 src/IRTS/Compiler.hs+2−2
codegen/idris-c/Main.hs → codegen/idris-codegen-c/Main.hsrenamed+14−9
@@ -16,17 +16,21 @@ import Paths_idris
1616
1717import Util.System
1818
19−data Opts = Opts { inputs :: [FilePath],
19+data Opts = Opts { really :: Bool,
20+ inputs :: [FilePath],
2021 interface :: Bool,
2122 output :: FilePath }
2223
23−showUsage = do putStrLn "Usage: idris-c <ibc-files> [-o <output-file>]"
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"
26+ putStrLn "Usage: idris-codegen-c [--yes-really] <ibc-files> [-o <output-file>]"
2427 exitWith ExitSuccess
2528
2629getOpts :: IO Opts
2730getOpts = do xs <- getArgs
28− return $ process (Opts [] False "a.out") xs
31+ return $ process (Opts False [] False "a.out") xs
2932 where
33+ process opts ("--yes-really":xs) = process (opts { really = True }) xs
3034 process opts ("-o":o:xs) = process (opts { output = o }) xs
3135 process opts ("--interface":xs) = process (opts { interface = True }) xs
3236 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
@@ -36,7 +40,7 @@ c_main :: Opts -> Idris ()
3640c_main opts = do runIO setupBundledCC
3741 elabPrims
3842 loadInputs (inputs opts) Nothing
39− mainProg <- if interface opts
43+ mainProg <- if interface opts
4044 then liftM Just elabMain
4145 else return Nothing
4246 ir <- compile (Via "c") (output opts) mainProg
@@ -44,9 +48,10 @@ c_main opts = do runIO setupBundledCC
4448
4549main :: IO ()
4650main = do opts <- getOpts
47− if (null (inputs opts))
51+ if (null (inputs opts))
4852 then showUsage
49− else runMain (c_main opts)
50−
51−
52−
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."
56+ exitWith ExitSuccess
57+ else runMain (c_main opts)
codegen/idris-javascript/Main.hs → codegen/idris-codegen-javascript/Main.hsrenamed+12−4
@@ -13,17 +13,21 @@ import System.Exit
1313
1414import Paths_idris
1515
16−data Opts = Opts { inputs :: [FilePath]
16+data Opts = Opts { really :: Bool
17+ , inputs :: [FilePath]
1718 , output :: FilePath
1819 }
1920
20−showUsage = do putStrLn "Usage: idris-javascript <ibc-files> [-o <output-file>]"
21+showUsage = do putStrLn "A code generator which is intended to be called by the compiler, not by a user."
22+ putStrLn "To call the code generator manually, pass the --yes-really option.\n"
23+ putStrLn "Usage: idris-codegen-c [--yes-really] <ibc-files> [-o <output-file>]"
2124 exitWith ExitSuccess
2225
2326getOpts :: IO Opts
2427getOpts = do xs <- getArgs
25− return $ process (Opts [] "main.js") xs
28+ return $ process (Opts False [] "main.js") xs
2629 where
30+ process opts ("--yes-really":xs) = process (opts { really = True }) xs
2731 process opts ("-o":o:xs) = process (opts { output = o }) xs
2832 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
2933 process opts [] = opts
@@ -39,4 +43,8 @@ main :: IO ()
3943main = do opts <- getOpts
4044 if (null (inputs opts))
4145 then showUsage
42− else runMain (jsMain opts)
46+ else if (not $ really opts)
47+ then do putStrLn "This code generator is intended to be called by the Idris compiler. \
48+ \Please pass Idris the '--codegen' flag to choose a backend."
49+ exitWith ExitSuccess
50+ else runMain (jsMain opts)
codegen/idris-node/Main.hs → codegen/idris-codegen-node/Main.hsrenamed+12−4
@@ -13,17 +13,21 @@ import System.Exit
1313
1414import Paths_idris
1515
16−data Opts = Opts { inputs :: [FilePath]
16+data Opts = Opts { really :: Bool
17+ , inputs :: [FilePath]
1718 , output :: FilePath
1819 }
1920
20−showUsage = do putStrLn "Usage: idris-node <ibc-files> [-o <output-file>]"
21+showUsage = do putStrLn "A code generator which is intended to be called by the compiler, not by a user."
22+ putStrLn "To call the code generator manually, pass the --yes-really option.\n"
23+ putStrLn "Usage: idris-codegen-c [--yes-really] <ibc-files> [-o <output-file>]"
2124 exitWith ExitSuccess
2225
2326getOpts :: IO Opts
2427getOpts = do xs <- getArgs
25− return $ process (Opts [] "main.js") xs
28+ return $ process (Opts False [] "main.js") xs
2629 where
30+ process opts ("--yes-really":xs) = process (opts { really = True }) xs
2731 process opts ("-o":o:xs) = process (opts { output = o }) xs
2832 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
2933 process opts [] = opts
@@ -39,4 +43,8 @@ main :: IO ()
3943main = do opts <- getOpts
4044 if (null (inputs opts))
4145 then showUsage
42− else runMain (jsMain opts)
46+ else if (not $ really opts)
47+ then do putStrLn "This code generator is intended to be called by the Idris compiler. \
48+ \Please pass Idris the '--codegen' flag to choose a backend."
49+ exitWith ExitSuccess
50+ else runMain (jsMain opts)
idris.cabal+6−6
@@ -964,9 +964,9 @@ Executable idris
964964 ghc-prof-options: -auto-all -caf-all
965965 ghc-options: -threaded -rtsopts -funbox-strict-fields
966966
967−Executable idris-c
967+Executable idris-codegen-c
968968 Main-is: Main.hs
969− hs-source-dirs: codegen/idris-c
969+ hs-source-dirs: codegen/idris-codegen-c
970970
971971 Build-depends: idris
972972 , base
@@ -977,9 +977,9 @@ Executable idris-c
977977 ghc-prof-options: -auto-all -caf-all
978978 ghc-options: -threaded -rtsopts -funbox-strict-fields
979979
980−Executable idris-javascript
980+Executable idris-codegen-javascript
981981 Main-is: Main.hs
982− hs-source-dirs: codegen/idris-javascript
982+ hs-source-dirs: codegen/idris-codegen-javascript
983983
984984 Build-depends: idris
985985 , base
@@ -990,9 +990,9 @@ Executable idris-javascript
990990 ghc-prof-options: -auto-all -caf-all
991991 ghc-options: -threaded -rtsopts -funbox-strict-fields
992992
993−Executable idris-node
993+Executable idris-codegen-node
994994 Main-is: Main.hs
995− hs-source-dirs: codegen/idris-node
995+ hs-source-dirs: codegen/idris-codegen-node
996996
997997 Build-depends: idris
998998 , base
src/IRTS/Compiler.hs+2−2
@@ -135,8 +135,8 @@ generate codegen mainmod ir
135135 -- Built-in code generators (FIXME: lift these out!)
136136 Via "c" -> codegenC ir
137137 -- Any external code generator
138− Via cg -> do let cmd = "idris-" ++ cg
139− args = [mainmod, "-o", outputFile ir] ++ compilerFlags ir
138+ Via cg -> do let cmd = "idris-codegen-" ++ cg
139+ args = ["--yes-really", mainmod, "-o", outputFile ir] ++ compilerFlags ir
140140 exit <- rawSystem cmd args
141141 when (exit /= ExitSuccess) $
142142 putStrLn ("FAILURE: " ++ show cmd ++ " " ++ show args)