From e3c426e870b6f7f08bf373753f5733bb279f3699 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 26 Nov 2008 12:48:48 +0000 Subject: [PATCH] Added full-compile support for the CHP backend --- Main.hs | 20 +++++++------------- backends/GenerateCHP.hs | 6 +++++- config/CompilerCommands.hs.in | 3 +++ configure.ac | 1 + 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Main.hs b/Main.hs index f458a55..7c6a085 100644 --- a/Main.hs +++ b/Main.hs @@ -276,11 +276,10 @@ compileFull inputFile moutputFile ("-", Nothing) -> dieReport (Nothing, "Must specify an output file when using full-compile mode") (file, _) -> return file - let (cExtension, hExtension) - = case csBackend optsPS of - BackendC -> (".tock.c", ".tock.h") - BackendCPPCSP -> (".tock.cpp", ".tock.hpp") - _ -> ("", "") + let extension = case csBackend optsPS of + BackendC -> ".c" + BackendCPPCSP -> ".cpp" + _ -> "" -- Translate input file to C/C++ let cFile = outputFile ++ cExtension @@ -331,14 +330,9 @@ compileFull inputFile moutputFile -- For C++, just compile the source file directly into a binary BackendCPPCSP -> - do cs <- lift getCompState - if csHasMain optsPS - then let otherOFiles = [usedFile ++ ".tock.o" - | usedFile <- Set.toList $ csUsedFiles cs] - in exec $ cxxCommand cFile outputFile - (concat (intersperse " " otherOFiles) ++ " " ++ csCompilerFlags optsPS ++ " " ++ csCompilerLinkFlags optsPS) - else exec $ cxxCommand cFile (outputFile ++ ".tock.o") - ("-c " ++ csCompilerFlags optsPS) + exec $ cxxCommand cFile outputFile + (csCompilerFlags optsPS ++ " " ++ csCompilerLinkFlags optsPS) + _ -> dieReport (Nothing, "Cannot use specified backend: " ++ show (csBackend optsPS) ++ " with full-compile mode") diff --git a/backends/GenerateCHP.hs b/backends/GenerateCHP.hs index 844b895..a517dcc 100644 --- a/backends/GenerateCHP.hs +++ b/backends/GenerateCHP.hs @@ -19,12 +19,16 @@ with this program. If not, see . -- | Generate CHP code from the AST module GenerateCHP where +import Control.Monad.Trans import System.IO import qualified AST as A import Pass generateCHP :: Handle -> A.AST -> PassM () -generateCHP h tr = genAST tr +generateCHP h tr = do + liftIO $ hPutStrLn h "main :: IO ()" + liftIO $ hPutStrLn h "main = return ()" + genAST tr genAST _ = return () diff --git a/config/CompilerCommands.hs.in b/config/CompilerCommands.hs.in index 61e5daa..0e0aed9 100644 --- a/config/CompilerCommands.hs.in +++ b/config/CompilerCommands.hs.in @@ -23,3 +23,6 @@ cLinkCommand files out extra = "@CC@ @TOCK_CFLAGS@ -o " ++ out ++ " " ++ (concat cxxCommand :: String -> String -> String -> String cxxCommand inp out extra = "@CXX@ @TOCK_CXXFLAGS@ " ++ tockIncludeFlags ++ " -o " ++ out ++ " " ++ inp ++ " @TOCK_CXXLDFLAGS@" ++ " " ++ extra + +hCommand :: String -> String -> String +hCommand inp out = "@GHC@ --make " ++ inp ++ " -o " ++ out diff --git a/configure.ac b/configure.ac index 1d7aa44..902c40d 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,7 @@ AC_DEFUN([AC_NEED_PROG], #Check that they have alex, GHC, svn and the CCSP headers: AC_NEED_PROG(ghc,HAVE_ghc) +AC_PATH_PROG(GHC,ghc) AC_NEED_PROG(ghc-pkg,HAVE_ghcpkg) AC_NEED_PROG(alex,HAVE_alex)