It now completely compiles without LLVM!!!
This commit is contained in:
parent
b7314c7caf
commit
b8d5c74c99
|
@ -1343,6 +1343,7 @@ dependencies = [
|
|||
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"graphviz 0.0.0",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc 0.0.0",
|
||||
"rustc_allocator 0.0.0",
|
||||
"rustc_back 0.0.0",
|
||||
|
|
|
@ -12,6 +12,7 @@ crate-type = ["dylib"]
|
|||
arena = { path = "../libarena" }
|
||||
graphviz = { path = "../libgraphviz" }
|
||||
log = { version = "0.3", features = ["release_max_level_info"] }
|
||||
owning_ref = "0.3.3"
|
||||
env_logger = { version = "0.4", default-features = false }
|
||||
rustc = { path = "../librustc" }
|
||||
rustc_allocator = { path = "../librustc_allocator" }
|
||||
|
|
|
@ -18,7 +18,9 @@ use rustc::session::CompileIncomplete;
|
|||
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
|
||||
use rustc::session::search_paths::PathKind;
|
||||
use rustc::lint;
|
||||
use rustc::middle::{self, dependency_format, stability, reachable};
|
||||
use rustc::middle::{self, stability, reachable};
|
||||
#[cfg(feature="llvm")]
|
||||
use rustc::middle::dependency_format;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
|
||||
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
|
||||
|
@ -71,6 +73,11 @@ pub fn compile_input(sess: &Session,
|
|||
output: &Option<PathBuf>,
|
||||
addl_plugins: Option<Vec<String>>,
|
||||
control: &CompileController) -> CompileResult {
|
||||
#[cfg(feature="llvm")]
|
||||
use rustc_trans::back::write::OngoingCrateTranslation;
|
||||
#[cfg(not(feature="llvm"))]
|
||||
type OngoingCrateTranslation = ();
|
||||
|
||||
macro_rules! controller_entry_point {
|
||||
($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
|
||||
let state = &mut $make_state;
|
||||
|
@ -90,7 +97,7 @@ pub fn compile_input(sess: &Session,
|
|||
// We need nested scopes here, because the intermediate results can keep
|
||||
// large chunks of memory alive and we want to free them as soon as
|
||||
// possible to keep the peak memory usage low
|
||||
let (outputs, trans) = {
|
||||
let (outputs, trans): (OutputFilenames, OngoingCrateTranslation) = {
|
||||
let krate = match phase_1_parse_input(control, sess, input) {
|
||||
Ok(krate) => krate,
|
||||
Err(mut parse_error) => {
|
||||
|
@ -213,8 +220,6 @@ pub fn compile_input(sess: &Session,
|
|||
#[cfg(feature="llvm")]
|
||||
let trans = phase_4_translate_to_llvm(tcx, analysis, incremental_hashes_map,
|
||||
&outputs);
|
||||
#[cfg(not(feature="llvm"))]
|
||||
let trans = { panic!("LLVM not supported by this rustc."); () };
|
||||
|
||||
if log_enabled!(::log::LogLevel::Info) {
|
||||
println!("Post-trans");
|
||||
|
@ -228,12 +233,25 @@ pub fn compile_input(sess: &Session,
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature="llvm"))]
|
||||
{
|
||||
let _ = incremental_hashes_map;
|
||||
sess.err(&format!("LLVM is not supported by this rustc"));
|
||||
sess.abort_if_errors();
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
#[cfg(feature="llvm")]
|
||||
Ok((outputs, trans))
|
||||
})??
|
||||
};
|
||||
|
||||
#[cfg(not(feature="llvm"))]
|
||||
unreachable!();
|
||||
{
|
||||
let _ = outputs;
|
||||
let _ = trans;
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
#[cfg(feature="llvm")]
|
||||
{
|
||||
|
@ -505,6 +523,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="llvm")]
|
||||
fn state_when_compilation_done(input: &'a Input,
|
||||
session: &'tcx Session,
|
||||
out_dir: &'a Option<PathBuf>,
|
||||
|
@ -1145,7 +1164,12 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, crate_name: &str) {
|
|||
match *output_type {
|
||||
OutputType::Exe => {
|
||||
for output in sess.crate_types.borrow().iter() {
|
||||
let p = ::rustc_trans_utils::link::filename_for_input(sess, *output, crate_name, outputs);
|
||||
let p = ::rustc_trans_utils::link::filename_for_input(
|
||||
sess,
|
||||
*output,
|
||||
crate_name,
|
||||
outputs
|
||||
);
|
||||
out_filenames.push(p);
|
||||
}
|
||||
}
|
||||
|
@ -1263,7 +1287,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
|
|||
|
||||
base.into_iter()
|
||||
.filter(|crate_type| {
|
||||
let res = !rustc_trans_utils::link::invalid_output_for_target(session, *crate_type);
|
||||
let res = !::rustc_trans_utils::link::invalid_output_for_target(session, *crate_type);
|
||||
|
||||
if !res {
|
||||
session.warn(&format!("dropping unsupported crate type `{}` for target `{}`",
|
||||
|
|
|
@ -35,6 +35,8 @@ 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;
|
||||
|
@ -70,8 +72,6 @@ use rustc_resolve as resolve;
|
|||
use rustc_save_analysis as save;
|
||||
use rustc_save_analysis::DumpHandler;
|
||||
#[cfg(feature="llvm")]
|
||||
use rustc_trans::back::link;
|
||||
#[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};
|
||||
|
@ -82,7 +82,7 @@ use rustc::session::{early_error, early_warn};
|
|||
use rustc::lint::Lint;
|
||||
use rustc::lint;
|
||||
#[cfg(not(feature="llvm"))]
|
||||
use rustc::middle::cstore::MetadataLoader;
|
||||
use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait;
|
||||
use rustc_metadata::locator;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
use rustc::util::common::{time, ErrorReported};
|
||||
|
@ -114,6 +114,9 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
|
|||
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;
|
||||
|
||||
|
@ -174,7 +177,7 @@ pub use NoLLvmMetadataLoader as MetadataLoader;
|
|||
pub use rustc_trans::LlvmMetadataLoader as MetadataLoader;
|
||||
|
||||
#[cfg(not(feature="llvm"))]
|
||||
impl MetadataLoader for NoLLvmMetadataLoader {
|
||||
impl MetadataLoaderTrait for NoLLvmMetadataLoader {
|
||||
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<ErasedBoxRef<[u8]>, String> {
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
|
@ -185,11 +188,11 @@ impl MetadataLoader for NoLLvmMetadataLoader {
|
|||
|
||||
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() == METADATA_FILENAME {
|
||||
if entry.header().identifier() == "rust.metadata.bin" {
|
||||
let mut buf = Vec::new();
|
||||
io::copy(&mut entry, &mut buf).unwrap();
|
||||
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
|
||||
return Ok(buf.erase_owner());
|
||||
return Ok(buf.map_owner_box().erase_owner());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,8 +200,8 @@ impl MetadataLoader for NoLLvmMetadataLoader {
|
|||
}
|
||||
|
||||
fn get_dylib_metadata(&self,
|
||||
target: &Target,
|
||||
filename: &Path)
|
||||
_target: &Target,
|
||||
_filename: &Path)
|
||||
-> Result<ErasedBoxRef<[u8]>, String> {
|
||||
panic!("Dylib metadata loading not supported without LLVM")
|
||||
}
|
||||
|
@ -207,6 +210,7 @@ impl MetadataLoader for NoLLvmMetadataLoader {
|
|||
// 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<Box<FileLoader + 'static>>,
|
||||
|
@ -516,6 +520,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
Compilation::Continue
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature="llvm"), allow(unused_mut))]
|
||||
fn no_input(&mut self,
|
||||
matches: &getopts::Matches,
|
||||
sopts: &config::Options,
|
||||
|
@ -743,7 +748,12 @@ impl RustcDefaultCalls {
|
|||
}
|
||||
let crate_types = driver::collect_crate_types(sess, attrs);
|
||||
for &style in &crate_types {
|
||||
let fname = rustc_trans_utils::link::filename_for_input(sess, style, &id, &t_outputs);
|
||||
let fname = rustc_trans_utils::link::filename_for_input(
|
||||
sess,
|
||||
style,
|
||||
&id,
|
||||
&t_outputs
|
||||
);
|
||||
println!("{}",
|
||||
fname.file_name()
|
||||
.unwrap()
|
||||
|
@ -792,7 +802,7 @@ impl RustcDefaultCalls {
|
|||
}
|
||||
PrintRequest::RelocationModels => {
|
||||
println!("Available relocation models:");
|
||||
#[cfg(features="llvm")]
|
||||
#[cfg(feature="llvm")]
|
||||
for &(name, _) in RELOC_MODEL_ARGS.iter() {
|
||||
println!(" {}", name);
|
||||
}
|
||||
|
@ -800,7 +810,7 @@ impl RustcDefaultCalls {
|
|||
}
|
||||
PrintRequest::CodeModels => {
|
||||
println!("Available code models:");
|
||||
#[cfg(features="llvm")]
|
||||
#[cfg(feature="llvm")]
|
||||
for &(name, _) in CODE_GEN_MODEL_ARGS.iter(){
|
||||
println!(" {}", name);
|
||||
}
|
||||
|
|
|
@ -88,7 +88,8 @@ pub const RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET: usize =
|
|||
pub const RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET: usize =
|
||||
RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET + 8;
|
||||
|
||||
pub use self::rustc_trans_utils::link::{find_crate_name, filename_for_input, default_output_for_target, invalid_output_for_target};
|
||||
pub use self::rustc_trans_utils::link::{find_crate_name, filename_for_input,
|
||||
default_output_for_target, invalid_output_for_target};
|
||||
|
||||
pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMeta {
|
||||
let krate_dep_node = &DepNode::new_no_params(DepKind::Krate);
|
||||
|
|
Loading…
Reference in New Issue