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.
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.
11 //! Some stuff used by rustc that doesn't have many dependencies
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
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
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/")]
32 #![feature(box_syntax)]
36 #![cfg_attr(test, feature(rand))]
40 extern crate serialize;
41 #[macro_use] extern crate log;
43 extern crate serialize as rustc_serialize; // used by deriving
50 use serialize::json::{Json, ToJson};
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 {
61 pub const fn one_of() -> &'static str {
62 concat!("one of: ", $($string, " ",)+)
65 pub fn from_str(s: &str) -> Option<Self> {
67 $($string => LinkerFlavor::$variant,)+
72 pub fn desc(&self) -> &str {
74 $(LinkerFlavor::$variant => $string,)+
79 impl ToJson for LinkerFlavor {
80 fn to_json(&self) -> Json {
94 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
95 pub enum PanicStrategy {
101 pub fn desc(&self) -> &str {
103 PanicStrategy::Unwind => "unwind",
104 PanicStrategy::Abort => "abort",
109 impl ToJson for PanicStrategy {
110 fn to_json(&self) -> Json {
112 PanicStrategy::Abort => "abort".to_json(),
113 PanicStrategy::Unwind => "unwind".to_json(),
118 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
119 pub enum RelroLevel {
126 pub fn desc(&self) -> &str {
128 RelroLevel::Full => "full",
129 RelroLevel::Partial => "partial",
130 RelroLevel::Off => "off",
135 impl ToJson for RelroLevel {
136 fn to_json(&self) -> Json {
138 RelroLevel::Full => "full".to_json(),
139 RelroLevel::Partial => "partial".to_json(),
140 RelroLevel::Off => "off".to_json(),