From 90986ea97b6a78df6815f503459535197340246c Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 17 May 2008 22:20:38 +0000 Subject: [PATCH] Added a backend that prints out the AST as source (rather than dumping the raw AST) --- Main.hs | 8 ++++++-- data/CompState.hs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Main.hs b/Main.hs index c2fbf82..ecfbd15 100644 --- a/Main.hs +++ b/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 "}}}" diff --git a/data/CompState.hs b/data/CompState.hs index 9a4d93c..dcaa775 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -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.