Added backend-selecting command-line options

This commit is contained in:
Neil Brown 2007-07-26 21:18:27 +00:00
parent ba60da71d6
commit fa9c108e50
2 changed files with 21 additions and 3 deletions

View File

@ -16,6 +16,7 @@ data CompState = CompState {
csVerboseLevel :: Int, csVerboseLevel :: Int,
csParseOnly :: Bool, csParseOnly :: Bool,
csOutputFile :: String, csOutputFile :: String,
csBackend :: String,
-- Set by preprocessor -- Set by preprocessor
csSourceFiles :: Map String String, csSourceFiles :: Map String String,
@ -47,6 +48,7 @@ emptyState = CompState {
csVerboseLevel = 0, csVerboseLevel = 0,
csParseOnly = False, csParseOnly = False,
csOutputFile = "-", csOutputFile = "-",
csBackend = "CIF",
csSourceFiles = Map.empty, csSourceFiles = Map.empty,
csIndentLinesIn = [], csIndentLinesIn = [],

22
Main.hs
View File

@ -12,6 +12,7 @@ import System.IO
import CompState import CompState
import Errors import Errors
import GenerateC import GenerateC
import GenerateCPPCSP
import Parse import Parse
import Pass import Pass
import PrettyShow import PrettyShow
@ -34,6 +35,7 @@ options :: [OptDescr OptFunc]
options = options =
[ Option [] ["parse-only"] (NoArg optParseOnly) "only parse input file" [ Option [] ["parse-only"] (NoArg optParseOnly) "only parse input file"
, Option ['v'] ["verbose"] (NoArg $ optVerbose) "be more verbose (use multiple times for more detail)" , Option ['v'] ["verbose"] (NoArg $ optVerbose) "be more verbose (use multiple times for more detail)"
, Option [] ["backend"] (ReqArg optBackend "BACKEND") "backend (options: CIF, CPPCSP)"
, Option ['o'] ["output"] (ReqArg optOutput "FILE") "output file (default \"-\")" , Option ['o'] ["output"] (ReqArg optOutput "FILE") "output file (default \"-\")"
] ]
@ -46,6 +48,9 @@ optVerbose ps = return $ ps { csVerboseLevel = csVerboseLevel ps + 1 }
optOutput :: String -> OptFunc optOutput :: String -> OptFunc
optOutput s ps = return $ ps { csOutputFile = s } optOutput s ps = return $ ps { csOutputFile = s }
optBackend :: String -> OptFunc
optBackend s ps = return $ ps { csBackend = s }
getOpts :: [String] -> IO ([OptFunc], [String]) getOpts :: [String] -> IO ([OptFunc], [String])
getOpts argv = getOpts argv =
case getOpt RequireOrder options argv of case getOpt RequireOrder options argv of
@ -96,9 +101,20 @@ compile fn
do progress "Passes:" do progress "Passes:"
ast2 <- (runPasses passes) ast1 ast2 <- (runPasses passes) ast1
debug "{{{ Generate C" debug "{{{ Generate Code"
progress "Generate C" c <-
c <- generateC ast2 case csBackend optsPS of
"CPPCSP" ->
do progress "Generate C++CSP"
c' <- generateCPPCSP ast2
return c'
"CIF" ->
do progress "Generate C/CIF"
c' <- generateC ast2
return c'
_ ->
do error ("Unknown backend: " ++ (csBackend optsPS))
debug "}}}" debug "}}}"
return c return c