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 std::str::FromStr;
52 use serialize::json::{Json, ToJson};
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 {
63 pub const fn one_of() -> &'static str {
64 concat!("one of: ", $($string, " ",)+)
67 pub fn from_str(s: &str) -> Option<Self> {
69 $($string => LinkerFlavor::$variant,)+
74 pub fn desc(&self) -> &str {
76 $(LinkerFlavor::$variant => $string,)+
81 impl ToJson for LinkerFlavor {
82 fn to_json(&self) -> Json {
96 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
97 pub enum PanicStrategy {
103 pub fn desc(&self) -> &str {
105 PanicStrategy::Unwind => "unwind",
106 PanicStrategy::Abort => "abort",
111 impl ToJson for PanicStrategy {
112 fn to_json(&self) -> Json {
114 PanicStrategy::Abort => "abort".to_json(),
115 PanicStrategy::Unwind => "unwind".to_json(),
120 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
121 pub enum RelroLevel {
128 pub fn desc(&self) -> &str {
130 RelroLevel::Full => "full",
131 RelroLevel::Partial => "partial",
132 RelroLevel::Off => "off",
137 impl FromStr for RelroLevel {
140 fn from_str(s: &str) -> Result<RelroLevel, ()> {
142 "full" => Ok(RelroLevel::Full),
143 "partial" => Ok(RelroLevel::Partial),
144 "off" => Ok(RelroLevel::Off),
150 impl ToJson for RelroLevel {
151 fn to_json(&self) -> Json {
153 RelroLevel::Full => "full".to_json(),
154 RelroLevel::Partial => "partial".to_json(),
155 RelroLevel::Off => "off".to_json(),