@@ -18,7 +18,9 @@ use rustc::session::CompileIncomplete;
1818use rustc:: session:: config:: { self , Input , OutputFilenames , OutputType } ;
1919use rustc:: session:: search_paths:: PathKind ;
2020use rustc:: lint;
21- use rustc:: middle:: { self , dependency_format, stability, reachable} ;
21+ use rustc:: middle:: { self , stability, reachable} ;
22+ #[ cfg( feature="llvm" ) ]
23+ use rustc:: middle:: dependency_format;
2224use rustc:: middle:: privacy:: AccessLevels ;
2325use rustc:: mir:: transform:: { MIR_CONST , MIR_VALIDATED , MIR_OPTIMIZED , Passes } ;
2426use rustc:: ty:: { self , TyCtxt , Resolutions , GlobalArenas } ;
@@ -31,7 +33,9 @@ use rustc_incremental::{self, IncrementalHashesMap};
3133use rustc_resolve:: { MakeGlobMap , Resolver } ;
3234use rustc_metadata:: creader:: CrateLoader ;
3335use rustc_metadata:: cstore:: { self , CStore } ;
36+ #[ cfg( feature="llvm" ) ]
3437use rustc_trans:: back:: { link, write} ;
38+ #[ cfg( feature="llvm" ) ]
3539use rustc_trans as trans;
3640use rustc_typeck as typeck;
3741use rustc_privacy;
@@ -69,6 +73,11 @@ pub fn compile_input(sess: &Session,
6973 output : & Option < PathBuf > ,
7074 addl_plugins : Option < Vec < String > > ,
7175 control : & CompileController ) -> CompileResult {
76+ #[ cfg( feature="llvm" ) ]
77+ use rustc_trans:: back:: write:: OngoingCrateTranslation ;
78+ #[ cfg( not( feature="llvm" ) ) ]
79+ type OngoingCrateTranslation = ( ) ;
80+
7281 macro_rules! controller_entry_point {
7382 ( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
7483 let state = & mut $make_state;
@@ -88,7 +97,7 @@ pub fn compile_input(sess: &Session,
8897 // We need nested scopes here, because the intermediate results can keep
8998 // large chunks of memory alive and we want to free them as soon as
9099 // possible to keep the peak memory usage low
91- let ( outputs, trans) = {
100+ let ( outputs, trans) : ( OutputFilenames , OngoingCrateTranslation ) = {
92101 let krate = match phase_1_parse_input ( control, sess, input) {
93102 Ok ( krate) => krate,
94103 Err ( mut parse_error) => {
@@ -113,7 +122,8 @@ pub fn compile_input(sess: &Session,
113122 } ;
114123
115124 let outputs = build_output_filenames ( input, outdir, output, & krate. attrs , sess) ;
116- let crate_name = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
125+ let crate_name =
126+ :: rustc_trans_utils:: link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
117127 let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
118128 phase_2_configure_and_expand (
119129 sess, & cstore, krate, registry, & crate_name, addl_plugins, control. make_glob_map ,
@@ -206,6 +216,8 @@ pub fn compile_input(sess: &Session,
206216 println ! ( "Pre-trans" ) ;
207217 tcx. print_debug_stats ( ) ;
208218 }
219+
220+ #[ cfg( feature="llvm" ) ]
209221 let trans = phase_4_translate_to_llvm ( tcx, analysis, incremental_hashes_map,
210222 & outputs) ;
211223
@@ -221,38 +233,59 @@ pub fn compile_input(sess: &Session,
221233 }
222234 }
223235
236+ #[ cfg( not( feature="llvm" ) ) ]
237+ {
238+ let _ = incremental_hashes_map;
239+ sess. err ( & format ! ( "LLVM is not supported by this rustc" ) ) ;
240+ sess. abort_if_errors ( ) ;
241+ unreachable ! ( ) ;
242+ }
243+
244+ #[ cfg( feature="llvm" ) ]
224245 Ok ( ( outputs, trans) )
225246 } ) ??
226247 } ;
227248
228- if sess. opts . debugging_opts . print_type_sizes {
229- sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
249+ #[ cfg( not( feature="llvm" ) ) ]
250+ {
251+ let _ = outputs;
252+ let _ = trans;
253+ unreachable ! ( ) ;
230254 }
231255
232- let ( phase5_result, trans) = phase_5_run_llvm_passes ( sess, trans) ;
256+ #[ cfg( feature="llvm" ) ]
257+ {
258+ if sess. opts . debugging_opts . print_type_sizes {
259+ sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
260+ }
233261
234- controller_entry_point ! ( after_llvm,
235- sess,
236- CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
237- phase5_result) ;
238- phase5_result?;
262+ let ( phase5_result, trans) = phase_5_run_llvm_passes ( sess, trans) ;
239263
240- phase_6_link_output ( sess, & trans, & outputs) ;
264+ controller_entry_point ! ( after_llvm,
265+ sess,
266+ CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
267+ phase5_result) ;
268+ phase5_result?;
241269
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 ) ;
270+ phase_6_link_output ( sess, & trans, & outputs) ;
245271
246- if sess . opts . debugging_opts . perf_stats {
247- sess . print_perf_stats ( ) ;
248- }
272+ // Now that we won't touch anything in the incremental compilation directory
273+ // any more, we can finalize it (which involves renaming it)
274+ rustc_incremental :: finalize_session_directory ( sess , trans . link . crate_hash ) ;
249275
250- controller_entry_point ! ( compilation_done,
251- sess,
252- CompileState :: state_when_compilation_done( input, sess, outdir, output) ,
253- Ok ( ( ) ) ) ;
276+ if sess. opts . debugging_opts . perf_stats {
277+ sess. print_perf_stats ( ) ;
278+ }
279+
280+ controller_entry_point ! (
281+ compilation_done,
282+ sess,
283+ CompileState :: state_when_compilation_done( input, sess, outdir, output) ,
284+ Ok ( ( ) )
285+ ) ;
254286
255- Ok ( ( ) )
287+ Ok ( ( ) )
288+ }
256289}
257290
258291fn keep_hygiene_data ( sess : & Session ) -> bool {
@@ -360,6 +393,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
360393 pub resolutions : Option < & ' a Resolutions > ,
361394 pub analysis : Option < & ' a ty:: CrateAnalysis > ,
362395 pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
396+ #[ cfg( feature="llvm" ) ]
363397 pub trans : Option < & ' a trans:: CrateTranslation > ,
364398}
365399
@@ -386,6 +420,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
386420 resolutions : None ,
387421 analysis : None ,
388422 tcx : None ,
423+ #[ cfg( feature="llvm" ) ]
389424 trans : None ,
390425 }
391426 }
@@ -474,7 +509,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
474509 }
475510 }
476511
477-
512+ # [ cfg ( feature= "llvm" ) ]
478513 fn state_after_llvm ( input : & ' a Input ,
479514 session : & ' tcx Session ,
480515 out_dir : & ' a Option < PathBuf > ,
@@ -488,6 +523,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
488523 }
489524 }
490525
526+ #[ cfg( feature="llvm" ) ]
491527 fn state_when_compilation_done ( input : & ' a Input ,
492528 session : & ' tcx Session ,
493529 out_dir : & ' a Option < PathBuf > ,
@@ -906,6 +942,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
906942 mir:: provide ( & mut local_providers) ;
907943 reachable:: provide ( & mut local_providers) ;
908944 rustc_privacy:: provide ( & mut local_providers) ;
945+ #[ cfg( feature="llvm" ) ]
909946 trans:: provide ( & mut local_providers) ;
910947 typeck:: provide ( & mut local_providers) ;
911948 ty:: provide ( & mut local_providers) ;
@@ -918,6 +955,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
918955
919956 let mut extern_providers = ty:: maps:: Providers :: default ( ) ;
920957 cstore:: provide ( & mut extern_providers) ;
958+ #[ cfg( feature="llvm" ) ]
921959 trans:: provide ( & mut extern_providers) ;
922960 ty:: provide_extern ( & mut extern_providers) ;
923961 traits:: provide_extern ( & mut extern_providers) ;
@@ -1064,6 +1102,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
10641102
10651103/// Run the translation phase to LLVM, after which the AST and analysis can
10661104/// be discarded.
1105+ #[ cfg( feature="llvm" ) ]
10671106pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
10681107 analysis : ty:: CrateAnalysis ,
10691108 incremental_hashes_map : IncrementalHashesMap ,
@@ -1085,6 +1124,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10851124
10861125/// Run LLVM itself, producing a bitcode file, assembly file or object file
10871126/// as a side effect.
1127+ #[ cfg( feature="llvm" ) ]
10881128pub fn phase_5_run_llvm_passes ( sess : & Session ,
10891129 trans : write:: OngoingCrateTranslation )
10901130 -> ( CompileResult , trans:: CrateTranslation ) {
@@ -1103,6 +1143,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11031143
11041144/// Run the linker on any artifacts that resulted from the LLVM run.
11051145/// This should produce either a finished executable or library.
1146+ #[ cfg( feature="llvm" ) ]
11061147pub fn phase_6_link_output ( sess : & Session ,
11071148 trans : & trans:: CrateTranslation ,
11081149 outputs : & OutputFilenames ) {
@@ -1124,7 +1165,12 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, crate_name: &str) {
11241165 match * output_type {
11251166 OutputType :: Exe => {
11261167 for output in sess. crate_types . borrow ( ) . iter ( ) {
1127- let p = link:: filename_for_input ( sess, * output, crate_name, outputs) ;
1168+ let p = :: rustc_trans_utils:: link:: filename_for_input (
1169+ sess,
1170+ * output,
1171+ crate_name,
1172+ outputs
1173+ ) ;
11281174 out_filenames. push ( p) ;
11291175 }
11301176 }
@@ -1234,15 +1280,15 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
12341280 if base. is_empty ( ) {
12351281 base. extend ( attr_types) ;
12361282 if base. is_empty ( ) {
1237- base. push ( link:: default_output_for_target ( session) ) ;
1283+ base. push ( :: rustc_trans_utils :: link:: default_output_for_target ( session) ) ;
12381284 }
12391285 base. sort ( ) ;
12401286 base. dedup ( ) ;
12411287 }
12421288
12431289 base. into_iter ( )
12441290 . filter ( |crate_type| {
1245- let res = !link:: invalid_output_for_target ( session, * crate_type) ;
1291+ let res = !:: rustc_trans_utils :: link:: invalid_output_for_target ( session, * crate_type) ;
12461292
12471293 if !res {
12481294 session. warn ( & format ! ( "dropping unsupported crate type `{}` for target `{}`" ,
0 commit comments