diff --git a/Assembly.zig b/Assembly.zig new file mode 100644 index 0000000000000000000000000000000000000000..d8d3b65f2718a97c7c45fe27afa8302cb5b00f03 --- /dev/null +++ b/Assembly.zig @@ -0,0 +1,24 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; + +data: []const u8, +text: []const u8, + +const Assembly = @This(); + +pub fn deinit(self: *const Assembly, gpa: Allocator) void { + gpa.free(self.data); + gpa.free(self.text); +} + +pub fn writeToAllFile(self: Assembly, file: std.fs.File) !void { + /// 将程序集的数据段和文本段写入到指定的文件 + /// 使用向量IO(iovec)同时写入两个缓冲区以提高效率 + /// - data: 包含编译后的机器码数据 + /// - text: 包含文本段内容(如汇编指令或调试信息) + 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.writeAll(&vec); +} \ No newline at end of file