@@ -6,7 +6,6 @@ import front::parser;
6
6
import front:: token;
7
7
import front:: eval;
8
8
import front:: ast;
9
- import front:: attr;
10
9
import middle:: trans;
11
10
import middle:: resolve;
12
11
import middle:: ty;
@@ -36,42 +35,22 @@ import back::link::output_type;
36
35
37
36
tag pp_mode { ppm_normal; ppm_typed; ppm_identified; }
38
37
39
- fn default_configuration ( session:: session sess, str argv0 , str input ) ->
40
- ast :: crate_cfg {
38
+ fn default_environment ( session:: session sess, str argv0 , str input ) ->
39
+ eval :: env {
41
40
auto libc =
42
41
alt ( sess. get_targ_cfg ( ) . os ) {
43
42
case ( session:: os_win32) { "msvcrt.dll" }
44
43
case ( session:: os_macos) { "libc.dylib" }
45
44
case ( session:: os_linux) { "libc.so.6" }
46
45
case ( _) { "libc.so" }
47
46
} ;
48
-
49
- auto mk = attr:: mk_name_value_item;
50
-
51
47
ret [ // Target bindings.
52
- mk ( "target_os" , std:: os:: target_os ( ) ) ,
53
- mk ( "target_arch" , "x86" ) ,
54
- mk ( "target_libc" , libc) ,
48
+ tup ( "target_os" , eval :: val_str ( std:: os:: target_os ( ) ) ) ,
49
+ tup ( "target_arch" , eval :: val_str ( "x86" ) ) ,
50
+ tup ( "target_libc" , eval :: val_str ( libc) ) ,
55
51
// Build bindings.
56
- mk ( "build_compiler" , argv0) ,
57
- mk ( "build_input" , input) ] ;
58
- }
59
-
60
- fn build_configuration ( session:: session sess, str argv0 ,
61
- str input ) -> ast:: crate_cfg {
62
- // Combine the configuration requested by the session (command line) with
63
- // some default configuration items
64
- ret sess. get_opts ( ) . cfg + default_configuration ( sess, argv0, input) ;
65
- }
66
-
67
- // Convert strings provided as --cfg [cfgspec] into a crate_cfg
68
- fn parse_cfgspecs ( & vec[ str] cfgspecs ) -> ast:: crate_cfg {
69
- // FIXME: It would be nice to use the parser to parse all varieties of
70
- // meta_item here. At the moment we just support the meta_word variant.
71
- fn to_meta_word ( & str cfgspec ) -> @ast:: meta_item {
72
- attr:: mk_word_item ( cfgspec)
73
- }
74
- ret vec:: map ( to_meta_word, cfgspecs) ;
52
+ tup ( "build_compiler" , eval:: val_str ( argv0) ) ,
53
+ tup ( "build_input" , eval:: val_str ( input) ) ] ;
75
54
}
76
55
77
56
fn parse_input ( session:: session sess, parser:: parser p, str input ) ->
@@ -94,10 +73,10 @@ fn time[T](bool do_it, str what, fn() -> T thunk) -> T {
94
73
ret rv;
95
74
}
96
75
97
- fn compile_input ( session:: session sess, ast :: crate_cfg cfg , str input ,
76
+ fn compile_input ( session:: session sess, eval :: env env , str input ,
98
77
str output ) {
99
78
auto time_passes = sess. get_opts ( ) . time_passes ;
100
- auto p = parser:: new_parser ( sess, cfg , input, 0 u, 0 ) ;
79
+ auto p = parser:: new_parser ( sess, env , input, 0 u, 0 ) ;
101
80
auto crate =
102
81
time ( time_passes, "parsing" , bind parse_input ( sess, p, input) ) ;
103
82
if ( sess. get_opts ( ) . output_type == link:: output_type_none) { ret; }
@@ -125,9 +104,9 @@ fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
125
104
bind link:: write:: run_passes ( sess, llmod, output) ) ;
126
105
}
127
106
128
- fn pretty_print_input ( session:: session sess, ast :: crate_cfg cfg ,
129
- str input , pp_mode ppm) {
130
- auto p = front:: parser:: new_parser ( sess, cfg , input, 0 u, 0 ) ;
107
+ fn pretty_print_input ( session:: session sess, eval :: env env , str input ,
108
+ pp_mode ppm) {
109
+ auto p = front:: parser:: new_parser ( sess, env , input, 0 u, 0 ) ;
131
110
auto crate = parse_input ( sess, p, input) ;
132
111
auto mode;
133
112
alt ( ppm) {
@@ -177,7 +156,6 @@ options:
177
156
--emit-llvm produce an LLVM bitcode file
178
157
--save-temps write intermediate files in addition to normal output
179
158
--stats gather and report various compilation statistics
180
- --cfg [cfgspec] configure the compilation environment
181
159
--time-passes time the individual phases of the compiler
182
160
--time-llvm-passes time the individual phases of the LLVM backend
183
161
--sysroot <path> override the system root (default: rustc's directory)
@@ -275,7 +253,6 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
275
253
case ( none) { get_default_sysroot ( binary) }
276
254
case ( some ( ?s) ) { s }
277
255
} ;
278
- auto cfg = parse_cfgspecs( getopts:: opt_strs( match , "cfg" ) ) ;
279
256
let @session:: options sopts =
280
257
@rec ( shared=shared,
281
258
optimize=opt_level,
@@ -288,8 +265,7 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
288
265
time_llvm_passes=time_llvm_passes,
289
266
output_type=output_type,
290
267
library_search_paths=library_search_paths,
291
- sysroot=sysroot,
292
- cfg=cfg) ;
268
+ sysroot=sysroot) ;
293
269
ret sopts;
294
270
}
295
271
@@ -299,7 +275,7 @@ fn build_session(@session::options sopts) -> session::session {
299
275
auto target_crate_num = 0 ;
300
276
auto sess =
301
277
session:: session ( target_crate_num, target_cfg, sopts, crate_cache, [ ] ,
302
- [ ] , [ ] , front:: codemap:: new_codemap( ) , 0 u) ;
278
+ [ ] , front:: codemap:: new_codemap ( ) , 0 u) ;
303
279
ret sess;
304
280
}
305
281
@@ -322,7 +298,7 @@ fn main(vec[str] args) {
322
298
optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) , optflag ( "save-temps" ) ,
323
299
optopt ( "sysroot" ) , optflag ( "stats" ) , optflag ( "time-passes" ) ,
324
300
optflag ( "time-llvm-passes" ) , optflag ( "no-typestate" ) ,
325
- optflag ( "noverify" ) , optmulti ( "cfg" ) ] ;
301
+ optflag ( "noverify" ) ] ;
326
302
auto binary = vec:: shift[ str] ( args) ;
327
303
auto binary_dir = fs:: dirname ( binary) ;
328
304
auto match =
@@ -361,15 +337,15 @@ fn main(vec[str] args) {
361
337
}
362
338
auto ifile = match . free . ( 0 ) ;
363
339
let str saved_out_filename = "" ;
364
- auto cfg = build_configuration ( sess, binary, ifile) ;
340
+ auto env = default_environment ( sess, binary, ifile) ;
365
341
auto pretty =
366
342
option:: map[ str,
367
343
pp_mode] ( bind parse_pretty ( sess, _) ,
368
344
getopts:: opt_default ( match , "pretty" , "normal" ) ) ;
369
345
auto ls = opt_present ( match , "ls" ) ;
370
346
alt ( pretty) {
371
347
case ( some[ pp_mode] ( ?ppm) ) {
372
- pretty_print_input ( sess, cfg , ifile, ppm) ;
348
+ pretty_print_input ( sess, env , ifile, ppm) ;
373
349
ret;
374
350
}
375
351
case ( none[ pp_mode] ) { /* continue */ }
@@ -395,7 +371,7 @@ fn main(vec[str] args) {
395
371
case ( link:: output_type_exe) { parts += [ "o" ] ; }
396
372
}
397
373
auto ofile = str:: connect ( parts, "." ) ;
398
- compile_input ( sess, cfg , ifile, ofile) ;
374
+ compile_input ( sess, env , ifile, ofile) ;
399
375
}
400
376
case ( some ( ?ofile) ) {
401
377
// FIXME: what about windows? This will create a foo.exe.o.
@@ -410,7 +386,7 @@ fn main(vec[str] args) {
410
386
}
411
387
case ( _) { temp_filename = ofile; }
412
388
}
413
- compile_input ( sess, cfg , ifile, temp_filename) ;
389
+ compile_input ( sess, env , ifile, temp_filename) ;
414
390
}
415
391
}
416
392
@@ -430,11 +406,16 @@ fn main(vec[str] args) {
430
406
saved_out_filename, saved_out_filename + ".o" ] ;
431
407
auto shared_cmd;
432
408
433
- auto os = sess. get_targ_cfg ( ) . os ;
434
- if ( os == session:: os_macos) {
409
+ alt ( sess. get_targ_cfg ( ) . os ) {
410
+ case ( session:: os_win32) {
411
+ shared_cmd = "-shared" ;
412
+ }
413
+ case ( session:: os_macos) {
435
414
shared_cmd = "-dynamiclib" ;
436
- } else {
415
+ }
416
+ case ( session:: os_linux) {
437
417
shared_cmd = "-shared" ;
418
+ }
438
419
}
439
420
440
421
// Converts a library file name into a gcc -l argument
@@ -460,7 +441,7 @@ fn main(vec[str] args) {
460
441
case ( _) { rmext ( filename) }
461
442
} ;
462
443
}
463
-
444
+
464
445
for ( str cratepath in sess. get_used_crate_files( ) ) {
465
446
auto dir = fs:: dirname( cratepath) ;
466
447
if ( dir != "" ) {
@@ -470,7 +451,6 @@ fn main(vec[str] args) {
470
451
gcc_args += [ "-l" + libarg] ;
471
452
}
472
453
473
- gcc_args += sess. get_used_link_args( ) ;
474
454
auto used_libs = sess. get_used_libraries( ) ;
475
455
for ( str l in used_libs) {
476
456
gcc_args += [ "-l" + l] ;
@@ -479,8 +459,9 @@ fn main(vec[str] args) {
479
459
if ( sopts. shared) {
480
460
gcc_args += [ shared_cmd] ;
481
461
} else {
482
- // FIXME: why do we hardcode -lm?
483
- gcc_args += [ "-lm" , main] ;
462
+ // FIXME: having -Lrustllvm hardcoded in here is hack
463
+ // FIXME: same for -lm
464
+ gcc_args += [ "-Lrustllvm" , "-lm" , main] ;
484
465
}
485
466
// We run 'gcc' here
486
467
0 commit comments