@@ -108,6 +108,30 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
108
108
ret rv;
109
109
}
110
110
111
+ fn inject_libcore_reference ( sess : session:: session ,
112
+ crate : @ast:: crate ) -> @ast:: crate {
113
+
114
+ fn spanned < copy T > ( x : T ) -> @ast:: spanned < T > {
115
+ ret @{ node : x,
116
+ span : { lo: 0 u, hi: 0 u,
117
+ expanded_from: codemap:: os_none} } ;
118
+ }
119
+
120
+ let n1 = sess. next_node_id ( ) ;
121
+ let n2 = sess. next_node_id ( ) ;
122
+
123
+ let vi1 = spanned ( ast:: view_item_use ( "core" , [ ] , n1) ) ;
124
+ let vi2 = spanned ( ast:: view_item_import_glob ( @[ "core" ] , n2) ) ;
125
+
126
+ let cd1 = spanned ( ast:: cdir_view_item ( vi1) ) ;
127
+ let cd2 = spanned ( ast:: cdir_view_item ( vi2) ) ;
128
+
129
+ let cdirs = [ cd1, cd2] + crate . node. directives ;
130
+
131
+ ret @{ node : { directives: cdirs with crate . node } with * crate }
132
+ }
133
+
134
+
111
135
fn compile_input ( sess : session:: session , cfg : ast:: crate_cfg , input : str ,
112
136
output : str ) {
113
137
let time_passes = sess. get_opts ( ) . time_passes ;
@@ -126,6 +150,10 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
126
150
time ( time_passes, "expansion" ,
127
151
bind syntax:: ext:: expand:: expand_crate ( sess, crate ) ) ;
128
152
153
+ if sess. get_opts ( ) . libcore {
154
+ crate = inject_libcore_reference ( sess, crate ) ;
155
+ }
156
+
129
157
let ast_map =
130
158
time ( time_passes, "ast indexing" ,
131
159
bind middle:: ast_map:: map_crate ( * crate ) ) ;
@@ -257,6 +285,7 @@ options:
257
285
-o <filename> write output to <filename>
258
286
--lib compile a library crate
259
287
--static use or produce static libraries
288
+ --no-core omit the 'core' library (used and imported by default)
260
289
--pretty [type] pretty-print the input instead of compiling
261
290
--ls list the symbols defined by a crate file
262
291
-L <path> add a directory to the library search path
@@ -362,6 +391,7 @@ fn build_session_options(match: getopts::match)
362
391
} else if opt_present( match , "emit-llvm" ) {
363
392
link:: output_type_bitcode
364
393
} else { link : : output_type_exe } ;
394
+ let libcore = !opt_present( match , "no-core" ) ;
365
395
let verify = !opt_present( match , "no-verify" ) ;
366
396
let save_temps = opt_present( match , "save-temps" ) ;
367
397
let debuginfo = opt_present( match , "g" ) ;
@@ -409,6 +439,7 @@ fn build_session_options(match: getopts::match)
409
439
let sopts: @session:: options =
410
440
@{ library: library,
411
441
static : static ,
442
+ libcore: libcore ,
412
443
optimize : opt_level ,
413
444
debuginfo : debuginfo ,
414
445
verify : verify ,
@@ -465,6 +496,7 @@ fn opts() -> [getopts::opt] {
465
496
optflag ( "time-passes" ) , optflag ( "time-llvm-passes" ) ,
466
497
optflag ( "no-verify" ) ,
467
498
optmulti ( "cfg" ) , optflag ( "test" ) ,
499
+ optflag ( "no-core" ) ,
468
500
optflag ( "lib" ) , optflag ( "static" ) , optflag ( "gc" ) ,
469
501
optflag ( "stack-growth" ) ,
470
502
optflag ( "no-asm-comments" ) ,
0 commit comments