]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/lib.rs
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
[rust.git] / src / librustc_codegen_ssa / lib.rs
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.
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 //! # Note
12 //!
13 //! This API is completely unstable and subject to change.
14
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/")]
18
19 #![feature(box_patterns)]
20 #![feature(box_syntax)]
21 #![feature(custom_attribute)]
22 #![feature(nll)]
23 #![allow(unused_attributes)]
24 #![allow(dead_code)]
25 #![feature(quote)]
26 #![feature(rustc_diagnostic_macros)]
27
28 #![recursion_limit="256"]
29
30 extern crate rustc;
31 extern crate rustc_target;
32 extern crate rustc_mir;
33 extern crate syntax;
34 extern crate syntax_pos;
35 extern crate rustc_data_structures;
36
37 use std::path::PathBuf;
38 use rustc::dep_graph::WorkProduct;
39 use rustc::session::config::{OutputFilenames, OutputType};
40
41 pub mod common;
42 pub mod interfaces;
43
44 pub struct ModuleCodegen<M> {
45     /// The name of the module. When the crate may be saved between
46     /// compilations, incremental compilation requires that name be
47     /// unique amongst **all** crates.  Therefore, it should contain
48     /// something unique to this crate (e.g., a module path) as well
49     /// as the crate name and disambiguator.
50     /// We currently generate these names via CodegenUnit::build_cgu_name().
51     pub name: String,
52     pub module_llvm: M,
53     pub kind: ModuleKind,
54 }
55
56 pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";
57
58 impl<M> ModuleCodegen<M> {
59     pub fn into_compiled_module(self,
60                             emit_obj: bool,
61                             emit_bc: bool,
62                             emit_bc_compressed: bool,
63                             outputs: &OutputFilenames) -> CompiledModule {
64         let object = if emit_obj {
65             Some(outputs.temp_path(OutputType::Object, Some(&self.name)))
66         } else {
67             None
68         };
69         let bytecode = if emit_bc {
70             Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)))
71         } else {
72             None
73         };
74         let bytecode_compressed = if emit_bc_compressed {
75             Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
76                     .with_extension(RLIB_BYTECODE_EXTENSION))
77         } else {
78             None
79         };
80
81         CompiledModule {
82             name: self.name.clone(),
83             kind: self.kind,
84             object,
85             bytecode,
86             bytecode_compressed,
87         }
88     }
89 }
90
91 #[derive(Debug)]
92 pub struct CompiledModule {
93     pub name: String,
94     pub kind: ModuleKind,
95     pub object: Option<PathBuf>,
96     pub bytecode: Option<PathBuf>,
97     pub bytecode_compressed: Option<PathBuf>,
98 }
99
100 pub struct CachedModuleCodegen {
101     pub name: String,
102     pub source: WorkProduct,
103 }
104
105 #[derive(Copy, Clone, Debug, PartialEq)]
106 pub enum ModuleKind {
107     Regular,
108     Metadata,
109     Allocator,
110 }
111
112
113 __build_diagnostic_array! { librustc_codegen_ssa, DIAGNOSTICS }