@@ -18,7 +18,9 @@ use rustc::session::CompileIncomplete;
18
18
use rustc:: session:: config:: { self , Input , OutputFilenames , OutputType } ;
19
19
use rustc:: session:: search_paths:: PathKind ;
20
20
use 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;
22
24
use rustc:: middle:: privacy:: AccessLevels ;
23
25
use rustc:: mir:: transform:: { MIR_CONST , MIR_VALIDATED , MIR_OPTIMIZED , Passes } ;
24
26
use rustc:: ty:: { self , TyCtxt , Resolutions , GlobalArenas } ;
@@ -31,7 +33,9 @@ use rustc_incremental::{self, IncrementalHashesMap};
31
33
use rustc_resolve:: { MakeGlobMap , Resolver } ;
32
34
use rustc_metadata:: creader:: CrateLoader ;
33
35
use rustc_metadata:: cstore:: { self , CStore } ;
36
+ #[ cfg( feature="llvm" ) ]
34
37
use rustc_trans:: back:: { link, write} ;
38
+ #[ cfg( feature="llvm" ) ]
35
39
use rustc_trans as trans;
36
40
use rustc_typeck as typeck;
37
41
use rustc_privacy;
@@ -69,6 +73,11 @@ pub fn compile_input(sess: &Session,
69
73
output : & Option < PathBuf > ,
70
74
addl_plugins : Option < Vec < String > > ,
71
75
control : & CompileController ) -> CompileResult {
76
+ #[ cfg( feature="llvm" ) ]
77
+ use rustc_trans:: back:: write:: OngoingCrateTranslation ;
78
+ #[ cfg( not( feature="llvm" ) ) ]
79
+ type OngoingCrateTranslation = ( ) ;
80
+
72
81
macro_rules! controller_entry_point {
73
82
( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
74
83
let state = & mut $make_state;
@@ -88,7 +97,7 @@ pub fn compile_input(sess: &Session,
88
97
// We need nested scopes here, because the intermediate results can keep
89
98
// large chunks of memory alive and we want to free them as soon as
90
99
// possible to keep the peak memory usage low
91
- let ( outputs, trans) = {
100
+ let ( outputs, trans) : ( OutputFilenames , OngoingCrateTranslation ) = {
92
101
let krate = match phase_1_parse_input ( control, sess, input) {
93
102
Ok ( krate) => krate,
94
103
Err ( mut parse_error) => {
@@ -113,7 +122,8 @@ pub fn compile_input(sess: &Session,
113
122
} ;
114
123
115
124
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) ;
117
127
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
118
128
phase_2_configure_and_expand (
119
129
sess, & cstore, krate, registry, & crate_name, addl_plugins, control. make_glob_map ,
@@ -206,6 +216,8 @@ pub fn compile_input(sess: &Session,
206
216
println ! ( "Pre-trans" ) ;
207
217
tcx. print_debug_stats ( ) ;
208
218
}
219
+
220
+ #[ cfg( feature="llvm" ) ]
209
221
let trans = phase_4_translate_to_llvm ( tcx, analysis, incremental_hashes_map,
210
222
& outputs) ;
211
223
@@ -221,38 +233,59 @@ pub fn compile_input(sess: &Session,
221
233
}
222
234
}
223
235
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" ) ]
224
245
Ok ( ( outputs, trans) )
225
246
} ) ??
226
247
} ;
227
248
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 ! ( ) ;
230
254
}
231
255
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
+ }
233
261
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) ;
239
263
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?;
241
269
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) ;
245
271
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 ) ;
249
275
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
+ ) ;
254
286
255
- Ok ( ( ) )
287
+ Ok ( ( ) )
288
+ }
256
289
}
257
290
258
291
fn keep_hygiene_data ( sess : & Session ) -> bool {
@@ -360,6 +393,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
360
393
pub resolutions : Option < & ' a Resolutions > ,
361
394
pub analysis : Option < & ' a ty:: CrateAnalysis > ,
362
395
pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
396
+ #[ cfg( feature="llvm" ) ]
363
397
pub trans : Option < & ' a trans:: CrateTranslation > ,
364
398
}
365
399
@@ -386,6 +420,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
386
420
resolutions : None ,
387
421
analysis : None ,
388
422
tcx : None ,
423
+ #[ cfg( feature="llvm" ) ]
389
424
trans : None ,
390
425
}
391
426
}
@@ -474,7 +509,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
474
509
}
475
510
}
476
511
477
-
512
+ # [ cfg ( feature= "llvm" ) ]
478
513
fn state_after_llvm ( input : & ' a Input ,
479
514
session : & ' tcx Session ,
480
515
out_dir : & ' a Option < PathBuf > ,
@@ -488,6 +523,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
488
523
}
489
524
}
490
525
526
+ #[ cfg( feature="llvm" ) ]
491
527
fn state_when_compilation_done ( input : & ' a Input ,
492
528
session : & ' tcx Session ,
493
529
out_dir : & ' a Option < PathBuf > ,
@@ -906,6 +942,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
906
942
mir:: provide ( & mut local_providers) ;
907
943
reachable:: provide ( & mut local_providers) ;
908
944
rustc_privacy:: provide ( & mut local_providers) ;
945
+ #[ cfg( feature="llvm" ) ]
909
946
trans:: provide ( & mut local_providers) ;
910
947
typeck:: provide ( & mut local_providers) ;
911
948
ty:: provide ( & mut local_providers) ;
@@ -918,6 +955,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
918
955
919
956
let mut extern_providers = ty:: maps:: Providers :: default ( ) ;
920
957
cstore:: provide ( & mut extern_providers) ;
958
+ #[ cfg( feature="llvm" ) ]
921
959
trans:: provide ( & mut extern_providers) ;
922
960
ty:: provide_extern ( & mut extern_providers) ;
923
961
traits:: provide_extern ( & mut extern_providers) ;
@@ -1064,6 +1102,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
1064
1102
1065
1103
/// Run the translation phase to LLVM, after which the AST and analysis can
1066
1104
/// be discarded.
1105
+ #[ cfg( feature="llvm" ) ]
1067
1106
pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1068
1107
analysis : ty:: CrateAnalysis ,
1069
1108
incremental_hashes_map : IncrementalHashesMap ,
@@ -1085,6 +1124,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1085
1124
1086
1125
/// Run LLVM itself, producing a bitcode file, assembly file or object file
1087
1126
/// as a side effect.
1127
+ #[ cfg( feature="llvm" ) ]
1088
1128
pub fn phase_5_run_llvm_passes ( sess : & Session ,
1089
1129
trans : write:: OngoingCrateTranslation )
1090
1130
-> ( CompileResult , trans:: CrateTranslation ) {
@@ -1103,6 +1143,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
1103
1143
1104
1144
/// Run the linker on any artifacts that resulted from the LLVM run.
1105
1145
/// This should produce either a finished executable or library.
1146
+ #[ cfg( feature="llvm" ) ]
1106
1147
pub fn phase_6_link_output ( sess : & Session ,
1107
1148
trans : & trans:: CrateTranslation ,
1108
1149
outputs : & OutputFilenames ) {
@@ -1124,7 +1165,12 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, crate_name: &str) {
1124
1165
match * output_type {
1125
1166
OutputType :: Exe => {
1126
1167
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
+ ) ;
1128
1174
out_filenames. push ( p) ;
1129
1175
}
1130
1176
}
@@ -1234,15 +1280,15 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
1234
1280
if base. is_empty ( ) {
1235
1281
base. extend ( attr_types) ;
1236
1282
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) ) ;
1238
1284
}
1239
1285
base. sort ( ) ;
1240
1286
base. dedup ( ) ;
1241
1287
}
1242
1288
1243
1289
base. into_iter ( )
1244
1290
. 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) ;
1246
1292
1247
1293
if !res {
1248
1294
session. warn ( & format ! ( "dropping unsupported crate type `{}` for target `{}`" ,
0 commit comments