@@ -56,8 +56,8 @@ fn default_environment(session::session sess,
56
56
}
57
57
58
58
fn parse_input ( session:: session sess,
59
- parser:: parser p,
60
- str input ) -> @ast:: crate {
59
+ parser:: parser p,
60
+ str input ) -> @ast:: crate {
61
61
if ( str:: ends_with ( input, ".rc" ) ) {
62
62
ret parser:: parse_crate_from_crate_file ( p) ;
63
63
} else if ( str:: ends_with ( input, ".rs" ) ) {
@@ -207,8 +207,7 @@ fn get_default_sysroot(str binary) -> str {
207
207
ret dirname;
208
208
}
209
209
210
- fn main( vec[ str] args ) {
211
-
210
+ fn build_target_config ( ) -> @session:: config {
212
211
let str triple =
213
212
std:: str:: rustrt:: str_from_cstr ( llvm:: llvm:: LLVMRustGetHostTriple ( ) ) ;
214
213
@@ -219,45 +218,12 @@ fn main(vec[str] args) {
219
218
uint_type = common:: ty_u32,
220
219
float_type = common:: ty_f64) ;
221
220
222
- auto opts = [ optflag ( "h" ) , optflag ( "help" ) ,
223
- optflag ( "v" ) , optflag ( "version" ) ,
224
- optflag ( "glue" ) , optflag ( "emit-llvm" ) ,
225
- optflag ( "pretty" ) , optflag ( "typed-pretty" ) ,
226
- optflag ( "ls" ) , optflag ( "parse-only" ) ,
227
- optflag ( "O" ) , optopt ( "OptLevel" ) ,
228
- optflag ( "shared" ) , optmulti ( "L" ) ,
229
- optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) ,
230
- optflag ( "save-temps" ) , optopt ( "sysroot" ) ,
231
- optflag ( "stats" ) ,
232
- optflag ( "time-passes" ) , optflag ( "time-llvm-passes" ) ,
233
- optflag ( "no-typestate" ) , optflag ( "noverify" ) ] ;
234
- auto binary = vec:: shift[ str] ( args) ;
235
- auto match;
236
- alt ( getopts:: getopts ( args, opts) ) {
237
- case ( getopts:: failure ( ?f) ) {
238
- log_err #fmt( "error: %s" , getopts:: fail_str ( f) ) ;
239
- fail;
240
- }
241
- case ( getopts:: success ( ?m) ) { match = m; }
242
- }
243
- if ( opt_present( match , "h" ) ||
244
- opt_present( match , "help" ) ) {
245
- usage( binary) ;
246
- ret;
247
- }
248
-
249
- if ( opt_present( match, "v" ) ||
250
- opt_present( match, "version" ) ) {
251
- version( binary) ;
252
- ret;
253
- }
221
+ ret target_cfg;
222
+ }
254
223
255
- auto pretty = opt_present( match, "pretty" ) ;
256
- auto typed_pretty = opt_present( match, "typed-pretty" ) ;
257
- auto ls = opt_present( match, "ls" ) ;
258
- auto glue = opt_present( match, "glue" ) ;
224
+ fn build_session_options( str binary , getopts:: match match)
225
+ -> @session:: options {
259
226
auto shared = opt_present ( match , "shared" ) ;
260
- auto output_file = getopts:: opt_maybe_str( match, "o" ) ;
261
227
auto library_search_paths = getopts:: opt_strs ( match , "L" ) ;
262
228
263
229
auto output_type = link:: output_type_exe;
@@ -331,15 +297,63 @@ fn main(vec[str] args) {
331
297
library_search_paths = library_search_paths,
332
298
sysroot = sysroot) ;
333
299
300
+ ret sopts;
301
+ }
302
+
303
+ fn build_session ( @session:: options sopts) -> session:: session {
304
+ auto target_cfg = build_target_config ( ) ;
334
305
auto crate_cache = common:: new_int_hash[ session:: crate_metadata] ( ) ;
335
306
auto target_crate_num = 0 ;
336
307
let vec[ @ast:: meta_item] md = [ ] ;
337
308
auto sess =
338
309
session:: session ( target_crate_num, target_cfg, sopts,
339
- crate_cache, md, front:: codemap:: new_codemap ( ) ) ;
310
+ crate_cache, md, front:: codemap:: new_codemap ( ) ) ;
311
+ ret sess;
312
+ }
313
+
314
+ fn main( vec[ str] args ) {
315
+
316
+ auto opts = [ optflag ( "h" ) , optflag ( "help" ) ,
317
+ optflag ( "v" ) , optflag ( "version" ) ,
318
+ optflag ( "glue" ) , optflag ( "emit-llvm" ) ,
319
+ optflag ( "pretty" ) , optflag ( "typed-pretty" ) ,
320
+ optflag ( "ls" ) , optflag ( "parse-only" ) ,
321
+ optflag ( "O" ) , optopt ( "OptLevel" ) ,
322
+ optflag ( "shared" ) , optmulti ( "L" ) ,
323
+ optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) ,
324
+ optflag ( "save-temps" ) , optopt ( "sysroot" ) ,
325
+ optflag ( "stats" ) ,
326
+ optflag ( "time-passes" ) , optflag ( "time-llvm-passes" ) ,
327
+ optflag ( "no-typestate" ) , optflag ( "noverify" ) ] ;
328
+
329
+ auto binary = vec:: shift[ str] ( args) ;
330
+ auto match = alt ( getopts:: getopts ( args, opts) ) {
331
+ case ( getopts:: success ( ?m) ) { m }
332
+ case ( getopts:: failure ( ?f) ) {
333
+ log_err #fmt( "error: %s" , getopts:: fail_str ( f) ) ;
334
+ fail
335
+ }
336
+ } ;
337
+
338
+ if ( opt_present( match , "h" ) ||
339
+ opt_present( match , "help" ) ) {
340
+ usage( binary) ;
341
+ ret;
342
+ }
343
+
344
+ if ( opt_present( match, "v" ) ||
345
+ opt_present( match, "version" ) ) {
346
+ version( binary) ;
347
+ ret;
348
+ }
349
+
350
+ auto sopts = build_session_options( binary, match) ;
351
+ auto sess = build_session( sopts) ;
340
352
341
353
auto n_inputs = vec:: len[ str] ( match. free) ;
342
354
355
+ auto output_file = getopts:: opt_maybe_str( match, "o" ) ;
356
+ auto glue = opt_present( match, "glue" ) ;
343
357
if ( glue) {
344
358
if ( n_inputs > 0 u) {
345
359
sess. err ( "No input files allowed with --glue." ) ;
@@ -357,7 +371,10 @@ fn main(vec[str] args) {
357
371
358
372
auto ifile = match . free . ( 0 ) ;
359
373
let str saved_out_filename = "" ;
360
- auto env = default_environment ( sess, args. ( 0 ) , ifile) ;
374
+ auto env = default_environment ( sess, binary, ifile) ;
375
+ auto pretty = opt_present ( match , "pretty" ) ;
376
+ auto typed_pretty = opt_present ( match , "typed-pretty" ) ;
377
+ auto ls = opt_present ( match , "ls" ) ;
361
378
if ( pretty || typed_pretty) {
362
379
pretty_print_input ( sess, env, ifile, typed_pretty) ;
363
380
} else if ( ls) {
@@ -368,7 +385,7 @@ fn main(vec[str] args) {
368
385
let vec[ str] parts = str:: split ( ifile, '.' as u8 ) ;
369
386
vec:: pop[ str] ( parts) ;
370
387
saved_out_filename = parts. ( 0 ) ;
371
- alt ( output_type) {
388
+ alt ( sopts . output_type ) {
372
389
case ( link:: output_type_none) { parts += [ "pp" ] ; }
373
390
case ( link:: output_type_bitcode) { parts += [ "bc" ] ; }
374
391
case ( link:: output_type_assembly) { parts += [ "s" ] ; }
@@ -389,7 +406,7 @@ fn main(vec[str] args) {
389
406
390
407
// If the user wants an exe generated we need to invoke
391
408
// gcc to link the object file with some libs
392
- if ( output_type == link:: output_type_exe) {
409
+ if ( sopts . output_type == link:: output_type_exe) {
393
410
394
411
//FIXME: Should we make the 'stage3's variable here?
395
412
let str glu = "stage3/glue.o" ;
@@ -438,7 +455,7 @@ fn main(vec[str] args) {
438
455
}
439
456
440
457
// Remove the temporary object file if we aren't saving temps
441
- if ( !save_temps) {
458
+ if ( !sopts . save_temps ) {
442
459
run:: run_program ( "rm" , [ saved_out_filename + ".o" ] ) ;
443
460
}
444
461
}
0 commit comments