aboutsummaryrefslogtreecommitdiff
path: root/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-29 23:33:25 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-29 23:33:25 -0400
commit898d65baa9198f2fb1c5df91fba51a58c3148626 (patch)
treefd4f7178f974b7be7236782aacde4981df03238b /std/debug.zig
parent910a96f0468c635a135d9fccd39f139ba0775ef9 (diff)
downloadzig-898d65baa9198f2fb1c5df91fba51a58c3148626.tar.gz
zig-898d65baa9198f2fb1c5df91fba51a58c3148626.zip
more alignment improvements
* add alignment capability for fn protos * add @alignCast * fix some ast rendering code * fix some ir rendering code * add error for pointer cast increasing alignment * update allocators in std to correctly align See #37
Diffstat (limited to 'std/debug.zig')
-rw-r--r--std/debug.zig17
1 files changed, 11 insertions, 6 deletions
diff --git a/std/debug.zig b/std/debug.zig
index 6d7138a551..0b80f4b104 100644
--- a/std/debug.zig
+++ b/std/debug.zig
@@ -957,16 +957,21 @@ pub var global_allocator = mem.Allocator {
var some_mem: [100 * 1024]u8 = undefined;
var some_mem_index: usize = 0;
-fn globalAlloc(self: &mem.Allocator, n: usize) -> %[]u8 {
- const result = some_mem[some_mem_index .. some_mem_index + n];
- some_mem_index += n;
+fn globalAlloc(self: &mem.Allocator, n: usize, alignment: usize) -> %[]u8 {
+ const addr = @ptrToInt(&some_mem[some_mem_index]);
+ const rem = @rem(addr, alignment);
+ const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
+ const adjusted_index = some_mem_index + march_forward_bytes;
+ const end_index = adjusted_index + n;
+ const result = some_mem[adjusted_index .. end_index];
+ some_mem_index = end_index;
return result;
}
-fn globalRealloc(self: &mem.Allocator, old_mem: []u8, new_size: usize) -> %[]u8 {
- const result = %return globalAlloc(self, new_size);
+fn globalRealloc(self: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: usize) -> %[]u8 {
+ const result = %return globalAlloc(self, new_size, alignment);
@memcpy(result.ptr, old_mem.ptr, old_mem.len);
return result;
}
-fn globalFree(self: &mem.Allocator, old_mem: []u8) { }
+fn globalFree(self: &mem.Allocator, ptr: &u8) { }