Skip to content

Commit b0ed773

Browse files
dylanmckayshepmaster
authored andcommitted
[AVR][No Upstream] Expose the 'target_cpu' feature flag
1 parent 6581234 commit b0ed773

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/librustc/session/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ pub fn default_lib_output() -> CrateType {
11151115
pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
11161116
let end = &sess.target.target.target_endian;
11171117
let arch = &sess.target.target.arch;
1118+
let cpu = &sess.target.target.options.cpu;
11181119
let wordsz = &sess.target.target.target_pointer_width;
11191120
let os = &sess.target.target.target_os;
11201121
let env = &sess.target.target.target_env;
@@ -1136,6 +1137,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
11361137
ret.insert((Symbol::intern("target_pointer_width"), Some(Symbol::intern(wordsz))));
11371138
ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env))));
11381139
ret.insert((Symbol::intern("target_vendor"), Some(Symbol::intern(vendor))));
1140+
if sess.target.target.options.is_specific_cpu() {
1141+
ret.insert((Symbol::intern("target_cpu"), Some(Symbol::intern(cpu))));
1142+
}
1143+
11391144
if sess.target.target.options.has_elf_tls {
11401145
ret.insert((Symbol::intern("target_thread_local"), None));
11411146
}

src/librustc_back/target/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ impl Target {
807807
}
808808
}
809809

810+
impl TargetOptions {
811+
pub fn is_specific_cpu(&self) -> bool {
812+
self.cpu != "generic"
813+
}
814+
}
815+
810816
impl ToJson for Target {
811817
fn to_json(&self) -> Json {
812818
let mut d = BTreeMap::new();

src/test/run-pass/cfg-target-cpu.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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.
4+
//
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.
10+
11+
pub fn main() {
12+
if cfg!(target_cpu = "cortex-a8") {
13+
println!("Running on Cortex A8!");
14+
} else {
15+
println!("Running on an arbitrary cpu");
16+
}
17+
}
18+

0 commit comments

Comments
 (0)