]> git.lizzy.rs Git - rust.git/blob - src/librustc_back/lib.rs
Refactor away `inferred_obligations` from the trait selector
[rust.git] / src / librustc_back / 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 //! Some stuff used by rustc that doesn't have many dependencies
12 //!
13 //! Originally extracted from rustc::back, which was nominally the
14 //! compiler 'backend', though LLVM is rustc's backend, so rustc_back
15 //! is really just odds-and-ends relating to code gen and linking.
16 //! This crate mostly exists to make rustc smaller, so we might put
17 //! more 'stuff' here in the future.  It does not have a dependency on
18 //! rustc_llvm.
19 //!
20 //! FIXME: Split this into two crates: one that has deps on syntax, and
21 //! one that doesn't; the one that doesn't might get decent parallel
22 //! build speedups.
23
24 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
25       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
26       html_root_url = "https://doc.rust-lang.org/nightly/")]
27 #![deny(warnings)]
28
29 #![feature(box_syntax)]
30 #![feature(const_fn)]
31 #![feature(fs_read_write)]
32
33 extern crate syntax;
34 extern crate rand;
35 extern crate serialize;
36 #[macro_use] extern crate log;
37
38 extern crate serialize as rustc_serialize; // used by deriving
39
40 pub mod target;
41
42 use std::str::FromStr;
43
44 use serialize::json::{Json, ToJson};
45
46 macro_rules! linker_flavor {
47     ($(($variant:ident, $string:expr),)+) => {
48         #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
49                  RustcEncodable, RustcDecodable)]
50         pub enum LinkerFlavor {
51             $($variant,)+
52         }
53
54         impl LinkerFlavor {
55             pub const fn one_of() -> &'static str {
56                 concat!("one of: ", $($string, " ",)+)
57             }
58
59             pub fn from_str(s: &str) -> Option<Self> {
60                 Some(match s {
61                     $($string => LinkerFlavor::$variant,)+
62                     _ => return None,
63                 })
64             }
65
66             pub fn desc(&self) -> &str {
67                 match *self {
68                     $(LinkerFlavor::$variant => $string,)+
69                 }
70             }
71         }
72
73         impl ToJson for LinkerFlavor {
74             fn to_json(&self) -> Json {
75                 self.desc().to_json()
76             }
77         }
78     }
79 }
80
81 linker_flavor! {
82     (Em, "em"),
83     (Binaryen, "binaryen"),
84     (Gcc, "gcc"),
85     (Ld, "ld"),
86     (Msvc, "msvc"),
87 }
88
89 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
90 pub enum PanicStrategy {
91     Unwind,
92     Abort,
93 }
94
95 impl PanicStrategy {
96     pub fn desc(&self) -> &str {
97         match *self {
98             PanicStrategy::Unwind => "unwind",
99             PanicStrategy::Abort => "abort",
100         }
101     }
102 }
103
104 impl ToJson for PanicStrategy {
105     fn to_json(&self) -> Json {
106         match *self {
107             PanicStrategy::Abort => "abort".to_json(),
108             PanicStrategy::Unwind => "unwind".to_json(),
109         }
110     }
111 }
112
113 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
114 pub enum RelroLevel {
115     Full,
116     Partial,
117     Off,
118 }
119
120 impl RelroLevel {
121     pub fn desc(&self) -> &str {
122         match *self {
123             RelroLevel::Full => "full",
124             RelroLevel::Partial => "partial",
125             RelroLevel::Off => "off",
126         }
127     }
128 }
129
130 impl FromStr for RelroLevel {
131     type Err = ();
132
133     fn from_str(s: &str) -> Result<RelroLevel, ()> {
134         match s {
135             "full" => Ok(RelroLevel::Full),
136             "partial" => Ok(RelroLevel::Partial),
137             "off" => Ok(RelroLevel::Off),
138             _ => Err(()),
139         }
140     }
141 }
142
143 impl ToJson for RelroLevel {
144     fn to_json(&self) -> Json {
145         match *self {
146             RelroLevel::Full => "full".to_json(),
147             RelroLevel::Partial => "partial".to_json(),
148             RelroLevel::Off => "off".to_json(),
149         }
150     }
151 }