]>
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 | ||
24 | #![crate_name = "rustc_back"] | |
1a4d82fc JJ |
25 | #![crate_type = "dylib"] |
26 | #![crate_type = "rlib"] | |
e9174d1e | 27 | #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", |
62682a34 | 28 | html_favicon_url = "https://doc.rust-lang.org/favicon.ico", |
e9174d1e | 29 | html_root_url = "https://doc.rust-lang.org/nightly/")] |
32a655c1 | 30 | #![deny(warnings)] |
85aaf69f SL |
31 | |
32 | #![feature(box_syntax)] | |
54a0048b | 33 | #![feature(const_fn)] |
62682a34 | 34 | #![feature(libc)] |
62682a34 | 35 | #![feature(rand)] |
c30ab7b3 | 36 | #![cfg_attr(test, feature(rand))] |
1a4d82fc JJ |
37 | |
38 | extern crate syntax; | |
9346a6ac | 39 | extern crate libc; |
1a4d82fc JJ |
40 | extern crate serialize; |
41 | #[macro_use] extern crate log; | |
42 | ||
c30ab7b3 SL |
43 | extern crate serialize as rustc_serialize; // used by deriving |
44 | ||
c34b1796 | 45 | pub mod tempdir; |
1a4d82fc | 46 | pub mod target; |
b039eaaf | 47 | pub mod slice; |
54a0048b | 48 | pub mod dynamic_lib; |
c30ab7b3 SL |
49 | |
50 | use serialize::json::{Json, ToJson}; | |
51 | ||
cc61c64b XL |
52 | macro_rules! linker_flavor { |
53 | ($(($variant:ident, $string:expr),)+) => { | |
54 | #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash, | |
55 | RustcEncodable, RustcDecodable)] | |
56 | pub enum LinkerFlavor { | |
57 | $($variant,)+ | |
58 | } | |
59 | ||
60 | impl LinkerFlavor { | |
61 | pub const fn one_of() -> &'static str { | |
62 | concat!("one of: ", $($string, " ",)+) | |
63 | } | |
64 | ||
65 | pub fn from_str(s: &str) -> Option<Self> { | |
66 | Some(match s { | |
67 | $($string => LinkerFlavor::$variant,)+ | |
68 | _ => return None, | |
69 | }) | |
70 | } | |
71 | ||
72 | pub fn desc(&self) -> &str { | |
73 | match *self { | |
74 | $(LinkerFlavor::$variant => $string,)+ | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | impl ToJson for LinkerFlavor { | |
80 | fn to_json(&self) -> Json { | |
81 | self.desc().to_json() | |
82 | } | |
83 | } | |
84 | } | |
85 | } | |
86 | ||
87 | linker_flavor! { | |
88 | (Em, "em"), | |
89 | (Gcc, "gcc"), | |
90 | (Ld, "ld"), | |
91 | (Msvc, "msvc"), | |
92 | } | |
93 | ||
c30ab7b3 SL |
94 | #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] |
95 | pub enum PanicStrategy { | |
96 | Unwind, | |
97 | Abort, | |
98 | } | |
99 | ||
100 | impl PanicStrategy { | |
101 | pub fn desc(&self) -> &str { | |
102 | match *self { | |
103 | PanicStrategy::Unwind => "unwind", | |
104 | PanicStrategy::Abort => "abort", | |
105 | } | |
106 | } | |
107 | } | |
108 | ||
109 | impl ToJson for PanicStrategy { | |
110 | fn to_json(&self) -> Json { | |
111 | match *self { | |
112 | PanicStrategy::Abort => "abort".to_json(), | |
113 | PanicStrategy::Unwind => "unwind".to_json(), | |
114 | } | |
115 | } | |
116 | } |