]>
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)] |
62682a34 | 32 | #![feature(rand)] |
c30ab7b3 | 33 | #![cfg_attr(test, feature(rand))] |
1a4d82fc JJ |
34 | |
35 | extern crate syntax; | |
9346a6ac | 36 | extern crate libc; |
1a4d82fc JJ |
37 | extern crate serialize; |
38 | #[macro_use] extern crate log; | |
39 | ||
c30ab7b3 SL |
40 | extern crate serialize as rustc_serialize; // used by deriving |
41 | ||
c34b1796 | 42 | pub mod tempdir; |
1a4d82fc | 43 | pub mod target; |
b039eaaf | 44 | pub mod slice; |
54a0048b | 45 | pub mod dynamic_lib; |
c30ab7b3 | 46 | |
3b2f2976 XL |
47 | use std::str::FromStr; |
48 | ||
c30ab7b3 SL |
49 | use serialize::json::{Json, ToJson}; |
50 | ||
cc61c64b XL |
51 | macro_rules! linker_flavor { |
52 | ($(($variant:ident, $string:expr),)+) => { | |
53 | #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash, | |
54 | RustcEncodable, RustcDecodable)] | |
55 | pub enum LinkerFlavor { | |
56 | $($variant,)+ | |
57 | } | |
58 | ||
59 | impl LinkerFlavor { | |
60 | pub const fn one_of() -> &'static str { | |
61 | concat!("one of: ", $($string, " ",)+) | |
62 | } | |
63 | ||
64 | pub fn from_str(s: &str) -> Option<Self> { | |
65 | Some(match s { | |
66 | $($string => LinkerFlavor::$variant,)+ | |
67 | _ => return None, | |
68 | }) | |
69 | } | |
70 | ||
71 | pub fn desc(&self) -> &str { | |
72 | match *self { | |
73 | $(LinkerFlavor::$variant => $string,)+ | |
74 | } | |
75 | } | |
76 | } | |
77 | ||
78 | impl ToJson for LinkerFlavor { | |
79 | fn to_json(&self) -> Json { | |
80 | self.desc().to_json() | |
81 | } | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
86 | linker_flavor! { | |
87 | (Em, "em"), | |
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 | } |