summaryrefslogtreecommitdiff
path: root/compiler/main/CodeOutput.lhs
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-01-31 10:32:24 +0000
committerSimon Marlow <marlowsd@gmail.com>2011-04-05 14:12:19 +0100
commit7b0ff1792d699ff02a604163c9ccf4a98a1ca3eb (patch)
tree39d13b2316841d8566e9dfda06fe6b9a07aa389f /compiler/main/CodeOutput.lhs
parent0ce8f5e727dfb59857a0f6e34d7617796e76baac (diff)
downloadhaskell-7b0ff1792d699ff02a604163c9ccf4a98a1ca3eb.tar.gz
Merge _stub.o files into the main .o file (Fixes #3687 and #706)
Now GHC still generates the _stub.c files, but the object file is automatically merged into the main .o file for a module. This means that build systems (including GHC's own) no longer need to worry about looking for _stub.o files and including them when linking. I had to do lots of refactoring in DriverPipeline to make this work; now there's a monad to carry around all the information, and everything is a lot tidier. The _stub.c is now created as a temporary file and removed after compilation (unless the -keep-tmp-files flag is on).
Diffstat (limited to 'compiler/main/CodeOutput.lhs')
-rw-r--r--compiler/main/CodeOutput.lhs30
1 files changed, 17 insertions, 13 deletions
diff --git a/compiler/main/CodeOutput.lhs b/compiler/main/CodeOutput.lhs
index 85f34025fc..e9906a6c5b 100644
--- a/compiler/main/CodeOutput.lhs
+++ b/compiler/main/CodeOutput.lhs
@@ -30,6 +30,7 @@ import OldCmm ( RawCmm )
import HscTypes
import DynFlags
import Config
+import SysTools
import ErrUtils ( dumpIfSet_dyn, showPass, ghcExit )
import Outputable
@@ -56,7 +57,7 @@ codeOutput :: DynFlags
-> ForeignStubs
-> [PackageId]
-> [RawCmm] -- Compiled C--
- -> IO (Bool{-stub_h_exists-}, Bool{-stub_c_exists-})
+ -> IO (Bool{-stub_h_exists-}, Maybe FilePath{-stub_c_exists-})
codeOutput dflags this_mod location foreign_stubs pkg_deps flat_abstractC
=
@@ -212,18 +213,21 @@ outputJava dflags filenm mod tycons core_binds
\begin{code}
outputForeignStubs :: DynFlags -> Module -> ModLocation -> ForeignStubs
-> IO (Bool, -- Header file created
- Bool) -- C file created
+ Maybe FilePath) -- C file created
outputForeignStubs dflags mod location stubs
- = case stubs of
- NoStubs -> do
+ = do
+ let stub_h = mkStubPaths dflags (moduleName mod) location
+ stub_c <- newTempName dflags "c"
+
+ case stubs of
+ NoStubs -> do
-- When compiling External Core files, may need to use stub
-- files from a previous compilation
- stub_c_exists <- doesFileExist stub_c
- stub_h_exists <- doesFileExist stub_h
- return (stub_h_exists, stub_c_exists)
+ stub_h_exists <- doesFileExist stub_h
+ return (stub_h_exists, Nothing)
- ForeignStubs h_code c_code -> do
- let
+ ForeignStubs h_code c_code -> do
+ let
stub_c_output_d = pprCode CStyle c_code
stub_c_output_w = showSDoc stub_c_output_d
@@ -266,10 +270,10 @@ outputForeignStubs dflags mod location stubs
-- isn't really HC code, so we need to define IN_STG_CODE==0 to
-- avoid the register variables etc. being enabled.
- return (stub_h_file_exists, stub_c_file_exists)
- where
- (stub_c, stub_h, _) = mkStubPaths dflags (moduleName mod) location
-
+ return (stub_h_file_exists, if stub_c_file_exists
+ then Just stub_c
+ else Nothing )
+ where
cplusplus_hdr = "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
cplusplus_ftr = "#ifdef __cplusplus\n}\n#endif\n"