From 8153cfc65975ffb837b959a058ea40339301e7d0 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 1 Apr 2009 18:32:39 +0000 Subject: [PATCH] Added code for full compilation mode to include the relevant C files from occam #USE directives, and link to the relevant object files --- Main.hs | 8 +++++++- backends/GenerateC.hs | 3 +++ config/CompilerCommands.hs.in | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index 05f0a60..ca5c396 100644 --- a/Main.hs +++ b/Main.hs @@ -285,9 +285,15 @@ compileFull inputFile moutputFile lift $ withOutputFile postCFile $ \h -> postCAnalyse sFile ((h,intErr),intErr) -- Compile this new "post" C file into an object file exec $ cCommand postCFile postOFile (csCompilerFlags optsPS) + + cs <- lift getCompState + let otherOFiles = [usedFile ++ ".o" + | usedFile <- Set.toList $ csUsedFiles cs] + + -- Link the object files into a binary when shouldLink $ - exec $ cLinkCommand [oFile, postOFile] outputFile (csCompilerLinkFlags optsPS) + exec $ cLinkCommand (oFile : postOFile : otherOFiles) outputFile (csCompilerLinkFlags optsPS) -- For C++, just compile the source file directly into a binary BackendCPPCSP -> diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 841ae4b..7aa1fbb 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -169,6 +169,9 @@ cgenTopLevel headerName s tell ["#include \"", dropPath headerName, "\"\n"] + sequence_ [tell ["#include \"", usedFile, ".h\"\n"] + | usedFile <- Set.toList $ csUsedFiles cs] + sequence_ [tell ["extern int ", nameString n, "_stack_size;\n"] | n <- (Set.toList $ csParProcs cs) ++ [A.Name emptyMeta n | A.NameDef diff --git a/config/CompilerCommands.hs.in b/config/CompilerCommands.hs.in index e4689e0..61e5daa 100644 --- a/config/CompilerCommands.hs.in +++ b/config/CompilerCommands.hs.in @@ -6,7 +6,7 @@ import Data.List import Paths tockIncludeFlags :: String -tockIncludeFlags = "-I" ++ pkgIncludeDir +tockIncludeFlags = "-I. -I" ++ pkgIncludeDir cCommand :: String -> String -> String -> String cCommand inp out extra = "@CC@ @TOCK_CFLAGS@ " ++ tockIncludeFlags ++ " -c -o " ++ out ++ " " ++ inp