\section{Code output phase}
\begin{code}
-{-# OPTIONS_GHC -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
--- http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
--- for details
-
module CodeOutput( codeOutput, outputForeignStubs ) where
#include "HsVersions.h"
import PprC ( writeCs )
import CmmLint ( cmmLint )
import Packages
-import PackageConfig ( rtsPackageId )
import Util
import FastString ( unpackFS )
import Cmm ( RawCmm )
import ErrUtils ( dumpIfSet_dyn, showPass, ghcExit )
import Outputable
-import Pretty ( Mode(..), printDoc )
-import Module ( Module, ModLocation(..), moduleName )
+import Module
import List ( nub )
import Maybes ( firstJust )
#else
panic "Java support not compiled into this ghc";
#endif
+ HscNothing -> panic "codeOutput: HscNothing"
}
; return stubs_exist
}
%************************************************************************
\begin{code}
+outputC :: DynFlags
+ -> FilePath -> Module -> ModLocation
+ -> [RawCmm]
+ -> (Bool, Bool)
+ -> [PackageId]
+ -> ForeignStubs
+ -> IO ()
+
outputC dflags filenm mod location flat_absC
(stub_h_exists, _) packages foreign_stubs
= do
hPutStr h ("/* GHC_PACKAGES " ++ unwords pkg_names ++ "\n*/\n")
hPutStr h cc_injects
when stub_h_exists $
- hPutStrLn h ("#include \"" ++ (filenameOf stub_h) ++ "\"")
+ hPutStrLn h ("#include \"" ++ inc_stub_h ++ "\"")
writeCs dflags h flat_absC
where
- (_, stub_h) = mkStubPaths dflags (moduleName mod) location
+ (_, _, inc_stub_h) = mkStubPaths dflags (moduleName mod) location
\end{code}
%************************************************************************
\begin{code}
+outputAsm :: DynFlags -> FilePath -> [RawCmm] -> IO ()
outputAsm dflags filenm flat_absC
#ifndef OMIT_NATIVE_CODEGEN
= do ncg_uniqs <- mkSplitUniqSupply 'n'
- ncg_output_d <- {-# SCC "NativeCodeGen" #-}
- nativeCodeGen dflags flat_absC ncg_uniqs
- dumpIfSet_dyn dflags Opt_D_dump_asm "Asm code" (docToSDoc ncg_output_d)
+
{-# SCC "OutputAsm" #-} doOutput filenm $
- \f -> printDoc LeftMode f ncg_output_d
+ \f -> {-# SCC "NativeCodeGen" #-}
+ nativeCodeGen dflags f ncg_uniqs flat_absC
where
#else /* OMIT_NATIVE_CODEGEN */
-> IO (Bool, -- Header file created
Bool) -- C file created
outputForeignStubs dflags mod location stubs
- | NoStubs <- stubs = do
+ = 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)
- | ForeignStubs h_code c_code _ <- stubs
- = do
+ ForeignStubs h_code c_code _ -> do
let
stub_c_output_d = pprCode CStyle c_code
stub_c_output_w = showSDoc stub_c_output_d
return (stub_h_file_exists, stub_c_file_exists)
where
- (stub_c, stub_h) = mkStubPaths dflags (moduleName mod) location
+ (stub_c, stub_h, _) = mkStubPaths dflags (moduleName mod) location
+
+ cplusplus_hdr = "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
+ cplusplus_ftr = "#ifdef __cplusplus\n}\n#endif\n"
-cplusplus_hdr = "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
-cplusplus_ftr = "#ifdef __cplusplus\n}\n#endif\n"
-- Don't use doOutput for dumping the f. export stubs
-- since it is more than likely that the stubs file will
-- turn out to be empty, in which case no file should be created.
-outputForeignStubs_help fname "" header footer = return False
+outputForeignStubs_help :: FilePath -> String -> String -> String -> IO Bool
+outputForeignStubs_help _fname "" _header _footer = return False
outputForeignStubs_help fname doc_str header footer
= do writeFile fname (header ++ doc_str ++ '\n':footer ++ "\n")
return True