2010-06-23 23:03:09 -05:00
|
|
|
// -*- rust -*-
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
import front::creader;
|
|
|
|
import front::parser;
|
|
|
|
import front::token;
|
|
|
|
import front::eval;
|
|
|
|
import front::ast;
|
|
|
|
import middle::trans;
|
|
|
|
import middle::resolve;
|
|
|
|
import middle::ty;
|
|
|
|
import middle::typeck;
|
2011-05-14 21:02:30 -05:00
|
|
|
import middle::tstate::ck;
|
2011-05-17 19:42:23 -05:00
|
|
|
import pretty::pprust;
|
2011-05-13 15:47:37 -05:00
|
|
|
import back::link;
|
2011-05-12 10:24:54 -05:00
|
|
|
import lib::llvm;
|
|
|
|
import util::common;
|
|
|
|
|
|
|
|
import std::fs;
|
|
|
|
import std::map::mk_hashmap;
|
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2011-05-17 13:41:41 -05:00
|
|
|
import std::str;
|
|
|
|
import std::vec;
|
2011-05-12 10:24:54 -05:00
|
|
|
import std::io;
|
2011-05-16 10:01:36 -05:00
|
|
|
import std::run;
|
2011-05-12 10:24:54 -05:00
|
|
|
|
|
|
|
import std::getopts;
|
|
|
|
import std::getopts::optopt;
|
|
|
|
import std::getopts::optmulti;
|
|
|
|
import std::getopts::optflag;
|
|
|
|
import std::getopts::opt_present;
|
|
|
|
|
2011-05-13 15:47:37 -05:00
|
|
|
import back::link::output_type;
|
2011-05-12 10:24:54 -05:00
|
|
|
|
|
|
|
fn default_environment(session::session sess,
|
2011-03-01 17:57:55 -06:00
|
|
|
str argv0,
|
2011-05-12 10:24:54 -05:00
|
|
|
str input) -> eval::env {
|
2011-03-01 17:57:55 -06:00
|
|
|
|
2011-05-13 12:51:13 -05:00
|
|
|
auto libc = "libc.so";
|
2011-03-01 17:57:55 -06:00
|
|
|
alt (sess.get_targ_cfg().os) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (session::os_win32) { libc = "msvcrt.dll"; }
|
2011-05-13 12:51:13 -05:00
|
|
|
case (session::os_macos) { libc = "libc.dylib"; }
|
|
|
|
case (session::os_linux) { libc = "libc.so.6"; }
|
2011-03-01 17:57:55 -06:00
|
|
|
}
|
|
|
|
|
2011-05-22 15:07:30 -05:00
|
|
|
ret [// 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))
|
|
|
|
];
|
2011-03-01 17:57:55 -06:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn parse_input(session::session sess,
|
|
|
|
parser::parser p,
|
|
|
|
str input) -> @ast::crate {
|
2011-05-17 13:41:41 -05:00
|
|
|
if (str::ends_with(input, ".rc")) {
|
2011-05-12 10:24:54 -05:00
|
|
|
ret parser::parse_crate_from_crate_file(p);
|
2011-05-17 13:41:41 -05:00
|
|
|
} else if (str::ends_with(input, ".rs")) {
|
2011-05-12 10:24:54 -05:00
|
|
|
ret parser::parse_crate_from_source_file(p);
|
2011-01-03 22:41:11 -06:00
|
|
|
}
|
2011-03-15 17:07:41 -05:00
|
|
|
sess.err("unknown input file type: " + input);
|
2011-01-03 22:41:11 -06:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-04-29 13:55:20 -05:00
|
|
|
fn time[T](bool do_it, str what, fn()->T thunk) -> T {
|
|
|
|
if (!do_it) { ret thunk(); }
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
auto start = std::time::get_time();
|
2011-04-29 13:55:20 -05:00
|
|
|
auto rv = thunk();
|
2011-05-12 10:24:54 -05:00
|
|
|
auto end = std::time::get_time();
|
2011-04-29 13:55:20 -05:00
|
|
|
|
|
|
|
// FIXME: Actually do timeval math.
|
|
|
|
log_err #fmt("time: %s took %u s", what, (end.sec - start.sec) as uint);
|
|
|
|
ret rv;
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn compile_input(session::session sess,
|
|
|
|
eval::env env,
|
2011-05-04 18:53:42 -05:00
|
|
|
str input, str output) {
|
|
|
|
auto time_passes = sess.get_opts().time_passes;
|
2011-05-12 10:24:54 -05:00
|
|
|
auto def = tup(ast::local_crate, 0);
|
|
|
|
auto p = parser::new_parser(sess, env, def, input, 0u, 0u);
|
2011-05-12 06:25:18 -05:00
|
|
|
auto crate = time(time_passes, "parsing",
|
|
|
|
bind parse_input(sess, p, input));
|
2011-05-13 15:47:37 -05:00
|
|
|
if (sess.get_opts().output_type == link::output_type_none) {ret;}
|
2011-04-20 20:52:04 -05:00
|
|
|
|
2011-05-12 06:25:18 -05:00
|
|
|
crate = time(time_passes, "external crate reading",
|
2011-05-12 10:24:54 -05:00
|
|
|
bind creader::read_crates(sess, crate));
|
2011-05-13 03:51:36 -05:00
|
|
|
auto def_map = time(time_passes, "resolution",
|
|
|
|
bind resolve::resolve_crate(sess, crate));
|
2011-04-20 20:52:04 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
auto ty_cx = ty::mk_ctxt(sess, def_map);
|
2011-05-19 17:47:15 -05:00
|
|
|
time[()](time_passes, "typechecking",
|
|
|
|
bind typeck::check_crate(ty_cx, crate));
|
2011-04-29 13:55:20 -05:00
|
|
|
|
2011-05-04 18:53:42 -05:00
|
|
|
if (sess.get_opts().run_typestate) {
|
2011-05-18 20:04:07 -05:00
|
|
|
time(time_passes, "typestate checking",
|
2011-05-19 17:47:15 -05:00
|
|
|
bind middle::tstate::ck::check_crate(ty_cx, crate));
|
2011-04-29 14:16:14 -05:00
|
|
|
}
|
2011-04-29 13:55:20 -05:00
|
|
|
|
2011-05-19 17:47:15 -05:00
|
|
|
auto llmod =
|
|
|
|
time[llvm::ModuleRef](time_passes, "translation",
|
|
|
|
bind trans::trans_crate(sess, crate,
|
|
|
|
ty_cx, output));
|
2011-05-02 19:45:07 -05:00
|
|
|
|
|
|
|
time[()](time_passes, "LLVM passes",
|
2011-05-13 15:47:37 -05:00
|
|
|
bind link::write::run_passes(sess, llmod, output));
|
2010-10-22 13:47:28 -05:00
|
|
|
}
|
2010-07-13 16:26:59 -05:00
|
|
|
|
2011-05-17 19:42:23 -05:00
|
|
|
fn pretty_print_input(session::session sess, eval::env env, str input,
|
|
|
|
bool typed) {
|
2011-05-12 10:24:54 -05:00
|
|
|
auto def = tup(ast::local_crate, 0);
|
|
|
|
auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u);
|
|
|
|
auto crate = front::parser::parse_crate_from_source_file(p);
|
2011-05-17 19:42:23 -05:00
|
|
|
|
|
|
|
auto mode;
|
|
|
|
if (typed) {
|
|
|
|
crate = creader::read_crates(sess, crate);
|
|
|
|
auto def_map = resolve::resolve_crate(sess, crate);
|
|
|
|
auto ty_cx = ty::mk_ctxt(sess, def_map);
|
2011-05-19 17:47:15 -05:00
|
|
|
typeck::check_crate(ty_cx, crate);
|
|
|
|
mode = pprust::mo_typed(ty_cx);
|
2011-05-17 19:42:23 -05:00
|
|
|
} else {
|
|
|
|
mode = pprust::mo_untyped;
|
|
|
|
}
|
|
|
|
|
|
|
|
pprust::print_file(sess, crate.node.module, input, std::io::stdout(),
|
|
|
|
mode);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2011-05-05 14:03:23 -05:00
|
|
|
fn version(str argv0) {
|
2011-05-06 13:21:51 -05:00
|
|
|
auto vers = "unknown version";
|
|
|
|
auto env_vers = #env("CFG_VERSION");
|
2011-05-17 13:41:41 -05:00
|
|
|
if (str::byte_len(env_vers) != 0u) {
|
2011-05-06 13:21:51 -05:00
|
|
|
vers = env_vers;
|
2011-05-05 14:03:23 -05:00
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
io::stdout().write_str(#fmt("%s %s\n", argv0, vers));
|
2011-05-05 14:03:23 -05:00
|
|
|
}
|
|
|
|
|
2011-05-04 18:53:42 -05:00
|
|
|
fn usage(str argv0) {
|
2011-05-12 10:24:54 -05:00
|
|
|
io::stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) + "
|
2011-04-19 05:02:06 -05:00
|
|
|
options:
|
|
|
|
|
2011-05-05 14:03:23 -05:00
|
|
|
-h --help display this message
|
|
|
|
-v --version print version info and exit
|
|
|
|
|
2011-04-19 05:02:06 -05:00
|
|
|
-o <filename> write output to <filename>
|
2011-04-26 13:32:08 -05:00
|
|
|
--glue generate glue.bc file
|
|
|
|
--shared compile a shared-library crate
|
|
|
|
--pretty pretty-print the input instead of compiling
|
2011-05-17 19:42:23 -05:00
|
|
|
--typed-pretty pretty-print the input with types instead of compiling
|
2011-04-26 13:32:08 -05:00
|
|
|
--ls list the symbols defined by a crate file
|
2011-04-19 05:02:06 -05:00
|
|
|
-L <path> add a directory to the library search path
|
2011-04-26 13:32:08 -05:00
|
|
|
--noverify suppress LLVM verification step (slight speedup)
|
2011-05-03 17:50:56 -05:00
|
|
|
--depend print dependencies, in makefile-rule form
|
2011-04-26 13:32:08 -05:00
|
|
|
--parse-only parse only; do not compile, assemble, or link
|
2011-05-04 17:36:42 -05:00
|
|
|
-g produce debug info
|
2011-05-19 14:46:10 -05:00
|
|
|
--OptLevel= optimize with possible levels 0-3
|
|
|
|
-O equivalent to --OptLevel=2
|
2011-04-25 16:08:12 -05:00
|
|
|
-S compile only; do not assemble or link
|
|
|
|
-c compile and assemble, but do not link
|
2011-05-16 13:14:24 -05:00
|
|
|
--emit-llvm produce an LLVM bitcode file
|
2011-04-26 13:32:08 -05:00
|
|
|
--save-temps write intermediate files in addition to normal output
|
2011-05-12 17:42:12 -05:00
|
|
|
--stats gather and report various compilation statistics
|
2011-04-29 13:55:20 -05:00
|
|
|
--time-passes time the individual phases of the compiler
|
2011-05-10 18:10:08 -05:00
|
|
|
--time-llvm-passes time the individual phases of the LLVM backend
|
2011-05-04 21:27:54 -05:00
|
|
|
--sysroot <path> override the system root (default: rustc's directory)
|
2011-05-05 14:03:23 -05:00
|
|
|
--no-typestate don't run the typestate pass (unsafe!)\n\n");
|
2010-10-22 13:47:28 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn get_os(str triple) -> session::os {
|
2011-05-17 13:41:41 -05:00
|
|
|
if (str::find(triple, "win32") >= 0 ||
|
|
|
|
str::find(triple, "mingw32") >= 0 ) {
|
2011-05-12 10:24:54 -05:00
|
|
|
ret session::os_win32;
|
2011-05-17 13:41:41 -05:00
|
|
|
} else if (str::find(triple, "darwin") >= 0) { ret session::os_macos; }
|
|
|
|
else if (str::find(triple, "linux") >= 0) { ret session::os_linux; }
|
2011-05-16 16:33:22 -05:00
|
|
|
else { log_err "Unknown operating system!"; fail; }
|
2011-05-06 08:59:33 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn get_arch(str triple) -> session::arch {
|
2011-05-17 13:41:41 -05:00
|
|
|
if (str::find(triple, "i386") >= 0 ||
|
|
|
|
str::find(triple, "i486") >= 0 ||
|
|
|
|
str::find(triple, "i586") >= 0 ||
|
|
|
|
str::find(triple, "i686") >= 0 ||
|
|
|
|
str::find(triple, "i786") >= 0 ) {
|
2011-05-12 10:24:54 -05:00
|
|
|
ret session::arch_x86;
|
2011-05-17 13:41:41 -05:00
|
|
|
} else if (str::find(triple, "x86_64") >= 0) {
|
2011-05-12 10:24:54 -05:00
|
|
|
ret session::arch_x64;
|
2011-05-17 13:41:41 -05:00
|
|
|
} else if (str::find(triple, "arm") >= 0 ||
|
|
|
|
str::find(triple, "xscale") >= 0 ) {
|
2011-05-12 10:24:54 -05:00
|
|
|
ret session::arch_arm;
|
2011-05-06 08:59:33 -05:00
|
|
|
}
|
2011-05-16 16:33:22 -05:00
|
|
|
else {
|
|
|
|
log_err ("Unknown architecture! " + triple);
|
|
|
|
fail;
|
|
|
|
}
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
|
|
|
|
2011-05-04 21:27:54 -05:00
|
|
|
fn get_default_sysroot(str binary) -> str {
|
2011-05-12 10:24:54 -05:00
|
|
|
auto dirname = fs::dirname(binary);
|
2011-05-17 13:41:41 -05:00
|
|
|
if (str::eq(dirname, binary)) { ret "."; }
|
2011-05-04 21:27:54 -05:00
|
|
|
ret dirname;
|
|
|
|
}
|
|
|
|
|
2011-04-19 15:35:49 -05:00
|
|
|
fn main(vec[str] args) {
|
2010-07-13 16:26:59 -05:00
|
|
|
|
2011-05-06 08:59:33 -05:00
|
|
|
let str triple =
|
2011-05-17 13:41:41 -05:00
|
|
|
std::str::rustrt::str_from_cstr(llvm::llvm::LLVMRustGetHostTriple());
|
2011-05-06 08:59:33 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
let @session::config target_cfg =
|
2011-05-06 08:59:33 -05:00
|
|
|
@rec(os = get_os(triple),
|
|
|
|
arch = get_arch(triple),
|
2011-05-12 10:24:54 -05:00
|
|
|
int_type = common::ty_i32,
|
|
|
|
uint_type = common::ty_u32,
|
|
|
|
float_type = common::ty_f64);
|
2011-03-25 12:42:57 -05:00
|
|
|
|
2011-05-16 20:21:22 -05:00
|
|
|
auto opts = [optflag("h"), optflag("help"),
|
2011-05-05 14:03:23 -05:00
|
|
|
optflag("v"), optflag("version"),
|
2011-05-16 13:14:24 -05:00
|
|
|
optflag("glue"), optflag("emit-llvm"),
|
2011-05-17 19:42:23 -05:00
|
|
|
optflag("pretty"), optflag("typed-pretty"),
|
|
|
|
optflag("ls"), optflag("parse-only"),
|
2011-05-19 14:46:10 -05:00
|
|
|
optflag("O"), optopt("OptLevel"),
|
|
|
|
optflag("shared"), optmulti("L"),
|
2011-05-20 17:20:48 -05:00
|
|
|
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
|
2011-05-04 21:27:54 -05:00
|
|
|
optflag("save-temps"), optopt("sysroot"),
|
2011-05-12 17:42:12 -05:00
|
|
|
optflag("stats"),
|
2011-05-10 18:10:08 -05:00
|
|
|
optflag("time-passes"), optflag("time-llvm-passes"),
|
2011-05-16 20:21:22 -05:00
|
|
|
optflag("no-typestate"), optflag("noverify")];
|
2011-05-17 13:41:41 -05:00
|
|
|
auto binary = vec::shift[str](args);
|
2011-04-26 13:32:08 -05:00
|
|
|
auto match;
|
2011-05-12 10:24:54 -05:00
|
|
|
alt (getopts::getopts(args, opts)) {
|
|
|
|
case (getopts::failure(?f)) {
|
|
|
|
log_err #fmt("error: %s", getopts::fail_str(f));
|
2011-05-04 18:53:42 -05:00
|
|
|
fail;
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (getopts::success(?m)) { match = m; }
|
2011-04-26 13:32:08 -05:00
|
|
|
}
|
2011-05-05 14:03:23 -05:00
|
|
|
if (opt_present(match, "h") ||
|
|
|
|
opt_present(match, "help")) {
|
2011-05-04 18:53:42 -05:00
|
|
|
usage(binary);
|
2011-04-26 13:32:08 -05:00
|
|
|
ret;
|
|
|
|
}
|
2010-10-22 13:47:28 -05:00
|
|
|
|
2011-05-05 14:03:23 -05:00
|
|
|
if (opt_present(match, "v") ||
|
|
|
|
opt_present(match, "version")) {
|
|
|
|
version(binary);
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2011-04-26 13:32:08 -05:00
|
|
|
auto pretty = opt_present(match, "pretty");
|
2011-05-17 19:42:23 -05:00
|
|
|
auto typed_pretty = opt_present(match, "typed-pretty");
|
2011-04-26 13:32:08 -05:00
|
|
|
auto ls = opt_present(match, "ls");
|
|
|
|
auto glue = opt_present(match, "glue");
|
|
|
|
auto shared = opt_present(match, "shared");
|
2011-05-12 10:24:54 -05:00
|
|
|
auto output_file = getopts::opt_maybe_str(match, "o");
|
|
|
|
auto library_search_paths = getopts::opt_strs(match, "L");
|
2011-05-05 12:48:02 -05:00
|
|
|
|
2011-05-16 10:01:36 -05:00
|
|
|
auto output_type = link::output_type_exe;
|
2011-04-26 13:32:08 -05:00
|
|
|
if (opt_present(match, "parse-only")) {
|
2011-05-13 15:47:37 -05:00
|
|
|
output_type = link::output_type_none;
|
2011-04-26 13:32:08 -05:00
|
|
|
} else if (opt_present(match, "S")) {
|
2011-05-13 15:47:37 -05:00
|
|
|
output_type = link::output_type_assembly;
|
2011-04-26 13:32:08 -05:00
|
|
|
} else if (opt_present(match, "c")) {
|
2011-05-13 15:47:37 -05:00
|
|
|
output_type = link::output_type_object;
|
2011-05-16 13:14:24 -05:00
|
|
|
} else if (opt_present(match, "emit-llvm")) {
|
2011-05-16 10:01:36 -05:00
|
|
|
output_type = link::output_type_bitcode;
|
2011-04-26 13:32:08 -05:00
|
|
|
}
|
2011-05-05 12:48:02 -05:00
|
|
|
|
2011-04-26 13:32:08 -05:00
|
|
|
auto verify = !opt_present(match, "noverify");
|
|
|
|
auto save_temps = opt_present(match, "save-temps");
|
2011-05-04 17:36:42 -05:00
|
|
|
auto debuginfo = opt_present(match, "g");
|
2011-05-12 17:42:12 -05:00
|
|
|
auto stats = opt_present(match, "stats");
|
2011-04-29 13:55:20 -05:00
|
|
|
auto time_passes = opt_present(match, "time-passes");
|
2011-05-10 18:10:08 -05:00
|
|
|
auto time_llvm_passes = opt_present(match, "time-llvm-passes");
|
2011-04-29 14:16:14 -05:00
|
|
|
auto run_typestate = !opt_present(match, "no-typestate");
|
2011-05-12 10:24:54 -05:00
|
|
|
auto sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
|
2011-05-04 21:27:54 -05:00
|
|
|
|
2011-05-19 14:46:10 -05:00
|
|
|
let uint optLevel = 0u;
|
|
|
|
if (opt_present(match, "O")) {
|
|
|
|
optLevel = 2u;
|
|
|
|
if (opt_present(match, "OptLevel")) {
|
2011-05-22 15:07:30 -05:00
|
|
|
log_err "error: -O and --OptLevel both provided";
|
2011-05-19 14:46:10 -05:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_present(match, "OptLevel")) {
|
|
|
|
auto opt = getopts::opt_maybe_str(match, "OptLevel");
|
|
|
|
alt (opt) {
|
|
|
|
case (some[str](?s)) {
|
|
|
|
alt (s) {
|
|
|
|
case ("0") { optLevel = 0u; }
|
|
|
|
case ("1") { optLevel = 1u; }
|
|
|
|
case ("2") { optLevel = 2u; }
|
|
|
|
case ("3") { optLevel = 3u; }
|
|
|
|
case (_) {
|
2011-05-22 15:07:30 -05:00
|
|
|
log_err "error: optimization level needs to be between 0-3";
|
2011-05-19 14:46:10 -05:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (none[str]) {
|
2011-05-22 15:07:30 -05:00
|
|
|
log_err "error: expected optimization level after --OptLevel=";
|
2011-05-19 14:46:10 -05:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-04 21:27:54 -05:00
|
|
|
auto sysroot;
|
|
|
|
alt (sysroot_opt) {
|
|
|
|
case (none[str]) { sysroot = get_default_sysroot(binary); }
|
|
|
|
case (some[str](?s)) { sysroot = s; }
|
|
|
|
}
|
2011-05-04 18:53:42 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
let @session::options sopts =
|
2011-05-04 18:53:42 -05:00
|
|
|
@rec(shared = shared,
|
2011-05-19 14:46:10 -05:00
|
|
|
optimize = optLevel,
|
2011-05-04 18:53:42 -05:00
|
|
|
debuginfo = debuginfo,
|
|
|
|
verify = verify,
|
|
|
|
run_typestate = run_typestate,
|
|
|
|
save_temps = save_temps,
|
2011-05-12 17:42:12 -05:00
|
|
|
stats = stats,
|
2011-05-04 18:53:42 -05:00
|
|
|
time_passes = time_passes,
|
2011-05-10 18:10:08 -05:00
|
|
|
time_llvm_passes = time_llvm_passes,
|
2011-05-04 18:53:42 -05:00
|
|
|
output_type = output_type,
|
2011-05-04 21:27:54 -05:00
|
|
|
library_search_paths = library_search_paths,
|
|
|
|
sysroot = sysroot);
|
2011-05-04 18:53:42 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
auto crate_cache = common::new_int_hash[session::crate_metadata]();
|
2011-05-04 18:53:42 -05:00
|
|
|
auto target_crate_num = 0;
|
2011-05-16 20:21:22 -05:00
|
|
|
let vec[@ast::meta_item] md = [];
|
2011-05-04 18:53:42 -05:00
|
|
|
auto sess =
|
2011-05-12 10:24:54 -05:00
|
|
|
session::session(target_crate_num, target_cfg, sopts,
|
|
|
|
crate_cache, md, front::codemap::new_codemap());
|
2011-05-04 18:53:42 -05:00
|
|
|
|
2011-05-17 13:41:41 -05:00
|
|
|
auto n_inputs = vec::len[str](match.free);
|
2011-04-07 14:42:06 -05:00
|
|
|
|
2011-04-26 13:32:08 -05:00
|
|
|
if (glue) {
|
|
|
|
if (n_inputs > 0u) {
|
|
|
|
sess.err("No input files allowed with --glue.");
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
auto out = option::from_maybe[str]("glue.bc", output_file);
|
|
|
|
middle::trans::make_common_glue(sess, out);
|
2011-04-26 13:32:08 -05:00
|
|
|
ret;
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
2010-10-22 13:47:28 -05:00
|
|
|
|
2011-04-26 13:32:08 -05:00
|
|
|
if (n_inputs == 0u) {
|
|
|
|
sess.err("No input filename given.");
|
|
|
|
} else if (n_inputs > 1u) {
|
|
|
|
sess.err("Multiple input filenames provided.");
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
2010-10-22 13:47:28 -05:00
|
|
|
|
2011-04-26 13:32:08 -05:00
|
|
|
auto ifile = match.free.(0);
|
2011-05-16 10:01:36 -05:00
|
|
|
let str saved_out_filename = "";
|
2011-04-26 13:32:08 -05:00
|
|
|
auto env = default_environment(sess, args.(0), ifile);
|
2011-05-17 19:42:23 -05:00
|
|
|
if (pretty || typed_pretty) {
|
|
|
|
pretty_print_input(sess, env, ifile, typed_pretty);
|
2011-04-26 13:32:08 -05:00
|
|
|
} else if (ls) {
|
2011-05-12 10:24:54 -05:00
|
|
|
front::creader::list_file_metadata(ifile, std::io::stdout());
|
2011-04-26 13:32:08 -05:00
|
|
|
} else {
|
2011-03-10 19:25:11 -06:00
|
|
|
alt (output_file) {
|
|
|
|
case (none[str]) {
|
2011-05-17 13:41:41 -05:00
|
|
|
let vec[str] parts = str::split(ifile, '.' as u8);
|
|
|
|
vec::pop[str](parts);
|
2011-05-16 10:01:36 -05:00
|
|
|
saved_out_filename = parts.(0);
|
2011-05-04 18:53:42 -05:00
|
|
|
alt (output_type) {
|
2011-05-16 20:21:22 -05:00
|
|
|
case (link::output_type_none) { parts += ["pp"]; }
|
|
|
|
case (link::output_type_bitcode) { parts += ["bc"]; }
|
|
|
|
case (link::output_type_assembly) { parts += ["s"]; }
|
2011-05-16 10:01:36 -05:00
|
|
|
|
|
|
|
// Object and exe output both use the '.o' extension here
|
2011-05-16 20:21:22 -05:00
|
|
|
case (link::output_type_object) { parts += ["o"]; }
|
|
|
|
case (link::output_type_exe) { parts += ["o"]; }
|
2011-05-04 18:53:42 -05:00
|
|
|
}
|
2011-05-17 13:41:41 -05:00
|
|
|
auto ofile = str::connect(parts, ".");
|
2011-05-04 18:53:42 -05:00
|
|
|
compile_input(sess, env, ifile, ofile);
|
2011-03-10 19:25:11 -06:00
|
|
|
}
|
2011-04-26 13:32:08 -05:00
|
|
|
case (some[str](?ofile)) {
|
2011-05-16 10:01:36 -05:00
|
|
|
saved_out_filename = ofile;
|
2011-05-04 18:53:42 -05:00
|
|
|
compile_input(sess, env, ifile, ofile);
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-16 10:01:36 -05:00
|
|
|
|
|
|
|
// If the user wants an exe generated we need to invoke
|
|
|
|
// gcc to link the object file with some libs
|
|
|
|
if (output_type == link::output_type_exe) {
|
|
|
|
|
|
|
|
//FIXME: Should we make the 'stage3's variable here?
|
|
|
|
let str glu = "stage3/glue.o";
|
|
|
|
let str stage = "-Lstage3";
|
|
|
|
let vec[str] gcc_args;
|
|
|
|
let str prog = "gcc";
|
|
|
|
let str exe_suffix = "";
|
|
|
|
|
|
|
|
// The invocations of gcc share some flags across platforms
|
2011-05-16 20:21:22 -05:00
|
|
|
let vec[str] common_cflags = ["-fno-strict-aliasing", "-fPIC",
|
|
|
|
"-Wall", "-fno-rtti", "-fno-exceptions", "-g"];
|
|
|
|
let vec[str] common_libs = [stage, "-Lrustllvm", "-Lrt",
|
|
|
|
"-lrustrt", "-lrustllvm", "-lstd", "-lm"];
|
2011-05-16 10:01:36 -05:00
|
|
|
|
|
|
|
alt (sess.get_targ_cfg().os) {
|
|
|
|
case (session::os_win32) {
|
|
|
|
exe_suffix = ".exe";
|
2011-05-16 20:21:22 -05:00
|
|
|
gcc_args = common_cflags + [
|
2011-05-16 10:01:36 -05:00
|
|
|
"-march=i686", "-O2",
|
|
|
|
glu, "-o",
|
|
|
|
saved_out_filename + exe_suffix,
|
2011-05-16 20:21:22 -05:00
|
|
|
saved_out_filename + ".o"] + common_libs;
|
2011-05-16 10:01:36 -05:00
|
|
|
}
|
|
|
|
case (session::os_macos) {
|
2011-05-16 20:21:22 -05:00
|
|
|
gcc_args = common_cflags + [
|
2011-05-16 10:01:36 -05:00
|
|
|
"-arch i386", "-O0", "-m32",
|
|
|
|
glu, "-o",
|
|
|
|
saved_out_filename + exe_suffix,
|
2011-05-16 20:21:22 -05:00
|
|
|
saved_out_filename + ".o"] + common_libs;
|
2011-05-16 10:01:36 -05:00
|
|
|
}
|
|
|
|
case (session::os_linux) {
|
2011-05-16 20:21:22 -05:00
|
|
|
gcc_args = common_cflags + [
|
2011-05-16 10:01:36 -05:00
|
|
|
"-march=i686", "-O2", "-m32",
|
|
|
|
glu, "-o",
|
|
|
|
saved_out_filename + exe_suffix,
|
2011-05-16 20:21:22 -05:00
|
|
|
saved_out_filename + ".o"] + common_libs;
|
2011-05-16 10:01:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We run 'gcc' here
|
|
|
|
run::run_program(prog, gcc_args);
|
|
|
|
|
|
|
|
// Clean up on Darwin
|
|
|
|
if (sess.get_targ_cfg().os == session::os_macos) {
|
2011-05-16 20:21:22 -05:00
|
|
|
run::run_program("dsymutil", [saved_out_filename]);
|
2011-05-16 10:01:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the temporary object file if we aren't saving temps
|
|
|
|
if (!save_temps) {
|
2011-05-16 20:21:22 -05:00
|
|
|
run::run_program("rm", [saved_out_filename + ".o"]);
|
2011-05-16 10:01:36 -05:00
|
|
|
}
|
|
|
|
}
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
2010-08-12 12:29:23 -05:00
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
2011-03-25 17:07:27 -05:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2010-08-12 12:29:23 -05:00
|
|
|
// End:
|