Skip to content

Commit dc3a48d

Browse files
committed
---
yaml --- r: 2352 b: refs/heads/master c: cdb6822 h: refs/heads/master v: v3
1 parent ffb19d3 commit dc3a48d

File tree

6 files changed

+107
-88
lines changed

6 files changed

+107
-88
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: 619b4743e340f4d3d69addd66282e50fb1fb2cf0
2+
refs/heads/master: cdb68224054eddddb0c1d2519f9c12b654a6ff8f

trunk/src/comp/driver/rustc.rs

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -78,50 +78,39 @@ fn time[T](bool do_it, str what, fn()->T thunk) -> T {
7878
}
7979

8080
fn compile_input(session.session sess,
81-
eval.env env,
82-
str input, str output,
83-
bool shared,
84-
bool optimize,
85-
bool debuginfo,
86-
bool verify,
87-
bool save_temps,
88-
trans.output_type ot,
89-
bool time_passes,
90-
bool run_typestate,
91-
vec[str] library_search_paths) {
81+
eval.env env,
82+
str input, str output) {
83+
auto time_passes = sess.get_opts().time_passes;
9284
auto def = tup(0, 0);
9385
auto p = parser.new_parser(sess, env, def, input, 0u);
9486
auto crate = time[@ast.crate](time_passes, "parsing",
95-
bind parse_input(sess, p, input));
96-
if (ot == trans.output_type_none) {ret;}
87+
bind parse_input(sess, p, input));
88+
if (sess.get_opts().output_type == trans.output_type_none) {ret;}
9789

9890
crate = time[@ast.crate](time_passes, "external crate reading",
99-
bind creader.read_crates(sess, crate, library_search_paths));
91+
bind creader.read_crates(sess, crate));
10092
crate = time[@ast.crate](time_passes, "resolution",
101-
bind resolve.resolve_crate(sess, crate));
93+
bind resolve.resolve_crate(sess, crate));
10294
time[()](time_passes, "capture checking",
103-
bind capture.check_for_captures(sess, crate));
95+
bind capture.check_for_captures(sess, crate));
10496

10597
auto ty_cx = ty.mk_ctxt(sess);
10698
auto typeck_result =
10799
time[typeck.typecheck_result](time_passes, "typechecking",
108-
bind typeck.check_crate(ty_cx, crate));
100+
bind typeck.check_crate(ty_cx, crate));
109101
crate = typeck_result._0;
110102
auto type_cache = typeck_result._1;
111103

112-
if (run_typestate) {
104+
if (sess.get_opts().run_typestate) {
113105
crate = time[@ast.crate](time_passes, "typestate checking",
114106
bind typestate_check.check_crate(crate));
115107
}
116108

117109
auto llmod = time[llvm.ModuleRef](time_passes, "translation",
118-
bind trans.trans_crate(sess, crate, ty_cx, type_cache, output,
119-
debuginfo, shared));
110+
bind trans.trans_crate(sess, crate, ty_cx, type_cache, output));
120111

121112
time[()](time_passes, "LLVM passes",
122-
bind trans.run_passes(llmod, optimize, debuginfo,
123-
verify, save_temps, output,
124-
ot));
113+
bind trans.run_passes(sess, llmod, output));
125114
}
126115

