Skip to content

Commit b54c69e

Browse files
committed
---
yaml --- r: 3569 b: refs/heads/master c: 5c9fb0b h: refs/heads/master i: 3567: 0c3b199 v: v3
1 parent bc2795b commit b54c69e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1062
-885
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1e4f198a1d94e82530456334fe90abd5bfc470b6
2+
refs/heads/master: 5c9fb0bc98dbd744fc82bccd9e09a2d3090b4528

trunk/AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ Paul Stansifer <[email protected]>
3030
Peter Hull <[email protected]>
3131
Ralph Giles <[email protected]>
3232
Rafael Ávila de Espíndola <[email protected]>
33+
Rob Arnold <[email protected]>
3334
Roy Frostig <[email protected]>
3435
Tim Chevalier <[email protected]>

trunk/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ endif
4747
CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
4848
CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
4949
CFG_STDLIB :=$(call CFG_LIB_NAME,std)
50+
CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
5051

5152
# version-string calculation
5253
CFG_GIT_DIR := $(CFG_SRC_DIR).git

trunk/mk/fuzzer.mk

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
# At the moment the fuzzer only exists in stage2. That's the first
2-
# stage built by the non-snapshot compiler so it seems a convenient
3-
# stage to work at.
1+
# At the moment the fuzzer only exists in stage1.
42

53
FUZZER_CRATE := $(S)src/fuzzer/fuzzer.rc
64
FUZZER_INPUTS := $(wildcard $(addprefix $(S)src/fuzzer/, *.rs))
75

8-
stage2/fuzzer.o: $(FUZZER_CRATE) $(FUZZER_INPUTS) $(SREQ1)
9-
@$(call E, compile: $@)
10-
$(STAGE1) -c -o $@ $<
11-
12-
stage2/fuzzer$(X): stage2/fuzzer.o $(SREQ1)
13-
@$(call E, link [gcc]: $@)
14-
$(Q)gcc $(CFG_GCCISH_CFLAGS) rt/main.o stage2/glue.o -o $@ $< \
15-
-Lstage2 -Lrustllvm -Lrt -lrustrt -lrustllvm -lstd -lm -lrustc
16-
@# dsymutil sometimes fails or prints a warning, but the
17-
@# program still runs. Since it simplifies debugging other
18-
@# programs, I\'ll live with the noise.
19-
-$(Q)$(CFG_DSYMUTIL) $@
6+
stage1/fuzzer$(X): $(FUZZER_CRATE) $(FUZZER_INPUTS) $(SREQ1)
7+
@$(call E, compile_and_link: $@)
8+
$(STAGE1) -o $@ $<

trunk/mk/stage1.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ stage1/%.o: stage1/%.s
2929
stage1/%$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ0) stage0/intrinsics.bc
3030
@$(call E, compile_and_link: $@)
3131
$(STAGE0) -o $@ $<
32+
33+
stage1/lib/$(CFG_LIBRUSTC): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ1) \
34+
stage1/intrinsics.bc
35+
@$(call E, compile_and_link: $@)
36+
$(STAGE1) --shared -o $@ $<

trunk/src/comp/back/link.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ fn build_link_meta(&session::session sess, &ast::crate c,
332332
sha.input_str(len_and_str(name));
333333
}
334334
case (ast::meta_list(_, _)) {
335+
// FIXME (#607): Implement this
335336
fail "unimplemented meta_item variant";
336337
}
337338
}

trunk/src/comp/driver/rustc.rs

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import front::parser;
66
import front::token;
77
import front::eval;
88
import front::ast;
9+
import front::attr;
910
import middle::trans;
1011
import middle::resolve;
1112
import middle::ty;
@@ -35,22 +36,42 @@ import back::link::output_type;
3536

3637
tag pp_mode { ppm_normal; ppm_typed; ppm_identified; }
3738

