zig fmt on the standard library

This commit is contained in:
Andrew Kelley 2019-05-12 12:56:01 -04:00
parent ed5a6d74ad
commit c1793d6106
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
25 changed files with 141 additions and 214 deletions

View File

@ -29,7 +29,7 @@ const combinedTable = init: {
const mem = std.mem; const mem = std.mem;
const alpha = []u1{ const alpha = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -41,7 +41,7 @@ const combinedTable = init: {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
}; };
const lower = []u1{ const lower = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -53,7 +53,7 @@ const combinedTable = init: {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
}; };
const upper = []u1{ const upper = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -65,7 +65,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
const digit = []u1{ const digit = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -77,7 +77,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
const hex = []u1{ const hex = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -89,7 +89,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
const space = []u1{ const space = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -101,7 +101,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
const punct = []u1{ const punct = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -113,7 +113,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
}; };
const graph = []u1{ const graph = []u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15 // 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -129,7 +129,7 @@ const combinedTable = init: {
inline while (i < 128) : (i += 1) { inline while (i < 128) : (i += 1) {
table[i] = table[i] =
u8(alpha[i]) << @enumToInt(tIndex.Alpha) | u8(alpha[i]) << @enumToInt(tIndex.Alpha) |
u8(hex[i]) << @enumToInt(tIndex.Hex) | u8(hex[i]) << @enumToInt(tIndex.Hex) |
u8(space[i]) << @enumToInt(tIndex.Space) | u8(space[i]) << @enumToInt(tIndex.Space) |
u8(digit[i]) << @enumToInt(tIndex.Digit) | u8(digit[i]) << @enumToInt(tIndex.Digit) |
u8(lower[i]) << @enumToInt(tIndex.Lower) | u8(lower[i]) << @enumToInt(tIndex.Lower) |
@ -146,8 +146,8 @@ fn inTable(c: u8, t: tIndex) bool {
} }
pub fn isAlNum(c: u8) bool { pub fn isAlNum(c: u8) bool {
return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) | return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) |
u8(1) << @enumToInt(tIndex.Digit))) != 0; u8(1) << @enumToInt(tIndex.Digit))) != 0;
} }
pub fn isAlpha(c: u8) bool { pub fn isAlpha(c: u8) bool {

View File

@ -44,16 +44,22 @@ pub const pthread_attr_t = extern struct {
pub const msghdr = extern struct { pub const msghdr = extern struct {
/// optional address /// optional address
msg_name: ?*sockaddr, msg_name: ?*sockaddr,
/// size of address /// size of address
msg_namelen: socklen_t, msg_namelen: socklen_t,
/// scatter/gather array /// scatter/gather array
msg_iov: [*]iovec, msg_iov: [*]iovec,
/// # elements in msg_iov /// # elements in msg_iov
msg_iovlen: i32, msg_iovlen: i32,
/// ancillary data /// ancillary data
msg_control: ?*c_void, msg_control: ?*c_void,
/// ancillary data buffer len /// ancillary data buffer len
msg_controllen: socklen_t, msg_controllen: socklen_t,
/// flags on received message /// flags on received message
msg_flags: i32, msg_flags: i32,
}; };
@ -61,16 +67,22 @@ pub const msghdr = extern struct {
pub const msghdr_const = extern struct { pub const msghdr_const = extern struct {
/// optional address /// optional address
msg_name: ?*const sockaddr, msg_name: ?*const sockaddr,
/// size of address /// size of address
msg_namelen: socklen_t, msg_namelen: socklen_t,
/// scatter/gather array /// scatter/gather array
msg_iov: [*]iovec_const, msg_iov: [*]iovec_const,
/// # elements in msg_iov /// # elements in msg_iov
msg_iovlen: i32, msg_iovlen: i32,
/// ancillary data /// ancillary data
msg_control: ?*c_void, msg_control: ?*c_void,
/// ancillary data buffer len /// ancillary data buffer len
msg_controllen: socklen_t, msg_controllen: socklen_t,
/// flags on received message /// flags on received message
msg_flags: i32, msg_flags: i32,
}; };

View File

@ -44,16 +44,22 @@ pub const pthread_attr_t = extern struct {
pub const msghdr = extern struct { pub const msghdr = extern struct {
/// optional address /// optional address
msg_name: ?*sockaddr, msg_name: ?*sockaddr,
/// size of address /// size of address
msg_namelen: socklen_t, msg_namelen: socklen_t,
/// scatter/gather array /// scatter/gather array
msg_iov: [*]iovec, msg_iov: [*]iovec,
/// # elements in msg_iov /// # elements in msg_iov
msg_iovlen: i32, msg_iovlen: i32,
/// ancillary data /// ancillary data
msg_control: ?*c_void, msg_control: ?*c_void,
/// ancillary data buffer len /// ancillary data buffer len
msg_controllen: socklen_t, msg_controllen: socklen_t,
/// flags on received message /// flags on received message
msg_flags: i32, msg_flags: i32,
}; };
@ -61,16 +67,22 @@ pub const msghdr = extern struct {
pub const msghdr_const = extern struct { pub const msghdr_const = extern struct {
/// optional address /// optional address
msg_name: ?*const sockaddr, msg_name: ?*const sockaddr,
/// size of address /// size of address
msg_namelen: socklen_t, msg_namelen: socklen_t,
/// scatter/gather array /// scatter/gather array
msg_iov: [*]iovec_const, msg_iov: [*]iovec_const,
/// # elements in msg_iov /// # elements in msg_iov
msg_iovlen: i32, msg_iovlen: i32,
/// ancillary data /// ancillary data
msg_control: ?*c_void, msg_control: ?*c_void,
/// ancillary data buffer len /// ancillary data buffer len
msg_controllen: socklen_t, msg_controllen: socklen_t,
/// flags on received message /// flags on received message
msg_flags: i32, msg_flags: i32,
}; };

View File

@ -206,8 +206,8 @@ test "crypto.chacha20 test vector sunscreen" {
const input = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."; const input = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
var result: [114]u8 = undefined; var result: [114]u8 = undefined;
const key = []u8{ const key = []u8{
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 24, 25, 26, 27, 28, 29, 30, 31,
}; };

View File

@ -71,12 +71,12 @@ pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {
for (phdrs) |*phdr| { for (phdrs) |*phdr| {
if (phdr.p_type == elf.PT_DYNAMIC) { if (phdr.p_type == elf.PT_DYNAMIC) {
const ptr = @intToPtr([*]elf.Dyn, va_offset + phdr.p_vaddr); const ptr = @intToPtr([*]elf.Dyn, va_offset + phdr.p_vaddr);
break :init ptr[0..phdr.p_memsz / @sizeOf(elf.Dyn)]; break :init ptr[0 .. phdr.p_memsz / @sizeOf(elf.Dyn)];
} }
} }
// No PT_DYNAMIC means this is either a statically-linked program or a // No PT_DYNAMIC means this is either a statically-linked program or a
// badly corrupted one // badly corrupted one
return LinkMap.Iterator{.current = null}; return LinkMap.Iterator{ .current = null };
}; };
const link_map_ptr = init: { const link_map_ptr = init: {
@ -93,13 +93,13 @@ pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {
// second slot // second slot
break :init @intToPtr(?*LinkMap, got_table[1]); break :init @intToPtr(?*LinkMap, got_table[1]);
}, },
else => { } else => {},
} }
} }
return error.InvalidExe; return error.InvalidExe;
}; };
return LinkMap.Iterator{.current = link_map_ptr}; return LinkMap.Iterator{ .current = link_map_ptr };
} }
pub const LinuxDynLib = struct { pub const LinuxDynLib = struct {

View File

@ -34,7 +34,7 @@ pub fn Locked(comptime T: type) type {
pub async fn acquire(self: *Self) HeldLock { pub async fn acquire(self: *Self) HeldLock {
return HeldLock{ return HeldLock{
// TODO guaranteed allocation elision // TODO guaranteed allocation elision
.held = await (async self.lock.acquire() catch unreachable), .held = await (async self.lock.acquire() catch unreachable),
.value = &self.private_data, .value = &self.private_data,
}; };

View File

@ -183,7 +183,7 @@ pub fn formatType(
} }
try output(context, @memberName(T, field_i)); try output(context, @memberName(T, field_i));
try output(context, " = "); try output(context, " = ");
try formatType(@field(value, @memberName(T, field_i)), "", context, Errors, output, max_depth-1); try formatType(@field(value, @memberName(T, field_i)), "", context, Errors, output, max_depth - 1);
} }
try output(context, " }"); try output(context, " }");
}, },
@ -198,7 +198,7 @@ pub fn formatType(
try output(context, " = "); try output(context, " = ");
inline for (info.fields) |u_field| { inline for (info.fields) |u_field| {
if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) { if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) {
try formatType(@field(value, u_field.name), "", context, Errors, output, max_depth-1); try formatType(@field(value, u_field.name), "", context, Errors, output, max_depth - 1);
} }
} }
try output(context, " }"); try output(context, " }");

