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