diff --git a/src/backend/Assembly.zig b/src/backend/Assembly.zig index 5a2afae9a79eb452cc99603cdd138335f7175be7..dab571960f86f8b74287dbd04a96c49c94665d31 100644 --- a/src/backend/Assembly.zig +++ b/src/backend/Assembly.zig @@ -2,20 +2,36 @@ const std = @import("std"); const Allocator = std.mem.Allocator; /// Assembly holds the data and text sections of compiled code. +/// +/// # Fields +/// * `data` - The data section containing initialized data +/// * `text` - The text section containing executable code data: []const u8, text: []const u8, const Assembly = @This(); +/// Frees the memory allocated for both the data and text sections. +/// +/// # Arguments +/// * `gpa` - The allocator used to free memory pub fn deinit(self: *const Assembly, gpa: Allocator) void { gpa.free(self.data); gpa.free(self.text); } -pub fn writeToFile(self: Assembly, file: std.fs.File) !void { +/// Writes both the data and text sections of the Assembly to a file. +/// Uses writevAll to efficiently write both sections in a single system call. +/// +/// # Arguments +/// * `file` - The file to write to +/// +/// # Errors +/// Returns an error if the write operation fails. +pub fn writeToAllFile(self: Assembly, file: std.fs.File) !void { var vec: [2]std.posix.iovec_const = .{ .{ .base = self.data.ptr, .len = self.data.len }, .{ .base = self.text.ptr, .len = self.text.len }, }; return file.writevAll(&vec); -} +} \ No newline at end of file