View File

@ -155,7 +155,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
/// capacity is greater than the current capacity. /// capacity is greater than the current capacity.
/// New capacity must be a power of two. /// New capacity must be a power of two.
fn ensureCapacityExact(self: *Self, new_capacity: usize) !void { fn ensureCapacityExact(self: *Self, new_capacity: usize) !void {
const is_power_of_two = new_capacity & (new_capacity-1) == 0; const is_power_of_two = new_capacity & (new_capacity - 1) == 0;
assert(is_power_of_two); assert(is_power_of_two);
if (new_capacity <= self.entries.len) { if (new_capacity <= self.entries.len) {
@ -474,9 +474,9 @@ test "ensure capacity" {
try map.ensureCapacity(20); try map.ensureCapacity(20);
const initialCapacity = map.entries.len; const initialCapacity = map.entries.len;
testing.expect(initialCapacity >= 20); testing.expect(initialCapacity >= 20);
var i : i32 = 0; var i: i32 = 0;
while (i < 20) : (i += 1) { while (i < 20) : (i += 1) {
testing.expect(map.putAssumeCapacity(i, i+10) == null); testing.expect(map.putAssumeCapacity(i, i + 10) == null);
} }
// shouldn't resize from putAssumeCapacity // shouldn't resize from putAssumeCapacity
testing.expect(initialCapacity == map.entries.len); testing.expect(initialCapacity == map.entries.len);

View File

@ -86,8 +86,7 @@ const tls_dtv_offset = switch (builtin.arch) {
}; };
// Per-thread storage for Zig's use // Per-thread storage for Zig's use
const CustomData = packed struct { const CustomData = packed struct {};
};
// Dynamic Thread Vector // Dynamic Thread Vector
const DTV = packed struct { const DTV = packed struct {
@ -109,14 +108,14 @@ pub var tls_image: ?TLSImage = null;
pub fn setThreadPointer(addr: usize) void { pub fn setThreadPointer(addr: usize) void {
switch (builtin.arch) { switch (builtin.arch) {
.x86_64 => { .x86_64 => {
const rc = std.os.linux.syscall2(std.os.linux.SYS_arch_prctl, const rc = std.os.linux.syscall2(std.os.linux.SYS_arch_prctl, std.os.linux.ARCH_SET_FS, addr);
std.os.linux.ARCH_SET_FS, addr);
assert(rc == 0); assert(rc == 0);
}, },
.aarch64 => { .aarch64 => {
asm volatile ( asm volatile (
\\ msr tpidr_el0, %[addr] \\ msr tpidr_el0, %[addr]
: : [addr] "r" (addr) :
: [addr] "r" (addr)
); );
}, },
else => @compileError("Unsupported architecture"), else => @compileError("Unsupported architecture"),
@ -137,7 +136,7 @@ pub fn initTLS() void {
switch (auxv[i].a_type) { switch (auxv[i].a_type) {
elf.AT_PHENT => at_phent = auxv[i].a_un.a_val, elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,
elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val, elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,
elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val, elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,
else => continue, else => continue,
} }
} }
@ -151,7 +150,7 @@ pub fn initTLS() void {
for (phdrs) |*phdr| { for (phdrs) |*phdr| {
switch (phdr.p_type) { switch (phdr.p_type) {
elf.PT_PHDR => img_base = at_phdr - phdr.p_vaddr, elf.PT_PHDR => img_base = at_phdr - phdr.p_vaddr,
elf.PT_TLS => tls_phdr = phdr, elf.PT_TLS => tls_phdr = phdr,
else => continue, else => continue,
} }
} }
@ -194,7 +193,7 @@ pub fn initTLS() void {
dtv_offset = l; dtv_offset = l;
l += @sizeOf(DTV); l += @sizeOf(DTV);
break :blk l; break :blk l;
} },
}; };
tls_image = TLSImage{ tls_image = TLSImage{
@ -238,8 +237,7 @@ pub fn allocateTLS(size: usize) usize {
return @ptrToInt(&main_thread_tls_buffer); return @ptrToInt(&main_thread_tls_buffer);
} }
const addr = posix.mmap(null, size, posix.PROT_READ | posix.PROT_WRITE, const addr = posix.mmap(null, size, posix.PROT_READ | posix.PROT_WRITE, posix.MAP_PRIVATE | posix.MAP_ANONYMOUS, -1, 0);
posix.MAP_PRIVATE | posix.MAP_ANONYMOUS, -1, 0);
if (posix.getErrno(addr) != 0) @panic("out of memory"); if (posix.getErrno(addr) != 0) @panic("out of memory");

View File

@ -1,4 +1,3 @@
use @import("../windows.zig"); use @import("../windows.zig");
pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT; pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;

View File

@ -338,7 +338,10 @@ extern fn __umoddi3(a: u64, b: u64) u64 {
return r; return r;
} }
extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct{q: u32, r: u32} { extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {
q: u32,
r: u32,
} {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined; var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined;
@ -346,7 +349,10 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct{q: u32, r: u32} {
return result; return result;
} }
extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct{q: u64, r: u64} { extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {
q: u64,
r: u64,
} {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined; var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined;
@ -354,7 +360,10 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct{q: u64, r: u64} {
return result; return result;
} }
extern fn __aeabi_idivmod(n: i32, d: i32) extern struct{q: i32, r: i32} { extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {
q: i32,
r: i32,
} {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_idivmod).ReturnType = undefined; var result: @typeOf(__aeabi_idivmod).ReturnType = undefined;
@ -362,7 +371,10 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct{q: i32, r: i32} {
return result; return result;
} }
extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct{q: i64, r:i64} { extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct {
q: i64,
r: i64,
} {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined; var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined;

View File

@ -4,7 +4,7 @@ const testing = @import("std").testing;
fn test__ashrti3(a: i128, b: i32, expected: i128) void { fn test__ashrti3(a: i128, b: i32, expected: i128) void {
const x = __ashrti3(a, b); const x = __ashrti3(a, b);
// @import("std").debug.warn("got 0x{x}\nexp 0x{x}\n", @truncate(u64, // @import("std").debug.warn("got 0x{x}\nexp 0x{x}\n", @truncate(u64,
// @bitCast(u128, x) >> 64), @truncate(u64, @bitCast(u128, expected)) >> 64); // @bitCast(u128, x) >> 64), @truncate(u64, @bitCast(u128, expected)) >> 64);
testing.expect(x == expected); testing.expect(x == expected);
} }

View File

@ -12,7 +12,6 @@ fn test__fixdfdi(a: f64, expected: i64) void {
test "fixdfdi" { test "fixdfdi" {
//warn("\n"); //warn("\n");
test__fixdfdi(-math.f64_max, math.minInt(i64)); test__fixdfdi(-math.f64_max, math.minInt(i64));
test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));

View File

@ -12,7 +12,6 @@ fn test__fixdfsi(a: f64, expected: i32) void {
test "fixdfsi" { test "fixdfsi" {
//warn("\n"); //warn("\n");
test__fixdfsi(-math.f64_max, math.minInt(i32)); test__fixdfsi(-math.f64_max, math.minInt(i32));
test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
@ -22,10 +21,10 @@ test "fixdfsi" {
test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
test__fixdfsi(-0x1.0000000000001p+63, -0x80000000); test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);
test__fixdfsi(-0x1.0000000000000p+63, -0x80000000); test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);
test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000); test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);
test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000); test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);

View File

@ -12,7 +12,6 @@ fn test__fixdfti(a: f64, expected: i128) void {
test "fixdfti" { test "fixdfti" {
//warn("\n"); //warn("\n");
test__fixdfti(-math.f64_max, math.minInt(i128)); test__fixdfti(-math.f64_max, math.minInt(i128));
test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));

View File

@ -82,7 +82,7 @@ test "fixint.i32" {
test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32)); test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32));
test__fixint(f64, i32, f64(math.minInt(i32))+1, math.minInt(i32)+1); test__fixint(f64, i32, f64(math.minInt(i32)) + 1, math.minInt(i32) + 1);
test__fixint(f64, i32, -2.0, -2); test__fixint(f64, i32, -2.0, -2);
test__fixint(f64, i32, -1.9, -1); test__fixint(f64, i32, -1.9, -1);
test__fixint(f64, i32, -1.1, -1); test__fixint(f64, i32, -1.1, -1);
@ -96,7 +96,7 @@ test "fixint.i32" {
test__fixint(f64, i32, 0.1, 0); test__fixint(f64, i32, 0.1, 0);
test__fixint(f64, i32, 0.9, 0); test__fixint(f64, i32, 0.9, 0);
test__fixint(f64, i32, 1.0, 1); test__fixint(f64, i32, 1.0, 1);
test__fixint(f64, i32, f64(math.maxInt(i32))-1, math.maxInt(i32)-1); test__fixint(f64, i32, f64(math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32)); test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32));
test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
@ -106,8 +106,8 @@ test "fixint.i64" {
test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64)); test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64));
test__fixint(f64, i64, f64(math.minInt(i64))+1, math.minInt(i64)); test__fixint(f64, i64, f64(math.minInt(i64)) + 1, math.minInt(i64));
test__fixint(f64, i64, f64(math.minInt(i64)/2), math.minInt(i64)/2); test__fixint(f64, i64, f64(math.minInt(i64) / 2), math.minInt(i64) / 2);
test__fixint(f64, i64, -2.0, -2); test__fixint(f64, i64, -2.0, -2);
test__fixint(f64, i64, -1.9, -1); test__fixint(f64, i64, -1.9, -1);
test__fixint(f64, i64, -1.1, -1); test__fixint(f64, i64, -1.1, -1);
@ -121,7 +121,7 @@ test "fixint.i64" {
test__fixint(f64, i64, 0.1, 0); test__fixint(f64, i64, 0.1, 0);
test__fixint(f64, i64, 0.9, 0); test__fixint(f64, i64, 0.9, 0);
test__fixint(f64, i64, 1.0, 1); test__fixint(f64, i64, 1.0, 1);
test__fixint(f64, i64, f64(math.maxInt(i64))-1, math.maxInt(i64)); test__fixint(f64, i64, f64(math.maxInt(i64)) - 1, math.maxInt(i64));
test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64)); test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64));
test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
@ -131,7 +131,7 @@ test "fixint.i128" {
test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128)); test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128));
test__fixint(f64, i128, f64(math.minInt(i128))+1, math.minInt(i128)); test__fixint(f64, i128, f64(math.minInt(i128)) + 1, math.minInt(i128));
test__fixint(f64, i128, -2.0, -2); test__fixint(f64, i128, -2.0, -2);
test__fixint(f64, i128, -1.9, -1); test__fixint(f64, i128, -1.9, -1);
test__fixint(f64, i128, -1.1, -1); test__fixint(f64, i128, -1.1, -1);
@ -145,7 +145,7 @@ test "fixint.i128" {
test__fixint(f64, i128, 0.1, 0); test__fixint(f64, i128, 0.1, 0);
test__fixint(f64, i128, 0.9, 0); test__fixint(f64, i128, 0.9, 0);
test__fixint(f64, i128, 1.0, 1); test__fixint(f64, i128, 1.0, 1);
test__fixint(f64, i128, f64(math.maxInt(i128))-1, math.maxInt(i128)); test__fixint(f64, i128, f64(math.maxInt(i128)) - 1, math.maxInt(i128));
test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128)); test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128));
test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));