38-
fn default_environment(session::session sess, str argv0, str input) ->
39-
eval::env {
39+
fn default_configuration(session::session sess, str argv0, str input) ->
40+
ast::crate_cfg {
4041
auto libc =
4142
alt (sess.get_targ_cfg().os) {
4243
case (session::os_win32) { "msvcrt.dll" }
4344
case (session::os_macos) { "libc.dylib" }
4445
case (session::os_linux) { "libc.so.6" }
4546
case (_) { "libc.so" }
4647
};
48+
49+
auto mk = attr::mk_name_value_item;
50+
4751
ret [ // Target bindings.
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)),
52+
mk("target_os", std::os::target_os()),
53+
mk("target_arch", "x86"),
54+
mk("target_libc", libc),
5155
// Build bindings.
52-
tup("build_compiler", eval::val_str(argv0)),
53-
tup("build_input", eval::val_str(input))];
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);
5475
}
5576

5677
fn parse_input(session::session sess, parser::parser p, str input) ->
@@ -73,10 +94,10 @@ fn time[T](bool do_it, str what, fn() -> T thunk) -> T {
7394
ret rv;
7495
}
7596

76-
fn compile_input(session::session sess, eval::env env, str input,
97+
fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
7798
str output) {
7899
auto time_passes = sess.get_opts().time_passes;
79-
auto p = parser::new_parser(sess, env, input, 0u, 0);
100+
auto p = parser::new_parser(sess, cfg, input, 0u, 0);
80101
auto crate =
81102
time(time_passes, "parsing", bind parse_input(sess, p, input));
82103
if (sess.get_opts().output_type == link::output_type_none) { ret; }
@@ -104,9 +125,9 @@ fn compile_input(session::session sess, eval::env env, str input,
104125
bind link::write::run_passes(sess, llmod, output));
105126
}
106127

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, 0u, 0);
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, 0u, 0);
110131
auto crate = parse_input(sess, p, input);
111132
auto mode;
112133
alt (ppm) {
@@ -156,6 +177,7 @@ options:
156177
--emit-llvm produce an LLVM bitcode file
157178
--save-temps write intermediate files in addition to normal output
158179
--stats gather and report various compilation statistics
180+
--cfg [cfgspec] configure the compilation environment
159181
--time-passes time the individual phases of the compiler
160182
--time-llvm-passes time the individual phases of the LLVM backend
161183
--sysroot <path> override the system root (default: rustc's directory)
@@ -253,6 +275,7 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
253275
case (none) { get_default_sysroot(binary) }
254276
case (some(?s)) { s }
255277
};
278+
auto cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
256279
let @session::options sopts =
257280
@rec(shared=shared,
258281
optimize=opt_level,
@@ -265,7 +288,8 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
265288
time_llvm_passes=time_llvm_passes,
266289
output_type=output_type,
267290
library_search_paths=library_search_paths,
268-
sysroot=sysroot);
291+
sysroot=sysroot,
292+
cfg=cfg);
269293
ret sopts;
270294
}
271295

@@ -275,7 +299,7 @@ fn build_session(@session::options sopts) -> session::session {
275299
auto target_crate_num = 0;
276300
auto sess =
277301
session::session(target_crate_num, target_cfg, sopts, crate_cache, [],
278-
[], front::codemap::new_codemap(), 0u);
302+
[], [], front::codemap::new_codemap(), 0u);
279303
ret sess;
280304
}
281305

