Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Teach GHC to compile objective-c files; trac #5025

  • Loading branch information...
commit 9e27ad106ef7036f356475daa0412ad72b56067b 1 parent be89531
authored April 03, 2011
7  compiler/main/DriverPhases.hs
@@ -75,6 +75,7 @@ data Phase
75 75
         | Hsc   HscSource
76 76
         | Ccpp
77 77
         | Cc
  78
+        | Cobjc
78 79
         | HCc           -- Haskellised C (as opposed to vanilla C) compilation
79 80
         | Mangle        -- assembly mangling, now done by a separate script.
80 81
         | SplitMangle   -- after mangler if splitting
@@ -110,6 +111,7 @@ eqPhase (HsPp  _)   (HsPp  _)   = True
110 111
 eqPhase (Hsc   _)   (Hsc   _)   = True
111 112
 eqPhase Ccpp        Ccpp        = True
112 113
 eqPhase Cc          Cc          = True
  114
+eqPhase Cobjc       Cobjc       = True
113 115
 eqPhase HCc         HCc         = True
114 116
 eqPhase Mangle      Mangle      = True
115 117
 eqPhase SplitMangle SplitMangle = True
@@ -152,6 +154,7 @@ nextPhase LlvmMangle    = As
152 154
 nextPhase SplitAs       = StopLn
153 155
 nextPhase Ccpp          = As
154 156
 nextPhase Cc            = As
  157
+nextPhase Cobjc         = As
155 158
 nextPhase CmmCpp        = Cmm
156 159
 nextPhase Cmm           = HCc
157 160
 nextPhase StopLn        = panic "nextPhase: nothing after StopLn"
@@ -170,6 +173,7 @@ startPhase "hc"       = HCc
170 173
 startPhase "c"        = Cc
171 174
 startPhase "cpp"      = Ccpp
172 175
 startPhase "C"        = Cc
  176
+startPhase "m"        = Cobjc
173 177
 startPhase "cc"       = Ccpp
174 178
 startPhase "cxx"      = Ccpp
175 179
 startPhase "raw_s"    = Mangle
@@ -199,6 +203,7 @@ phaseInputExt (Hsc   _)           = "hspp"      -- intermediate only
199 203
         --     output filename.  That could be fixed, but watch out.
200 204
 phaseInputExt HCc                 = "hc"
201 205
 phaseInputExt Ccpp                = "cpp"
  206
+phaseInputExt Cobjc               = "m"
202 207
 phaseInputExt Cc                  = "c"
203 208
 phaseInputExt Mangle              = "raw_s"
204 209
 phaseInputExt SplitMangle         = "split_s"   -- not really generated
@@ -217,7 +222,7 @@ haskellish_src_suffixes, haskellish_suffixes, cish_suffixes,
217 222
 haskellish_src_suffixes      = haskellish_user_src_suffixes ++
218 223
                                [ "hspp", "hscpp", "hcr", "cmm", "cmmcpp" ]
219 224
 haskellish_suffixes          = haskellish_src_suffixes ++ ["hc", "raw_s"]
220  
-cish_suffixes                = [ "c", "cpp", "C", "cc", "cxx", "s", "S", "ll", "bc" ]
  225
+cish_suffixes                = [ "c", "cpp", "C", "cc", "cxx", "s", "S", "ll", "bc", "m" ]
221 226
 extcoreish_suffixes          = [ "hcr" ]
222 227
 -- Will not be deleted as temp files:
223 228
 haskellish_user_src_suffixes = [ "hs", "lhs", "hs-boot", "lhs-boot" ]
11  compiler/main/DriverPipeline.hs
@@ -912,7 +912,7 @@ runPhase Cmm stop hsc_env basename _ input_fn get_output_fn maybe_loc
912 912
 -- way too many hacks, and I can't say I've ever used it anyway.
913 913
 
914 914
 runPhase cc_phase _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
915  
-   | cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc
  915
+   | cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc || cc_phase `eqPhase` Cobjc
916 916
    = do let dflags = hsc_dflags hsc_env
917 917
         let cc_opts = getOpts dflags opt_c
918 918
             hcc = cc_phase `eqPhase` HCc
@@ -983,15 +983,16 @@ runPhase cc_phase _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
983 983
                 -- very weakly typed, being derived from C--.
984 984
                 ["-fno-strict-aliasing"]
985 985
 
  986
+        let gcc_lang_opt | cc_phase `eqPhase` Ccpp  = "c++"
  987
+                         | cc_phase `eqPhase` Cobjc = "objective-c"
  988
+                         | otherwise                = "c"
986 989
         SysTools.runCc dflags (
987 990
                 -- force the C compiler to interpret this file as C when
988 991
                 -- compiling .hc files, by adding the -x c option.
989 992
                 -- Also useful for plain .c files, just in case GHC saw a
990 993
                 -- -x c option.
991  
-                        [ SysTools.Option "-x", if cc_phase `eqPhase` Ccpp
992  
-                                                then SysTools.Option "c++"
993  
-                                                else SysTools.Option "c"] ++
994  
-                        [ SysTools.FileOption "" input_fn
  994
+                        [ SysTools.Option "-x", SysTools.Option gcc_lang_opt
  995
+                        , SysTools.FileOption "" input_fn
995 996
                         , SysTools.Option "-o"
996 997
                         , SysTools.FileOption "" output_fn
997 998
                         ]
2  ghc/Main.hs
@@ -591,7 +591,7 @@ doMake srcs  = do
591 591
 	haskellish (f,Nothing) = 
592 592
 	  looksLikeModuleName f || isHaskellSrcFilename f || '.' `notElem` f
593 593
 	haskellish (_,Just phase) = 
594  
-	  phase `notElem` [As, Cc, CmmCpp, Cmm, StopLn]
  594
+	  phase `notElem` [As, Cc, Cobjc, CmmCpp, Cmm, StopLn]
595 595
 
596 596
     hsc_env <- GHC.getSession
597 597
 

0 notes on commit 9e27ad1

Please sign in to comment.
Something went wrong with that request. Please try again.