Commit d1545b69 authored by David Himmelstrup's avatar David Himmelstrup
Browse files

More work thrown at HscMain.

MkIface.writeIfaceFile doesn't check GhcMode anymore. All it does
is what the name say: write an interface to disk.
I've refactored HscMain so the logic is easier to manage. That means
we can avoid running the simplifier when typechecking (: And best of
all, HscMain doesn't use GhcMode at all, anymore!

The new HscMain intro looks like this:

It's the task of the compilation proper to compile Haskell, hs-boot and
core files to either byte-code, hard-code (C, asm, Java, ect) or to
nothing at all (the module is still parsed and type-checked. This
feature is mostly used by IDE's and the likes).
Compilation can happen in either 'one-shot', 'batch', 'nothing',
or 'interactive' mode. 'One-shot' mode targets hard-code, 'batch' mode
targets hard-code, 'nothing' mode targets nothing and 'interactive' mode
targets byte-code.
The modes are kept separate because of their different types and meanings.
In 'one-shot' mode, we're only compiling a single file and can therefore
discard the new ModIface and ModDetails. This is also the reason it only
targets hard-code; compiling to byte-code or nothing doesn't make sense
when we discard the result.
'Batch' mode is like 'one-shot' except that we keep the resulting ModIface
and ModDetails. 'Batch' mode doesn't target byte-code since that require
us to return the newly compiled byte-code.
'Nothing' mode has exactly the same type as 'batch' mode but they're still
kept separate. This is because compiling to nothing is fairly special: We
don't output any interface files, we don't run the simplifier and we don't
generate any code.
'Interactive' mode is similar to 'batch' mode except that we return the
compiled byte-code together with the ModIface and ModDetails.
parent abf158bf
......@@ -336,18 +336,11 @@ mkIface hsc_env maybe_old_iface
writeIfaceFile :: HscEnv -> ModLocation -> ModIface -> Bool -> IO ()
-- Write the interface file, if necessary
writeIfaceFile hsc_env location new_iface no_change_at_all
| no_change_at_all = return ()
| ghc_mode == Interactive = return ()
| ghc_mode == JustTypecheck = return ()
| otherwise
= do { createDirectoryHierarchy (directoryOf hi_file_path)
; writeBinIface hi_file_path new_iface }
ghc_mode = ghcMode (hsc_dflags hsc_env)
hi_file_path = ml_hi_file location
writeIfaceFile :: ModLocation -> ModIface -> IO ()
writeIfaceFile location new_iface
= do createDirectoryHierarchy (directoryOf hi_file_path)
writeBinIface hi_file_path new_iface
where hi_file_path = ml_hi_file location
......@@ -171,10 +171,10 @@ compile hsc_env mod_summary maybe_old_linkable old_iface mod_index nmods = do
= do stub_o <- compileStub dflags' this_mod location
return [ DotO stub_o ]
handleMake (HscNoRecomp, iface, details)
handleBatch (HscNoRecomp, iface, details)
= ASSERT (isJust maybe_old_linkable)
return (CompOK details iface maybe_old_linkable)
handleMake (HscRecomp hasStub, iface, details)
handleBatch (HscRecomp hasStub, iface, details)
| isHsBoot src_flavour
= return (CompOK details iface Nothing)
| otherwise
......@@ -223,8 +223,10 @@ compile hsc_env mod_summary maybe_old_linkable old_iface mod_index nmods = do
HscInterpreted | not (isHsBoot src_flavour) -- We can't compile boot files to
-- bytecode so don't even try.
-> runCompiler hscCompileInteractive handleInterpreted
-> runCompiler hscCompileNothing handleBatch
-> runCompiler hscCompileMake handleMake
-> runCompiler hscCompileBatch handleBatch
-- stub .h and .c files (for foreign export support)
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment