1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! The Rust compiler.
15 //! This API is completely unstable and subject to change.
17 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
18 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
19 html_root_url = "https://doc.rust-lang.org/nightly/")]
22 #![feature(box_patterns)]
23 #![feature(box_syntax)]
25 #![feature(custom_attribute)]
26 #![allow(unused_attributes)]
27 #![feature(i128_type)]
30 #![feature(rustc_diagnostic_macros)]
31 #![feature(slice_patterns)]
32 #![feature(conservative_impl_trait)]
34 use rustc::dep_graph::WorkProduct;
35 use syntax_pos::symbol::Symbol;
39 extern crate owning_ref;
40 #[macro_use] extern crate rustc;
41 extern crate rustc_allocator;
42 extern crate rustc_back;
43 extern crate rustc_data_structures;
44 extern crate rustc_incremental;
45 extern crate rustc_llvm as llvm;
46 extern crate rustc_platform_intrinsics as intrinsics;
47 extern crate rustc_const_math;
50 extern crate rustc_bitflags;
51 extern crate rustc_demangle;
52 extern crate jobserver;
53 extern crate num_cpus;
55 #[macro_use] extern crate log;
56 #[macro_use] extern crate syntax;
57 extern crate syntax_pos;
58 extern crate rustc_errors as errors;
59 extern crate serialize;
61 extern crate gcc; // Used to locate MSVC, not gcc :)
63 pub use base::trans_crate;
64 pub use back::symbol_names::provide;
66 pub use metadata::LlvmMetadataLoader;
67 pub use llvm_util::{init, target_features, print_version, print_passes, print, enable_llvm_debug};
71 use rustc::hir::def_id::CrateNum;
72 use rustc::util::nodemap::{FxHashSet, FxHashMap};
73 use rustc::middle::cstore::NativeLibrary;
77 pub(crate) mod linker;
80 pub(crate) mod symbol_export;
81 pub(crate) mod symbol_names;
92 mod assert_module_sources;
129 mod symbol_names_test;
137 pub struct ModuleTranslation {
138 /// The name of the module. When the crate may be saved between
139 /// compilations, incremental compilation requires that name be
140 /// unique amongst **all** crates. Therefore, it should contain
141 /// something unique to this crate (e.g., a module path) as well
142 /// as the crate name and disambiguator.
144 symbol_name_hash: u64,
145 pub source: ModuleSource,
146 pub kind: ModuleKind,
149 #[derive(Copy, Clone, Debug)]
150 pub enum ModuleKind {
156 impl ModuleTranslation {
157 pub fn into_compiled_module(self, emit_obj: bool, emit_bc: bool) -> CompiledModule {
158 let pre_existing = match self.source {
159 ModuleSource::Preexisting(_) => true,
160 ModuleSource::Translated(_) => false,
164 name: self.name.clone(),
166 symbol_name_hash: self.symbol_name_hash,
174 impl Drop for ModuleTranslation {
177 ModuleSource::Preexisting(_) => {
178 // Nothing to dispose.
180 ModuleSource::Translated(llvm) => {
182 llvm::LLVMDisposeModule(llvm.llmod);
183 llvm::LLVMContextDispose(llvm.llcx);
191 pub struct CompiledModule {
193 pub kind: ModuleKind,
194 pub symbol_name_hash: u64,
195 pub pre_existing: bool,
201 pub enum ModuleSource {
202 /// Copy the `.o` files or whatever from the incr. comp. directory.
203 Preexisting(WorkProduct),
205 /// Rebuild from this LLVM module.
206 Translated(ModuleLlvm),
209 #[derive(Copy, Clone, Debug)]
210 pub struct ModuleLlvm {
211 llcx: llvm::ContextRef,
212 pub llmod: llvm::ModuleRef,
215 unsafe impl Send for ModuleTranslation { }
216 unsafe impl Sync for ModuleTranslation { }
218 pub struct CrateTranslation {
219 pub crate_name: Symbol,
220 pub modules: Vec<CompiledModule>,
221 allocator_module: Option<CompiledModule>,
222 pub link: rustc::middle::cstore::LinkMeta,
223 pub metadata: rustc::middle::cstore::EncodedMetadata,
224 windows_subsystem: Option<String>,
225 linker_info: back::linker::LinkerInfo,
226 crate_info: CrateInfo,
229 // Misc info we load from metadata to persist beyond the tcx
230 pub struct CrateInfo {
231 panic_runtime: Option<CrateNum>,
232 compiler_builtins: Option<CrateNum>,
233 profiler_runtime: Option<CrateNum>,
234 sanitizer_runtime: Option<CrateNum>,
235 is_no_builtins: FxHashSet<CrateNum>,
236 native_libraries: FxHashMap<CrateNum, Rc<Vec<NativeLibrary>>>,
237 used_libraries: Rc<Vec<NativeLibrary>>,
238 link_args: Rc<Vec<String>>,
241 __build_diagnostic_array! { librustc_trans, DIAGNOSTICS }