]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/lib.rs
5c76f778f8d63610553bd35a36eadc57e2d684e8
[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 #![crate_name = "rustc_trans"]
18 #![crate_type = "dylib"]
19 #![crate_type = "rlib"]
20 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
21       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
22       html_root_url = "https://doc.rust-lang.org/nightly/")]
23 #![deny(warnings)]
24
25 #![feature(associated_consts)]
26 #![feature(box_patterns)]
27 #![feature(box_syntax)]
28 #![feature(const_fn)]
29 #![feature(custom_attribute)]
30 #![allow(unused_attributes)]
31 #![feature(i128_type)]
32 #![feature(libc)]
33 #![feature(quote)]
34 #![feature(rustc_diagnostic_macros)]
35 #![feature(slice_patterns)]
36 #![feature(conservative_impl_trait)]
37
38 use rustc::dep_graph::WorkProduct;
39 use syntax_pos::symbol::Symbol;
40
41 extern crate flate2;
42 extern crate crossbeam;
43 extern crate libc;
44 extern crate owning_ref;
45 #[macro_use] extern crate rustc;
46 extern crate rustc_allocator;
47 extern crate rustc_back;
48 extern crate rustc_data_structures;
49 extern crate rustc_incremental;
50 pub extern crate rustc_llvm as llvm;
51 extern crate rustc_platform_intrinsics as intrinsics;
52 extern crate rustc_const_math;
53 #[macro_use]
54 #[no_link]
55 extern crate rustc_bitflags;
56 extern crate rustc_demangle;
57 extern crate jobserver;
58
59 #[macro_use] extern crate log;
60 #[macro_use] extern crate syntax;
61 extern crate syntax_pos;
62 extern crate rustc_errors as errors;
63 extern crate serialize;
64 #[cfg(windows)]
65 extern crate gcc; // Used to locate MSVC, not gcc :)
66
67 pub use base::trans_crate;
68 pub use back::symbol_names::provide;
69
70 pub use metadata::LlvmMetadataLoader;
71 pub use llvm_util::{init, target_features, print_version, print_passes, print, enable_llvm_debug};
72
73 pub mod back {
74     mod archive;
75     pub(crate) mod linker;
76     pub mod link;
77     mod lto;
78     pub(crate) mod symbol_export;
79     pub(crate) mod symbol_names;
80     pub mod write;
81     pub mod rpath;
82 }
83
84 mod diagnostics;
85
86 mod abi;
87 mod adt;
88 mod allocator;
89 mod asm;
90 mod assert_module_sources;
91 mod attributes;
92 mod base;
93 mod builder;
94 mod cabi_aarch64;
95 mod cabi_arm;
96 mod cabi_asmjs;
97 mod cabi_hexagon;
98 mod cabi_mips;
99 mod cabi_mips64;
100 mod cabi_msp430;
101 mod cabi_nvptx;
102 mod cabi_nvptx64;
103 mod cabi_powerpc;
104 mod cabi_powerpc64;
105 mod cabi_s390x;
106 mod cabi_sparc;
107 mod cabi_sparc64;
108 mod cabi_x86;
109 mod cabi_x86_64;
110 mod cabi_x86_win64;
111 mod callee;
112 mod collector;
113 mod common;
114 mod consts;
115 mod context;
116 mod debuginfo;
117 mod declare;
118 mod glue;
119 mod intrinsic;
120 mod llvm_util;
121 mod machine;
122 mod metadata;
123 mod meth;
124 mod mir;
125 mod monomorphize;
126 mod partitioning;
127 mod symbol_names_test;
128 mod trans_item;
129 mod tvec;
130 mod type_;
131 mod type_of;
132 mod value;
133
134 #[derive(Clone)]
135 pub struct ModuleTranslation {
136     /// The name of the module. When the crate may be saved between
137     /// compilations, incremental compilation requires that name be
138     /// unique amongst **all** crates.  Therefore, it should contain
139     /// something unique to this crate (e.g., a module path) as well
140     /// as the crate name and disambiguator.
141     pub name: String,
142     pub symbol_name_hash: u64,
143     pub source: ModuleSource,
144 }
145
146 #[derive(Clone)]
147 pub enum ModuleSource {
148     /// Copy the `.o` files or whatever from the incr. comp. directory.
149     Preexisting(WorkProduct),
150
151     /// Rebuild from this LLVM module.
152     Translated(ModuleLlvm),
153 }
154
155 #[derive(Copy, Clone)]
156 pub struct ModuleLlvm {
157     pub llcx: llvm::ContextRef,
158     pub llmod: llvm::ModuleRef,
159 }
160
161 unsafe impl Send for ModuleTranslation { }
162 unsafe impl Sync for ModuleTranslation { }
163
164 pub struct CrateTranslation {
165     pub crate_name: Symbol,
166     pub modules: Vec<ModuleTranslation>,
167     pub metadata_module: ModuleTranslation,
168     pub allocator_module: Option<ModuleTranslation>,
169     pub link: rustc::middle::cstore::LinkMeta,
170     pub metadata: rustc::middle::cstore::EncodedMetadata,
171     pub exported_symbols: back::symbol_export::ExportedSymbols,
172     pub no_builtins: bool,
173     pub windows_subsystem: Option<String>,
174     pub linker_info: back::linker::LinkerInfo
175 }
176
177 __build_diagnostic_array! { librustc_trans, DIAGNOSTICS }