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)]
31 #![feature(fs_read_write)]
35 extern crate serialize;
36 #[macro_use] extern crate log;
38 extern crate serialize as rustc_serialize; // used by deriving
42 use std::str::FromStr;
44 use serialize::json::{Json, ToJson};
46 macro_rules! linker_flavor {
47 ($(($variant:ident, $string:expr),)+) => {
48 #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
49 RustcEncodable, RustcDecodable)]
50 pub enum LinkerFlavor {
55 pub const fn one_of() -> &'static str {
56 concat!("one of: ", $($string, " ",)+)
59 pub fn from_str(s: &str) -> Option<Self> {
61 $($string => LinkerFlavor::$variant,)+
66 pub fn desc(&self) -> &str {
68 $(LinkerFlavor::$variant => $string,)+
73 impl ToJson for LinkerFlavor {
74 fn to_json(&self) -> Json {
83 (Binaryen, "binaryen"),
89 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
90 pub enum PanicStrategy {
96 pub fn desc(&self) -> &str {
98 PanicStrategy::Unwind => "unwind",
99 PanicStrategy::Abort => "abort",
104 impl ToJson for PanicStrategy {
105 fn to_json(&self) -> Json {
107 PanicStrategy::Abort => "abort".to_json(),
108 PanicStrategy::Unwind => "unwind".to_json(),
113 #[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
114 pub enum RelroLevel {
121 pub fn desc(&self) -> &str {
123 RelroLevel::Full => "full",
124 RelroLevel::Partial => "partial",
125 RelroLevel::Off => "off",
130 impl FromStr for RelroLevel {
133 fn from_str(s: &str) -> Result<RelroLevel, ()> {
135 "full" => Ok(RelroLevel::Full),
136 "partial" => Ok(RelroLevel::Partial),
137 "off" => Ok(RelroLevel::Off),
143 impl ToJson for RelroLevel {
144 fn to_json(&self) -> Json {
146 RelroLevel::Full => "full".to_json(),
147 RelroLevel::Partial => "partial".to_json(),
148 RelroLevel::Off => "off".to_json(),