-doOutput filenm io_action
- = (do handle <- openFile filenm WriteMode
- io_action handle
- hClose handle)
- `catch` (\err -> pprPanic "Failed to open or write code output file"
- (text filenm))
+doOutput filenm io_action = bracket (openFile filenm WriteMode) hClose io_action
let (stix_final, ncg_output_d) = _scc_ "NativeCodeGen"
nativeCodeGen flat_absC ncg_uniqs
dumpIfSet_dyn dflags Opt_D_dump_stix "Final stix code" stix_final
let (stix_final, ncg_output_d) = _scc_ "NativeCodeGen"
nativeCodeGen flat_absC ncg_uniqs
dumpIfSet_dyn dflags Opt_D_dump_stix "Final stix code" stix_final
- dumpIfSet_dyn dflags Opt_D_dump_asm "Asm code" ncg_output_d
- _scc_ "OutputAsm" doOutput filenm ( \f -> printForAsm f ncg_output_d)
+ dumpIfSet_dyn dflags Opt_D_dump_asm "Asm code" (docToSDoc ncg_output_d)
+ _scc_ "OutputAsm" doOutput filenm $
+ \f -> printDoc LeftMode f ncg_output_d
outputJava dflags filenm mod tycons core_binds
= doOutput filenm (\ f -> printForUser f alwaysQualify pp_java)
-- User style printing for now to keep indentation
outputJava dflags filenm mod tycons core_binds
= doOutput filenm (\ f -> printForUser f alwaysQualify pp_java)
-- User style printing for now to keep indentation
-- 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
-- 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
-- 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.
-- 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.
-- 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.
-- 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 "" injects = return False
-outputForeignStubs_help fname doc_str injects
- = do writeFile fname (injects ++ doc_str)
+outputForeignStubs_help fname "" header footer = return False
+outputForeignStubs_help fname doc_str header footer
+ = do writeFile fname (header ++ doc_str ++ '\n':footer ++ "\n")