- ----------- ----- ---- --- -- -- - - -
- start = startPhase suffix
-
- -- special case for mkdependHS: .hspp files go through MkDependHS
- start_phase | todo == DoMkDependHS && start == Hsc = MkDependHS
- | otherwise = start
-
- haskellish = haskellish_suffix suffix
- cish = cish_suffix suffix
-
- -- for a .hc file we need to force lang to HscC
- real_lang | start_phase == HCc || start_phase == Mangle = HscC
- | otherwise = lang
-
- let
- ----------- ----- ---- --- -- -- - - -
- pipeline = preprocess ++ compile
-
- preprocess
- | haskellish = [ Unlit, Cpp, HsPp ]
- | otherwise = [ ]
-
- compile
- | todo == DoMkDependHS = [ MkDependHS ]
-
- | cish = [ Cc, As ]
-
- | haskellish =
- case real_lang of
- HscC | split && mangle -> [ Hsc, HCc, Mangle, SplitMangle, SplitAs ]
- | mangle -> [ Hsc, HCc, Mangle, As ]
- | split -> not_valid
- | otherwise -> [ Hsc, HCc, As ]
-
- HscAsm | split -> [ Hsc, SplitMangle, SplitAs ]
- | otherwise -> [ Hsc, As ]
-
- HscJava | split -> not_valid
- | otherwise -> error "not implemented: compiling via Java"
-#ifdef ILX
- HscILX | split -> not_valid
- | otherwise -> [ Hsc, Ilx2Il, Ilasm ]
-#endif
- HscNothing -> [ Hsc, HCc ] -- HCc is a dummy stop phase
-
- | otherwise = [ ] -- just pass this file through to the linker
-
- -- ToDo: this is somewhat cryptic
- not_valid = throwDyn (UsageError ("invalid option combination"))
-
- stop_phase = case todo of
- StopBefore As | split -> SplitAs
-#ifdef ILX
- | real_lang == HscILX -> Ilasm
-#endif
- StopBefore phase -> phase
- DoMkDependHS -> Ln
- DoLink -> Ln
- DoMkDLL -> Ln
- ----------- ----- ---- --- -- -- - - -
-
- -- this shouldn't happen.
- when (start_phase /= Ln && start_phase `notElem` pipeline)
- (throwDyn (CmdLineError ("can't find starting phase for "
- ++ filename)))
- -- if we can't find the phase we're supposed to stop before,
- -- something has gone wrong. This test carefully avoids the
- -- case where we aren't supposed to do any compilation, because the file
- -- is already in linkable form (for example).
--- hPutStrLn stderr (show ((start_phase `elem` pipeline,stop_phase /= Ln,stop_phase `notElem` pipeline), start_phase, stop_phase, pipeline,todo))
--- hFlush stderr
- when (start_phase `elem` pipeline &&
- (stop_phase /= Ln && stop_phase `notElem` pipeline))
- (do
- throwDyn (UsageError
- ("flag `" ++ stop_flag
- ++ "' is incompatible with source file `"
- ++ filename ++ "'" ++ show pipeline ++ show stop_phase)))
- let
- -- .o and .hc suffixes can be overriden by command-line options:
- myPhaseInputExt HCc | Just s <- hcsuf = s
- myPhaseInputExt Ln = osuf
- myPhaseInputExt other = phaseInputExt other
-
- annotatePipeline
- :: [Phase] -- raw pipeline
- -> Phase -- phase to stop before
- -> [(Phase, IntermediateFileType, String{-file extension-})]
- annotatePipeline [] _ = []
- annotatePipeline (Ln:_) _ = []
- annotatePipeline (phase:next_phase:ps) stop =
- (phase, keep_this_output, myPhaseInputExt next_phase)
- : annotatePipeline (next_phase:ps) stop
- where
- keep_this_output
- | next_phase == stop
- = if persistent_output then Persistent else Temporary
- | otherwise