]> git.lizzy.rs Git - rust.git/blob - src/librustc_back/lib.rs
Fixes issue #43205: ICE in Rvalue::Len evaluation.
[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 #![crate_name = "rustc_back"]
25 #![crate_type = "dylib"]
26 #![crate_type = "rlib"]
27 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
28       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
29       html_root_url = "https://doc.rust-lang.org/nightly/")]
30 #![deny(warnings)]
31
32 #![feature(box_syntax)]
33 #![feature(const_fn)]
34 #![feature(libc)]
35 #![feature(rand)]
36 #![cfg_attr(test, feature(rand))]
37
38 extern crate syntax;
39 extern crate libc;
40 extern crate serialize;
41 #[macro_use] extern crate log;
42
43 extern crate serialize as rustc_serialize; // used by deriving
44
45 pub mod tempdir;
46 pub mod target;
47 pub mod slice;
48 pub mod dynamic_lib;
49
50 use std::str::FromStr;
51
52 use serialize::json::{Json, ToJson};
53
54 macro_rules! linker_flavor {
55     ($(($variant:ident, $string:expr),)+) => {
56         #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
57                  RustcEncodable, RustcDecodable)]
58         pub enum LinkerFlavor {
59             $($variant,)+
60         }
61
62         impl LinkerFlavor {
63             pub const fn one_of() -> &'static str {
64                 concat!("one of: ", $($string, " ",)+)
65             }
66
67             pub fn from_str(s: &str) -> Option<Self> {
68                 Some(match s {
69                     $($string => LinkerFlavor::$variant,)+
70                     _ => return None,
71                 })
72             }
73
74             pub fn desc(&self) -> &str {
75                 match *self {
76                     $(LinkerFlavor::$variant => $string,)+
77                 }
78             }
79         }
80
81         impl ToJson for LinkerFlavor {
82             fn to_json(&self) -> Json {
83                 self.desc().to_json()
84             }
85         }
86     }
87 }
88
89 linker_flavor! {
90     (Em, "em"),
91     (Gcc, "gcc"),
92     (Ld, "ld"),
93     (Msvc, "msvc"),
94 }
95
96 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
97 pub enum PanicStrategy {
98     Unwind,
99     Abort,
100 }
101
102 impl PanicStrategy {
103     pub fn desc(&self) -> &str {
104         match *self {
105             PanicStrategy::Unwind => "unwind",
106             PanicStrategy::Abort => "abort",
107         }
108     }
109 }
110
111 impl ToJson for PanicStrategy {
112     fn to_json(&self) -> Json {
113         match *self {
114             PanicStrategy::Abort => "abort".to_json(),
115             PanicStrategy::Unwind => "unwind".to_json(),
116         }
117     }
118 }
119
120 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
121 pub enum RelroLevel {
122     Full,
123     Partial,
124     Off,
125 }
126
127 impl RelroLevel {
128     pub fn desc(&self) -> &str {
129         match *self {
130             RelroLevel::Full => "full",
131             RelroLevel::Partial => "partial",
132             RelroLevel::Off => "off",
133         }
134     }
135 }
136
137 impl FromStr for RelroLevel {
138     type Err = ();
139
140     fn from_str(s: &str) -> Result<RelroLevel, ()> {
141         match s {
142             "full" => Ok(RelroLevel::Full),
143             "partial" => Ok(RelroLevel::Partial),
144             "off" => Ok(RelroLevel::Off),
145             _ => Err(()),
146         }
147     }
148 }
149
150 impl ToJson for RelroLevel {
151     fn to_json(&self) -> Json {
152         match *self {
153             RelroLevel::Full => "full".to_json(),
154             RelroLevel::Partial => "partial".to_json(),
155             RelroLevel::Off => "off".to_json(),
156         }
157     }
158 }