From 0761c5f4626153eba8478c66f93ba27e021f4dc2 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 1 Mar 2011 15:13:50 -0800 Subject: Fix typo in comment. --- src/comp/driver/rustc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 004c9d4c..278b6873 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -38,7 +38,7 @@ fn warn_wrong_compiler() { log "This is the rust 'self-hosted' compiler."; log "The one written in rust."; log "It is currently incomplete."; - log "You may want rustboot insteaad, the compiler next door."; + log "You may want rustboot instead, the compiler next door."; } fn usage(session.session sess, str argv0) { -- cgit v1.2.3 From 348c77c31b7dcd5be85438dfcf4292f7e0951dd6 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 1 Mar 2011 15:57:55 -0800 Subject: Populate default compilation environment as in rustboot. --- src/comp/driver/rustc.rs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 278b6873..69e61aa0 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -2,6 +2,7 @@ import front.parser; import front.token; +import front.eval; import middle.trans; import middle.resolve; import middle.typeck; @@ -13,6 +14,30 @@ import std.option.none; import std._str; import std._vec; +fn default_environment(session.session sess, + str argv0, + str input) -> eval.env { + + auto libc = "libc.so"; + alt (sess.get_targ_cfg().os) { + case (session.os_win32) { libc = "msvcrt.dll"; } + case (session.os_macos) { libc = "libc.dylib"; } + case (session.os_linux) { libc = "libc.so.6"; } + } + + ret + vec( + // Target bindings. + tup("target_os", eval.val_str(std.os.target_os())), + tup("target_arch", eval.val_str("x86")), + tup("target_libc", eval.val_str(libc)), + + // Build bindings. + tup("build_compiler", eval.val_str(argv0)), + tup("build_input", eval.val_str(input)) + ); +} + impure fn parse_input(session.session sess, parser.parser p, str input) -> @front.ast.crate { @@ -25,9 +50,11 @@ impure fn parse_input(session.session sess, fail; } -impure fn compile_input(session.session sess, str input, str output, +impure fn compile_input(session.session sess, + eval.env env, + str input, str output, bool shared) { - auto p = parser.new_parser(sess, 0, input); + auto p = parser.new_parser(sess, env, 0, input); auto crate = parse_input(sess, p, input); crate = resolve.resolve_crate(sess, crate); crate = typeck.check_crate(sess, crate); @@ -131,16 +158,19 @@ impure fn main(vec[str] args) { sess.err("no input filename"); } case (some[str](?ifile)) { + + auto env = default_environment(sess, args.(0), 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, shared); + compile_input(sess, env, ifile, ofile, shared); } case (some[str](?ofile)) { - compile_input(sess, ifile, ofile, shared); + compile_input(sess, env, ifile, ofile, shared); } } } -- cgit v1.2.3 From b893bec4bbdfda549a1c45bd5328b3dd78a2e05c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 13:00:52 -0500 Subject: Flatten conditionals in rustc.rs. Remove FIXME --- src/comp/driver/rustc.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 69e61aa0..67275b9b 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -113,24 +113,19 @@ impure fn main(vec[str] args) { do_warn = false; } else if (_str.eq(arg, "-shared")) { shared = true; - } 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, "-o")) { + if (i+1u < len) { + output_file = some(args.(i+1u)); + i += 1u; } else { - if (_str.eq(arg, "-h")) { - usage(sess, args.(0)); - } else { - usage(sess, args.(0)); - sess.err("unrecognized option: " + arg); - } + 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) { -- cgit v1.2.3 From d39da6f97819becd9ea41c194b5f0daa178814fe Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 13:56:38 -0500 Subject: Remove typestate workarounds --- src/comp/driver/rustc.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 67275b9b..90fe0e0c 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -137,8 +137,6 @@ impure fn main(vec[str] args) { input_file = some[str](arg); } } - // FIXME: dummy node to work around typestate mis-wiring bug. - i = i; } i += 1u; } -- cgit v1.2.3 From 0624f9db4aeaa5681941750c3a1a17ca5fbb7e72 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 4 Mar 2011 07:22:43 +0100 Subject: Add a pretty-printer Adds a -pp option to the compiler which will cause it to simply pretty-print the given file. --- src/comp/driver/rustc.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 90fe0e0c..7ad0cdc7 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -61,6 +61,14 @@ impure fn compile_input(session.session sess, trans.trans_crate(sess, crate, output, shared); } +impure fn pretty_print_input(session.session sess, + eval.env env, + str input) { + auto p = front.parser.new_parser(sess, env, 0, input); + auto crate = front.parser.parse_crate_from_source_file(p); + pretty.pprust.print_ast(crate.node.module); +} + fn warn_wrong_compiler() { log "This is the rust 'self-hosted' compiler."; log "The one written in rust."; @@ -75,6 +83,7 @@ fn usage(session.session sess, str argv0) { log " -o write output to "; log " -nowarn suppress wrong-compiler warning"; log " -shared compile a shared-library crate"; + log " -pp pretty-print the input instead of compiling"; log " -h display this message"; log ""; log ""; @@ -101,6 +110,7 @@ impure fn main(vec[str] args) { let option.t[str] output_file = none[str]; let bool do_warn = true; let bool shared = false; + let bool pretty = false; auto i = 1u; auto len = _vec.len[str](args); @@ -113,6 +123,8 @@ impure fn main(vec[str] args) { do_warn = false; } else if (_str.eq(arg, "-shared")) { shared = true; + } else if (_str.eq(arg, "-pp")) { + pretty = true; } else if (_str.eq(arg, "-o")) { if (i+1u < len) { output_file = some(args.(i+1u)); @@ -153,24 +165,27 @@ impure fn main(vec[str] args) { case (some[str](?ifile)) { auto env = default_environment(sess, args.(0), 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, env, ifile, ofile, shared); - } - case (some[str](?ofile)) { - compile_input(sess, env, ifile, ofile, shared); + if (pretty) { + pretty_print_input(sess, env, ifile); + } + else { + 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, env, ifile, ofile, shared); + } + case (some[str](?ofile)) { + compile_input(sess, env, ifile, ofile, shared); + } } } } } } - // Local Variables: // mode: rust // fill-column: 78; -- cgit v1.2.3