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 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
25 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
26 html_root_url = "https://doc.rust-lang.org/nightly/")]
29 #![feature(box_syntax)]
33 #![cfg_attr(test, feature(rand))]
37 extern crate serialize;
38 #[macro_use] extern crate log;
40 extern crate serialize as rustc_serialize; // used by deriving
47 use std::str::FromStr;
49 use serialize::json::{Json, ToJson};
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 {
60 pub const fn one_of() -> &'static str {
61 concat!("one of: ", $($string, " ",)+)
64 pub fn from_str(s: &str) -> Option<Self> {
66 $($string => LinkerFlavor::$variant,)+
71 pub fn desc(&self) -> &str {
73 $(LinkerFlavor::$variant => $string,)+
78 impl ToJson for LinkerFlavor {
79 fn to_json(&self) -> Json {
93 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
94 pub enum PanicStrategy {
100 pub fn desc(&self) -> &str {
102 PanicStrategy::Unwind => "unwind",
103 PanicStrategy::Abort => "abort",
108 impl ToJson for PanicStrategy {
109 fn to_json(&self) -> Json {
111 PanicStrategy::Abort => "abort".to_json(),
112 PanicStrategy::Unwind => "unwind".to_json(),
117 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
118 pub enum RelroLevel {
125 pub fn desc(&self) -> &str {
127 RelroLevel::Full => "full",
128 RelroLevel::Partial => "partial",
129 RelroLevel::Off => "off",
134 impl FromStr for RelroLevel {
137 fn from_str(s: &str) -> Result<RelroLevel, ()> {
139 "full" => Ok(RelroLevel::Full),
140 "partial" => Ok(RelroLevel::Partial),
141 "off" => Ok(RelroLevel::Off),
147 impl ToJson for RelroLevel {
148 fn to_json(&self) -> Json {
150 RelroLevel::Full => "full".to_json(),
151 RelroLevel::Partial => "partial".to_json(),
152 RelroLevel::Off => "off".to_json(),