@@ -31,7 +31,11 @@ use rustc_incremental::{self, IncrementalHashesMap};
31
31
use rustc_resolve:: { MakeGlobMap , Resolver } ;
32
32
use rustc_metadata:: creader:: CrateLoader ;
33
33
use rustc_metadata:: cstore:: { self , CStore } ;
34
+ #[ cfg( feature="llvm" ) ]
34
35
use rustc_trans:: back:: { link, write} ;
36
+ #[ cfg( not( feature="llvm" ) ) ]
37
+ use :: link;
38
+ #[ cfg( feature="llvm" ) ]
35
39
use rustc_trans as trans;
36
40
use rustc_typeck as typeck;
37
41
use rustc_privacy;
@@ -111,7 +115,7 @@ pub fn compile_input(sess: &Session,
111
115
} ;
112
116
113
117
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) ;
115
119
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
116
120
phase_2_configure_and_expand (
117
121
sess, & cstore, krate, registry, & crate_name, addl_plugins, control. make_glob_map ,
@@ -204,55 +208,71 @@ pub fn compile_input(sess: &Session,
204
208
println ! ( "Pre-trans" ) ;
205
209
tcx. print_debug_stats ( ) ;
206
210
}
207
- let trans = phase_4_translate_to_llvm ( tcx, analysis, & incremental_hashes_map,
208
- & outputs) ;
209
211
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
+ }
214
221
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
+ }
219
227
}
228
+
229
+ return Ok ( ( outputs, trans) )
220
230
}
221
231
222
- Ok ( ( outputs, trans) )
232
+ #[ cfg( not( feature="llvm" ) ) ]
233
+ panic ! ( "Unreachable" )
223
234
} ) ??
224
235
} ;
225
236
226
237
if sess. opts . debugging_opts . print_type_sizes {
227
238
sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
228
239
}
229
240
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) ;
231
244
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?;
237
250
238
- write:: cleanup_llvm ( & trans) ;
251
+ write:: cleanup_llvm ( & trans) ;
239
252
240
- phase_6_link_output ( sess, & trans, & outputs) ;
253
+ phase_6_link_output ( sess, & trans, & outputs) ;
241
254
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 ) ;
245
258
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 ( ( ) ) ) ;
249
270
250
- controller_entry_point ! ( compilation_done,
251
- sess,
252
- CompileState :: state_when_compilation_done( input, sess, outdir, output) ,
253
- Ok ( ( ) ) ) ;
271
+ return Ok ( ( ) )
272
+ }
254
273
255
- Ok ( ( ) )
274
+ #[ cfg( not( feature="llvm" ) ) ]
275
+ panic ! ( "Unreachable" )
256
276
}
257
277
258
278
fn keep_hygiene_data ( sess : & Session ) -> bool {
@@ -355,6 +375,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
355
375
pub resolutions : Option < & ' a Resolutions > ,
356
376
pub analysis : Option < & ' a ty:: CrateAnalysis > ,
357
377
pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
378
+ #[ cfg( feature="llvm" ) ]
358
379
pub trans : Option < & ' a trans:: CrateTranslation > ,
359
380
}
360
381
@@ -381,6 +402,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
381
402
resolutions : None ,
382
403
analysis : None ,
383
404
tcx : None ,
405
+ #[ cfg( feature="llvm" ) ]
384
406
trans : None ,
385
407
}
386
408
}
@@ -470,6 +492,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
470
492
}
471
493
472
494
495
+ #[ cfg( feature="llvm" ) ]
473
496
fn state_after_llvm ( input : & ' a Input ,
474
497
session : & ' tcx Session ,
475
498
out_dir : & ' a Option < PathBuf > ,
@@ -893,6 +916,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
893
916
mir:: provide ( & mut local_providers) ;
894
917
reachable:: provide ( & mut local_providers) ;
895
918
rustc_privacy:: provide ( & mut local_providers) ;
919
+ #[ cfg( feature="llvm" ) ]
896
920
trans:: provide ( & mut local_providers) ;
897
921
typeck:: provide ( & mut local_providers) ;
898
922
ty:: provide ( & mut local_providers) ;
@@ -904,6 +928,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
904
928
905
929
let mut extern_providers = ty:: maps:: Providers :: default ( ) ;
906
930
cstore:: provide ( & mut extern_providers) ;
931
+ #[ cfg( feature="llvm" ) ]
907
932
trans:: provide ( & mut extern_providers) ;
908
933
ty:: provide_extern ( & mut extern_providers) ;
909
934
traits:: provide_extern ( & mut extern_providers) ;
@@ -1045,6 +1070,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
1045
1070
1046
1071
/// Run the translation phase to LLVM, after which the AST and analysis can
1047
1072
/// be discarded.
1073
+ #[ cfg( feature="llvm" ) ]
1048
1074
pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1049
1075
analysis : ty:: CrateAnalysis ,
1050
1076
incremental_hashes_map : & IncrementalHashesMap ,
@@ -1076,6 +1102,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1076
1102
1077
1103
/// Run LLVM itself, producing a bitcode file, assembly file or object file
1078
1104
/// as a side effect.
1105
+ #[ cfg( feature="llvm" ) ]
1079
1106
pub fn phase_5_run_llvm_passes ( sess : & Session ,
1080
1107
trans : & trans:: CrateTranslation ,
1081
1108
outputs : & OutputFilenames ) -> CompileResult {
@@ -1124,6 +1151,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
1124
1151
1125
1152
/// Run the linker on any artifacts that resulted from the LLVM run.
1126
1153
/// This should produce either a finished executable or library.
1154
+ #[ cfg( feature="llvm" ) ]
1127
1155
pub fn phase_6_link_output ( sess : & Session ,
1128
1156
trans : & trans:: CrateTranslation ,
1129
1157
outputs : & OutputFilenames ) {
0 commit comments