+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Java}
+%* *
+%************************************************************************
+
+\begin{code}
+#ifdef JAVA
+outputJava dflags filenm mod tycons core_binds
+ = doOutput filenm (\ f -> printForUser f alwaysQualify pp_java)
+ -- User style printing for now to keep indentation
+ where
+ occ_anal_binds = occurAnalyseBinds core_binds
+ -- Make sure we have up to date dead-var information
+ java_code = javaGen mod [{- Should be imports-}] tycons occ_anal_binds
+ pp_java = PrintJava.compilationUnit java_code
+#endif
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Ilx}
+%* *
+%************************************************************************
+
+\begin{code}
+#ifdef ILX
+outputIlx dflags filename mod tycons stg_binds
+ = doOutput filename (\ f -> printForC f pp_ilx)
+ where
+ pp_ilx = ilxGen mod tycons stg_binds
+#endif
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Foreign import/export}
+%* *
+%************************************************************************
+
+\begin{code}
+outputForeignStubs :: DynFlags -> Module -> ModLocation -> ForeignStubs
+ -> IO (Bool, -- Header file created
+ Bool) -- C file created
+outputForeignStubs dflags mod location stubs
+ | NoStubs <- stubs = 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
+ let
+ stub_c_output_d = pprCode CStyle c_code
+ stub_c_output_w = showSDoc stub_c_output_d
+
+ -- Header file protos for "foreign export"ed functions.
+ stub_h_output_d = pprCode CStyle h_code
+ stub_h_output_w = showSDoc stub_h_output_d
+ -- in
+
+ createDirectoryHierarchy (directoryOf stub_c)
+
+ dumpIfSet_dyn dflags Opt_D_dump_foreign
+ "Foreign export header file" stub_h_output_d
+
+ -- we need the #includes from the rts package for the stub files
+ let rtsid = rtsPackageId (pkgState dflags)
+ rts_includes
+ | ExtPackage pid <- rtsid =
+ let rts_pkg = getPackageDetails (pkgState dflags) pid in
+ concatMap mk_include (includes rts_pkg)
+ | otherwise = []
+ mk_include i = "#include \"" ++ i ++ "\"\n"
+
+ stub_h_file_exists
+ <- outputForeignStubs_help stub_h stub_h_output_w
+ ("#include \"HsFFI.h\"\n" ++ cplusplus_hdr) cplusplus_ftr
+
+ dumpIfSet_dyn dflags Opt_D_dump_foreign
+ "Foreign export stubs" stub_c_output_d
+
+ stub_c_file_exists
+ <- outputForeignStubs_help stub_c stub_c_output_w
+ ("#define IN_STG_CODE 0\n" ++
+ "#include \"Rts.h\"\n" ++
+ rts_includes ++
+ cplusplus_hdr)
+ cplusplus_ftr
+ -- We're adding the default hc_header to the stub file, but this
+ -- 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 mod location