Added a backend that prints out the AST as source (rather than dumping the raw AST)
This commit is contained in:
parent
e53fda754e
commit
90986ea97b
8
Main.hs
8
Main.hs
|
@ -49,13 +49,14 @@ import Pass
|
|||
import PassList
|
||||
import PreprocessOccam
|
||||
import PrettyShow
|
||||
import ShowCode
|
||||
import Utils
|
||||
|
||||
type OptFunc = CompState -> IO CompState
|
||||
|
||||
options :: [OptDescr OptFunc]
|
||||
options =
|
||||
[ Option [] ["backend"] (ReqArg optBackend "BACKEND") "code-generating backend (options: c, cppcsp, dumpast)"
|
||||
[ Option [] ["backend"] (ReqArg optBackend "BACKEND") "code-generating backend (options: c, cppcsp, dumpast,src)"
|
||||
, Option ['h'] ["help"] (NoArg optPrintHelp) "print this help"
|
||||
, Option ['k'] ["keep-temporaries"] (NoArg $ optKeepTemporaries) "keep temporary files"
|
||||
, Option [] ["frontend"] (ReqArg optFrontend "FRONTEND") "language frontend (options: occam, rain)"
|
||||
|
@ -83,6 +84,7 @@ optBackend s ps
|
|||
"c" -> return BackendC
|
||||
"cppcsp" -> return BackendCPPCSP
|
||||
"dumpast" -> return BackendDumpAST
|
||||
"src" -> return BackendSource
|
||||
_ -> dieIO (Nothing, "Unknown backend: " ++ s)
|
||||
return $ ps { csBackend = backend }
|
||||
|
||||
|
@ -315,11 +317,13 @@ compile mode fn outHandle
|
|||
|
||||
debug "{{{ Generate code"
|
||||
progress $ "- Backend: " ++ (show $ csBackend optsPS)
|
||||
let generator
|
||||
let generator :: A.AST -> PassM ()
|
||||
generator
|
||||
= case csBackend optsPS of
|
||||
BackendC -> generateC outHandle
|
||||
BackendCPPCSP -> generateCPPCSP outHandle
|
||||
BackendDumpAST -> liftIO . hPutStr outHandle . pshow
|
||||
BackendSource -> (liftIO . hPutStr outHandle) <.< showCode
|
||||
generator ast2
|
||||
debug "}}}"
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ data CompMode = ModeFlowGraph | ModeParse | ModeCompile | ModePostC | ModeFull
|
|||
deriving (Show, Data, Typeable, Eq)
|
||||
|
||||
-- | Backends that Tock can use.
|
||||
data CompBackend = BackendC | BackendCPPCSP | BackendDumpAST
|
||||
data CompBackend = BackendC | BackendCPPCSP | BackendDumpAST | BackendSource
|
||||
deriving (Show, Data, Typeable, Eq)
|
||||
|
||||
-- | Frontends that Tock can use.
|
||||
|
|
Loading…
Reference in New Issue
Block a user