@@ -17,16 +17,14 @@ use driver::session::Session;
17
17
18
18
use back;
19
19
use back:: write;
20
- use back:: target_strs;
21
- use back:: { arm, x86, x86_64, mips, mipsel} ;
20
+ use rustc_back:: target:: Target ;
22
21
use lint;
23
22
24
- use syntax:: abi;
25
23
use syntax:: ast;
26
24
use syntax:: ast:: { IntTy , UintTy } ;
27
25
use syntax:: attr;
28
26
use syntax:: attr:: AttrMetaMethods ;
29
- use syntax:: diagnostic:: { ColorConfig , Auto , Always , Never } ;
27
+ use syntax:: diagnostic:: { ColorConfig , Auto , Always , Never , SpanHandler } ;
30
28
use syntax:: parse;
31
29
use syntax:: parse:: token:: InternedString ;
32
30
@@ -39,9 +37,7 @@ use std::fmt;
39
37
use llvm;
40
38
41
39
pub struct Config {
42
- pub os : abi:: Os ,
43
- pub arch : abi:: Architecture ,
44
- pub target_strs : target_strs:: t ,
40
+ pub target : Target ,
45
41
pub int_type : IntTy ,
46
42
pub uint_type : UintTy ,
47
43
}
@@ -291,6 +287,13 @@ macro_rules! cgoptions(
291
287
}
292
288
}
293
289
290
+ fn parse_opt_bool( slot: & mut Option <bool >, v: Option <& str >) -> bool {
291
+ match v {
292
+ Some ( ..) => false ,
293
+ None => { * slot = Some ( true ) ; true }
294
+ }
295
+ }
296
+
294
297
fn parse_opt_string( slot: & mut Option <String >, v: Option <& str >) -> bool {
295
298
match v {
296
299
Some ( s) => { * slot = Some ( s. to_string( ) ) ; true } ,
@@ -318,6 +321,18 @@ macro_rules! cgoptions(
318
321
}
319
322
}
320
323
324
+ fn parse_opt_list( slot: & mut Option <Vec <String >>, v: Option <& str >)
325
+ -> bool {
326
+ match v {
327
+ Some ( s) => {
328
+ let v = s. words( ) . map( |s| s. to_string( ) ) . collect( ) ;
329
+ * slot = Some ( v) ;
330
+ true
331
+ } ,
332
+ None => false ,
333
+ }
334
+ }
335
+
321
336
fn parse_uint( slot: & mut uint, v: Option <& str >) -> bool {
322
337
use std:: from_str:: FromStr ;
323
338
match v. and_then( FromStr :: from_str) {
@@ -351,9 +366,9 @@ cgoptions!(
351
366
"tool to assemble archives with" ) ,
352
367
linker: Option <String > = ( None , parse_opt_string,
353
368
"system linker to link outputs with" ) ,
354
- link_args: Vec <String > = ( Vec :: new ( ) , parse_list ,
369
+ link_args: Option < Vec <String >> = ( None , parse_opt_list ,
355
370
"extra arguments to pass to the linker (space separated)" ) ,
356
- target_cpu: String = ( "generic" . to_string ( ) , parse_string ,
371
+ target_cpu: Option < String > = ( None , parse_opt_string ,
357
372
"select target processor (llc -mcpu=help for details)" ) ,
358
373
target_feature: String = ( "" . to_string( ) , parse_string,
359
374
"target specific attributes (llc -mattr=help for details)" ) ,
@@ -377,11 +392,11 @@ cgoptions!(
377
392
"prefer dynamic linking to static linking" ) ,
378
393
no_integrated_as: bool = ( false , parse_bool,
379
394
"use an external assembler rather than LLVM's integrated one" ) ,
380
- no_redzone: bool = ( false , parse_bool ,
395
+ no_redzone: Option < bool > = ( None , parse_opt_bool ,
381
396
"disable the use of the redzone" ) ,
382
- relocation_model: String = ( "pic" . to_string ( ) , parse_string ,
397
+ relocation_model: Option < String > = ( None , parse_opt_string ,
383
398
"choose the relocation model to use (llc -relocation-model for details)" ) ,
384
- code_model: String = ( "default" . to_string ( ) , parse_string ,
399
+ code_model: Option < String > = ( None , parse_opt_string ,
385
400
"choose the code model to use (llc -code-model for details)" ) ,
386
401
metadata: Vec <String > = ( Vec :: new( ) , parse_list,
387
402
"metadata to mangle symbol names with" ) ,
@@ -433,40 +448,27 @@ pub fn default_lib_output() -> CrateType {
433
448
}
434
449
435
450
pub fn default_configuration ( sess : & Session ) -> ast:: CrateConfig {
436
- let tos = match sess. targ_cfg . os {
437
- abi:: OsWindows => InternedString :: new ( "windows" ) ,
438
- abi:: OsMacos => InternedString :: new ( "macos" ) ,
439
- abi:: OsLinux => InternedString :: new ( "linux" ) ,
440
- abi:: OsAndroid => InternedString :: new ( "android" ) ,
441
- abi:: OsFreebsd => InternedString :: new ( "freebsd" ) ,
442
- abi:: OsDragonfly => InternedString :: new ( "dragonfly" ) ,
443
- abi:: OsiOS => InternedString :: new ( "ios" ) ,
444
- } ;
451
+ use syntax:: parse:: token:: intern_and_get_ident as intern;
445
452
446
- // ARM is bi-endian, however using NDK seems to default
447
- // to little-endian unless a flag is provided.
448
- let ( end, arch, wordsz) = match sess. targ_cfg . arch {
449
- abi:: X86 => ( "little" , "x86" , "32" ) ,
450
- abi:: X86_64 => ( "little" , "x86_64" , "64" ) ,
451
- abi:: Arm => ( "little" , "arm" , "32" ) ,
452
- abi:: Mips => ( "big" , "mips" , "32" ) ,
453
- abi:: Mipsel => ( "little" , "mipsel" , "32" )
454
- } ;
453
+ let end = sess. target . target . target_endian . as_slice ( ) ;
454
+ let arch = sess. target . target . arch . as_slice ( ) ;
455
+ let wordsz = sess. target . target . target_word_size . as_slice ( ) ;
456
+ let os = sess. target . target . target_os . as_slice ( ) ;
455
457
456
- let fam = match sess. targ_cfg . os {
457
- abi :: OsWindows => InternedString :: new ( "windows" ) ,
458
- _ => InternedString :: new ( "unix" )
458
+ let fam = match sess. target . target . options . is_like_windows {
459
+ true => InternedString :: new ( "windows" ) ,
460
+ false => InternedString :: new ( "unix" )
459
461
} ;
460
462
461
463
let mk = attr:: mk_name_value_item_str;
462
464
return vec ! ( // Target bindings.
463
465
attr:: mk_word_item( fam. clone( ) ) ,
464
- mk( InternedString :: new( "target_os" ) , tos ) ,
466
+ mk( InternedString :: new( "target_os" ) , intern ( os ) ) ,
465
467
mk( InternedString :: new( "target_family" ) , fam) ,
466
- mk( InternedString :: new( "target_arch" ) , InternedString :: new ( arch) ) ,
467
- mk( InternedString :: new( "target_endian" ) , InternedString :: new ( end) ) ,
468
+ mk( InternedString :: new( "target_arch" ) , intern ( arch) ) ,
469
+ mk( InternedString :: new( "target_endian" ) , intern ( end) ) ,
468
470
mk( InternedString :: new( "target_word_size" ) ,
469
- InternedString :: new ( wordsz) )
471
+ intern ( wordsz) )
470
472
) ;
471
473
}
472
474
@@ -489,76 +491,23 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
489
491
user_cfg. into_iter ( ) . collect :: < Vec < _ > > ( ) . append ( default_cfg. as_slice ( ) )
490
492
}
491
493
492
- pub fn get_os ( triple : & str ) -> Option < abi:: Os > {
493
- for & ( name, os) in os_names. iter ( ) {
494
- if triple. contains ( name) { return Some ( os) }
495
- }
496
- None
497
- }
498
- static os_names : & ' static [ ( & ' static str , abi:: Os ) ] = & [
499
- ( "mingw32" , abi:: OsWindows ) ,
500
- ( "win32" , abi:: OsWindows ) ,
501
- ( "windows" , abi:: OsWindows ) ,
502
- ( "darwin" , abi:: OsMacos ) ,
503
- ( "android" , abi:: OsAndroid ) ,
504
- ( "linux" , abi:: OsLinux ) ,
505
- ( "freebsd" , abi:: OsFreebsd ) ,
506
- ( "dragonfly" , abi:: OsDragonfly ) ,
507
- ( "ios" , abi:: OsiOS ) ] ;
508
-
509
- pub fn get_arch ( triple : & str ) -> Option < abi:: Architecture > {
510
- for & ( arch, abi) in architecture_abis. iter ( ) {
511
- if triple. contains ( arch) { return Some ( abi) }
512
- }
513
- None
514
- }
515
- static architecture_abis : & ' static [ ( & ' static str , abi:: Architecture ) ] = & [
516
- ( "i386" , abi:: X86 ) ,
517
- ( "i486" , abi:: X86 ) ,
518
- ( "i586" , abi:: X86 ) ,
519
- ( "i686" , abi:: X86 ) ,
520
- ( "i786" , abi:: X86 ) ,
521
-
522
- ( "x86_64" , abi:: X86_64 ) ,
523
-
524
- ( "arm" , abi:: Arm ) ,
525
- ( "xscale" , abi:: Arm ) ,
526
- ( "thumb" , abi:: Arm ) ,
527
-
528
- ( "mipsel" , abi:: Mipsel ) ,
529
- ( "mips" , abi:: Mips ) ] ;
530
-
531
- pub fn build_target_config ( sopts : & Options ) -> Config {
532
- let os = match get_os ( sopts. target_triple . as_slice ( ) ) {
533
- Some ( os) => os,
534
- None => early_error ( "unknown operating system" )
535
- } ;
536
- let arch = match get_arch ( sopts. target_triple . as_slice ( ) ) {
537
- Some ( arch) => arch,
538
- None => {
539
- early_error ( format ! ( "unknown architecture: {}" ,
540
- sopts. target_triple. as_slice( ) ) . as_slice ( ) )
541
- }
542
- } ;
543
- let ( int_type, uint_type) = match arch {
544
- abi:: X86 => ( ast:: TyI32 , ast:: TyU32 ) ,
545
- abi:: X86_64 => ( ast:: TyI64 , ast:: TyU64 ) ,
546
- abi:: Arm => ( ast:: TyI32 , ast:: TyU32 ) ,
547
- abi:: Mips => ( ast:: TyI32 , ast:: TyU32 ) ,
548
- abi:: Mipsel => ( ast:: TyI32 , ast:: TyU32 )
494
+ pub fn build_target_config ( opts : & Options , sp : & SpanHandler ) -> Config {
495
+ let target = match Target :: search ( opts. target_triple . as_slice ( ) ) {
496
+ Ok ( t) => t,
497
+ Err ( e) => {
498
+ sp. handler ( ) . fatal ( ( format ! ( "Error loading target specification: {}" , e) ) . as_slice ( ) ) ;
499
+ }
549
500
} ;
550
- let target_triple = sopts. target_triple . clone ( ) ;
551
- let target_strs = match arch {
552
- abi:: X86 => x86:: get_target_strs ( target_triple, os) ,
553
- abi:: X86_64 => x86_64:: get_target_strs ( target_triple, os) ,
554
- abi:: Arm => arm:: get_target_strs ( target_triple, os) ,
555
- abi:: Mips => mips:: get_target_strs ( target_triple, os) ,
556
- abi:: Mipsel => mipsel:: get_target_strs ( target_triple, os)
501
+
502
+ let ( int_type, uint_type) = match target. target_word_size . as_slice ( ) {
503
+ "32" => ( ast:: TyI32 , ast:: TyU32 ) ,
504
+ "64" => ( ast:: TyI64 , ast:: TyU64 ) ,
505
+ w => sp. handler ( ) . fatal ( ( format ! ( "target specification was invalid: unrecognized \
506
+ target-word-size {}", w) ) . as_slice ( ) )
557
507
} ;
508
+
558
509
Config {
559
- os : os,
560
- arch : arch,
561
- target_strs : target_strs,
510
+ target : target,
562
511
int_type : int_type,
563
512
uint_type : uint_type,
564
513
}
0 commit comments