1 // Copyright 2015 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 use syntax
::{ast, attr}
;
12 use llvm
::LLVMRustHasFeature
;
13 use rustc
::session
::Session
;
14 use rustc_trans
::back
::write
::create_target_machine
;
15 use syntax
::parse
::token
::InternedString
;
16 use syntax
::parse
::token
::intern_and_get_ident
as intern
;
19 // WARNING: the features must be known to LLVM or the feature
20 // detection code will walk past the end of the feature array,
21 // leading to crashes.
23 const ARM_WHITELIST
: &'
static [&'
static str] = &[
30 const X86_WHITELIST
: &'
static [&'
static str] = &[
44 /// Add `target_feature = "..."` cfgs for a variety of platform
45 /// specific features (SSE, NEON etc.).
47 /// This is performed by checking whether a whitelisted set of
48 /// features is available on the target machine, by querying LLVM.
49 pub fn add_configuration(cfg
: &mut ast
::CrateConfig
, sess
: &Session
) {
50 let target_machine
= create_target_machine(sess
);
52 let whitelist
= match &*sess
.target
.target
.arch
{
53 "arm" => ARM_WHITELIST
,
54 "x86" | "x86_64" => X86_WHITELIST
,
58 let tf
= InternedString
::new("target_feature");
59 for feat
in whitelist
{
60 assert_eq
!(feat
.chars().last(), Some('
\0'
));
61 if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) }
{
62 cfg
.push(attr
::mk_name_value_item_str(tf
.clone(), intern(&feat
[..feat
.len()-1])))