X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_driver%2Flib.rs;h=a726a792767e20ecf40fab1205640141dec1ae3f;hb=6f4ab9458a7ad06c8ce630604f533c8c0c0acef4;hp=91ba7ed1958e7c85299cf4795b54fc30ddcc486b;hpb=7ebd81377db0e24f57be9c4f7aa84d2556931f1a;p=rust.git diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 91ba7ed1958..a726a792767 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -28,15 +28,10 @@ #![feature(rustc_diagnostic_macros)] #![feature(set_stdio)] -#[cfg(not(feature="llvm"))] -extern crate ar; - extern crate arena; extern crate getopts; extern crate graphviz; extern crate env_logger; -#[cfg(not(feature="llvm"))] -extern crate owning_ref; extern crate libc; extern crate rustc; extern crate rustc_allocator; @@ -71,8 +66,6 @@ use rustc_resolve as resolve; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; -#[cfg(feature="llvm")] -use rustc_trans::back::write::{RELOC_MODEL_ARGS, CODE_GEN_MODEL_ARGS}; use rustc::dep_graph::DepGraph; use rustc::session::{self, config, Session, build_session, CompileResult}; use rustc::session::CompileIncomplete; @@ -81,13 +74,9 @@ use rustc::session::{early_error, early_warn}; use rustc::lint::Lint; use rustc::lint; -#[cfg(not(feature="llvm"))] -use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait; use rustc_metadata::locator; use rustc_metadata::cstore::CStore; use rustc::util::common::{time, ErrorReported}; -#[cfg(not(feature="llvm"))] -use rustc_back::target::Target; use serialize::json::ToJson; @@ -100,8 +89,6 @@ use std::io::{self, Read, Write}; use std::iter::repeat; use std::path::PathBuf; -#[cfg(not(feature="llvm"))] -use std::path::Path; use std::process::{self, Command, Stdio}; use std::rc::Rc; use std::str; @@ -114,15 +101,11 @@ use syntax::parse::{self, PResult}; use syntax_pos::{DUMMY_SP, MultiSpan}; -#[cfg(not(feature="llvm"))] -use owning_ref::{OwningRef, ErasedBoxRef}; - #[cfg(test)] pub mod test; pub mod driver; pub mod pretty; -#[cfg(feature="llvm")] pub mod target_features; mod derive_registrar; @@ -169,48 +152,106 @@ pub fn run(run_compiler: F) -> isize } #[cfg(not(feature="llvm"))] -pub struct NoLLvmMetadataLoader; - -#[cfg(not(feature="llvm"))] -pub use NoLLvmMetadataLoader as MetadataLoader; +pub use no_llvm_metadata_loader::NoLLvmMetadataLoader as MetadataLoader; #[cfg(feature="llvm")] pub use rustc_trans::LlvmMetadataLoader as MetadataLoader; #[cfg(not(feature="llvm"))] -impl MetadataLoaderTrait for NoLLvmMetadataLoader { - fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result, String> { - use std::fs::File; - use std::io; - use self::ar::Archive; - - let file = File::open(filename).map_err(|e|format!("metadata file open err: {:?}", e))?; - let mut archive = Archive::new(file); - - while let Some(entry_result) = archive.next_entry() { - let mut entry = entry_result.map_err(|e|format!("metadata section read err: {:?}", e))?; - if entry.header().identifier() == "rust.metadata.bin" { - let mut buf = Vec::new(); - io::copy(&mut entry, &mut buf).unwrap(); - let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); - return Ok(buf.map_owner_box().erase_owner()); +mod no_llvm_metadata_loader { + extern crate ar; + extern crate owning_ref; + + use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait; + use rustc_back::target::Target; + use std::io; + use std::fs::File; + use std::path::Path; + + use self::ar::Archive; + use self::owning_ref::{OwningRef, ErasedBoxRef}; + + pub struct NoLLvmMetadataLoader; + + impl MetadataLoaderTrait for NoLLvmMetadataLoader { + fn get_rlib_metadata( + &self, + _: &Target, + filename: &Path + ) -> Result, String> { + let file = File::open(filename).map_err(|e| { + format!("metadata file open err: {:?}", e) + })?; + let mut archive = Archive::new(file); + + while let Some(entry_result) = archive.next_entry() { + let mut entry = entry_result.map_err(|e| { + format!("metadata section read err: {:?}", e) + })?; + if entry.header().identifier() == "rust.metadata.bin" { + let mut buf = Vec::new(); + io::copy(&mut entry, &mut buf).unwrap(); + let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); + return Ok(buf.map_owner_box().erase_owner()); + } } + + Err("Couldnt find metadata section".to_string()) } - Err("Couldnt find metadata section".to_string()) + fn get_dylib_metadata(&self, + _target: &Target, + _filename: &Path) + -> Result, String> { + panic!("Dylib metadata loading not supported without LLVM") + } } +} - fn get_dylib_metadata(&self, - _target: &Target, - _filename: &Path) - -> Result, String> { - panic!("Dylib metadata loading not supported without LLVM") +#[cfg(not(feature="llvm"))] +mod rustc_trans { + use syntax_pos::symbol::Symbol; + use rustc::session::Session; + use rustc::session::config::{PrintRequest, OutputFilenames}; + use rustc::ty::{TyCtxt, CrateAnalysis}; + use rustc::ty::maps::Providers; + use rustc_incremental::IncrementalHashesMap; + + use self::back::write::OngoingCrateTranslation; + + pub fn init(_sess: &Session) {} + pub fn enable_llvm_debug() {} + pub fn provide(_providers: &mut Providers) {} + pub fn print_version() {} + pub fn print_passes() {} + pub fn print(_req: PrintRequest, _sess: &Session) {} + pub fn target_features(_sess: &Session) -> Vec { vec![] } + + pub fn trans_crate<'a, 'tcx>( + _tcx: TyCtxt<'a, 'tcx, 'tcx>, + _analysis: CrateAnalysis, + _incr_hashes_map: IncrementalHashesMap, + _output_filenames: &OutputFilenames + ) -> OngoingCrateTranslation { + OngoingCrateTranslation(()) } + + pub struct CrateTranslation(()); + + pub mod back { + pub mod write { + pub struct OngoingCrateTranslation(pub (in ::rustc_trans) ()); + + pub const RELOC_MODEL_ARGS: [(&'static str, ()); 0] = []; + pub const CODE_GEN_MODEL_ARGS: [(&'static str, ()); 0] = []; + } + } + + __build_diagnostic_array! { librustc_trans, DIAGNOSTICS } } // Parse args and run the compiler. This is the primary entry point for rustc. // See comments on CompilerCalls below for details about the callbacks argument. // The FileLoader provides a way to load files from sources other than the file system. -#[cfg_attr(not(feature="llvm"), allow(unused_mut))] pub fn run_compiler<'a>(args: &[String], callbacks: &mut CompilerCalls<'a>, file_loader: Option>, @@ -232,7 +273,6 @@ macro_rules! do_or_return {($expr: expr, $sess: expr) => { let (sopts, cfg) = config::build_session_options_and_crate_config(&matches); if sopts.debugging_opts.debug_llvm { - #[cfg(feature="llvm")] rustc_trans::enable_llvm_debug(); } @@ -262,12 +302,10 @@ macro_rules! do_or_return {($expr: expr, $sess: expr) => { let mut sess = session::build_session_with_codemap( sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest, ); - #[cfg(feature="llvm")] rustc_trans::init(&sess); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let mut cfg = config::build_configuration(&sess, cfg); - #[cfg(feature="llvm")] target_features::add_configuration(&mut cfg, &sess); sess.parse_sess.config = cfg; @@ -520,7 +558,6 @@ fn early_callback(&mut self, Compilation::Continue } - #[cfg_attr(not(feature="llvm"), allow(unused_mut))] fn no_input(&mut self, matches: &getopts::Matches, sopts: &config::Options, @@ -544,11 +581,9 @@ fn no_input(&mut self, None, descriptions.clone(), cstore.clone()); - #[cfg(feature="llvm")] rustc_trans::init(&sess); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let mut cfg = config::build_configuration(&sess, cfg.clone()); - #[cfg(feature="llvm")] target_features::add_configuration(&mut cfg, &sess); sess.parse_sess.config = cfg; let should_stop = @@ -767,7 +802,7 @@ fn print_crate_info(sess: &Session, let mut cfgs = Vec::new(); for &(name, ref value) in sess.parse_sess.config.iter() { let gated_cfg = GatedCfg::gate(&ast::MetaItem { - name: name, + name, node: ast::MetaItemKind::Word, span: DUMMY_SP, }); @@ -802,25 +837,20 @@ fn print_crate_info(sess: &Session, } PrintRequest::RelocationModels => { println!("Available relocation models:"); - #[cfg(feature="llvm")] - for &(name, _) in RELOC_MODEL_ARGS.iter() { + for &(name, _) in rustc_trans::back::write::RELOC_MODEL_ARGS.iter() { println!(" {}", name); } println!(""); } PrintRequest::CodeModels => { println!("Available code models:"); - #[cfg(feature="llvm")] - for &(name, _) in CODE_GEN_MODEL_ARGS.iter(){ + for &(name, _) in rustc_trans::back::write::CODE_GEN_MODEL_ARGS.iter(){ println!(" {}", name); } println!(""); } PrintRequest::TargetCPUs | PrintRequest::TargetFeatures => { - #[cfg(feature="llvm")] rustc_trans::print(*req, sess); - #[cfg(not(feature="llvm"))] - panic!("LLVM not supported by this rustc") } } } @@ -859,7 +889,6 @@ fn unw(x: Option<&str>) -> &str { println!("commit-date: {}", unw(commit_date_str())); println!("host: {}", config::host_triple()); println!("release: {}", unw(release_str())); - #[cfg(feature="llvm")] rustc_trans::print_version(); } } @@ -1157,7 +1186,6 @@ pub fn handle_options(args: &[String]) -> Option { } if cg_flags.contains(&"passes=list".to_string()) { - #[cfg(feature="llvm")] rustc_trans::print_passes(); return None; } @@ -1285,7 +1313,6 @@ pub fn diagnostics_registry() -> errors::registry::Registry { all_errors.extend_from_slice(&rustc_borrowck::DIAGNOSTICS); all_errors.extend_from_slice(&rustc_resolve::DIAGNOSTICS); all_errors.extend_from_slice(&rustc_privacy::DIAGNOSTICS); - #[cfg(feature="llvm")] all_errors.extend_from_slice(&rustc_trans::DIAGNOSTICS); all_errors.extend_from_slice(&rustc_const_eval::DIAGNOSTICS); all_errors.extend_from_slice(&rustc_metadata::DIAGNOSTICS);