2019-11-06 14:14:15 -08:00
|
|
|
const Target = @import("std").Target;
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const CInt = struct {
|
2018-07-18 21:08:47 -07:00
|
|
|
id: Id,
|
|
|
|
zig_name: []const u8,
|
|
|
|
c_name: []const u8,
|
|
|
|
is_signed: bool,
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const Id = enum {
|
2018-07-18 21:08:47 -07:00
|
|
|
Short,
|
|
|
|
UShort,
|
|
|
|
Int,
|
|
|
|
UInt,
|
|
|
|
Long,
|
|
|
|
ULong,
|
|
|
|
LongLong,
|
|
|
|
ULongLong,
|
|
|
|
};
|
|
|
|
|
2019-06-09 16:24:24 -07:00
|
|
|
pub const list = [_]CInt{
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .Short,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_short",
|
|
|
|
.c_name = "short",
|
|
|
|
.is_signed = true,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .UShort,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_ushort",
|
|
|
|
.c_name = "unsigned short",
|
|
|
|
.is_signed = false,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .Int,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_int",
|
|
|
|
.c_name = "int",
|
|
|
|
.is_signed = true,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .UInt,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_uint",
|
|
|
|
.c_name = "unsigned int",
|
|
|
|
.is_signed = false,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .Long,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_long",
|
|
|
|
.c_name = "long",
|
|
|
|
.is_signed = true,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .ULong,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_ulong",
|
|
|
|
.c_name = "unsigned long",
|
|
|
|
.is_signed = false,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .LongLong,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_longlong",
|
|
|
|
.c_name = "long long",
|
|
|
|
.is_signed = true,
|
|
|
|
},
|
2018-11-13 05:08:37 -08:00
|
|
|
CInt{
|
2019-11-06 22:31:00 -08:00
|
|
|
.id = .ULongLong,
|
2018-07-18 21:08:47 -07:00
|
|
|
.zig_name = "c_ulonglong",
|
|
|
|
.c_name = "unsigned long long",
|
|
|
|
.is_signed = false,
|
|
|
|
},
|
|
|
|
};
|
2019-11-06 14:14:15 -08:00
|
|
|
|
2019-11-07 00:05:29 -08:00
|
|
|
pub fn sizeInBits(cint: CInt, self: Target) u32 {
|
2019-11-06 14:14:15 -08:00
|
|
|
const arch = self.getArch();
|
|
|
|
switch (self.getOs()) {
|
2019-12-04 11:42:18 -08:00
|
|
|
.freestanding, .other => switch (self.getArch()) {
|
2019-11-07 00:05:29 -08:00
|
|
|
.msp430 => switch (cint.id) {
|
2019-11-06 14:14:15 -08:00
|
|
|
.Short,
|
|
|
|
.UShort,
|
|
|
|
.Int,
|
|
|
|
.UInt,
|
|
|
|
=> return 16,
|
|
|
|
.Long,
|
|
|
|
.ULong,
|
|
|
|
=> return 32,
|
|
|
|
.LongLong,
|
|
|
|
.ULongLong,
|
|
|
|
=> return 64,
|
|
|
|
},
|
2019-11-07 00:05:29 -08:00
|
|
|
else => switch (cint.id) {
|
2019-11-06 14:14:15 -08:00
|
|
|
.Short,
|
|
|
|
.UShort,
|
|
|
|
=> return 16,
|
|
|
|
.Int,
|
|
|
|
.UInt,
|
|
|
|
=> return 32,
|
|
|
|
.Long,
|
|
|
|
.ULong,
|
|
|
|
=> return self.getArchPtrBitWidth(),
|
|
|
|
.LongLong,
|
|
|
|
.ULongLong,
|
|
|
|
=> return 64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
.linux,
|
|
|
|
.macosx,
|
|
|
|
.freebsd,
|
|
|
|
.openbsd,
|
2019-11-07 00:05:29 -08:00
|
|
|
=> switch (cint.id) {
|
2019-11-06 14:14:15 -08:00
|
|
|
.Short,
|
|
|
|
.UShort,
|
|
|
|
=> return 16,
|
|
|
|
.Int,
|
|
|
|
.UInt,
|
|
|
|
=> return 32,
|
|
|
|
.Long,
|
|
|
|
.ULong,
|
|
|
|
=> return self.getArchPtrBitWidth(),
|
|
|
|
.LongLong,
|
|
|
|
.ULongLong,
|
|
|
|
=> return 64,
|
|
|
|
},
|
|
|
|
|
2019-11-07 00:05:29 -08:00
|
|
|
.windows, .uefi => switch (cint.id) {
|
2019-11-06 14:14:15 -08:00
|
|
|
.Short,
|
|
|
|
.UShort,
|
|
|
|
=> return 16,
|
|
|
|
.Int,
|
|
|
|
.UInt,
|
|
|
|
=> return 32,
|
|
|
|
.Long,
|
|
|
|
.ULong,
|
|
|
|
.LongLong,
|
|
|
|
.ULongLong,
|
|
|
|
=> return 64,
|
|
|
|
},
|
|
|
|
|
|
|
|
.ananas,
|
|
|
|
.cloudabi,
|
|
|
|
.dragonfly,
|
|
|
|
.fuchsia,
|
|
|
|
.ios,
|
|
|
|
.kfreebsd,
|
|
|
|
.lv2,
|
|
|
|
.netbsd,
|
|
|
|
.solaris,
|
|
|
|
.haiku,
|
|
|
|
.minix,
|
|
|
|
.rtems,
|
|
|
|
.nacl,
|
|
|
|
.cnk,
|
|
|
|
.aix,
|
|
|
|
.cuda,
|
|
|
|
.nvcl,
|
|
|
|
.amdhsa,
|
|
|
|
.ps4,
|
|
|
|
.elfiamcu,
|
|
|
|
.tvos,
|
|
|
|
.watchos,
|
|
|
|
.mesa3d,
|
|
|
|
.contiki,
|
|
|
|
.amdpal,
|
|
|
|
.hermit,
|
|
|
|
.hurd,
|
|
|
|
.wasi,
|
|
|
|
.emscripten,
|
|
|
|
=> @panic("TODO specify the C integer type sizes for this OS"),
|
|
|
|
}
|
|
|
|
}
|
2018-07-18 21:08:47 -07:00
|
|
|
};
|