X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FCodeOutput.lhs;h=e7e818fa50b3d255a08141ca7750d2015bdb663e;hb=6a05ec5ef5373f61b7f9f5bdc344483417fa801b;hp=6b07eadd65ddaac169ca6e056647c4e4d17c5393;hpb=17b297d97d327620ed6bfab942f8992b2446f1bf;p=ghc-hetmet.git diff --git a/compiler/main/CodeOutput.lhs b/compiler/main/CodeOutput.lhs index 6b07ead..e7e818f 100644 --- a/compiler/main/CodeOutput.lhs +++ b/compiler/main/CodeOutput.lhs @@ -4,13 +4,6 @@ \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" @@ -30,7 +23,6 @@ import Finder ( mkStubPaths ) import PprC ( writeCs ) import CmmLint ( cmmLint ) import Packages -import PackageConfig ( rtsPackageId ) import Util import FastString ( unpackFS ) import Cmm ( RawCmm ) @@ -39,8 +31,7 @@ import DynFlags 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 ) @@ -98,6 +89,7 @@ codeOutput dflags this_mod location foreign_stubs pkg_deps flat_abstractC #else panic "Java support not compiled into this ghc"; #endif + HscNothing -> panic "codeOutput: HscNothing" } ; return stubs_exist } @@ -114,6 +106,14 @@ doOutput filenm io_action = bracket (openFile filenm WriteMode) hClose io_action %************************************************************************ \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 @@ -151,10 +151,10 @@ outputC dflags filenm mod location flat_absC 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} @@ -165,16 +165,16 @@ outputC dflags filenm mod location flat_absC %************************************************************************ \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 */ @@ -217,15 +217,15 @@ outputForeignStubs :: DynFlags -> Module -> ModLocation -> ForeignStubs -> 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 @@ -266,15 +266,17 @@ outputForeignStubs dflags mod location stubs 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