std.Target: Add a function for determining char signedess

Copied from arocc c1955a4742/src/target.zig (L7)
This commit is contained in:
Evan Haas 2023-04-22 10:26:27 -07:00
parent a72d634b73
commit 657fe55711
No known key found for this signature in database

View File

@ -1910,6 +1910,30 @@ pub const Target = struct {
}
}
/// Default signedness of `char` for the native C compiler for this target
/// Note that char signedness is implementation-defined and many compilers provide
/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
pub fn charSignedness(target: Target) std.builtin.Signedness {
switch (target.cpu.arch) {
.aarch64,
.aarch64_32,
.aarch64_be,
.arm,
.armeb,
.thumb,
.thumbeb,
=> return if (target.os.tag.isDarwin() or target.os.tag == .windows) .signed else .unsigned,
.powerpc, .powerpc64 => return if (target.os.tag.isDarwin()) .signed else .unsigned,
.powerpc64le,
.s390x,
.xcore,
.arc,
.msp430,
=> return .unsigned,
else => return .signed,
}
}
pub const CType = enum {
char,
short,