2010-06-23 23:03:09 -05:00
|
|
|
// -*- rust -*-
|
2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2011-06-30 00:35:49 -05:00
|
|
|
#[link(name = "rustc",
|
2012-10-12 18:41:25 -05:00
|
|
|
vers = "0.5",
|
2011-06-30 00:35:49 -05:00
|
|
|
uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf",
|
2012-03-28 15:42:17 -05:00
|
|
|
url = "https://github.com/mozilla/rust/tree/master/src/rustc")];
|
2011-06-30 00:35:49 -05:00
|
|
|
|
2012-01-23 18:25:15 -06:00
|
|
|
#[comment = "The Rust compiler"];
|
2012-01-08 18:21:43 -06:00
|
|
|
#[license = "MIT"];
|
2012-01-17 16:40:59 -06:00
|
|
|
#[crate_type = "lib"];
|
2011-05-05 21:44:00 -05:00
|
|
|
|
2012-04-05 19:30:26 -05:00
|
|
|
#[no_core];
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2012-09-18 17:52:21 -05:00
|
|
|
#[legacy_modes];
|
2012-09-25 17:22:28 -05:00
|
|
|
#[legacy_exports];
|
2012-09-18 17:52:21 -05:00
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
#[allow(vecs_implicitly_copyable)];
|
2012-09-18 13:20:57 -05:00
|
|
|
#[allow(non_camel_case_types)];
|
2012-09-28 20:38:59 -05:00
|
|
|
#[allow(deprecated_mode)];
|
2012-12-04 12:50:00 -06:00
|
|
|
#[warn(deprecated_pattern)];
|
2012-06-04 20:34:24 -05:00
|
|
|
|
2012-10-12 18:41:25 -05:00
|
|
|
extern mod core(vers = "0.5");
|
|
|
|
extern mod std(vers = "0.5");
|
|
|
|
extern mod syntax(vers = "0.5");
|
2012-04-05 19:30:26 -05:00
|
|
|
|
2012-09-05 13:46:25 -05:00
|
|
|
use core::*;
|
2012-03-22 17:27:35 -05:00
|
|
|
|
2012-05-13 17:56:45 -05:00
|
|
|
/*
|
|
|
|
Alternate names for some modules.
|
|
|
|
|
|
|
|
I am using this to help extract metadata into its own crate. In metadata.rs
|
|
|
|
it redefines all these modules in order to gate access from metadata to the
|
|
|
|
rest of the compiler, then uses these to access the original implementation.
|
|
|
|
*/
|
2012-09-05 13:46:25 -05:00
|
|
|
use util_ = util;
|
|
|
|
use lib_ = lib;
|
|
|
|
use driver_ = driver;
|
|
|
|
use middle_ = middle;
|
|
|
|
use back_ = back;
|
2012-05-13 17:56:45 -05:00
|
|
|
|
2011-04-19 18:40:46 -05:00
|
|
|
mod middle {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
2012-01-27 06:17:06 -06:00
|
|
|
mod trans {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/inline.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod inline;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/monomorphize.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod monomorphize;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/controlflow.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod controlflow;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/glue.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod glue;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/datum.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod datum;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/callee.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod callee;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/expr.rs"]
|
2012-08-28 17:54:45 -05:00
|
|
|
mod expr;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/common.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod common;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/consts.rs"]
|
2012-07-31 20:34:36 -05:00
|
|
|
mod consts;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/type_of.rs"]
|
2012-02-21 08:22:55 -06:00
|
|
|
mod type_of;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/build.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod build;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/base.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod base;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/alt.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod alt;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/uniq.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod uniq;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/closure.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod closure;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/tvec.rs"]
|
2012-01-27 06:17:06 -06:00
|
|
|
mod tvec;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/meth.rs"]
|
2012-09-11 21:28:14 -05:00
|
|
|
mod meth;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/foreign.rs"]
|
2012-06-26 18:18:37 -05:00
|
|
|
mod foreign;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/reflect.rs"]
|
2012-05-14 19:57:39 -05:00
|
|
|
mod reflect;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/shape.rs"]
|
2012-02-14 22:12:47 -06:00
|
|
|
mod shape;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/debuginfo.rs"]
|
2012-02-17 15:51:19 -06:00
|
|
|
mod debuginfo;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/type_use.rs"]
|
2012-03-12 10:31:22 -05:00
|
|
|
mod type_use;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/reachable.rs"]
|
2012-03-20 06:28:46 -05:00
|
|
|
mod reachable;
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/trans/machine.rs"]
|
2012-09-25 17:21:16 -05:00
|
|
|
mod machine;
|
2012-01-27 06:17:06 -06:00
|
|
|
}
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/ty.rs"]
|
2011-04-19 18:40:46 -05:00
|
|
|
mod ty;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/resolve.rs"]
|
2012-08-29 15:26:26 -05:00
|
|
|
mod resolve;
|
2012-11-28 18:20:41 -06:00
|
|
|
#[path = "middle/typeck/mod.rs"]
|
2012-11-28 14:33:00 -06:00
|
|
|
pub mod typeck;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/check_loop.rs"]
|
2012-03-26 05:39:20 -05:00
|
|
|
mod check_loop;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/check_alt.rs"]
|
2011-07-25 06:45:09 -05:00
|
|
|
mod check_alt;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/check_const.rs"]
|
2011-11-08 20:26:02 -06:00
|
|
|
mod check_const;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/lint.rs"]
|
2012-01-19 02:50:51 -06:00
|
|
|
mod lint;
|
2012-11-28 18:20:41 -06:00
|
|
|
#[path = "middle/borrowck/mod.rs"]
|
2012-11-28 14:33:00 -06:00
|
|
|
mod borrowck;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/mem_categorization.rs"]
|
2012-08-08 10:15:32 -05:00
|
|
|
mod mem_categorization;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/liveness.rs"]
|
2012-05-19 07:52:01 -05:00
|
|
|
mod liveness;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/kind.rs"]
|
2011-07-27 19:49:00 -05:00
|
|
|
mod kind;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/freevars.rs"]
|
2011-07-18 19:26:37 -05:00
|
|
|
mod freevars;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/capture.rs"]
|
2011-12-19 14:50:31 -06:00
|
|
|
mod capture;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/pat_util.rs"]
|
2012-01-14 18:05:07 -06:00
|
|
|
mod pat_util;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/region.rs"]
|
2012-03-09 18:39:54 -06:00
|
|
|
mod region;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/const_eval.rs"]
|
2012-03-22 16:56:56 -05:00
|
|
|
mod const_eval;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/astencode.rs"]
|
2012-05-14 18:15:11 -05:00
|
|
|
mod astencode;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/lang_items.rs"]
|
2012-07-25 20:36:18 -05:00
|
|
|
mod lang_items;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "middle/privacy.rs"]
|
2012-09-04 16:48:32 -05:00
|
|
|
mod privacy;
|
2012-12-04 17:38:04 -06:00
|
|
|
#[path = "middle/mode.rs"]
|
|
|
|
mod mode;
|
2011-04-19 18:40:46 -05:00
|
|
|
}
|
|
|
|
|
2010-09-23 17:46:31 -05:00
|
|
|
mod front {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "front/config.rs"]
|
2011-06-30 00:32:08 -05:00
|
|
|
mod config;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "front/test.rs"]
|
2011-07-06 16:29:50 -05:00
|
|
|
mod test;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "front/core_inject.rs"]
|
2012-01-26 17:20:29 -06:00
|
|
|
mod core_inject;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "front/intrinsic_inject.rs"]
|
2012-05-10 19:18:04 -05:00
|
|
|
mod intrinsic_inject;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2010-09-23 17:46:31 -05:00
|
|
|
mod back {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/link.rs"]
|
2012-09-18 13:46:39 -05:00
|
|
|
mod link;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/abi.rs"]
|
2010-09-23 17:46:31 -05:00
|
|
|
mod abi;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/upcall.rs"]
|
2011-05-09 17:32:12 -05:00
|
|
|
mod upcall;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/x86.rs"]
|
2010-09-23 17:46:31 -05:00
|
|
|
mod x86;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/x86_64.rs"]
|
2011-10-13 14:23:50 -05:00
|
|
|
mod x86_64;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/rpath.rs"]
|
2011-10-04 17:23:32 -05:00
|
|
|
mod rpath;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "back/target_strs.rs"]
|
2011-10-12 14:29:08 -05:00
|
|
|
mod target_strs;
|
2010-09-23 17:46:31 -05:00
|
|
|
}
|
|
|
|
|
2012-11-28 18:20:41 -06:00
|
|
|
#[path = "metadata/mod.rs"]
|
2012-11-28 14:33:00 -06:00
|
|
|
mod metadata;
|
2011-06-27 18:38:57 -05:00
|
|
|
|
2012-11-28 18:20:41 -06:00
|
|
|
#[path = "driver/mod.rs"]
|
2012-11-28 14:33:00 -06:00
|
|
|
mod driver;
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2010-08-18 13:34:47 -05:00
|
|
|
mod util {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "util/common.rs"]
|
2010-08-18 13:34:47 -05:00
|
|
|
mod common;
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "util/ppaux.rs"]
|
2011-07-05 04:48:19 -05:00
|
|
|
mod ppaux;
|
2010-08-18 13:34:47 -05:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:47:40 -05:00
|
|
|
mod lib {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
|
|
|
#[legacy_exports]
|
2012-11-28 14:33:00 -06:00
|
|
|
#[path = "lib/llvm.rs"]
|
2011-06-20 16:59:45 -05:00
|
|
|
mod llvm;
|
2010-07-12 19:47:40 -05:00
|
|
|
}
|
|
|
|
|
2012-11-28 14:33:00 -06:00
|
|
|
use result::{Ok, Err};
|
|
|
|
use io::ReaderUtil;
|
|
|
|
use std::getopts;
|
|
|
|
use std::map::HashMap;
|
|
|
|
use getopts::{opt_present};
|
|
|
|
use getopts::groups;
|
|
|
|
use syntax::codemap;
|
|
|
|
use syntax::diagnostic;
|
|
|
|
use driver::driver::{host_triple, optgroups, early_error,
|
|
|
|
str_input, file_input, build_session_options,
|
|
|
|
build_session, build_configuration, parse_pretty,
|
|
|
|
pp_mode, pretty_print_input, list_metadata,
|
|
|
|
compile_input};
|
|
|
|
use driver::session;
|
|
|
|
use middle::lint;
|
|
|
|
|
|
|
|
fn version(argv0: &str) {
|
|
|
|
let mut vers = ~"unknown version";
|
|
|
|
let env_vers = env!("CFG_VERSION");
|
|
|
|
if env_vers.len() != 0 { vers = env_vers; }
|
|
|
|
io::println(fmt!("%s %s", argv0, vers));
|
|
|
|
io::println(fmt!("host: %s", host_triple()));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(argv0: &str) {
|
|
|
|
let message = fmt!("Usage: %s [OPTIONS] INPUT", argv0);
|
|
|
|
io::println(groups::usage(message, optgroups()) +
|
|
|
|
~"Additional help:
|
|
|
|
-W help Print 'lint' options and default settings
|
|
|
|
-Z help Print internal options for debugging rustc
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn describe_warnings() {
|
|
|
|
io::println(fmt!("
|
|
|
|
Available lint options:
|
|
|
|
-W <foo> Warn about <foo>
|
|
|
|
-A <foo> Allow <foo>
|
|
|
|
-D <foo> Deny <foo>
|
|
|
|
-F <foo> Forbid <foo> (deny, and deny all overrides)
|
|
|
|
"));
|
|
|
|
|
|
|
|
let lint_dict = lint::get_lint_dict();
|
|
|
|
let mut max_key = 0;
|
|
|
|
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
|
|
|
|
fn padded(max: uint, s: &str) -> ~str {
|
|
|
|
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
|
|
|
|
}
|
|
|
|
io::println(fmt!("\nAvailable lint checks:\n"));
|
|
|
|
io::println(fmt!(" %s %7.7s %s",
|
|
|
|
padded(max_key, ~"name"), ~"default", ~"meaning"));
|
|
|
|
io::println(fmt!(" %s %7.7s %s\n",
|
|
|
|
padded(max_key, ~"----"), ~"-------", ~"-------"));
|
|
|
|
for lint_dict.each |k, v| {
|
|
|
|
let k = str::replace(k, ~"_", ~"-");
|
|
|
|
io::println(fmt!(" %s %7.7s %s",
|
|
|
|
padded(max_key, k),
|
|
|
|
match v.default {
|
|
|
|
lint::allow => ~"allow",
|
|
|
|
lint::warn => ~"warn",
|
|
|
|
lint::deny => ~"deny",
|
|
|
|
lint::forbid => ~"forbid"
|
|
|
|
},
|
|
|
|
v.desc));
|
|
|
|
}
|
|
|
|
io::println(~"");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn describe_debug_flags() {
|
|
|
|
io::println(fmt!("\nAvailable debug options:\n"));
|
|
|
|
for session::debugging_opts_map().each |pair| {
|
|
|
|
let (name, desc, _) = *pair;
|
|
|
|
io::println(fmt!(" -Z %-20s -- %s", name, desc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_compiler(args: &~[~str], demitter: diagnostic::emitter) {
|
|
|
|
// Don't display log spew by default. Can override with RUST_LOG.
|
|
|
|
logging::console_off();
|
|
|
|
|
|
|
|
let mut args = *args;
|
|
|
|
let binary = args.shift();
|
|
|
|
|
|
|
|
if args.is_empty() { usage(binary); return; }
|
|
|
|
|
|
|
|
let matches =
|
2012-11-28 14:38:53 -06:00
|
|
|
&match getopts::groups::getopts(args, optgroups()) {
|
2012-12-04 12:50:00 -06:00
|
|
|
Ok(ref m) => (*m),
|
|
|
|
Err(ref f) => {
|
|
|
|
early_error(demitter, getopts::fail_str((*f)))
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if opt_present(matches, ~"h") || opt_present(matches, ~"help") {
|
|
|
|
usage(binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let lint_flags = vec::append(getopts::opt_strs(matches, ~"W"),
|
|
|
|
getopts::opt_strs(matches, ~"warn"));
|
|
|
|
if lint_flags.contains(&~"help") {
|
|
|
|
describe_warnings();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if getopts::opt_strs(matches, ~"Z").contains(&~"help") {
|
|
|
|
describe_debug_flags();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if opt_present(matches, ~"v") || opt_present(matches, ~"version") {
|
|
|
|
version(binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let input = match vec::len(matches.free) {
|
|
|
|
0u => early_error(demitter, ~"no input filename given"),
|
|
|
|
1u => {
|
|
|
|
let ifile = matches.free[0];
|
|
|
|
if ifile == ~"-" {
|
|
|
|
let src = str::from_bytes(io::stdin().read_whole_stream());
|
|
|
|
str_input(src)
|
|
|
|
} else {
|
|
|
|
file_input(Path(ifile))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => early_error(demitter, ~"multiple input filenames provided")
|
|
|
|
};
|
|
|
|
|
|
|
|
let sopts = build_session_options(binary, matches, demitter);
|
|
|
|
let sess = build_session(sopts, demitter);
|
|
|
|
let odir = getopts::opt_maybe_str(matches, ~"out-dir");
|
|
|
|
let odir = odir.map(|o| Path(*o));
|
|
|
|
let ofile = getopts::opt_maybe_str(matches, ~"o");
|
|
|
|
let ofile = ofile.map(|o| Path(*o));
|
|
|
|
let cfg = build_configuration(sess, binary, input);
|
|
|
|
let pretty =
|
|
|
|
option::map(&getopts::opt_default(matches, ~"pretty",
|
|
|
|
~"normal"),
|
|
|
|
|a| parse_pretty(sess, *a) );
|
|
|
|
match pretty {
|
|
|
|
Some::<pp_mode>(ppm) => {
|
|
|
|
pretty_print_input(sess, cfg, input, ppm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
None::<pp_mode> => {/* continue */ }
|
|
|
|
}
|
|
|
|
let ls = opt_present(matches, ~"ls");
|
|
|
|
if ls {
|
|
|
|
match input {
|
2012-12-04 12:50:00 -06:00
|
|
|
file_input(ref ifile) => {
|
|
|
|
list_metadata(sess, &(*ifile), io::stdout());
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
str_input(_) => {
|
|
|
|
early_error(demitter, ~"can not list metadata for stdin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
compile_input(sess, cfg, input, &odir, &ofile);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum monitor_msg {
|
|
|
|
fatal,
|
|
|
|
done,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl monitor_msg : cmp::Eq {
|
|
|
|
pure fn eq(&self, other: &monitor_msg) -> bool {
|
|
|
|
((*self) as uint) == ((*other) as uint)
|
|
|
|
}
|
|
|
|
pure fn ne(&self, other: &monitor_msg) -> bool { !(*self).eq(other) }
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is a sanity check that any failure of the compiler is performed
|
|
|
|
through the diagnostic module and reported properly - we shouldn't be calling
|
|
|
|
plain-old-fail on any execution path that might be taken. Since we have
|
|
|
|
console logging off by default, hitting a plain fail statement would make the
|
|
|
|
compiler silently exit, which would be terrible.
|
|
|
|
|
|
|
|
This method wraps the compiler in a subtask and injects a function into the
|
|
|
|
diagnostic emitter which records when we hit a fatal error. If the task
|
|
|
|
fails without recording a fatal error then we've encountered a compiler
|
|
|
|
bug and need to present an error.
|
|
|
|
*/
|
|
|
|
fn monitor(+f: fn~(diagnostic::emitter)) {
|
|
|
|
let p = comm::Port();
|
|
|
|
let ch = comm::Chan(&p);
|
|
|
|
|
|
|
|
match do task::try |move f| {
|
|
|
|
|
|
|
|
// The 'diagnostics emitter'. Every error, warning, etc. should
|
|
|
|
// go through this function.
|
|
|
|
let demitter = fn@(cmsp: Option<(@codemap::CodeMap, codemap::span)>,
|
|
|
|
msg: &str, lvl: diagnostic::level) {
|
|
|
|
if lvl == diagnostic::fatal {
|
|
|
|
comm::send(ch, fatal);
|
|
|
|
}
|
|
|
|
diagnostic::emit(cmsp, msg, lvl);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct finally {
|
|
|
|
ch: comm::Chan<monitor_msg>,
|
|
|
|
drop { comm::send(self.ch, done); }
|
|
|
|
}
|
|
|
|
|
|
|
|
let _finally = finally { ch: ch };
|
|
|
|
|
|
|
|
f(demitter)
|
|
|
|
} {
|
|
|
|
result::Ok(_) => { /* fallthrough */ }
|
|
|
|
result::Err(_) => {
|
|
|
|
// Task failed without emitting a fatal diagnostic
|
|
|
|
if comm::recv(p) == done {
|
|
|
|
diagnostic::emit(
|
|
|
|
None,
|
|
|
|
diagnostic::ice_msg(~"unexpected failure"),
|
|
|
|
diagnostic::error);
|
|
|
|
|
|
|
|
for [
|
|
|
|
~"the compiler hit an unexpected failure path. \
|
|
|
|
this is a bug",
|
|
|
|
~"try running with RUST_LOG=rustc=1,::rt::backtrace \
|
|
|
|
to get further details and report the results \
|
|
|
|
to github.com/mozilla/rust/issues"
|
|
|
|
].each |note| {
|
|
|
|
diagnostic::emit(None, *note, diagnostic::note)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fail so the process returns a failure code
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut args = os::args();
|
|
|
|
do monitor |move args, demitter| {
|
|
|
|
run_compiler(&args, demitter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
// Local Variables:
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
2010-08-18 13:34:22 -05:00
|
|
|
// c-basic-offset: 4
|
2010-06-23 23:03:09 -05:00
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|