@@ -298,7 +322,7 @@ fn main(vec[str] args) {
298322
optflag("c"), optopt("o"), optflag("g"), optflag("save-temps"),
299323
optopt("sysroot"), optflag("stats"), optflag("time-passes"),
300324
optflag("time-llvm-passes"), optflag("no-typestate"),
301-
optflag("noverify")];
325+
optflag("noverify"), optmulti("cfg")];
302326
auto binary = vec::shift[str](args);
303327
auto binary_dir = fs::dirname(binary);
304328
auto match =
@@ -337,15 +361,15 @@ fn main(vec[str] args) {
337361
}
338362
auto ifile = match.free.(0);
339363
let str saved_out_filename = "";
340-
auto env = default_environment(sess, binary, ifile);
364+
auto cfg = build_configuration(sess, binary, ifile);
341365
auto pretty =
342366
option::map[str,
343367
pp_mode](bind parse_pretty(sess, _),
344368
getopts::opt_default(match, "pretty", "normal"));
345369
auto ls = opt_present(match, "ls");
346370
alt (pretty) {
347371
case (some[pp_mode](?ppm)) {
348-
pretty_print_input(sess, env, ifile, ppm);
372+
pretty_print_input(sess, cfg, ifile, ppm);
349373
ret;
350374
}
351375
case (none[pp_mode]) {/* continue */ }
@@ -371,7 +395,7 @@ fn main(vec[str] args) {
371395
case (link::output_type_exe) { parts += ["o"]; }
372396
}
373397
auto ofile = str::connect(parts, ".");
374-
compile_input(sess, env, ifile, ofile);
398+
compile_input(sess, cfg, ifile, ofile);
375399
}
376400
case (some(?ofile)) {
377401
// FIXME: what about windows? This will create a foo.exe.o.
@@ -386,7 +410,7 @@ fn main(vec[str] args) {
386410
}
387411
case (_) { temp_filename = ofile; }
388412
}
389-
compile_input(sess, env, ifile, temp_filename);
413+
compile_input(sess, cfg, ifile, temp_filename);
390414
}
391415
}
392416

@@ -406,16 +430,11 @@ fn main(vec[str] args) {
406430
saved_out_filename, saved_out_filename + ".o"];
407431
auto shared_cmd;
408432

