Skip to content

Commit

Permalink
[AVR][No Upstream] Expose the 'target_cpu' feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmckay committed Dec 19, 2018
1 parent e36cb59 commit 97eea42
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ pub fn default_lib_output() -> CrateType {
pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
let end = &sess.target.target.target_endian;
let arch = &sess.target.target.arch;
let cpu = &sess.target.target.options.cpu;
let wordsz = &sess.target.target.target_pointer_width;
let os = &sess.target.target.target_os;
let env = &sess.target.target.target_env;
Expand Down Expand Up @@ -1426,6 +1427,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
Symbol::intern("target_vendor"),
Some(Symbol::intern(vendor)),
));
if sess.target.target.options.is_specific_cpu() {
ret.insert((Symbol::intern("target_cpu"), Some(Symbol::intern(cpu))));
}

if sess.target.target.options.has_elf_tls {
ret.insert((Symbol::intern("target_thread_local"), None));
}
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,12 @@ impl Default for TargetOptions {
}
}

impl TargetOptions {
pub fn is_specific_cpu(&self) -> bool {
self.cpu != "generic"
}
}

impl Target {
/// Given a function ABI, turn it into the correct ABI for this target.
pub fn adjust_abi(&self, abi: Abi) -> Abi {
Expand Down
18 changes: 18 additions & 0 deletions src/test/run-pass/cfg-target-cpu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn main() {
if cfg!(target_cpu = "cortex-a8") {
println!("Running on Cortex A8!");
} else {
println!("Running on an arbitrary cpu");
}
}

0 comments on commit 97eea42

Please sign in to comment.