aboutsummaryrefslogtreecommitdiff
path: root/src/comp/driver
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-22 16:27:00 -0800
committerGraydon Hoare <[email protected]>2010-11-22 16:27:00 -0800
commitd3cb25d5d1ede9d9ef06db6c30cd8448ed425127 (patch)
tree51c12e7f2c5396f7af8e57d2d4e77bbf5a9d2373 /src/comp/driver
parentFix type disagreements in lowering typeck.ty to llvm TypeRefs, enable complex... (diff)
downloadrust-d3cb25d5d1ede9d9ef06db6c30cd8448ed425127.tar.xz
rust-d3cb25d5d1ede9d9ef06db6c30cd8448ed425127.zip
Check and translate 'as' cast-operator, lower target-specific types, reindent rustc.rs, enable uint test.
Diffstat (limited to 'src/comp/driver')
-rw-r--r--src/comp/driver/rustc.rs171
-rw-r--r--src/comp/driver/session.rs31
2 files changed, 123 insertions, 79 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index baf00780..9c0b2484 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -5,6 +5,7 @@ import front.token;
import middle.trans;
import middle.resolve;
import middle.typeck;
+import util.common;
import std.option;
import std.option.some;
@@ -13,18 +14,18 @@ import std._str;
import std._vec;
impure fn compile_input(session.session sess, str input, str output) {
- auto p = parser.new_parser(sess, 0, input);
- auto crate = parser.parse_crate(p);
- crate = resolve.resolve_crate(sess, crate);
- crate = typeck.check_crate(sess, crate);
- trans.trans_crate(sess, crate, output);
+ auto p = parser.new_parser(sess, 0, input);
+ auto crate = parser.parse_crate(p);
+ crate = resolve.resolve_crate(sess, crate);
+ crate = typeck.check_crate(sess, crate);
+ trans.trans_crate(sess, crate, output);
}
fn warn_wrong_compiler() {
- log "This is the rust 'self-hosted' compiler.";
- log "The one written in rust.";
- log "It does nothing yet, it's a placeholder.";
- log "You want rustboot, the compiler next door.";
+ log "This is the rust 'self-hosted' compiler.";
+ log "The one written in rust.";
+ log "It does nothing yet, it's a placeholder.";
+ log "You want rustboot, the compiler next door.";
}
fn usage(session.session sess, str argv0) {
@@ -38,81 +39,95 @@ fn usage(session.session sess, str argv0) {
log "";
}
+fn get_os() -> session.os {
+ auto s = std.os.target_os();
+ if (_str.eq(s, "win32")) { ret session.os_win32; }
+ if (_str.eq(s, "macos")) { ret session.os_macos; }
+ if (_str.eq(s, "linux")) { ret session.os_linux; }
+}
+
impure fn main(vec[str] args) {
- auto sess = session.session();
- let option.t[str] input_file = none[str];
- let option.t[str] output_file = none[str];
- let bool do_warn = true;
+ // FIXME: don't hard-wire this.
+ auto target_cfg = rec(os = get_os(),
+ arch = session.arch_x86,
+ int_type = common.ty_i32,
+ uint_type = common.ty_u32,
+ float_type = common.ty_f64 );
+
+ auto sess = session.session(target_cfg);
+ let option.t[str] input_file = none[str];
+ let option.t[str] output_file = none[str];
+ let bool do_warn = true;
- auto i = 1u;
- auto len = _vec.len[str](args);
+ auto i = 1u;
+ auto len = _vec.len[str](args);
- // FIXME: a getopt module would be nice.
- while (i < len) {
- auto arg = args.(i);
- if (_str.byte_len(arg) > 0u && arg.(0) == '-' as u8) {
- if (_str.eq(arg, "-nowarn")) {
- do_warn = false;
- } else {
- // FIXME: rust could use an elif construct.
- if (_str.eq(arg, "-o")) {
- if (i+1u < len) {
- output_file = some(args.(i+1u));
- i += 1u;
- } else {
- usage(sess, args.(0));
- sess.err("-o requires an argument");
- }
- } else {
- if (_str.eq(arg, "-h")) {
- usage(sess, args.(0));
- } else {
- usage(sess, args.(0));
- sess.err("unrecognized option: " + arg);
- }
- }
- }
- } else {
- alt (input_file) {
- case (some[str](_)) {
- usage(sess, args.(0));
- sess.err("multiple inputs provided");
- }
- case (none[str]) {
- input_file = some[str](arg);
- }
- }
- // FIXME: dummy node to work around typestate mis-wiring bug.
- i = i;
- }
- i += 1u;
- }
+ // FIXME: a getopt module would be nice.
+ while (i < len) {
+ auto arg = args.(i);
+ if (_str.byte_len(arg) > 0u && arg.(0) == '-' as u8) {
+ if (_str.eq(arg, "-nowarn")) {
+ do_warn = false;
+ } else {
+ // FIXME: rust could use an elif construct.
+ if (_str.eq(arg, "-o")) {
+ if (i+1u < len) {
+ output_file = some(args.(i+1u));
+ i += 1u;
+ } else {
+ usage(sess, args.(0));
+ sess.err("-o requires an argument");
+ }
+ } else {
+ if (_str.eq(arg, "-h")) {
+ usage(sess, args.(0));
+ } else {
+ usage(sess, args.(0));
+ sess.err("unrecognized option: " + arg);
+ }
+ }
+ }
+ } else {
+ alt (input_file) {
+ case (some[str](_)) {
+ usage(sess, args.(0));
+ sess.err("multiple inputs provided");
+ }
+ case (none[str]) {
+ input_file = some[str](arg);
+ }
+ }
+ // FIXME: dummy node to work around typestate mis-wiring bug.
+ i = i;
+ }
+ i += 1u;
+ }
- if (do_warn) {
- warn_wrong_compiler();
- }
+ if (do_warn) {
+ warn_wrong_compiler();
+ }
- alt (input_file) {
- case (none[str]) {
- usage(sess, args.(0));
- sess.err("no input filename");
- }
- case (some[str](?ifile)) {
- alt (output_file) {
- case (none[str]) {
- let vec[str] parts = _str.split(ifile, '.' as u8);
- parts = _vec.pop[str](parts);
- parts += ".bc";
- auto ofile = _str.concat(parts);
- compile_input(sess, ifile, ofile);
- }
- case (some[str](?ofile)) {
- compile_input(sess, ifile, ofile);
- }
- }
- }
- }
+ alt (input_file) {
+ case (none[str]) {
+ usage(sess, args.(0));
+ sess.err("no input filename");
+ }
+ case (some[str](?ifile)) {
+ alt (output_file) {
+ case (none[str]) {
+ let vec[str] parts = _str.split(ifile, '.' as u8);
+ parts = _vec.pop[str](parts);
+ parts += ".bc";
+ auto ofile = _str.concat(parts);
+ compile_input(sess, ifile, ofile);
+ }
+ case (some[str](?ofile)) {
+ compile_input(sess, ifile, ofile);
+ }
+ }
+ }
+ }
}
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index 831c6439..e23dbeed 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -1,7 +1,31 @@
import util.common.span;
+import util.common.ty_mach;
import std._uint;
-obj session() {
+tag os {
+ os_win32;
+ os_macos;
+ os_linux;
+}
+
+tag arch {
+ arch_x86;
+ arch_x64;
+ arch_arm;
+}
+
+type cfg = rec(os os,
+ arch arch,
+ ty_mach int_type,
+ ty_mach uint_type,
+ ty_mach float_type);
+
+obj session(cfg targ) {
+
+ fn get_targ_cfg() -> cfg {
+ ret targ;
+ }
+
fn span_err(span sp, str msg) {
log #fmt("%s:%u:%u:%u:%u: error: %s",
sp.filename,
@@ -16,6 +40,11 @@ obj session() {
fail;
}
+ fn bug(str msg) {
+ log #fmt("error: internal compiler error %s", msg);
+ fail;
+ }
+
fn unimpl(str msg) {
log #fmt("error: unimplemented %s", msg);
fail;