409-
alt (sess.get_targ_cfg().os) {
410-
case (session::os_win32) {
411-
shared_cmd = "-shared";
412-
}
413-
case (session::os_macos) {
433+
auto os = sess.get_targ_cfg().os;
434+
if (os == session::os_macos) {
414435
shared_cmd = "-dynamiclib";
415-
}
416-
case (session::os_linux) {
436+
} else {
417437
shared_cmd = "-shared";
418-
}
419438
}
420439

421440
// Converts a library file name into a gcc -l argument
@@ -441,7 +460,7 @@ fn main(vec[str] args) {
441460
case (_) { rmext(filename) }
442461
};
443462
}
444-
463+
445464
for (str cratepath in sess.get_used_crate_files()) {
446465
auto dir = fs::dirname(cratepath);
447466
if (dir != "") {
@@ -451,6 +470,7 @@ fn main(vec[str] args) {
451470
gcc_args += ["-l" + libarg];
452471
}
453472

473+
gcc_args += sess.get_used_link_args();
454474
auto used_libs = sess.get_used_libraries();
455475
for (str l in used_libs) {
456476
gcc_args += ["-l" + l];
@@ -459,9 +479,8 @@ fn main(vec[str] args) {
459479
if (sopts.shared) {
460480
gcc_args += [shared_cmd];
461481
} else {
462-
// FIXME: having -Lrustllvm hardcoded in here is hack
463-
// FIXME: same for -lm
464-
gcc_args += ["-Lrustllvm", "-lm", main];
482+
// FIXME: why do we hardcode -lm?
483+
gcc_args += ["-lm", main];
465484
}
466485
// We run 'gcc' here
467486

trunk/src/comp/driver/session.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import std::map;
1010
import std::option;
1111
import std::option::some;
1212
import std::option::none;
13+
import std::str;
1314

1415
tag os { os_win32; os_macos; os_linux; }
1516

@@ -34,7 +35,10 @@ type options =
3435
bool time_llvm_passes,
3536
back::link::output_type output_type,
3637
vec[str] library_search_paths,
37-
str sysroot);
38+
str sysroot,
39+
// The crate config requested for the session, which may be combined
40+
// with additional crate configurations during the compile process
41+
ast::crate_cfg cfg);
3842

3943
type crate_metadata = rec(str name, vec[u8] data);
4044

@@ -68,6 +72,7 @@ obj session(ast::crate_num cnum,
6872
map::hashmap[int, crate_metadata] crates,
6973
mutable vec[str] used_crate_files,
7074
mutable vec[str] used_libraries,
75+
mutable vec[str] used_link_args,
7176
codemap::codemap cm,
7277
mutable uint err_count) {
7378
fn get_targ_cfg() -> @config { ret targ_cfg; }
@@ -127,18 +132,25 @@ obj session(ast::crate_num cnum,
127132
crates.insert(num, metadata);
128133
}
129134
fn has_external_crate(int num) -> bool { ret crates.contains_key(num); }
130-
fn add_used_library(&str lib) {
135+
fn add_used_link_args(&str args) {
136+
used_link_args += str::split(args, ' ' as u8);
137+
}
138+
fn get_used_link_args() -> vec[str] {
139+
ret used_link_args;
140+
}
141+
fn add_used_library(&str lib) -> bool {
131142
if (lib == "") {
132-
ret;
143+
ret false;
133144
}
134145
// A program has a small number of libraries, so a vector is probably
135146
// a good data structure in here.
136147
for (str l in used_libraries) {
137148
if (l == lib) {
138-
ret;
149+
ret false;
139150
}
140151
}
141152
used_libraries += [lib];
153+
ret true;
142154
}
143155
fn get_used_libraries() -> vec[str] {
144156
ret used_libraries;

trunk/src/comp/front/ast.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ type crate_ = rec(vec[@crate_directive] directives,
8888
crate_cfg config);
8989

9090
tag crate_directive_ {
91-
cdir_expr(@expr);
92-
93-
// FIXME: cdir_let should be eliminated
94-
// and redirected to the use of const stmt_decls inside
95-
// crate directive blocks.
96-
cdir_let(ident, @expr, vec[@crate_directive]);
9791
cdir_src_mod(ident, option::t[filename], vec[attribute]);
9892
cdir_dir_mod(ident, option::t[filename],
9993
vec[@crate_directive], vec[attribute]);
@@ -116,13 +110,15 @@ type block = spanned[block_];
116110

117111
type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, node_id id);
118112

119-
type pat = spanned[pat_];
113+
type pat = rec(node_id id,
114+
pat_ node,
115+
span span);
120116

121117
tag pat_ {
122-
pat_wild(node_id);
123-
pat_bind(ident, node_id);
124-
pat_lit(@lit, node_id);
125-
pat_tag(path, vec[@pat], node_id);
118+
pat_wild;
119+
pat_bind(ident);
120+
pat_lit(@lit);
121+
pat_tag(path, vec[@pat]);
126122
}
127123

128124
tag mutability { mut; imm; maybe_mut; }
@@ -281,7 +277,7 @@ tag expr_ {
281277
expr_index(@expr, @expr);
282278
expr_path(path);
283279
expr_ext(path, vec[@expr], option::t[str], @expr);
284-
expr_fail(option::t[str]);
280+
expr_fail(option::t[@expr]);
285281
expr_break;
286282
expr_cont;
287283
expr_ret(option::t[@expr]);
@@ -604,6 +600,19 @@ fn ternary_to_if(&@expr e) -> @ast::expr {
604600
}
605601
}
606602

603+
// Path stringification
604+
fn path_to_str(&ast::path pth) -> str {
605+
auto result = str::connect(pth.node.idents, "::");
606+
if (vec::len[@ast::ty](pth.node.types) > 0u) {
607+
fn f(&@ast::ty t) -> str { ret pretty::pprust::ty_to_str(*t); }
608+
result += "[";
609+
result += str::connect(vec::map(f, pth.node.types), ",");
610+
result += "]";
611+
}
612+
ret result;
613+
}
614+
615+
607616
//
608617
// Local Variables:
609618
// mode: rust

0 commit comments

Comments
 (0)