View File

@ -12,7 +12,6 @@ fn test__fixsfdi(a: f32, expected: i64) void {
test "fixsfdi" { test "fixsfdi" {
//warn("\n"); //warn("\n");
test__fixsfdi(-math.f32_max, math.minInt(i64)); test__fixsfdi(-math.f32_max, math.minInt(i64));
test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));

View File

@ -12,7 +12,6 @@ fn test__fixsfsi(a: f32, expected: i32) void {
test "fixsfsi" { test "fixsfsi" {
//warn("\n"); //warn("\n");
test__fixsfsi(-math.f32_max, math.minInt(i32)); test__fixsfsi(-math.f32_max, math.minInt(i32));
test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
@ -22,10 +21,10 @@ test "fixsfsi" {
test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
test__fixsfsi(-0x1.0000000000001p+63, -0x80000000); test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);
test__fixsfsi(-0x1.0000000000000p+63, -0x80000000); test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);
test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000); test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);
test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000); test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);

View File

@ -12,7 +12,6 @@ fn test__fixsfti(a: f32, expected: i128) void {
test "fixsfti" { test "fixsfti" {
//warn("\n"); //warn("\n");
test__fixsfti(-math.f32_max, math.minInt(i128)); test__fixsfti(-math.f32_max, math.minInt(i128));
test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
@ -30,7 +29,7 @@ test "fixsfti" {
test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000); test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);
test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);

View File

@ -12,7 +12,6 @@ fn test__fixtfdi(a: f128, expected: i64) void {
test "fixtfdi" { test "fixtfdi" {
//warn("\n"); //warn("\n");
test__fixtfdi(-math.f128_max, math.minInt(i64)); test__fixtfdi(-math.f128_max, math.minInt(i64));
test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
@ -22,10 +21,10 @@ test "fixtfdi" {
test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000); test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);
test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000); test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);
test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000); test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);
test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000); test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);

