Merge pull request #5158 from ziglang/zir-to-elf

beginnings of (non-LLVM) self-hosted machine code generation and linking
This commit is contained in:
Andrew Kelley
2020-04-24 15:37:21 -04:00
committed by GitHub
8 changed files with 1457 additions and 999 deletions

View File

@@ -1345,8 +1345,10 @@ pub const Dir = struct {
mode: File.Mode = File.default_mode,
};
/// `dest_path` must remain valid for the lifetime of `AtomicFile`.
/// Call `AtomicFile.finish` to atomically replace `dest_path` with contents.
/// Directly access the `.file` field, and then call `AtomicFile.finish`
/// to atomically replace `dest_path` with contents.
/// Always call `AtomicFile.deinit` to clean up, regardless of whether `AtomicFile.finish` succeeded.
/// `dest_path` must remain valid until `AtomicFile.deinit` is called.
pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile {
if (path.dirname(dest_path)) |dirname| {
const dir = try self.openDir(dirname, .{});

View File

@@ -93,7 +93,7 @@ pub const File = struct {
/// This means that a process that does not respect the locking API can still get access
/// to the file, despite the lock.
///
/// Windows' file locks are mandatory, and any process attempting to access the file will
/// Windows's file locks are mandatory, and any process attempting to access the file will
/// receive an error.
///
/// [1]: https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt

View File

@@ -2027,7 +2027,13 @@ test "sliceAsBytes and bytesAsSlice back" {
/// Round an address up to the nearest aligned address
/// The alignment must be a power of 2 and greater than 0.
pub fn alignForward(addr: usize, alignment: usize) usize {
return alignBackward(addr + (alignment - 1), alignment);
return alignForwardGeneric(usize, addr, alignment);
}
/// Round an address up to the nearest aligned address
/// The alignment must be a power of 2 and greater than 0.
pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T {
return alignBackwardGeneric(T, addr + (alignment - 1), alignment);
}
test "alignForward" {
@@ -2048,8 +2054,14 @@ test "alignForward" {
/// Round an address up to the previous aligned address
/// The alignment must be a power of 2 and greater than 0.
pub fn alignBackward(addr: usize, alignment: usize) usize {
assert(@popCount(usize, alignment) == 1);
// 000010000 // example addr
return alignBackwardGeneric(usize, addr, alignment);
}
/// Round an address up to the previous aligned address
/// The alignment must be a power of 2 and greater than 0.
pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
assert(@popCount(T, alignment) == 1);
// 000010000 // example alignment
// 000001111 // subtract 1
// 111110000 // binary not
return addr & ~(alignment - 1);