Skip to content

Commit fc734bc

Browse files
committed
---
yaml --- r: 835 b: refs/heads/master c: 36aea66 h: refs/heads/master i: 833: c9b9215 831: b3e7c8b v: v3
1 parent 525f749 commit fc734bc

File tree

3 files changed

+100
-12
lines changed

3 files changed

+100
-12
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: 74eda5bb70b5f653ab835bc0f2ea6fb85e421356
2+
refs/heads/master: 36aea66e479708a9058dde1b2ad459972a62807c

trunk/src/comp/driver/rustc.rs

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,111 @@ import front.token;
55
import middle.trans;
66
import middle.resolve;
77

8-
io fn main(vec[str] args) {
8+
import std.util.option;
9+
import std.util.some;
10+
import std.util.none;
11+
import std._str;
12+
import std._vec;
13+
14+
io fn compile_input(session.session sess, str input, str output) {
15+
auto p = parser.new_parser(sess, 0, input);
16+
auto crate = parser.parse_crate(p);
17+
crate = resolve.resolve_crate(sess, crate);
18+
trans.trans_crate(sess, crate, output);
19+
}
920

21+
fn warn_wrong_compiler() {
1022
log "This is the rust 'self-hosted' compiler.";
1123
log "The one written in rust.";
1224
log "It does nothing yet, it's a placeholder.";
1325
log "You want rustboot, the compiler next door.";
26+
}
27+
28+
fn usage(session.session sess, str argv0) {
29+
log #fmt("usage: %s [options] <input>", argv0);
30+
log "options:";
31+
log "";
32+
log " -o <filename> write output to <filename>";
33+
log " -nowarn suppress wrong-compiler warning";
34+
log " -h display this message";
35+
log "";
36+
log "";
37+
}
38+
39+
io fn main(vec[str] args) {
1440

15-
auto i = 0;
1641
auto sess = session.session();
17-
for (str filename in args) {
18-
if (i > 0) {
19-
auto p = parser.new_parser(sess, 0, filename);
20-
auto crate = parser.parse_crate(p);
21-
crate = resolve.resolve_crate(sess, crate);
22-
trans.trans_crate(sess, crate);
42+
let option[str] input_file = none[str];
43+
let option[str] output_file = none[str];
44+
let bool do_warn = true;
45+
46+
auto i = 1u;
47+
auto len = _vec.len[str](args);
48+
49+
// FIXME: a getopt module would be nice.
50+
while (i < len) {
51+
auto arg = args.(i);
52+
if (_str.byte_len(arg) > 0u && arg.(0) == '-' as u8) {
53+
if (_str.eq(arg, "-nowarn")) {
54+
do_warn = false;
55+
} else {
56+
// FIXME: rust could use an elif construct.
57+
if (_str.eq(arg, "-o")) {
58+
if (i+1u < len) {
59+
output_file = some(args.(i+1u));
60+
i += 1u;
61+
} else {
62+
usage(sess, args.(0));
63+
sess.err("-o requires an argument");
64+
}
65+
} else {
66+
if (_str.eq(arg, "-h")) {
67+
usage(sess, args.(0));
68+
} else {
69+
usage(sess, args.(0));
70+
sess.err("unrecognized option: " + arg);
71+
}
72+
}
73+
}
74+
} else {
75+
alt (input_file) {
76+
case (some[str](_)) {
77+
usage(sess, args.(0));
78+
sess.err("multiple inputs provided");
79+
}
80+
case (none[str]) {
81+
input_file = some[str](arg);
82+
}
83+
}
84+
// FIXME: dummy node to work around typestate mis-wiring bug.
85+
i = i;
86+
}
87+
i += 1u;
88+
}
89+
90+
if (do_warn) {
91+
warn_wrong_compiler();
92+
}
93+
94+
alt (input_file) {
95+
case (none[str]) {
96+
usage(sess, args.(0));
97+
sess.err("no input filename");
98+
}
99+
case (some[str](?ifile)) {
100+
alt (output_file) {
101+
case (none[str]) {
102+
let vec[str] parts = _str.split(ifile, '.' as u8);
103+
parts = _vec.pop[str](parts);
104+
parts += ".bc";
105+
auto ofile = _str.concat(parts);
106+
compile_input(sess, ifile, ofile);
107+
}
108+
case (some[str](?ofile)) {
109+
compile_input(sess, ifile, ofile);
110+
}
111+
}
23112
}
24-
i += 1;
25113
}
26114
}
27115

trunk/src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
10951095

10961096
}
10971097

1098-
fn trans_crate(session.session sess, @ast.crate crate) {
1098+
fn trans_crate(session.session sess, @ast.crate crate, str output) {
10991099
auto llmod =
11001100
llvm.LLVMModuleCreateWithNameInContext(_str.buf("rust_out"),
11011101
llvm.LLVMGetGlobalContext());
@@ -1138,7 +1138,7 @@ fn trans_crate(session.session sess, @ast.crate crate) {
11381138
trans_exit_task_glue(cx);
11391139
trans_main_fn(cx, crate_constant(cx));
11401140

1141-
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf("rust_out.bc"));
1141+
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
11421142
llvm.LLVMDisposeModule(llmod);
11431143
}
11441144

0 commit comments

Comments
 (0)