1 // Copyright 2017 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.
13 //! This API is completely unstable and subject to change.
15 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
16 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
17 html_root_url = "https://doc.rust-lang.org/nightly/")]
19 #![feature(box_patterns)]
20 #![feature(box_syntax)]
21 #![feature(custom_attribute)]
23 #![feature(rustc_diagnostic_macros)]
24 #![feature(in_band_lifetimes)]
25 #![feature(slice_sort_by_cached_key)]
27 #![allow(unused_attributes)]
31 #[macro_use] extern crate bitflags;
32 #[macro_use] extern crate log;
33 extern crate rustc_apfloat;
34 #[macro_use] extern crate rustc;
35 extern crate rustc_target;
36 extern crate rustc_mir;
37 #[macro_use] extern crate syntax;
38 extern crate syntax_pos;
39 extern crate rustc_incremental;
40 extern crate rustc_codegen_utils;
41 extern crate rustc_data_structures;
44 use std::path::PathBuf;
45 use rustc::dep_graph::WorkProduct;
46 use rustc::session::config::{OutputFilenames, OutputType};
47 use rustc::middle::lang_items::LangItem;
48 use rustc::hir::def_id::CrateNum;
49 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
50 use rustc_data_structures::sync::Lrc;
51 use rustc::middle::cstore::{LibSource, CrateSource, NativeLibrary};
53 // NB: This module needs to be declared first so diagnostics are
54 // registered before they are used.
67 pub struct ModuleCodegen<M> {
68 /// The name of the module. When the crate may be saved between
69 /// compilations, incremental compilation requires that name be
70 /// unique amongst **all** crates. Therefore, it should contain
71 /// something unique to this crate (e.g., a module path) as well
72 /// as the crate name and disambiguator.
73 /// We currently generate these names via CodegenUnit::build_cgu_name().
79 pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";
81 impl<M> ModuleCodegen<M> {
82 pub fn into_compiled_module(self,
85 emit_bc_compressed: bool,
86 outputs: &OutputFilenames) -> CompiledModule {
87 let object = if emit_obj {
88 Some(outputs.temp_path(OutputType::Object, Some(&self.name)))
92 let bytecode = if emit_bc {
93 Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)))
97 let bytecode_compressed = if emit_bc_compressed {
98 Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
99 .with_extension(RLIB_BYTECODE_EXTENSION))
105 name: self.name.clone(),
115 pub struct CompiledModule {
117 pub kind: ModuleKind,
118 pub object: Option<PathBuf>,
119 pub bytecode: Option<PathBuf>,
120 pub bytecode_compressed: Option<PathBuf>,
123 pub struct CachedModuleCodegen {
125 pub source: WorkProduct,
128 #[derive(Copy, Clone, Debug, PartialEq)]
129 pub enum ModuleKind {
136 pub struct MemFlags: u8 {
137 const VOLATILE = 1 << 0;
138 const NONTEMPORAL = 1 << 1;
139 const UNALIGNED = 1 << 2;
143 /// Misc info we load from metadata to persist beyond the tcx
144 pub struct CrateInfo {
145 pub panic_runtime: Option<CrateNum>,
146 pub compiler_builtins: Option<CrateNum>,
147 pub profiler_runtime: Option<CrateNum>,
148 pub sanitizer_runtime: Option<CrateNum>,
149 pub is_no_builtins: FxHashSet<CrateNum>,
150 pub native_libraries: FxHashMap<CrateNum, Lrc<Vec<NativeLibrary>>>,
151 pub crate_name: FxHashMap<CrateNum, String>,
152 pub used_libraries: Lrc<Vec<NativeLibrary>>,
153 pub link_args: Lrc<Vec<String>>,
154 pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
155 pub used_crates_static: Vec<(CrateNum, LibSource)>,
156 pub used_crates_dynamic: Vec<(CrateNum, LibSource)>,
157 pub wasm_imports: FxHashMap<String, String>,
158 pub lang_item_to_crate: FxHashMap<LangItem, CrateNum>,
159 pub missing_lang_items: FxHashMap<CrateNum, Vec<LangItem>>,
162 __build_diagnostic_array! { librustc_codegen_ssa, DIAGNOSTICS }