Skip to content

Commit 2cef818

Browse files
committed
rustc: Add target_has_floating_point property
This adds a new target property, `target_has_floating_point` which can be used as a matcher for conditional compilation. The default value is `true`. Matching against the `target_has_floating_point` attribute with `#[cfg]` is currently feature gated as `cfg_target_has_floating_point`.
1 parent 30a3849 commit 2cef818

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

src/doc/reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ The following configurations must be defined by the implementation:
20872087
64-bit pointers.
20882088
* `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or
20892089
simply `"unknown"`.
2090+
* `target_has_floating_point` - Enabled if the target supports floating point operations.
20902091
* `test` - Enabled when compiling the test harness (using the `--test` flag).
20912092
* `unix` - See `target_family`.
20922093
* `windows` - See `target_family`.
@@ -2287,6 +2288,9 @@ The currently implemented features of the reference compiler are:
22872288
* `cfg_target_vendor` - Allows conditional compilation using the `target_vendor`
22882289
matcher which is subject to change.
22892290

2291+
* `cfg_target_has_floating_point` - Allows conditional compilation using the
2292+
`target_has_floating_point` matcher which is subject to change.
2293+
22902294
* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
22912295
ways insufficient for concatenating identifiers, and may be
22922296
removed entirely for something more wholesome.

src/librustc/session/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
710710
if sess.target.target.options.has_elf_tls {
711711
ret.push(attr::mk_word_item(InternedString::new("target_thread_local")));
712712
}
713+
if sess.target.target.options.has_floating_point {
714+
ret.push(attr::mk_word_item(InternedString::new("target_has_floating_point")));
715+
}
713716
if sess.opts.debug_assertions {
714717
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
715718
}

src/librustc_back/target/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ pub struct TargetOptions {
287287
// If we give emcc .o files that are actually .bc files it
288288
// will 'just work'.
289289
pub obj_is_bitcode: bool,
290+
291+
/// Flag indicating whether the target supports floating point instructions. Defaults to true.
292+
pub has_floating_point: bool,
290293
}
291294

292295
impl Default for TargetOptions {
@@ -335,6 +338,7 @@ impl Default for TargetOptions {
335338
allow_asm: true,
336339
has_elf_tls: false,
337340
obj_is_bitcode: false,
341+
has_floating_point: true,
338342
}
339343
}
340344
}
@@ -445,6 +449,7 @@ impl Target {
445449
key!(archive_format);
446450
key!(allow_asm, bool);
447451
key!(custom_unwind_resume, bool);
452+
key!(has_floating_point, bool);
448453

449454
base
450455
}

src/libsyntax/feature_gate.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
256256

257257
// impl specialization (RFC 1210)
258258
("specialization", "1.7.0", Some(31844), Active),
259+
260+
// Allows cfg(target_has_floating_point)
261+
("cfg_target_has_floating_point", "1.9.0", None, Active),
259262
];
260263
// (changing above list without updating src/doc/reference.md makes @cmr sad)
261264

@@ -460,6 +463,8 @@ const GATED_CFGS: &'static [(&'static str, &'static str, fn(&Features) -> bool)]
460463
("target_vendor", "cfg_target_vendor", cfg_fn!(|x| x.cfg_target_vendor)),
461464
("target_thread_local", "cfg_target_thread_local",
462465
cfg_fn!(|x| x.cfg_target_thread_local)),
466+
("target_has_floating_point", "cfg_target_has_floating_point",
467+
cfg_fn!(|x| x.cfg_target_has_floating_point)),
463468
];
464469

465470
#[derive(Debug, Eq, PartialEq)]
@@ -595,6 +600,7 @@ pub struct Features {
595600
pub cfg_target_feature: bool,
596601
pub cfg_target_vendor: bool,
597602
pub cfg_target_thread_local: bool,
603+
pub cfg_target_has_floating_point: bool,
598604
pub staged_api: bool,
599605
pub stmt_expr_attributes: bool,
600606
pub deprecated: bool,
@@ -631,6 +637,7 @@ impl Features {
631637
cfg_target_feature: false,
632638
cfg_target_vendor: false,
633639
cfg_target_thread_local: false,
640+
cfg_target_has_floating_point: true,
634641
staged_api: false,
635642
stmt_expr_attributes: false,
636643
deprecated: false,
@@ -1243,6 +1250,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
12431250
cfg_target_feature: cx.has_feature("cfg_target_feature"),
12441251
cfg_target_vendor: cx.has_feature("cfg_target_vendor"),
12451252
cfg_target_thread_local: cx.has_feature("cfg_target_thread_local"),
1253+
cfg_target_has_floating_point: cx.has_feature("cfg_target_has_floating_point"),
12461254
staged_api: cx.has_feature("staged_api"),
12471255
stmt_expr_attributes: cx.has_feature("stmt_expr_attributes"),
12481256
deprecated: cx.has_feature("deprecated"),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.
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+
#[cfg(target_has_floating_point)] //~ ERROR `cfg(target_has_floating_point)` is experimental
12+
#[cfg_attr(target_has_floating_point, repr(C))]
13+
//~^ ERROR `cfg(target_has_floating_point)` is experimental
14+
struct Foo(u64, u64);
15+
16+
#[cfg(not(any(all(target_has_floating_point))))]
17+
//~^ ERROR `cfg(target_has_floating_point)` is experimental
18+
fn foo() {}
19+
20+
fn main() {
21+
cfg!(target_has_floating_point);
22+
//~^ ERROR `cfg(target_has_floating_point)` is experimental and subject to change
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.
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+
#![feature(cfg_target_has_floating_point)]
12+
13+
#[cfg(target_has_floating_point)]
14+
pub fn main() {
15+
}
16+
17+
#[cfg(not(target_has_floating_point))]
18+
pub fn main() {
19+
}

0 commit comments

Comments
 (0)