View File

@ -12,7 +12,6 @@ fn test__fixtfsi(a: f128, expected: i32) void {
test "fixtfsi" { test "fixtfsi" {
//warn("\n"); //warn("\n");
test__fixtfsi(-math.f128_max, math.minInt(i32)); test__fixtfsi(-math.f128_max, math.minInt(i32));
test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
@ -22,10 +21,10 @@ test "fixtfsi" {
test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
test__fixtfsi(-0x1.0000000000001p+63, -0x80000000); test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);
test__fixtfsi(-0x1.0000000000000p+63, -0x80000000); test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);
test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000); test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);
test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000); test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);

View File

@ -12,7 +12,6 @@ fn test__fixtfti(a: f128, expected: i128) void {
test "fixtfti" { test "fixtfti" {
//warn("\n"); //warn("\n");
test__fixtfti(-math.f128_max, math.minInt(i128)); test__fixtfti(-math.f128_max, math.minInt(i128));
test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));

View File

@ -51,7 +51,7 @@ pub nakedcc fn zig_probe_stack() void {
\\ ret \\ ret
); );
}, },
else => { } else => {},
} }
unreachable; unreachable;
@ -103,7 +103,7 @@ fn win_probe_stack_only() void {
\\ ret \\ ret
); );
}, },
else => { } else => {},
} }
unreachable; unreachable;
@ -159,9 +159,9 @@ fn win_probe_stack_adjust_sp() void {
\\ push (%%eax) \\ push (%%eax)
\\ sub %%esp,%%eax \\ sub %%esp,%%eax
\\ ret \\ ret
); );
}, },
else => { }, else => {},
} }
unreachable; unreachable;
@ -189,7 +189,7 @@ pub nakedcc fn __chkstk() void {
switch (builtin.arch) { switch (builtin.arch) {
.i386 => @inlineCall(win_probe_stack_adjust_sp), .i386 => @inlineCall(win_probe_stack_adjust_sp),
.x86_64 => @inlineCall(win_probe_stack_only), .x86_64 => @inlineCall(win_probe_stack_only),
else => unreachable else => unreachable,
} }
} }
pub nakedcc fn ___chkstk() void { pub nakedcc fn ___chkstk() void {

View File

@ -1,11 +1,7 @@
const builtin = @import("builtin"); const builtin = @import("builtin");
const math = @import("index.zig").math; const math = @import("index.zig").math;
pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
pub fn doClientRequest(default: usize, request: usize,
a1: usize, a2: usize, a3: usize, a4: usize, a5: usize
) usize
{
if (!builtin.valgrind_support) { if (!builtin.valgrind_support) {
return default; return default;
} }
@ -16,8 +12,8 @@ pub fn doClientRequest(default: usize, request: usize,
\\ roll $3, %%edi ; roll $13, %%edi \\ roll $3, %%edi ; roll $13, %%edi
\\ roll $29, %%edi ; roll $19, %%edi \\ roll $29, %%edi ; roll $19, %%edi
\\ xchgl %%ebx,%%ebx \\ xchgl %%ebx,%%ebx
: [_] "={edx}" (-> usize) : [_] "={edx}" (-> usize)
: [_] "{eax}" (&[]usize{request, a1, a2, a3, a4, a5}), : [_] "{eax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),
[_] "0" (default) [_] "0" (default)
: "cc", "memory" : "cc", "memory"
); );
@ -27,8 +23,8 @@ pub fn doClientRequest(default: usize, request: usize,
\\ rolq $3, %%rdi ; rolq $13, %%rdi \\ rolq $3, %%rdi ; rolq $13, %%rdi
\\ rolq $61, %%rdi ; rolq $51, %%rdi \\ rolq $61, %%rdi ; rolq $51, %%rdi
\\ xchgq %%rbx,%%rbx \\ xchgq %%rbx,%%rbx
: [_] "={rdx}" (-> usize) : [_] "={rdx}" (-> usize)
: [_] "{rax}" (&[]usize{request, a1, a2, a3, a4, a5}), : [_] "{rax}" (&[]usize{ request, a1, a2, a3, a4, a5 }),
[_] "0" (default) [_] "0" (default)
: "cc", "memory" : "cc", "memory"
); );
@ -42,11 +38,10 @@ pub fn doClientRequest(default: usize, request: usize,
// mips64 // mips64
else => { else => {
return default; return default;
} },
} }
} }
pub const ClientRequest = extern enum { pub const ClientRequest = extern enum {
RunningOnValgrind = 4097, RunningOnValgrind = 4097,
DiscardTranslations = 4098, DiscardTranslations = 4098,
@ -81,59 +76,39 @@ pub const ClientRequest = extern enum {
InnerThreads = 6402, InnerThreads = 6402,
}; };
pub fn ToolBase(base: [2]u8) u32 { pub fn ToolBase(base: [2]u8) u32 {
return (u32(base[0]&0xff) << 24) | (u32(base[1]&0xff) << 16); return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16);
} }
pub fn IsTool(base: [2]u8, code: usize) bool { pub fn IsTool(base: [2]u8, code: usize) bool {
return ToolBase(base) == (code & 0xffff0000); return ToolBase(base) == (code & 0xffff0000);
} }
fn doClientRequestExpr(default: usize, request: ClientRequest, fn doClientRequestExpr(default: usize, request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
a1: usize, a2: usize, a3: usize, a4: usize, a5: usize return doClientRequest(default, @intCast(usize, @enumToInt(request)), a1, a2, a3, a4, a5);
) usize
{
return doClientRequest(
default,
@intCast(usize, @enumToInt(request)),
a1, a2, a3, a4, a5);
} }
fn doClientRequestStmt(request: ClientRequest, fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
a1: usize, a2: usize, a3: usize, a4: usize, a5: usize
) void
{
_ = doClientRequestExpr(0, request, a1, a2, a3, a4, a5); _ = doClientRequestExpr(0, request, a1, a2, a3, a4, a5);
} }
/// Returns the number of Valgrinds this code is running under. That /// Returns the number of Valgrinds this code is running under. That
/// is, 0 if running natively, 1 if running under Valgrind, 2 if /// is, 0 if running natively, 1 if running under Valgrind, 2 if
/// running under Valgrind which is running under another Valgrind, /// running under Valgrind which is running under another Valgrind,
/// etc. /// etc.
pub fn runningOnValgrind() usize { pub fn runningOnValgrind() usize {
return doClientRequestExpr(0, return doClientRequestExpr(0, ClientRequest.RunningOnValgrind, 0, 0, 0, 0, 0);
ClientRequest.RunningOnValgrind,
0, 0, 0, 0, 0);
} }
/// Discard translation of code in the slice qzz. Useful if you are debugging /// Discard translation of code in the slice qzz. Useful if you are debugging
/// a JITter or some such, since it provides a way to make sure valgrind will /// a JITter or some such, since it provides a way to make sure valgrind will
/// retranslate the invalidated area. Returns no value. /// retranslate the invalidated area. Returns no value.
pub fn discardTranslations(qzz: []const u8) void { pub fn discardTranslations(qzz: []const u8) void {
doClientRequestStmt(ClientRequest.DiscardTranslations, doClientRequestStmt(ClientRequest.DiscardTranslations, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
@ptrToInt(qzz.ptr), qzz.len,
0, 0, 0);
} }
pub fn innerThreads(qzz: [*]u8) void { pub fn innerThreads(qzz: [*]u8) void {
doClientRequestStmt(ClientRequest.InnerThreads, doClientRequestStmt(ClientRequest.InnerThreads, qzz, 0, 0, 0, 0);
qzz,
0, 0, 0, 0);
} }
//pub fn printf(format: [*]const u8, args: ...) usize { //pub fn printf(format: [*]const u8, args: ...) usize {
// return doClientRequestExpr(0, // return doClientRequestExpr(0,
// ClientRequest.PrintfValistByRef, // ClientRequest.PrintfValistByRef,
@ -141,7 +116,6 @@ pub fn innerThreads(qzz: [*]u8) void {
// 0, 0, 0); // 0, 0, 0);
//} //}
//pub fn printfBacktrace(format: [*]const u8, args: ...) usize { //pub fn printfBacktrace(format: [*]const u8, args: ...) usize {
// return doClientRequestExpr(0, // return doClientRequestExpr(0,
// ClientRequest.PrintfBacktraceValistByRef, // ClientRequest.PrintfBacktraceValistByRef,
@ -149,161 +123,105 @@ pub fn innerThreads(qzz: [*]u8) void {
// 0, 0, 0); // 0, 0, 0);
//} //}
pub fn nonSIMDCall0(func: fn (usize) usize) usize {
pub fn nonSIMDCall0(func: fn(usize) usize) usize { return doClientRequestExpr(0, ClientRequest.ClientCall0, @ptrToInt(func), 0, 0, 0, 0);
return doClientRequestExpr(0,
ClientRequest.ClientCall0,
@ptrToInt(func),
0, 0, 0, 0);
} }
pub fn nonSIMDCall1(func: fn(usize, usize) usize, a1: usize) usize { pub fn nonSIMDCall1(func: fn (usize, usize) usize, a1: usize) usize {
return doClientRequestExpr(0, return doClientRequestExpr(0, ClientRequest.ClientCall1, @ptrToInt(func), a1, 0, 0, 0);
ClientRequest.ClientCall1,
@ptrToInt(func), a1,
0, 0, 0);
} }
pub fn nonSIMDCall2(func: fn(usize, usize, usize) usize, pub fn nonSIMDCall2(func: fn (usize, usize, usize) usize, a1: usize, a2: usize) usize {
a1: usize, a2: usize) usize return doClientRequestExpr(0, ClientRequest.ClientCall2, @ptrToInt(func), a1, a2, 0, 0);
{
return doClientRequestExpr(0,
ClientRequest.ClientCall2,
@ptrToInt(func), a1, a2,
0, 0);
} }
pub fn nonSIMDCall3(func: fn(usize, usize, usize, usize) usize, pub fn nonSIMDCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: usize, a3: usize) usize {
a1: usize, a2: usize, a3: usize) usize return doClientRequestExpr(0, ClientRequest.ClientCall3, @ptrToInt(func), a1, a2, a3, 0);
{
return doClientRequestExpr(0,
ClientRequest.ClientCall3,
@ptrToInt(func), a1, a2, a3,
0);
} }
/// Counts the number of errors that have been recorded by a tool. Nb: /// Counts the number of errors that have been recorded by a tool. Nb:
/// the tool must record the errors with VG_(maybe_record_error)() or /// the tool must record the errors with VG_(maybe_record_error)() or
/// VG_(unique_error)() for them to be counted. /// VG_(unique_error)() for them to be counted.
pub fn countErrors() usize { pub fn countErrors() usize {
return doClientRequestExpr(0, // default return return doClientRequestExpr(0, // default return
ClientRequest.CountErrors, ClientRequest.CountErrors, 0, 0, 0, 0, 0);
0, 0, 0, 0, 0);
} }
pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void { pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void {
doClientRequestStmt(ClientRequest.MalloclikeBlock, doClientRequestStmt(ClientRequest.MalloclikeBlock, @ptrToInt(mem.ptr), mem.len, rzB, @boolToInt(is_zeroed), 0);
@ptrToInt(mem.ptr), mem.len, rzB, @boolToInt(is_zeroed),
0);
} }
pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void { pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void {
doClientRequestStmt(ClientRequest.ResizeinplaceBlock, doClientRequestStmt(ClientRequest.ResizeinplaceBlock, @ptrToInt(oldmem.ptr), oldmem.len, newsize, rzB, 0);
@ptrToInt(oldmem.ptr), oldmem.len, newsize, rzB,
0);
} }
pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void { pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void {
doClientRequestStmt(ClientRequest.FreelikeBlock, doClientRequestStmt(ClientRequest.FreelikeBlock, @ptrToInt(addr), rzB, 0, 0, 0);
@ptrToInt(addr), rzB,
0, 0, 0);
} }
/// Create a memory pool. /// Create a memory pool.
pub const MempoolFlags = extern enum { pub const MempoolFlags = extern enum {
AutoFree = 1, AutoFree = 1,
MetaPool = 2, MetaPool = 2,
}; };
pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void { pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void {
doClientRequestStmt(ClientRequest.CreateMempool, doClientRequestStmt(ClientRequest.CreateMempool, @ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags, 0);
@ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags,
0);
} }
/// Destroy a memory pool. /// Destroy a memory pool.
pub fn destroyMempool(pool: [*]u8) void { pub fn destroyMempool(pool: [*]u8) void {
doClientRequestStmt(ClientRequest.DestroyMempool, doClientRequestStmt(ClientRequest.DestroyMempool, pool, 0, 0, 0, 0);
pool,
0, 0, 0, 0);
} }
/// Associate a piece of memory with a memory pool. /// Associate a piece of memory with a memory pool.
pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void { pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void {
doClientRequestStmt(ClientRequest.MempoolAlloc, doClientRequestStmt(ClientRequest.MempoolAlloc, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0);
@ptrToInt(pool), @ptrToInt(mem.ptr), mem.len,
0, 0);
} }
/// Disassociate a piece of memory from a memory pool. /// Disassociate a piece of memory from a memory pool.
pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void { pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void {
doClientRequestStmt(ClientRequest.MempoolFree, doClientRequestStmt(ClientRequest.MempoolFree, @ptrToInt(pool), @ptrToInt(addr), 0, 0, 0);
@ptrToInt(pool), @ptrToInt(addr),
0, 0, 0);
} }
/// Disassociate any pieces outside a particular range. /// Disassociate any pieces outside a particular range.
pub fn mempoolTrim(pool: [*]u8, mem: []u8) void { pub fn mempoolTrim(pool: [*]u8, mem: []u8) void {
doClientRequestStmt(ClientRequest.MempoolTrim, doClientRequestStmt(ClientRequest.MempoolTrim, @ptrToInt(pool), @ptrToInt(mem.ptr), mem.len, 0, 0);
@ptrToInt(pool), @ptrToInt(mem.ptr), mem.len,
0, 0);
} }
/// Resize and/or move a piece associated with a memory pool. /// Resize and/or move a piece associated with a memory pool.
pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void { pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void {
doClientRequestStmt(ClientRequest.MoveMempool, doClientRequestStmt(ClientRequest.MoveMempool, @ptrToInt(poolA), @ptrToInt(poolB), 0, 0, 0);
@ptrToInt(poolA), @ptrToInt(poolB),
0, 0, 0);
} }
/// Resize and/or move a piece associated with a memory pool. /// Resize and/or move a piece associated with a memory pool.
pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void { pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void {
doClientRequestStmt(ClientRequest.MempoolChange, doClientRequestStmt(ClientRequest.MempoolChange, @ptrToInt(pool), @ptrToInt(addrA), @ptrToInt(mem.ptr), mem.len, 0);
@ptrToInt(pool), @ptrToInt(addrA), @ptrToInt(mem.ptr), mem.len,
0);
} }
/// Return if a mempool exists. /// Return if a mempool exists.
pub fn mempoolExists(pool: [*]u8) bool { pub fn mempoolExists(pool: [*]u8) bool {
return doClientRequestExpr(0, return doClientRequestExpr(0, ClientRequest.MempoolExists, @ptrToInt(pool), 0, 0, 0, 0) != 0;
ClientRequest.MempoolExists,
@ptrToInt(pool),
0, 0, 0, 0) != 0;
} }
/// Mark a piece of memory as being a stack. Returns a stack id. /// Mark a piece of memory as being a stack. Returns a stack id.
/// start is the lowest addressable stack byte, end is the highest /// start is the lowest addressable stack byte, end is the highest
/// addressable stack byte. /// addressable stack byte.
pub fn stackRegister(stack: []u8) usize { pub fn stackRegister(stack: []u8) usize {
return doClientRequestExpr(0, return doClientRequestExpr(0, ClientRequest.StackRegister, @ptrToInt(stack.ptr), @ptrToInt(stack.ptr) + stack.len, 0, 0, 0);
ClientRequest.StackRegister,
@ptrToInt(stack.ptr), @ptrToInt(stack.ptr) + stack.len,
0, 0, 0);
} }
/// Unmark the piece of memory associated with a stack id as being a stack. /// Unmark the piece of memory associated with a stack id as being a stack.
pub fn stackDeregister(id: usize) void { pub fn stackDeregister(id: usize) void {
doClientRequestStmt(ClientRequest.StackDeregister, doClientRequestStmt(ClientRequest.StackDeregister, id, 0, 0, 0, 0);
id,
0, 0, 0, 0);
} }
/// Change the start and end address of the stack id. /// Change the start and end address of the stack id.
/// start is the new lowest addressable stack byte, end is the new highest /// start is the new lowest addressable stack byte, end is the new highest
/// addressable stack byte. /// addressable stack byte.
pub fn stackChange(id: usize, newstack: []u8) void { pub fn stackChange(id: usize, newstack: []u8) void {
doClientRequestStmt(ClientRequest.StackChange, doClientRequestStmt(ClientRequest.StackChange, id, @ptrToInt(newstack.ptr), @ptrToInt(newstack.ptr) + newstack.len, 0, 0);
id, @ptrToInt(newstack.ptr), @ptrToInt(newstack.ptr) + newstack.len,
0, 0);
} }
// Load PDB debug info for Wine PE image_map. // Load PDB debug info for Wine PE image_map.
// pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void { // pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void {
// doClientRequestStmt(ClientRequest.LoadPdbDebuginfo, // doClientRequestStmt(ClientRequest.LoadPdbDebuginfo,
@ -311,19 +229,14 @@ pub fn stackChange(id: usize, newstack: []u8) void {
// 0); // 0);
// } // }
/// Map a code address to a source file name and line number. buf64 /// Map a code address to a source file name and line number. buf64
/// must point to a 64-byte buffer in the caller's address space. The /// must point to a 64-byte buffer in the caller's address space. The
/// result will be dumped in there and is guaranteed to be zero /// result will be dumped in there and is guaranteed to be zero
/// terminated. If no info is found, the first byte is set to zero. /// terminated. If no info is found, the first byte is set to zero.
pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize { pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize {
return doClientRequestExpr(0, return doClientRequestExpr(0, ClientRequest.MapIpToSrcloc, @ptrToInt(addr), @ptrToInt(&buf64[0]), 0, 0, 0);
ClientRequest.MapIpToSrcloc,
@ptrToInt(addr), @ptrToInt(&buf64[0]),
0, 0, 0);
} }
/// Disable error reporting for this thread. Behaves in a stack like /// Disable error reporting for this thread. Behaves in a stack like
/// way, so you can safely call this multiple times provided that /// way, so you can safely call this multiple times provided that
/// enableErrorReporting() is called the same number of times /// enableErrorReporting() is called the same number of times
@ -333,31 +246,22 @@ pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize {
/// reporting. Child threads do not inherit this setting from their /// reporting. Child threads do not inherit this setting from their
/// parents -- they are always created with reporting enabled. /// parents -- they are always created with reporting enabled.
pub fn disableErrorReporting() void { pub fn disableErrorReporting() void {
doClientRequestStmt(ClientRequest.ChangeErrDisablement, doClientRequestStmt(ClientRequest.ChangeErrDisablement, 1, 0, 0, 0, 0);
1,
0, 0, 0, 0);
} }
/// Re-enable error reporting, (see disableErrorReporting()) /// Re-enable error reporting, (see disableErrorReporting())
pub fn enableErrorReporting() void { pub fn enableErrorReporting() void {
doClientRequestStmt(ClientRequest.ChangeErrDisablement, doClientRequestStmt(ClientRequest.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0);
math.maxInt(usize),
0, 0, 0, 0);
} }
/// Execute a monitor command from the client program. /// Execute a monitor command from the client program.
/// If a connection is opened with GDB, the output will be sent /// If a connection is opened with GDB, the output will be sent
/// according to the output mode set for vgdb. /// according to the output mode set for vgdb.
/// If no connection is opened, output will go to the log output. /// If no connection is opened, output will go to the log output.
/// Returns 1 if command not recognised, 0 otherwise. /// Returns 1 if command not recognised, 0 otherwise.
pub fn monitorCommand(command: [*]u8) bool { pub fn monitorCommand(command: [*]u8) bool {
return doClientRequestExpr(0, return doClientRequestExpr(0, ClientRequest.GdbMonitorCommand, @ptrToInt(command.ptr), 0, 0, 0, 0) != 0;
ClientRequest.GdbMonitorCommand,
@ptrToInt(command.ptr),
0, 0, 0, 0) != 0;
} }
pub const memcheck = @import("memcheck.zig"); pub const memcheck = @import("memcheck.zig");
pub const callgrind = @import("callgrind.zig"); pub const callgrind = @import("callgrind.zig");

View File

@ -13,4 +13,3 @@ test "std.zig tests" {
_ = @import("zig/tokenizer.zig"); _ = @import("zig/tokenizer.zig");
_ = @import("zig/parse_string_literal.zig"); _ = @import("zig/parse_string_literal.zig");
} }