2014-11-16 01:30:33 +00:00
|
|
|
// Copyright 2012-2013 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.
|
|
|
|
|
2014-11-26 02:17:11 +00:00
|
|
|
//! The Rust compiler.
|
|
|
|
//!
|
|
|
|
//! # Note
|
|
|
|
//!
|
|
|
|
//! This API is completely unstable and subject to change.
|
2014-11-16 01:30:33 +00:00
|
|
|
|
2015-08-09 21:15:05 +00:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2015-05-15 23:04:01 +00:00
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
2015-08-09 21:15:05 +00:00
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
2016-12-29 17:47:34 +00:00
|
|
|
#![deny(warnings)]
|
2014-11-16 01:30:33 +00:00
|
|
|
|
2015-02-10 21:52:44 +00:00
|
|
|
#![feature(box_patterns)]
|
2015-01-30 20:26:44 +00:00
|
|
|
#![feature(box_syntax)]
|
2015-09-27 20:20:49 +00:00
|
|
|
#![feature(custom_attribute)]
|
|
|
|
#![allow(unused_attributes)]
|
2017-02-01 23:57:50 +00:00
|
|
|
#![feature(i128_type)]
|
2015-01-23 02:22:03 +00:00
|
|
|
#![feature(libc)]
|
2015-01-30 20:26:44 +00:00
|
|
|
#![feature(quote)]
|
|
|
|
#![feature(rustc_diagnostic_macros)]
|
2015-10-21 21:20:00 +00:00
|
|
|
#![feature(slice_patterns)]
|
2016-12-17 15:24:17 +00:00
|
|
|
#![feature(conservative_impl_trait)]
|
2014-11-16 01:30:33 +00:00
|
|
|
|
2017-09-08 18:26:54 +00:00
|
|
|
#![cfg_attr(stage0, feature(const_fn))]
|
|
|
|
#![cfg_attr(not(stage0), feature(const_atomic_bool_new))]
|
|
|
|
#![cfg_attr(not(stage0), feature(const_once_new))]
|
|
|
|
|
2016-07-25 14:51:14 +00:00
|
|
|
use rustc::dep_graph::WorkProduct;
|
2017-04-13 18:58:20 +00:00
|
|
|
use syntax_pos::symbol::Symbol;
|
2016-07-21 16:49:59 +00:00
|
|
|
|
2017-09-08 19:08:01 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bitflags;
|
2017-06-08 21:10:36 +00:00
|
|
|
extern crate flate2;
|
2014-11-16 01:30:33 +00:00
|
|
|
extern crate libc;
|
2017-04-26 21:22:45 +00:00
|
|
|
extern crate owning_ref;
|
2016-03-28 23:46:02 +00:00
|
|
|
#[macro_use] extern crate rustc;
|
2017-06-03 21:54:08 +00:00
|
|
|
extern crate rustc_allocator;
|
2014-11-16 01:30:33 +00:00
|
|
|
extern crate rustc_back;
|
2015-11-02 14:39:59 +00:00
|
|
|
extern crate rustc_data_structures;
|
2016-03-28 21:36:56 +00:00
|
|
|
extern crate rustc_incremental;
|
2017-08-19 00:09:55 +00:00
|
|
|
extern crate rustc_llvm as llvm;
|
2015-07-16 23:46:36 +00:00
|
|
|
extern crate rustc_platform_intrinsics as intrinsics;
|
2016-03-15 11:33:13 +00:00
|
|
|
extern crate rustc_const_math;
|
2017-09-16 15:27:29 +00:00
|
|
|
extern crate rustc_trans_traits;
|
2017-08-26 15:31:32 +00:00
|
|
|
extern crate rustc_trans_utils;
|
2017-06-29 14:52:43 +00:00
|
|
|
extern crate rustc_demangle;
|
2017-06-15 14:08:18 +00:00
|
|
|
extern crate jobserver;
|
2017-07-28 12:28:08 +00:00
|
|
|
extern crate num_cpus;
|
2014-11-16 01:30:33 +00:00
|
|
|
|
2015-01-06 17:24:46 +00:00
|
|
|
#[macro_use] extern crate log;
|
|
|
|
#[macro_use] extern crate syntax;
|
2016-06-21 22:08:13 +00:00
|
|
|
extern crate syntax_pos;
|
|
|
|
extern crate rustc_errors as errors;
|
2017-02-03 14:58:13 +00:00
|
|
|
extern crate serialize;
|
2017-05-24 02:02:23 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
extern crate gcc; // Used to locate MSVC, not gcc :)
|
2015-01-01 04:43:46 +00:00
|
|
|
|
2016-03-22 17:23:36 +00:00
|
|
|
pub use base::trans_crate;
|
|
|
|
|
2017-04-26 21:22:45 +00:00
|
|
|
pub use metadata::LlvmMetadataLoader;
|
2017-04-30 18:33:25 +00:00
|
|
|
pub use llvm_util::{init, target_features, print_version, print_passes, print, enable_llvm_debug};
|
2017-04-26 21:22:45 +00:00
|
|
|
|
2017-08-29 00:06:03 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2017-09-13 20:22:20 +00:00
|
|
|
use rustc::hir::def_id::CrateNum;
|
2017-08-31 19:08:29 +00:00
|
|
|
use rustc::middle::cstore::{NativeLibrary, CrateSource, LibSource};
|
2017-09-12 16:32:37 +00:00
|
|
|
use rustc::ty::maps::Providers;
|
|
|
|
use rustc::util::nodemap::{FxHashSet, FxHashMap};
|
2017-04-26 21:22:45 +00:00
|
|
|
|
2017-09-12 19:18:11 +00:00
|
|
|
mod diagnostics;
|
|
|
|
|
2014-11-16 01:30:33 +00:00
|
|
|
pub mod back {
|
2017-05-27 18:13:32 +00:00
|
|
|
mod archive;
|
2017-08-26 03:16:51 +00:00
|
|
|
mod command;
|
2017-05-27 18:13:32 +00:00
|
|
|
pub(crate) mod linker;
|
2014-11-16 01:30:33 +00:00
|
|
|
pub mod link;
|
2017-05-27 18:13:32 +00:00
|
|
|
mod lto;
|
|
|
|
pub(crate) mod symbol_export;
|
|
|
|
pub(crate) mod symbol_names;
|
2014-11-16 01:30:33 +00:00
|
|
|
pub mod write;
|
2017-08-19 00:09:55 +00:00
|
|
|
mod rpath;
|
2014-11-16 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:23:36 +00:00
|
|
|
mod abi;
|
|
|
|
mod adt;
|
2017-06-03 21:54:08 +00:00
|
|
|
mod allocator;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod asm;
|
2016-07-21 16:50:15 +00:00
|
|
|
mod assert_module_sources;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod attributes;
|
|
|
|
mod base;
|
|
|
|
mod builder;
|
|
|
|
mod cabi_aarch64;
|
|
|
|
mod cabi_arm;
|
|
|
|
mod cabi_asmjs;
|
2017-04-09 06:03:31 +00:00
|
|
|
mod cabi_hexagon;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod cabi_mips;
|
2016-08-26 22:06:13 +00:00
|
|
|
mod cabi_mips64;
|
2016-11-13 16:03:44 +00:00
|
|
|
mod cabi_msp430;
|
2016-12-22 21:24:29 +00:00
|
|
|
mod cabi_nvptx;
|
|
|
|
mod cabi_nvptx64;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod cabi_powerpc;
|
|
|
|
mod cabi_powerpc64;
|
2016-09-09 21:00:23 +00:00
|
|
|
mod cabi_s390x;
|
2016-12-12 17:41:45 +00:00
|
|
|
mod cabi_sparc;
|
2016-12-03 16:55:50 +00:00
|
|
|
mod cabi_sparc64;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod cabi_x86;
|
|
|
|
mod cabi_x86_64;
|
|
|
|
mod cabi_x86_win64;
|
|
|
|
mod callee;
|
2016-03-24 15:40:49 +00:00
|
|
|
mod collector;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod common;
|
|
|
|
mod consts;
|
|
|
|
mod context;
|
|
|
|
mod debuginfo;
|
|
|
|
mod declare;
|
|
|
|
mod glue;
|
|
|
|
mod intrinsic;
|
2017-04-30 18:33:25 +00:00
|
|
|
mod llvm_util;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod machine;
|
2017-04-26 21:22:45 +00:00
|
|
|
mod metadata;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod meth;
|
|
|
|
mod mir;
|
|
|
|
mod monomorphize;
|
2016-03-24 15:40:49 +00:00
|
|
|
mod partitioning;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod symbol_names_test;
|
2017-07-27 11:02:31 +00:00
|
|
|
mod time_graph;
|
2016-05-09 17:37:14 +00:00
|
|
|
mod trans_item;
|
2016-03-22 17:23:36 +00:00
|
|
|
mod tvec;
|
|
|
|
mod type_;
|
|
|
|
mod type_of;
|
|
|
|
mod value;
|
|
|
|
|
2017-09-16 15:27:29 +00:00
|
|
|
use rustc::ty::{self, TyCtxt, CrateAnalysis};
|
|
|
|
use rustc::session::Session;
|
|
|
|
use rustc::session::config::OutputFilenames;
|
|
|
|
use rustc::middle::cstore::MetadataLoader;
|
|
|
|
use rustc::dep_graph::DepGraph;
|
|
|
|
use rustc_incremental::IncrementalHashesMap;
|
|
|
|
|
|
|
|
pub struct LlvmTransCrate(());
|
|
|
|
|
|
|
|
impl LlvmTransCrate {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
LlvmTransCrate(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl rustc_trans_traits::TransCrate for LlvmTransCrate {
|
|
|
|
type MetadataLoader = metadata::LlvmMetadataLoader;
|
|
|
|
type OngoingCrateTranslation = back::write::OngoingCrateTranslation;
|
|
|
|
type TranslatedCrate = CrateTranslation;
|
|
|
|
|
|
|
|
fn metadata_loader() -> Box<MetadataLoader> {
|
|
|
|
box metadata::LlvmMetadataLoader
|
|
|
|
}
|
|
|
|
|
|
|
|
fn provide(providers: &mut ty::maps::Providers) {
|
|
|
|
back::symbol_names::provide(providers);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn trans_crate<'a, 'tcx>(
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
analysis: CrateAnalysis,
|
|
|
|
incr_hashes_map: IncrementalHashesMap,
|
|
|
|
output_filenames: &OutputFilenames
|
|
|
|
) -> Self::OngoingCrateTranslation {
|
|
|
|
base::trans_crate(tcx, analysis, incr_hashes_map, output_filenames)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn join_trans(
|
|
|
|
trans: Self::OngoingCrateTranslation,
|
|
|
|
sess: &Session,
|
|
|
|
dep_graph: &DepGraph
|
|
|
|
) -> Self::TranslatedCrate {
|
|
|
|
trans.join(sess, dep_graph)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn link_binary(sess: &Session, trans: &Self::TranslatedCrate, outputs: &OutputFilenames) {
|
|
|
|
back::link::link_binary(sess, trans, outputs, &trans.crate_name.as_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dump_incremental_data(trans: &Self::TranslatedCrate) {
|
|
|
|
back::write::dump_incremental_data(trans);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 17:23:36 +00:00
|
|
|
pub struct ModuleTranslation {
|
2016-07-25 14:51:14 +00:00
|
|
|
/// The name of the module. When the crate may be saved between
|
|
|
|
/// compilations, incremental compilation requires that name be
|
|
|
|
/// unique amongst **all** crates. Therefore, it should contain
|
|
|
|
/// something unique to this crate (e.g., a module path) as well
|
|
|
|
/// as the crate name and disambiguator.
|
2017-08-19 00:09:55 +00:00
|
|
|
name: String,
|
|
|
|
symbol_name_hash: u64,
|
2016-07-21 16:49:59 +00:00
|
|
|
pub source: ModuleSource,
|
2017-07-25 15:26:24 +00:00
|
|
|
pub kind: ModuleKind,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub enum ModuleKind {
|
|
|
|
Regular,
|
|
|
|
Metadata,
|
|
|
|
Allocator,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ModuleTranslation {
|
|
|
|
pub fn into_compiled_module(self, emit_obj: bool, emit_bc: bool) -> CompiledModule {
|
|
|
|
let pre_existing = match self.source {
|
|
|
|
ModuleSource::Preexisting(_) => true,
|
|
|
|
ModuleSource::Translated(_) => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
CompiledModule {
|
|
|
|
name: self.name.clone(),
|
|
|
|
kind: self.kind,
|
|
|
|
symbol_name_hash: self.symbol_name_hash,
|
|
|
|
pre_existing,
|
|
|
|
emit_obj,
|
|
|
|
emit_bc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for ModuleTranslation {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
match self.source {
|
|
|
|
ModuleSource::Preexisting(_) => {
|
|
|
|
// Nothing to dispose.
|
|
|
|
},
|
|
|
|
ModuleSource::Translated(llvm) => {
|
|
|
|
unsafe {
|
|
|
|
llvm::LLVMDisposeModule(llvm.llmod);
|
|
|
|
llvm::LLVMContextDispose(llvm.llcx);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct CompiledModule {
|
|
|
|
pub name: String,
|
|
|
|
pub kind: ModuleKind,
|
|
|
|
pub symbol_name_hash: u64,
|
|
|
|
pub pre_existing: bool,
|
|
|
|
pub emit_obj: bool,
|
|
|
|
pub emit_bc: bool,
|
2016-07-21 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum ModuleSource {
|
2016-07-25 14:51:14 +00:00
|
|
|
/// Copy the `.o` files or whatever from the incr. comp. directory.
|
|
|
|
Preexisting(WorkProduct),
|
|
|
|
|
|
|
|
/// Rebuild from this LLVM module.
|
2016-07-21 16:49:59 +00:00
|
|
|
Translated(ModuleLlvm),
|
|
|
|
}
|
|
|
|
|
2017-07-25 15:26:24 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2016-07-21 16:49:59 +00:00
|
|
|
pub struct ModuleLlvm {
|
2017-08-19 00:09:55 +00:00
|
|
|
llcx: llvm::ContextRef,
|
2016-03-22 17:23:36 +00:00
|
|
|
pub llmod: llvm::ModuleRef,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Send for ModuleTranslation { }
|
|
|
|
unsafe impl Sync for ModuleTranslation { }
|
2014-11-16 01:30:33 +00:00
|
|
|
|
2016-03-22 17:23:36 +00:00
|
|
|
pub struct CrateTranslation {
|
2017-04-13 18:58:20 +00:00
|
|
|
pub crate_name: Symbol,
|
2017-07-25 15:26:24 +00:00
|
|
|
pub modules: Vec<CompiledModule>,
|
2017-08-19 00:09:55 +00:00
|
|
|
allocator_module: Option<CompiledModule>,
|
2017-05-27 18:48:09 +00:00
|
|
|
pub link: rustc::middle::cstore::LinkMeta,
|
|
|
|
pub metadata: rustc::middle::cstore::EncodedMetadata,
|
2017-08-19 00:09:55 +00:00
|
|
|
windows_subsystem: Option<String>,
|
2017-08-28 22:55:32 +00:00
|
|
|
linker_info: back::linker::LinkerInfo,
|
|
|
|
crate_info: CrateInfo,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Misc info we load from metadata to persist beyond the tcx
|
|
|
|
pub struct CrateInfo {
|
|
|
|
panic_runtime: Option<CrateNum>,
|
|
|
|
compiler_builtins: Option<CrateNum>,
|
|
|
|
profiler_runtime: Option<CrateNum>,
|
|
|
|
sanitizer_runtime: Option<CrateNum>,
|
|
|
|
is_no_builtins: FxHashSet<CrateNum>,
|
2017-08-29 00:06:03 +00:00
|
|
|
native_libraries: FxHashMap<CrateNum, Rc<Vec<NativeLibrary>>>,
|
2017-08-31 15:07:39 +00:00
|
|
|
crate_name: FxHashMap<CrateNum, String>,
|
2017-08-30 21:48:57 +00:00
|
|
|
used_libraries: Rc<Vec<NativeLibrary>>,
|
|
|
|
link_args: Rc<Vec<String>>,
|
2017-08-31 19:08:29 +00:00
|
|
|
used_crate_source: FxHashMap<CrateNum, Rc<CrateSource>>,
|
|
|
|
used_crates_static: Vec<(CrateNum, LibSource)>,
|
|
|
|
used_crates_dynamic: Vec<(CrateNum, LibSource)>,
|
2014-11-16 01:30:33 +00:00
|
|
|
}
|
2015-11-22 04:52:25 +00:00
|
|
|
|
|
|
|
__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }
|
2017-09-12 16:32:37 +00:00
|
|
|
|
|
|
|
pub fn provide_local(providers: &mut Providers) {
|
|
|
|
back::symbol_names::provide(providers);
|
2017-09-13 20:22:20 +00:00
|
|
|
back::symbol_export::provide_local(providers);
|
2017-09-13 22:24:13 +00:00
|
|
|
base::provide_local(providers);
|
2017-09-12 16:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn provide_extern(providers: &mut Providers) {
|
|
|
|
back::symbol_names::provide(providers);
|
2017-09-13 20:22:20 +00:00
|
|
|
back::symbol_export::provide_extern(providers);
|
2017-09-13 22:24:13 +00:00
|
|
|
base::provide_extern(providers);
|
2017-09-12 16:32:37 +00:00
|
|
|
}
|