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