Skip to content

Commit

Permalink
Merge branch 'trac_5025' of https://github.com/thoughtpolice/ghc
Browse files Browse the repository at this point in the history
* 'trac_5025' of https://github.com/thoughtpolice/ghc:
  Teach GHC to compile objective-c files; trac #5025

Conflicts:
	compiler/main/DriverPipeline.hs
  • Loading branch information
simonmar committed Apr 6, 2011
2 parents 91bb651 + 9e27ad1 commit 6caa417
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion compiler/main/DriverPhases.hs
Expand Up @@ -75,6 +75,7 @@ data Phase
| Hsc HscSource
| Ccpp
| Cc
| Cobjc
| HCc -- Haskellised C (as opposed to vanilla C) compilation
| SplitMangle -- after mangler if splitting
| SplitAs
Expand Down Expand Up @@ -110,6 +111,7 @@ eqPhase (HsPp _) (HsPp _) = True
eqPhase (Hsc _) (Hsc _) = True
eqPhase Ccpp Ccpp = True
eqPhase Cc Cc = True
eqPhase Cobjc Cobjc = True
eqPhase HCc HCc = True
eqPhase SplitMangle SplitMangle = True
eqPhase SplitAs SplitAs = True
Expand Down Expand Up @@ -150,6 +152,7 @@ nextPhase LlvmMangle = As
nextPhase SplitAs = MergeStub
nextPhase Ccpp = As
nextPhase Cc = As
nextPhase Cobjc = As
nextPhase CmmCpp = Cmm
nextPhase Cmm = HCc
nextPhase HCc = As
Expand All @@ -170,6 +173,7 @@ startPhase "hc" = HCc
startPhase "c" = Cc
startPhase "cpp" = Ccpp
startPhase "C" = Cc
startPhase "m" = Cobjc
startPhase "cc" = Ccpp
startPhase "cxx" = Ccpp
startPhase "split_s" = SplitMangle
Expand Down Expand Up @@ -198,6 +202,7 @@ phaseInputExt (Hsc _) = "hspp" -- intermediate only
-- output filename. That could be fixed, but watch out.
phaseInputExt HCc = "hc"
phaseInputExt Ccpp = "cpp"
phaseInputExt Cobjc = "m"
phaseInputExt Cc = "c"
phaseInputExt SplitMangle = "split_s" -- not really generated
phaseInputExt As = "s"
Expand All @@ -216,7 +221,7 @@ haskellish_src_suffixes, haskellish_suffixes, cish_suffixes,
haskellish_src_suffixes = haskellish_user_src_suffixes ++
[ "hspp", "hscpp", "hcr", "cmm", "cmmcpp" ]
haskellish_suffixes = haskellish_src_suffixes ++ ["hc", "raw_s"]
cish_suffixes = [ "c", "cpp", "C", "cc", "cxx", "s", "S", "ll", "bc" ]
cish_suffixes = [ "c", "cpp", "C", "cc", "cxx", "s", "S", "ll", "bc", "m" ]
extcoreish_suffixes = [ "hcr" ]
-- Will not be deleted as temp files:
haskellish_user_src_suffixes = [ "hs", "lhs", "hs-boot", "lhs-boot" ]
Expand Down
11 changes: 6 additions & 5 deletions compiler/main/DriverPipeline.hs
Expand Up @@ -986,7 +986,7 @@ runPhase Cmm input_fn dflags
-- way too many hacks, and I can't say I've ever used it anyway.

runPhase cc_phase input_fn dflags
| cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc
| cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc || cc_phase `eqPhase` Cobjc
= do
let cc_opts = getOpts dflags opt_c
hcc = cc_phase `eqPhase` HCc
Expand Down Expand Up @@ -1054,15 +1054,16 @@ runPhase cc_phase input_fn dflags
-- very weakly typed, being derived from C--.
["-fno-strict-aliasing"]

let gcc_lang_opt | cc_phase `eqPhase` Ccpp = "c++"
| cc_phase `eqPhase` Cobjc = "objective-c"
| otherwise = "c"
io $ SysTools.runCc dflags (
-- force the C compiler to interpret this file as C when
-- compiling .hc files, by adding the -x c option.
-- Also useful for plain .c files, just in case GHC saw a
-- -x c option.
[ SysTools.Option "-x", if cc_phase `eqPhase` Ccpp
then SysTools.Option "c++"
else SysTools.Option "c"] ++
[ SysTools.FileOption "" input_fn
[ SysTools.Option "-x", SysTools.Option gcc_lang_opt
, SysTools.FileOption "" input_fn
, SysTools.Option "-o"
, SysTools.FileOption "" output_fn
]
Expand Down
2 changes: 1 addition & 1 deletion ghc/Main.hs
Expand Up @@ -591,7 +591,7 @@ doMake srcs = do
haskellish (f,Nothing) =
looksLikeModuleName f || isHaskellSrcFilename f || '.' `notElem` f
haskellish (_,Just phase) =
phase `notElem` [As, Cc, CmmCpp, Cmm, StopLn]
phase `notElem` [As, Cc, Cobjc, CmmCpp, Cmm, StopLn]

hsc_env <- GHC.getSession

Expand Down

0 comments on commit 6caa417

Please sign in to comment.