@@ -31,7 +31,11 @@ use rustc_incremental::{self, IncrementalHashesMap};
3131use rustc_resolve:: { MakeGlobMap , Resolver } ;
3232use rustc_metadata:: creader:: CrateLoader ;
3333use rustc_metadata:: cstore:: { self , CStore } ;
34+ #[ cfg( feature="llvm" ) ]
3435use rustc_trans:: back:: { link, write} ;
36+ #[ cfg( not( feature="llvm" ) ) ]
37+ use :: link;
38+ #[ cfg( feature="llvm" ) ]
3539use rustc_trans as trans;
3640use rustc_typeck as typeck;
3741use rustc_privacy;
@@ -111,7 +115,7 @@ pub fn compile_input(sess: &Session,
111115 } ;
112116
113117 let outputs = build_output_filenames ( input, outdir, output, & krate. attrs , sess) ;
114- let crate_name = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
118+ let crate_name: String = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
115119 let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
116120 phase_2_configure_and_expand (
117121 sess, & cstore, krate, registry, & crate_name, addl_plugins, control. make_glob_map ,
@@ -204,55 +208,71 @@ pub fn compile_input(sess: &Session,
204208 println ! ( "Pre-trans" ) ;
205209 tcx. print_debug_stats ( ) ;
206210 }
207- let trans = phase_4_translate_to_llvm ( tcx, analysis, & incremental_hashes_map,
208- & outputs) ;
209211
210- if log_enabled ! ( :: log:: LogLevel :: Info ) {
211- println ! ( "Post-trans" ) ;
212- tcx. print_debug_stats ( ) ;
213- }
212+ #[ cfg( feature="llvm" ) ]
213+ {
214+ let trans = phase_4_translate_to_llvm ( tcx, analysis, & incremental_hashes_map,
215+ & outputs) ;
216+
217+ if log_enabled ! ( :: log:: LogLevel :: Info ) {
218+ println ! ( "Post-trans" ) ;
219+ tcx. print_debug_stats ( ) ;
220+ }
214221
215- if tcx. sess . opts . output_types . contains_key ( & OutputType :: Mir ) {
216- if let Err ( e) = mir:: transform:: dump_mir:: emit_mir ( tcx, & outputs) {
217- sess. err ( & format ! ( "could not emit MIR: {}" , e) ) ;
218- sess. abort_if_errors ( ) ;
222+ if tcx. sess . opts . output_types . contains_key ( & OutputType :: Mir ) {
223+ if let Err ( e) = mir:: transform:: dump_mir:: emit_mir ( tcx, & outputs) {
224+ sess. err ( & format ! ( "could not emit MIR: {}" , e) ) ;
225+ sess. abort_if_errors ( ) ;
226+ }
219227 }
228+
229+ return Ok ( ( outputs, trans) )
220230 }
221231
222- Ok ( ( outputs, trans) )
232+ #[ cfg( not( feature="llvm" ) ) ]
233+ panic ! ( "Unreachable" )
223234 } ) ??
224235 } ;
225236
226237 if sess. opts . debugging_opts . print_type_sizes {
227238 sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
228239 }
229240
230- let phase5_result = phase_5_run_llvm_passes ( sess, & trans, & outputs) ;
241+ #[ cfg( feature="llvm" ) ]
242+ {
243+ let phase5_result = phase_5_run_llvm_passes ( sess, & trans, & outputs) ;
231244
232- controller_entry_point ! ( after_llvm,
233- sess,
234- CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
235- phase5_result) ;
236- phase5_result?;
245+ controller_entry_point ! ( after_llvm,
246+ sess,
247+ CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
248+ phase5_result) ;
249+ phase5_result?;
237250
238- write:: cleanup_llvm ( & trans) ;
251+ write:: cleanup_llvm ( & trans) ;
239252
240- phase_6_link_output ( sess, & trans, & outputs) ;
253+ phase_6_link_output ( sess, & trans, & outputs) ;
241254
242- // Now that we won't touch anything in the incremental compilation directory
243- // any more, we can finalize it (which involves renaming it)
244- rustc_incremental:: finalize_session_directory ( sess, trans. link . crate_hash ) ;
255+ // Now that we won't touch anything in the incremental compilation directory
256+ // any more, we can finalize it (which involves renaming it)
257+ rustc_incremental:: finalize_session_directory ( sess, trans. link . crate_hash ) ;
245258
246- if sess. opts . debugging_opts . perf_stats {
247- sess. print_perf_stats ( ) ;
248- }
259+ if sess. opts . debugging_opts . perf_stats {
260+ sess. print_perf_stats ( ) ;
261+ }
262+
263+ controller_entry_point ! ( compilation_done,
264+ sess,
265+ CompileState :: state_when_compilation_done( input,
266+ sess,
267+ outdir,
268+ output) ,
269+ Ok ( ( ) ) ) ;
249270
250- controller_entry_point ! ( compilation_done,
251- sess,
252- CompileState :: state_when_compilation_done( input, sess, outdir, output) ,
253- Ok ( ( ) ) ) ;
271+ return Ok ( ( ) )
272+ }
254273
255- Ok ( ( ) )
274+ #[ cfg( not( feature="llvm" ) ) ]
275+ panic ! ( "Unreachable" )
256276}
257277
258278fn keep_hygiene_data ( sess : & Session ) -> bool {
@@ -355,6 +375,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
355375 pub resolutions : Option < & ' a Resolutions > ,
356376 pub analysis : Option < & ' a ty:: CrateAnalysis > ,
357377 pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
378+ #[ cfg( feature="llvm" ) ]
358379 pub trans : Option < & ' a trans:: CrateTranslation > ,
359380}
360381
@@ -381,6 +402,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
381402 resolutions : None ,
382403 analysis : None ,
383404 tcx : None ,
405+ #[ cfg( feature="llvm" ) ]
384406 trans : None ,
385407 }
386408 }
@@ -470,6 +492,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
470492 }
471493
472494
495+ #[ cfg( feature="llvm" ) ]
473496 fn state_after_llvm ( input : & ' a Input ,
474497 session : & ' tcx Session ,
475498 out_dir : & ' a Option < PathBuf > ,
@@ -893,6 +916,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
893916 mir:: provide ( & mut local_providers) ;
894917 reachable:: provide ( & mut local_providers) ;
895918 rustc_privacy:: provide ( & mut local_providers) ;
919+ #[ cfg( feature="llvm" ) ]
896920 trans:: provide ( & mut local_providers) ;
897921 typeck:: provide ( & mut local_providers) ;
898922 ty:: provide ( & mut local_providers) ;
@@ -904,6 +928,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
904928
905929 let mut extern_providers = ty:: maps:: Providers :: default ( ) ;
906930 cstore:: provide ( & mut extern_providers) ;
931+ #[ cfg( feature="llvm" ) ]
907932 trans:: provide ( & mut extern_providers) ;
908933 ty:: provide_extern ( & mut extern_providers) ;
909934 traits:: provide_extern ( & mut extern_providers) ;
@@ -1045,6 +1070,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
10451070
10461071/// Run the translation phase to LLVM, after which the AST and analysis can
10471072/// be discarded.
1073+ #[ cfg( feature="llvm" ) ]
10481074pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
10491075 analysis : ty:: CrateAnalysis ,
10501076 incremental_hashes_map : & IncrementalHashesMap ,
@@ -1076,6 +1102,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10761102
10771103/// Run LLVM itself, producing a bitcode file, assembly file or object file
10781104/// as a side effect.
1105+ #[ cfg( feature="llvm" ) ]
10791106pub fn phase_5_run_llvm_passes ( sess : & Session ,
10801107 trans : & trans:: CrateTranslation ,
10811108 outputs : & OutputFilenames ) -> CompileResult {
@@ -1124,6 +1151,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11241151
11251152/// Run the linker on any artifacts that resulted from the LLVM run.
11261153/// This should produce either a finished executable or library.
1154+ #[ cfg( feature="llvm" ) ]
11271155pub fn phase_6_link_output ( sess : & Session ,
11281156 trans : & trans:: CrateTranslation ,
11291157 outputs : & OutputFilenames ) {
0 commit comments