rust/src/comp/driver/rustc.rs

118 lines
4.1 KiB
Rust
Raw Normal View History

use std;
use rustc;
// -*- rust -*-
import core::{option, str, vec, result};
import result::{ok, err};
import std::{io, getopts};
import io::writer_util;
import option::{some, none};
import getopts::{opt_present};
import rustc::driver::driver::*;
fn version(argv0: str) {
2011-09-02 17:34:58 -05:00
let vers = "unknown version";
let env_vers = #env["CFG_VERSION"];
if str::byte_len(env_vers) != 0u { vers = env_vers; }
2011-09-02 17:34:58 -05:00
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
io::stdout().write_str(#fmt["host: %s\n", host_triple()]);
}
fn usage(argv0: str) {
2011-09-02 17:34:58 -05:00
io::stdout().write_str(#fmt["usage: %s [options] <input>\n", argv0] +
"
options:
-h --help display this message
-v --version print version info and exit
-o <filename> write output to <filename>
2011-12-15 15:52:33 -06:00
--out-dir <dir> write output to compiler-chosen filename in <dir>
--lib compile a library crate
--bin compile an executable crate (default)
--static use or produce static libraries
--no-core omit the 'core' library (used and imported by default)
--pretty [type] pretty-print the input instead of compiling
--ls list the symbols defined by a crate file
-L <path> add a directory to the library search path
2011-12-06 15:02:59 -06:00
--no-verify suppress LLVM verification step (slight speedup)
--parse-only parse only; do not compile, assemble, or link
--no-trans run all passes except translation; no output
-g produce debug info
2011-10-28 14:51:46 -05:00
--opt-level <lvl> optimize with possible levels 0-3
-O equivalent to --opt-level=2
-S compile only; do not assemble or link
2011-11-14 16:03:20 -06:00
--no-asm-comments do not add comments into the assembly source
-c compile and assemble, but do not link
--emit-llvm produce an LLVM bitcode file
--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-10-28 14:51:46 -05:00
--cfg <cfgspec> configure the compilation environment
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-11-16 20:35:30 -06:00
--sysroot <path> override the system root
--target <triple> target to compile for (default: host triple)
--test build test harness
--gc garbage collect shared data (experimental/temporary)
--warn-unused-imports
warn about unnecessary imports
");
}
2011-09-02 17:34:58 -05:00
fn main(args: [str]) {
let args = args, binary = vec::shift(args);
if vec::len(args) == 0u { usage(binary); ret; }
2011-07-27 07:19:39 -05:00
let match =
alt getopts::getopts(args, opts()) {
ok(m) { m }
err(f) {
early_error(getopts::fail_str(f))
2011-07-27 07:19:39 -05:00
}
};
2011-09-02 17:34:58 -05:00
if opt_present(match, "h") || opt_present(match, "help") {
2011-05-22 15:41:32 -05:00
usage(binary);
ret;
}
2011-09-02 17:34:58 -05:00
if opt_present(match, "v") || opt_present(match, "version") {
2011-05-22 15:41:32 -05:00
version(binary);
ret;
}
let ifile = alt vec::len(match.free) {
0u { early_error("No input filename given.") }
1u { match.free[0] }
_ { early_error("Multiple input filenames provided.") }
};
let sopts = build_session_options(match);
let sess = build_session(sopts, ifile);
2011-12-15 15:52:33 -06:00
let odir = getopts::opt_maybe_str(match, "out-dir");
let ofile = getopts::opt_maybe_str(match, "o");
2011-09-02 17:34:58 -05:00
let cfg = build_configuration(sess, binary, ifile);
2011-07-27 07:19:39 -05:00
let pretty =
option::map(getopts::opt_default(match, "pretty",
"normal"),
bind parse_pretty(sess, _));
2011-07-27 07:19:39 -05:00
alt pretty {
2011-09-02 17:34:58 -05:00
some::<pp_mode>(ppm) { pretty_print_input(sess, cfg, ifile, ppm); ret; }
none::<pp_mode>. {/* continue */ }
}
2011-09-02 17:34:58 -05:00
let ls = opt_present(match, "ls");
if ls {
list_metadata(sess, ifile, io::stdout());
ret;
}
2011-12-15 15:52:33 -06:00
compile_input(sess, cfg, ifile, odir, ofile);
2010-06-23 23:03:09 -05:00
}
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End: