Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
\\#define __ATOMIC_CHAR16_T_LOCK_FREE 1
\\#define __ATOMIC_CHAR32_T_LOCK_FREE 1
\\#define __ATOMIC_WCHAR_T_LOCK_FREE 1
\\#define __ATOMIC_WINT_T_LOCK_FREE 1
\\#define __ATOMIC_SHORT_LOCK_FREE 1
\\#define __ATOMIC_INT_LOCK_FREE 1
\\#define __ATOMIC_LONG_LOCK_FREE 1
Expand All @@ -935,7 +936,15 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
}

// types
if (comp.getCharSignedness() == .unsigned) try w.writeAll("#define __CHAR_UNSIGNED__ 1\n");
if (comp.getCharSignedness() == .unsigned) {
try w.writeAll("#define __CHAR_UNSIGNED__ 1\n");
}
if (comp.type_store.wchar.signedness(comp) == .unsigned) {
try w.writeAll("#define __WCHAR_UNSIGNED__ 1\n");
}
if (comp.type_store.wint.signedness(comp) == .unsigned) {
try w.writeAll("#define __WINT_UNSIGNED__ 1\n");
}
try w.writeAll("#define __CHAR_BIT__ 8\n");

// int maxs
Expand All @@ -946,7 +955,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
try comp.generateIntMaxAndWidth(w, "LONG", .long);
try comp.generateIntMaxAndWidth(w, "LONG_LONG", .long_long);
try comp.generateIntMaxAndWidth(w, "WCHAR", comp.type_store.wchar);
// try comp.generateIntMax(w, "WINT", comp.type_store.wchar);
try comp.generateIntMaxAndWidth(w, "WINT", comp.type_store.wint);
try comp.generateIntMaxAndWidth(w, "INTMAX", comp.type_store.intmax);
try comp.generateIntMaxAndWidth(w, "SIZE", comp.type_store.size);
try comp.generateIntMaxAndWidth(w, "UINTMAX", try comp.type_store.intmax.makeIntUnsigned(comp));
Expand All @@ -970,7 +979,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
try comp.generateSizeofType(w, "__SIZEOF_PTRDIFF_T__", comp.type_store.ptrdiff);
try comp.generateSizeofType(w, "__SIZEOF_SIZE_T__", comp.type_store.size);
try comp.generateSizeofType(w, "__SIZEOF_WCHAR_T__", comp.type_store.wchar);
// try comp.generateSizeofType(w, "__SIZEOF_WINT_T__", .void_pointer);
try comp.generateSizeofType(w, "__SIZEOF_WINT_T__", comp.type_store.wint);

if (target.hasInt128()) {
try comp.generateSizeofType(w, "__SIZEOF_INT128__", .int128);
Expand All @@ -989,6 +998,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
try comp.generateTypeMacro(w, "__PTRDIFF_TYPE__", comp.type_store.ptrdiff);
try comp.generateTypeMacro(w, "__SIZE_TYPE__", comp.type_store.size);
try comp.generateTypeMacro(w, "__WCHAR_TYPE__", comp.type_store.wchar);
try comp.generateTypeMacro(w, "__WINT_TYPE__", comp.type_store.wint);
try comp.generateTypeMacro(w, "__CHAR16_TYPE__", comp.type_store.uint_least16_t);
try comp.generateTypeMacro(w, "__CHAR32_TYPE__", comp.type_store.uint_least32_t);

Expand Down
21 changes: 20 additions & 1 deletion src/aro/TypeStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,7 @@ attributes: std.ArrayList(Attribute) = .empty,
anon_name_arena: std.heap.ArenaAllocator.State = .{},

wchar: QualType = .invalid,
wint: QualType = .invalid,
uint_least16_t: QualType = .invalid,
uint_least32_t: QualType = .invalid,
ptrdiff: QualType = .invalid,
Expand Down Expand Up @@ -2098,13 +2099,14 @@ pub fn set(ts: *TypeStore, gpa: std.mem.Allocator, ty: Type, index: usize) !void

pub fn initNamedTypes(ts: *TypeStore, comp: *Compilation) !void {
const os = comp.target.os.tag;
const arch = comp.target.cpu.arch;
ts.wchar = switch (os) {
.openbsd, .netbsd => .int,
.ps4, .ps5 => .ushort,
.uefi => .ushort,
.windows => .ushort,
.driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => .int,
else => switch (comp.target.cpu.arch) {
else => switch (arch) {
.aarch64, .aarch64_be => .uint,
.arm, .armeb, .thumb, .thumbeb => .uint,
.ve, .msp430 => .uint,
Expand All @@ -2114,6 +2116,23 @@ pub fn initNamedTypes(ts: *TypeStore, comp: *Compilation) !void {
},
};

ts.wint = switch (os) {
.fuchsia => .uint,
.linux => .uint,
.openbsd => .int,
.uefi => .ushort,
.windows => .ushort,
else => switch (arch) {
.csky => .uint,
.loongarch32, .loongarch64 => .uint,
.riscv32, .riscv32be, .riscv64, .riscv64be => .uint,
.ve => .uint,
.xcore => .uint,
.xtensa, .xtensaeb => .uint,
else => .int,
},
};

const ptr_width = comp.target.ptrBitWidth();
ts.ptrdiff = if (os == .windows and ptr_width == 64)
.long_long
Expand Down