compiler: Change c_int_width to be an integer type

This commit is contained in:
Jubilee Young
2025-06-11 00:28:33 -07:00
parent 1c047506f9
commit b88c0061c4
3 changed files with 17 additions and 19 deletions

View File

@@ -44,10 +44,10 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
BaseTypeCodegenMethods + MiscCodegenMethods<'tcx> + HasTyCtxt<'tcx> + HasTypingEnv<'tcx> BaseTypeCodegenMethods + MiscCodegenMethods<'tcx> + HasTyCtxt<'tcx> + HasTypingEnv<'tcx>
{ {
fn type_int(&self) -> Self::Type { fn type_int(&self) -> Self::Type {
match &self.sess().target.c_int_width[..] { match &self.sess().target.c_int_width {
"16" => self.type_i16(), 16 => self.type_i16(),
"32" => self.type_i32(), 32 => self.type_i32(),
"64" => self.type_i64(), 64 => self.type_i64(),
width => bug!("Unsupported c_int_width: {}", width), width => bug!("Unsupported c_int_width: {}", width),
} }
} }

View File

@@ -80,6 +80,12 @@ impl Target {
base.$key_name = s; base.$key_name = s;
} }
} ); } );
($key_name:ident = $json_name:expr, u64 as $int_ty:ty) => ( {
let name = $json_name;
if let Some(s) = obj.remove(name).and_then(|b| b.as_u64()) {
base.$key_name = s as $int_ty;
}
} );
($key_name:ident, bool) => ( { ($key_name:ident, bool) => ( {
let name = (stringify!($key_name)).replace("_", "-"); let name = (stringify!($key_name)).replace("_", "-");
if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) { if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) {
@@ -554,7 +560,7 @@ impl Target {
} }
} }
key!(c_int_width = "target-c-int-width"); key!(c_int_width = "target-c-int-width", u64 as u16);
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
key!(os); key!(os);
key!(env); key!(env);

View File

@@ -2213,17 +2213,9 @@ impl Target {
}); });
} }
dl.c_enum_min_size = self dl.c_enum_min_size = Integer::from_size(Size::from_bits(
.c_enum_min_bits self.c_enum_min_bits.unwrap_or(self.c_int_width as _),
.map_or_else( ))
|| {
self.c_int_width
.parse()
.map_err(|_| String::from("failed to parse c_int_width"))
},
Ok,
)
.and_then(|i| Integer::from_size(Size::from_bits(i)))
.map_err(|err| TargetDataLayoutErrors::InvalidBitsSize { err })?; .map_err(|err| TargetDataLayoutErrors::InvalidBitsSize { err })?;
Ok(dl) Ok(dl)
@@ -2286,7 +2278,7 @@ pub struct TargetOptions {
/// Used as the `target_endian` `cfg` variable. Defaults to little endian. /// Used as the `target_endian` `cfg` variable. Defaults to little endian.
pub endian: Endian, pub endian: Endian,
/// Width of c_int type. Defaults to "32". /// Width of c_int type. Defaults to "32".
pub c_int_width: StaticCow<str>, pub c_int_width: u16,
/// OS name to use for conditional compilation (`target_os`). Defaults to "none". /// OS name to use for conditional compilation (`target_os`). Defaults to "none".
/// "none" implies a bare metal target without `std` library. /// "none" implies a bare metal target without `std` library.
/// A couple of targets having `std` also use "unknown" as an `os` value, /// A couple of targets having `std` also use "unknown" as an `os` value,
@@ -2783,7 +2775,7 @@ impl Default for TargetOptions {
fn default() -> TargetOptions { fn default() -> TargetOptions {
TargetOptions { TargetOptions {
endian: Endian::Little, endian: Endian::Little,
c_int_width: "32".into(), c_int_width: 32,
os: "none".into(), os: "none".into(),
env: "".into(), env: "".into(),
abi: "".into(), abi: "".into(),