提交 e135fa5b 编写于 作者: N Niko Matsakis

Remove dependencies on driver from trans et al. by moving various

structs out from driver and into other places.
上级 cc32f867
......@@ -92,6 +92,17 @@
// Data types
/// The complete set of all analyses described in this module. This is
/// produced by the driver and fed to trans and later passes.
pub struct CrateAnalysis<'tcx> {
pub exp_map2: middle::resolve::ExportMap2,
pub exported_items: middle::privacy::ExportedItems,
pub public_items: middle::privacy::PublicItems,
pub ty_cx: ty::ctxt<'tcx>,
pub reachable: NodeSet,
pub name: String,
}
#[deriving(PartialEq, Eq, Hash)]
pub struct field<'tcx> {
pub name: ast::Name,
......
......@@ -114,6 +114,59 @@ pub struct Options {
pub alt_std_name: Option<String>
}
pub enum Input {
/// Load source from file
File(Path),
/// The string is the source
Str(String)
}
impl Input {
pub fn filestem(&self) -> String {
match *self {
Input::File(ref ifile) => ifile.filestem_str().unwrap().to_string(),
Input::Str(_) => "rust_out".to_string(),
}
}
}
#[deriving(Clone)]
pub struct OutputFilenames {
pub out_directory: Path,
pub out_filestem: String,
pub single_output_file: Option<Path>,
pub extra: String,
}
impl OutputFilenames {
pub fn path(&self, flavor: OutputType) -> Path {
match self.single_output_file {
Some(ref path) => return path.clone(),
None => {}
}
self.temp_path(flavor)
}
pub fn temp_path(&self, flavor: OutputType) -> Path {
let base = self.out_directory.join(self.filestem());
match flavor {
OutputTypeBitcode => base.with_extension("bc"),
OutputTypeAssembly => base.with_extension("s"),
OutputTypeLlvmAssembly => base.with_extension("ll"),
OutputTypeObject => base.with_extension("o"),
OutputTypeExe => base,
}
}
pub fn with_extension(&self, extension: &str) -> Path {
self.out_directory.join(self.filestem()).with_extension(extension)
}
pub fn filestem(&self) -> String {
format!("{}{}", self.out_filestem, self.extra)
}
}
pub fn host_triple() -> &'static str {
// Get the host triple out of the build environment. This ensures that our
// idea of the host triple is the same as for the set of libraries we've
......
......@@ -13,15 +13,13 @@
use super::rpath;
use super::rpath::RPathConfig;
use super::svh::Svh;
use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput};
use session::config;
use session::config::NoDebugInfo;
use session::config::{OutputTypeBitcode, OutputTypeExe, OutputTypeObject};
use session::config::{OutputFilenames, Input, OutputTypeBitcode, OutputTypeExe, OutputTypeObject};
use session::Session;
use metadata::common::LinkMeta;
use metadata::{encoder, cstore, filesearch, csearch, creader};
use trans::context::CrateContext;
use trans::common::gensym_name;
use trans::{CrateContext, CrateTranslation, gensym_name};
use middle::ty::{mod, Ty};
use util::common::time;
use util::ppaux;
......@@ -156,7 +154,7 @@ pub fn find_crate_name(sess: Option<&Session>,
if let Some((attr, s)) = attr_crate_name {
return validate(s.get().to_string(), Some(attr.span));
}
if let FileInput(ref path) = *input {
if let Input::File(ref path) = *input {
if let Some(s) = path.filestem_str() {
return validate(s.to_string(), None);
}
......
......@@ -10,13 +10,13 @@
use back::lto;
use back::link::{get_cc_prog, remove};
use driver::driver::{CrateTranslation, ModuleTranslation, OutputFilenames};
use session::config::{NoDebugInfo, Passes, SomePasses, AllPasses};
use session::config::{OutputFilenames, NoDebugInfo, Passes, SomePasses, AllPasses};
use session::Session;
use session::config;
use llvm;
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
use llvm::SMDiagnosticRef;
use trans::{CrateTranslation, ModuleTranslation};
use util::common::time;
use syntax::codemap;
use syntax::diagnostic;
......
......@@ -8,15 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::Input::*;
use back::link;
use back::write;
use session::Session;
use session::config;
use session::config::{mod, Input, OutputFilenames};
use lint;
use llvm::{ContextRef, ModuleRef};
use metadata::common::LinkMeta;
use metadata::creader;
use middle::{stability, ty, reachable};
use middle::dependency_format;
......@@ -28,7 +24,6 @@
use trans;
use util::common::time;
use util::nodemap::{NodeSet};
use serialize::{json, Encodable};
......@@ -114,36 +109,19 @@ pub fn anon_src() -> String {
pub fn source_name(input: &Input) -> String {
match *input {
// FIXME (#9639): This needs to handle non-utf8 paths
FileInput(ref ifile) => ifile.as_str().unwrap().to_string(),
StrInput(_) => anon_src()
}
}
pub enum Input {
/// Load source from file
FileInput(Path),
/// The string is the source
StrInput(String)
}
impl Input {
fn filestem(&self) -> String {
match *self {
FileInput(ref ifile) => ifile.filestem_str().unwrap().to_string(),
StrInput(_) => "rust_out".to_string(),
}
Input::File(ref ifile) => ifile.as_str().unwrap().to_string(),
Input::Str(_) => anon_src()
}
}
pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
-> ast::Crate {
let krate = time(sess.time_passes(), "parsing", (), |_| {
match *input {
FileInput(ref file) => {
Input::File(ref file) => {
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
}
StrInput(ref src) => {
Input::Str(ref src) => {
parse::parse_crate_from_source_str(anon_src().to_string(),
src.to_string(),
cfg.clone(),
......@@ -343,23 +321,13 @@ fn new_id(&self, old_id: ast::NodeId) -> ast::NodeId {
map
}
pub struct CrateAnalysis<'tcx> {
pub exp_map2: middle::resolve::ExportMap2,
pub exported_items: middle::privacy::ExportedItems,
pub public_items: middle::privacy::PublicItems,
pub ty_cx: ty::ctxt<'tcx>,
pub reachable: NodeSet,
pub name: String,
}
/// Run the resolution, typechecking, region checking and other
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
ast_map: ast_map::Map<'tcx>,
type_arena: &'tcx TypedArena<ty::TyS<'tcx>>,
name: String) -> CrateAnalysis<'tcx> {
name: String) -> ty::CrateAnalysis<'tcx> {
let time_passes = sess.time_passes();
let krate = ast_map.krate();
......@@ -474,7 +442,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
time(time_passes, "lint checking", (), |_|
lint::check_crate(&ty_cx, &exported_items));
CrateAnalysis {
ty::CrateAnalysis {
exp_map2: exp_map2,
ty_cx: ty_cx,
exported_items: exported_items,
......@@ -486,7 +454,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
pub fn phase_save_analysis(sess: &Session,
krate: &ast::Crate,
analysis: &CrateAnalysis,
analysis: &ty::CrateAnalysis,
odir: &Option<Path>) {
if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 {
return;
......@@ -495,25 +463,10 @@ pub fn phase_save_analysis(sess: &Session,
save::process_crate(sess, krate, analysis, odir));
}
pub struct ModuleTranslation {
pub llcx: ContextRef,
pub llmod: ModuleRef,
}
pub struct CrateTranslation {
pub modules: Vec<ModuleTranslation>,
pub metadata_module: ModuleTranslation,
pub link: LinkMeta,
pub metadata: Vec<u8>,
pub reachable: Vec<String>,
pub crate_formats: dependency_format::Dependencies,
pub no_builtins: bool,
}
/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
pub fn phase_4_translate_to_llvm<'tcx>(analysis: CrateAnalysis<'tcx>)
-> (ty::ctxt<'tcx>, CrateTranslation) {
pub fn phase_4_translate_to_llvm<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
-> (ty::ctxt<'tcx>, trans::CrateTranslation) {
let time_passes = analysis.ty_cx.sess.time_passes();
time(time_passes, "resolving dependency formats", (), |_|
......@@ -521,13 +474,13 @@ pub fn phase_4_translate_to_llvm<'tcx>(analysis: CrateAnalysis<'tcx>)
// Option dance to work around the lack of stack once closures.
time(time_passes, "translation", analysis, |analysis|
trans::base::trans_crate(analysis))
trans::trans_crate(analysis))
}
/// Run LLVM itself, producing a bitcode file, assembly file or object file
/// as a side effect.
pub fn phase_5_run_llvm_passes(sess: &Session,
trans: &CrateTranslation,
trans: &trans::CrateTranslation,
outputs: &OutputFilenames) {
if sess.opts.cg.no_integrated_as {
let output_type = config::OutputTypeAssembly;
......@@ -555,7 +508,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
/// Run the linker on any artifacts that resulted from the LLVM run.
/// This should produce either a finished executable or library.
pub fn phase_6_link_output(sess: &Session,
trans: &CrateTranslation,
trans: &trans::CrateTranslation,
outputs: &OutputFilenames) {
let old_path = os::getenv("PATH").unwrap_or_else(||String::new());
let mut new_path = sess.host_filesearch().get_tools_search_paths();
......@@ -640,8 +593,8 @@ fn write_out_deps(sess: &Session,
// Use default filename: crate source filename with extension replaced
// by ".d"
(true, None) => match *input {
FileInput(..) => outputs.with_extension("d"),
StrInput(..) => {
Input::File(..) => outputs.with_extension("d"),
Input::Str(..) => {
sess.warn("can not write --dep-info without a filename \
when compiling stdin.");
return
......@@ -752,43 +705,6 @@ pub fn collect_crate_metadata(session: &Session,
session.opts.cg.metadata.clone()
}
#[deriving(Clone)]
pub struct OutputFilenames {
pub out_directory: Path,
pub out_filestem: String,
pub single_output_file: Option<Path>,
extra: String,
}
impl OutputFilenames {
pub fn path(&self, flavor: config::OutputType) -> Path {
match self.single_output_file {
Some(ref path) => return path.clone(),
None => {}
}
self.temp_path(flavor)
}
pub fn temp_path(&self, flavor: config::OutputType) -> Path {
let base = self.out_directory.join(self.filestem());
match flavor {
config::OutputTypeBitcode => base.with_extension("bc"),
config::OutputTypeAssembly => base.with_extension("s"),
config::OutputTypeLlvmAssembly => base.with_extension("ll"),
config::OutputTypeObject => base.with_extension("o"),
config::OutputTypeExe => base,
}
}
pub fn with_extension(&self, extension: &str) -> Path {
self.out_directory.join(self.filestem()).with_extension(extension)
}
fn filestem(&self) -> String {
format!("{}{}", self.out_filestem, self.extra)
}
}
pub fn build_output_filenames(input: &Input,
odir: &Option<Path>,
ofile: &Option<Path>,
......
......@@ -11,8 +11,8 @@
pub use syntax::diagnostic;
use back::link;
use driver::driver::{Input, FileInput, StrInput};
use session::{config, Session, build_session};
use session::config::Input;
use lint::Lint;
use lint;
use metadata;
......@@ -89,9 +89,9 @@ fn run_compiler(args: &[String]) {
if ifile == "-" {
let contents = io::stdin().read_to_end().unwrap();
let src = String::from_utf8(contents).unwrap();
(StrInput(src), None)
(Input::Str(src), None)
} else {
(FileInput(Path::new(ifile)), Some(Path::new(ifile)))
(Input::File(Path::new(ifile)), Some(Path::new(ifile)))
}
}
_ => early_error("multiple input filenames provided")
......@@ -116,11 +116,11 @@ fn run_compiler(args: &[String]) {
let r = matches.opt_strs("Z");
if r.contains(&("ls".to_string())) {
match input {
FileInput(ref ifile) => {
Input::File(ref ifile) => {
let mut stdout = io::stdout();
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
}
StrInput(_) => {
Input::Str(_) => {
early_error("can not list metadata for stdin");
}
}
......@@ -411,12 +411,12 @@ fn print_crate_info(sess: &Session,
fn parse_crate_attrs(sess: &Session, input: &Input) ->
Vec<ast::Attribute> {
let result = match *input {
FileInput(ref ifile) => {
Input::File(ref ifile) => {
parse::parse_crate_attrs_from_file(ifile,
Vec::new(),
&sess.parse_sess)
}
StrInput(ref src) => {
Input::Str(ref src) => {
parse::parse_crate_attrs_from_source_str(
driver::anon_src().to_string(),
src.to_string(),
......
......@@ -17,8 +17,9 @@
use back::link;
use session::{config, Session};
use driver::driver::{mod, CrateAnalysis};
use session::Session;
use session::config::{mod, Input};
use driver::driver::{mod};
use middle::ty;
use middle::borrowck::{mod, FnPartsWithCFG};
......@@ -242,7 +243,7 @@ fn post(&self,
struct TypedAnnotation<'tcx> {
analysis: CrateAnalysis<'tcx>,
analysis: ty::CrateAnalysis<'tcx>,
}
impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> {
......@@ -409,7 +410,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
pub fn pretty_print_input(sess: Session,
cfg: ast::CrateConfig,
input: &driver::Input,
input: &Input,
ppm: PpMode,
opt_uii: Option<UserIdentifiedItem>,
ofile: Option<Path>) {
......@@ -536,7 +537,7 @@ pub fn pretty_print_input(sess: Session,
}
fn print_flowgraph<W:io::Writer>(variants: Vec<borrowck_dot::Variant>,
analysis: CrateAnalysis,
analysis: ty::CrateAnalysis,
code: blocks::Code,
mut out: W) -> io::IoResult<()> {
let ty_cx = &analysis.ty_cx;
......
......@@ -27,7 +27,6 @@
//! the format of the output away from extracting it from the compiler.
//! DxrVisitor walks the AST and processes it.
use driver::driver::CrateAnalysis;
use session::Session;
use middle::def;
......@@ -68,7 +67,7 @@ fn generated_code(span: Span) -> bool {
struct DxrVisitor<'l, 'tcx: 'l> {
sess: &'l Session,
analysis: &'l CrateAnalysis<'tcx>,
analysis: &'l ty::CrateAnalysis<'tcx>,
collected_paths: Vec<(NodeId, ast::Path, bool, recorder::Row)>,
collecting: bool,
......@@ -1473,7 +1472,7 @@ fn visit_local(&mut self, l: &ast::Local) {
pub fn process_crate(sess: &Session,
krate: &ast::Crate,
analysis: &CrateAnalysis,
analysis: &ty::CrateAnalysis,
odir: &Option<Path>) {
if generated_code(krate.span) {
return;
......
......@@ -28,9 +28,11 @@
pub use self::ValueOrigin::*;
pub use self::scalar_type::*;
use super::CrateTranslation;
use super::ModuleTranslation;
use back::link::{mangle_exported_name};
use back::{link, abi};
use driver::driver::{CrateAnalysis, CrateTranslation, ModuleTranslation};
use lint;
use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param};
use llvm;
......@@ -1078,12 +1080,6 @@ pub fn store_ty(cx: Block, v: ValueRef, dst: ValueRef, t: Ty) {
};
}
pub fn ignore_lhs(_bcx: Block, local: &ast::Local) -> bool {
match local.pat.node {
ast::PatWild(ast::PatWildSingle) => true, _ => false
}
}
pub fn init_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, local: &ast::Local)
-> Block<'blk, 'tcx> {
debug!("init_local(bcx={}, local.id={})", bcx.to_str(), local.id);
......@@ -2916,12 +2912,6 @@ fn register_method(ccx: &CrateContext, id: ast::NodeId,
llfn
}
pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef {
unsafe {
return llvm::LLVMConstPtrToInt(v, ccx.int_type().to_ref());
}
}
pub fn crate_ctxt_to_encode_parms<'a, 'tcx>(cx: &'a SharedCrateContext<'tcx>,
ie: encoder::EncodeInlinedItem<'a>)
-> encoder::EncodeParams<'a, 'tcx> {
......@@ -3055,9 +3045,9 @@ fn next(&mut self) -> Option<ValueRef> {
}
}
pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>)
pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
-> (ty::ctxt<'tcx>, CrateTranslation) {
let CrateAnalysis { ty_cx: tcx, exp_map2, reachable, name, .. } = analysis;
let ty::CrateAnalysis { ty_cx: tcx, exp_map2, reachable, name, .. } = analysis;
let krate = tcx.map.krate();
// Before we touch LLVM, make sure that multithreading is enabled.
......
......@@ -272,11 +272,6 @@ pub fn arg_pos(&self, arg: uint) -> uint {
}
}
pub fn out_arg_pos(&self) -> uint {
assert!(self.caller_expects_out_pointer);
0u
}
pub fn env_arg_pos(&self) -> uint {
if self.caller_expects_out_pointer {
1u
......
......@@ -347,10 +347,6 @@ pub fn link_meta<'a>(&'a self) -> &'a LinkMeta {
&self.link_meta
}
pub fn symbol_hasher<'a>(&'a self) -> &'a RefCell<Sha256> {
&self.symbol_hasher
}
pub fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> {
&self.tcx
}
......
......@@ -352,13 +352,6 @@ pub fn assert_lvalue(self, bcx: Block) -> Datum<'tcx, Lvalue> {
|_| bcx.sess().bug("assert_lvalue given rvalue"))
}
/// Asserts that this datum *is* an lvalue and returns it.
pub fn assert_rvalue(self, bcx: Block) -> Datum<'tcx, Rvalue> {
self.match_kind(
|_| bcx.sess().bug("assert_rvalue given lvalue"),
|r| r)
}
pub fn store_to_dest<'blk>(self,
bcx: Block<'blk, 'tcx>,
dest: expr::Dest,
......
......@@ -8,40 +8,64 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub mod doc;
pub mod macros;
pub mod inline;
pub mod monomorphize;
pub mod controlflow;
pub mod glue;
pub mod datum;
pub mod callee;
pub mod expr;
pub mod common;
pub mod context;
pub mod consts;
pub mod type_of;
pub mod build;
pub mod builder;
pub mod base;
pub mod _match;
pub mod closure;
pub mod tvec;
pub mod meth;
pub mod cabi;
pub mod cabi_x86;
pub mod cabi_x86_64;
pub mod cabi_x86_win64;
pub mod cabi_arm;
pub mod cabi_mips;
pub mod foreign;
pub mod intrinsic;
pub mod debuginfo;
pub mod machine;
pub mod adt;
pub mod asm;
pub mod type_;
pub mod value;
pub mod basic_block;
pub mod llrepr;
pub mod cleanup;
use llvm::{ContextRef, ModuleRef};
use metadata::common::LinkMeta;
use middle::dependency_format;
pub use self::base::trans_crate;
pub use self::context::CrateContext;
pub use self::common::gensym_name;
mod doc;
mod macros;
mod inline;
mod monomorphize;
mod controlflow;
mod glue;
mod datum;
mod callee;
mod expr;
mod common;
mod context;
mod consts;
mod type_of;
mod build;
mod builder;
mod base;
mod _match;
mod closure;
mod tvec;
mod meth;
mod cabi;
mod cabi_x86;
mod cabi_x86_64;
mod cabi_x86_win64;
mod cabi_arm;
mod cabi_mips;
mod foreign;
mod intrinsic;
mod debuginfo;
mod machine;
mod adt;
mod asm;
mod type_;
mod value;
mod basic_block;
mod llrepr;
mod cleanup;
pub struct ModuleTranslation {
pub llcx: ContextRef,
pub llmod: ModuleRef,
}
pub struct CrateTranslation {
pub modules: Vec<ModuleTranslation>,
pub metadata_module: ModuleTranslation,
pub link: LinkMeta,
pub metadata: Vec<u8>,
pub reachable: Vec<String>,
pub crate_formats: dependency_format::Dependencies,
pub no_builtins: bool,
}
......@@ -39,7 +39,6 @@
use syntax::ptr::P;
use rustc_trans::back::link;
use rustc_trans::driver::driver;
use rustc::metadata::cstore;
use rustc::metadata::csearch;
use rustc::metadata::decoder;
......@@ -48,6 +47,7 @@
use rustc::middle::subst::VecPerParamSpace;
use rustc::middle::ty;
use rustc::middle::stability;
use rustc::session::config;
use std::rc::Rc;
use std::u32;
......@@ -131,7 +131,7 @@ fn clean(&self, cx: &DocContext) -> Crate {
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
// Figure out the name of this crate
let input = driver::FileInput(cx.src.clone());
let input = config::Input::File(cx.src.clone());
let name = link::find_crate_name(None, self.attrs.as_slice(), &input);
// Clean the crate, translating the entire libsyntax AST to one that is
......
......@@ -83,7 +83,7 @@ pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
// Parse, resolve, and typecheck the given crate.
let input = driver::FileInput(cpath.clone());
let input = config::Input::File(cpath.clone());
let warning_lint = lint::builtin::WARNINGS.name_lower();
......@@ -122,7 +122,7 @@ pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
let type_arena = TypedArena::new();
let driver::CrateAnalysis {
let ty::CrateAnalysis {
exported_items, public_items, ty_cx, ..
} = driver::phase_3_run_analysis_passes(sess, ast_map, &type_arena, name);
......
......@@ -42,7 +42,7 @@ pub fn run(input: &str,
crate_name: Option<String>)
-> int {
let input_path = Path::new(input);
let input = driver::FileInput(input_path.clone());
let input = config::Input::File(input_path.clone());
let sessopts = config::Options {
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
......@@ -110,7 +110,7 @@ fn runtest(test: &str, cratename: &str, libs: Vec<Path>, externs: core::Externs,
// the test harness wants its own `main` & top level functions, so
// never wrap the test in `fn main() { ... }`
let test = maketest(test, Some(cratename), true, as_test_harness);
let input = driver::StrInput(test.to_string());
let input = config::Input::Str(test.to_string());
let sessopts = config::Options {
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册