127116
fn pretty_print_input(session.session sess,
@@ -133,7 +122,7 @@ fn pretty_print_input(session.session sess,
133122
pretty.pprust.print_file(crate.node.module, input, std.io.stdout());
134123
}
135124

136-
fn usage(session.session sess, str argv0) {
125+
fn usage(str argv0) {
137126
io.stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) + "
138127
options:
139128
@@ -166,17 +155,12 @@ fn get_os() -> session.os {
166155
fn main(vec[str] args) {
167156

168157
// FIXME: don't hard-wire this.
169-
auto target_cfg = rec(os = get_os(),
170-
arch = session.arch_x86,
171-
int_type = common.ty_i32,
172-
uint_type = common.ty_u32,
173-
float_type = common.ty_f64 );
174-
175-
auto crate_cache = common.new_int_hash[session.crate_metadata]();
176-
auto target_crate_num = 0;
177-
let vec[@ast.meta_item] md = vec();
178-
auto sess = session.session(target_crate_num, target_cfg, crate_cache,
179-
md, front.codemap.new_codemap());
158+
let @session.config target_cfg =
159+
@rec(os = get_os(),
160+
arch = session.arch_x86,
161+
int_type = common.ty_i32,
162+
uint_type = common.ty_u32,
163+
float_type = common.ty_f64);
180164

181165
auto opts = vec(optflag("h"), optflag("glue"),
182166
optflag("pretty"), optflag("ls"), optflag("parse-only"),
@@ -187,11 +171,14 @@ fn main(vec[str] args) {
187171
auto binary = _vec.shift[str](args);
188172
auto match;
189173
alt (GetOpts.getopts(args, opts)) {
190-
case (GetOpts.failure(?f)) { sess.err(GetOpts.fail_str(f)); fail; }
174+
case (GetOpts.failure(?f)) {
175+
log_err #fmt("error: %s", GetOpts.fail_str(f));
176+
fail;
177+
}
191178
case (GetOpts.success(?m)) { match = m; }
192179
}
193180
if (opt_present(match, "h")) {
194-
usage(sess, binary);
181+
usage(binary);
195182
ret;
196183
}
197184

@@ -201,13 +188,13 @@ fn main(vec[str] args) {
201188
auto shared = opt_present(match, "shared");
202189
auto output_file = GetOpts.opt_maybe_str(match, "o");
203190
auto library_search_paths = GetOpts.opt_strs(match, "L");
204-
auto ot = trans.output_type_bitcode;
191+
auto output_type = trans.output_type_bitcode;
205192
if (opt_present(match, "parse-only")) {
206-
ot = trans.output_type_none;
193+
output_type = trans.output_type_none;
207194
} else if (opt_present(match, "S")) {
208-
ot = trans.output_type_assembly;
195+
output_type = trans.output_type_assembly;
209196
} else if (opt_present(match, "c")) {
210-
ot = trans.output_type_object;
197+
output_type = trans.output_type_object;
211198
}
212199
auto verify = !opt_present(match, "noverify");
213200
auto save_temps = opt_present(match, "save-temps");
@@ -216,14 +203,33 @@ fn main(vec[str] args) {
216203
auto debuginfo = opt_present(match, "g");
217204
auto time_passes = opt_present(match, "time-passes");
218205
auto run_typestate = !opt_present(match, "no-typestate");
206+
207+
let @session.options sopts =
208+
@rec(shared = shared,
209+
optimize = optimize,
210+
debuginfo = debuginfo,
211+
verify = verify,
212+
run_typestate = run_typestate,
213+
save_temps = save_temps,
214+
time_passes = time_passes,
215+
output_type = output_type,
216+
library_search_paths = library_search_paths);
217+
218+
auto crate_cache = common.new_int_hash[session.crate_metadata]();
219+
auto target_crate_num = 0;
220+
let vec[@ast.meta_item] md = vec();
221+
auto sess =
222+
session.session(target_crate_num, target_cfg, sopts,
223+
crate_cache, md, front.codemap.new_codemap());
224+
219225
auto n_inputs = _vec.len[str](match.free);
220226

221227
if (glue) {
222228
if (n_inputs > 0u) {
223229
sess.err("No input files allowed with --glue.");
224230
}
225231
auto out = option.from_maybe[str]("glue.bc", output_file);
226-
middle.trans.make_common_glue(out, optimize, verify, save_temps, ot);
232+
middle.trans.make_common_glue(sess, out);
227233
ret;
228234
}
229235

@@ -244,18 +250,21 @@ fn main(vec[str] args) {
244250
case (none[str]) {
245251
let vec[str] parts = _str.split(ifile, '.' as u8);
246252
_vec.pop[str](parts);
247-
parts += vec("bc");
253+
alt (output_type) {
254+
case (trans.output_type_none)
255+
{ parts += vec("pp"); }
256+
case (trans.output_type_bitcode)
257+
{ parts += vec("bc"); }
258+
case (trans.output_type_assembly)
259+
{ parts += vec("s"); }
260+
case (trans.output_type_object)
261+
{ parts += vec("o"); }
262+
}
248263
auto ofile = _str.connect(parts, ".");
249-
compile_input(sess, env, ifile, ofile, shared,
250-
optimize, debuginfo, verify,
251-
save_temps, ot, time_passes,
252-
run_typestate, library_search_paths);
264+
compile_input(sess, env, ifile, ofile);
253265
}
254266
case (some[str](?ofile)) {
255-
compile_input(sess, env, ifile, ofile, shared,
256-
optimize, debuginfo, verify,
257-
save_temps, ot, time_passes,
258-
run_typestate, library_search_paths);
267+
compile_input(sess, env, ifile, ofile);
259268
}
260269
}
261270
}

trunk/src/comp/driver/session.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ tag arch {
1919
arch_arm;
2020
}
2121

22-
type cfg = rec(os os,
23-
arch arch,
24-
ty_mach int_type,
25-
ty_mach uint_type,
26-
ty_mach float_type);
22+
type config = rec(os os,
23+
arch arch,
24+
ty_mach int_type,
25+
ty_mach uint_type,
26+
ty_mach float_type);
27+
28+
type options = rec(bool shared,
29+
bool optimize,
30+
bool debuginfo,
31+
bool verify,
32+
bool run_typestate,
33+
bool save_temps,
34+
bool time_passes,
35+
middle.trans.output_type output_type,
36+
vec[str] library_search_paths);
2737

2838
type crate_metadata = rec(str name,
2939
vec[u8] data);
@@ -47,13 +57,18 @@ fn emit_diagnostic(span sp, str msg, str kind, u8 color, codemap.codemap cm) {
4757
io.stdout().write_str(#fmt(" %s\n", msg));
4858
}
4959

50-
state obj session(ast.crate_num cnum, cfg targ,
60+
state obj session(ast.crate_num cnum,
61+
@config targ_cfg, @options opts,
5162
map.hashmap[int, crate_metadata] crates,
5263
mutable vec[@ast.meta_item] metadata,
5364
codemap.codemap cm) {
5465

55-
fn get_targ_cfg() -> cfg {
56-
ret targ;
66+
fn get_targ_cfg() -> @config {
67+
ret targ_cfg;
68+
}
69+
70+
fn get_opts() -> @options {
71+
ret opts;
5772
}
5873

5974
fn get_targ_crate_num() -> ast.crate_num {

trunk/src/comp/front/creader.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,11 @@ fn fold_view_item_use(&env e, &span sp, ast.ident ident,
459459

460460
// Reads external crates referenced by "use" directives.
461461
fn read_crates(session.session sess,
462-
@ast.crate crate,
463-
vec[str] library_search_paths) -> @ast.crate {
462+
@ast.crate crate) -> @ast.crate {
464463
auto e = @rec(
465464
sess=sess,
466465
crate_cache=@common.new_str_hash[int](),
467-
library_search_paths=library_search_paths,
466+
library_search_paths=sess.get_opts().library_search_paths,
468467
mutable next_crate_num=1
469468
);
470469

trunk/src/comp/middle/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,9 @@ fn encode_metadata(@trans.crate_ctxt cx, @ast.crate crate)
687687
ret C_postr(string_w.get_str());
688688
}
689689

690-
fn write_metadata(@trans.crate_ctxt cx, bool shared, @ast.crate crate) {
690+
fn write_metadata(@trans.crate_ctxt cx, @ast.crate crate) {
691691
auto llmeta = C_postr("");
692-
if (shared) {
692+
if (cx.sess.get_opts().shared) {
693693
llmeta = encode_metadata(cx, crate);
694694
}
695695

0 commit comments

Comments
 (0)