]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/lib.rs
Rollup merge of #43778 - topecongiro:handler-reset-err-count, r=arielb1
[rust.git] / src / librustc_trans / lib.rs
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.
4 //
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.
10
11 //! The Rust compiler.
12 //!
13 //! # Note
14 //!
15 //! This API is completely unstable and subject to change.
16
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/")]
20 #![deny(warnings)]
21
22 #![feature(box_patterns)]
23 #![feature(box_syntax)]
24 #![feature(const_fn)]
25 #![feature(custom_attribute)]
26 #![allow(unused_attributes)]
27 #![feature(i128_type)]
28 #![feature(libc)]
29 #![feature(quote)]
30 #![feature(rustc_diagnostic_macros)]
31 #![feature(slice_patterns)]
32 #![feature(conservative_impl_trait)]
33
34 use rustc::dep_graph::WorkProduct;
35 use syntax_pos::symbol::Symbol;
36
37 extern crate flate2;
38 extern crate libc;
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;
48 #[macro_use]
49 #[no_link]
50 extern crate rustc_bitflags;
51 extern crate rustc_demangle;
52 extern crate jobserver;
53 extern crate num_cpus;
54
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;
60 #[cfg(windows)]
61 extern crate gcc; // Used to locate MSVC, not gcc :)
62
63 pub use base::trans_crate;
64 pub use back::symbol_names::provide;
65
66 pub use metadata::LlvmMetadataLoader;
67 pub use llvm_util::{init, target_features, print_version, print_passes, print, enable_llvm_debug};
68
69 pub mod back {
70     mod archive;
71     pub(crate) mod linker;
72     pub mod link;
73     mod lto;
74     pub(crate) mod symbol_export;
75     pub(crate) mod symbol_names;
76     pub mod write;
77     mod rpath;
78 }
79
80 mod diagnostics;
81
82 mod abi;
83 mod adt;
84 mod allocator;
85 mod asm;
86 mod assert_module_sources;
87 mod attributes;
88 mod base;
89 mod builder;
90 mod cabi_aarch64;
91 mod cabi_arm;
92 mod cabi_asmjs;
93 mod cabi_hexagon;
94 mod cabi_mips;
95 mod cabi_mips64;
96 mod cabi_msp430;
97 mod cabi_nvptx;
98 mod cabi_nvptx64;
99 mod cabi_powerpc;
100 mod cabi_powerpc64;
101 mod cabi_s390x;
102 mod cabi_sparc;
103 mod cabi_sparc64;
104 mod cabi_x86;
105 mod cabi_x86_64;
106 mod cabi_x86_win64;
107 mod callee;
108 mod collector;
109 mod common;
110 mod consts;
111 mod context;
112 mod debuginfo;
113 mod declare;
114 mod glue;
115 mod intrinsic;
116 mod llvm_util;
117 mod machine;
118 mod metadata;
119 mod meth;
120 mod mir;
121 mod monomorphize;
122 mod partitioning;
123 mod symbol_names_test;
124 mod time_graph;
125 mod trans_item;
126 mod tvec;
127 mod type_;
128 mod type_of;
129 mod value;
130
131 pub struct ModuleTranslation {
132     /// The name of the module. When the crate may be saved between
133     /// compilations, incremental compilation requires that name be
134     /// unique amongst **all** crates.  Therefore, it should contain
135     /// something unique to this crate (e.g., a module path) as well
136     /// as the crate name and disambiguator.
137     name: String,
138     symbol_name_hash: u64,
139     pub source: ModuleSource,
140     pub kind: ModuleKind,
141 }
142
143 #[derive(Copy, Clone, Debug)]
144 pub enum ModuleKind {
145     Regular,
146     Metadata,
147     Allocator,
148 }
149
150 impl ModuleTranslation {
151     pub fn into_compiled_module(self, emit_obj: bool, emit_bc: bool) -> CompiledModule {
152         let pre_existing = match self.source {
153             ModuleSource::Preexisting(_) => true,
154             ModuleSource::Translated(_) => false,
155         };
156
157         CompiledModule {
158             name: self.name.clone(),
159             kind: self.kind,
160             symbol_name_hash: self.symbol_name_hash,
161             pre_existing,
162             emit_obj,
163             emit_bc,
164         }
165     }
166 }
167
168 impl Drop for ModuleTranslation {
169     fn drop(&mut self) {
170         match self.source {
171             ModuleSource::Preexisting(_) => {
172                 // Nothing to dispose.
173             },
174             ModuleSource::Translated(llvm) => {
175                 unsafe {
176                     llvm::LLVMDisposeModule(llvm.llmod);
177                     llvm::LLVMContextDispose(llvm.llcx);
178                 }
179             },
180         }
181     }
182 }
183
184 #[derive(Debug)]
185 pub struct CompiledModule {
186     pub name: String,
187     pub kind: ModuleKind,
188     pub symbol_name_hash: u64,
189     pub pre_existing: bool,
190     pub emit_obj: bool,
191     pub emit_bc: bool,
192 }
193
194 #[derive(Clone)]
195 pub enum ModuleSource {
196     /// Copy the `.o` files or whatever from the incr. comp. directory.
197     Preexisting(WorkProduct),
198
199     /// Rebuild from this LLVM module.
200     Translated(ModuleLlvm),
201 }
202
203 #[derive(Copy, Clone, Debug)]
204 pub struct ModuleLlvm {
205     llcx: llvm::ContextRef,
206     pub llmod: llvm::ModuleRef,
207 }
208
209 unsafe impl Send for ModuleTranslation { }
210 unsafe impl Sync for ModuleTranslation { }
211
212 pub struct CrateTranslation {
213     pub crate_name: Symbol,
214     pub modules: Vec<CompiledModule>,
215     allocator_module: Option<CompiledModule>,
216     pub link: rustc::middle::cstore::LinkMeta,
217     pub metadata: rustc::middle::cstore::EncodedMetadata,
218     windows_subsystem: Option<String>,
219     linker_info: back::linker::LinkerInfo
220 }
221
222 __build_diagnostic_array! { librustc_trans, DIAGNOSTICS }