diff --git a/modules/virtual-io/README.md b/modules/virtual-io/README.md new file mode 100644 index 000000000..50d8a4009 --- /dev/null +++ b/modules/virtual-io/README.md @@ -0,0 +1,4 @@ +# Virtual Io interface for Zig +A Zig Io implemention that keeps the directory structure and file contents in ram. +- All Io operations that would touch the disk go into ram, backed by a hash map +- Everything else fails diff --git a/modules/virtual-io/build.zig b/modules/virtual-io/build.zig new file mode 100644 index 000000000..14a49efe2 --- /dev/null +++ b/modules/virtual-io/build.zig @@ -0,0 +1,9 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + _ = b.addModule("virtual-io", .{ + .root_source_file = b.path("src/root.zig"), + .target = b.standardTargetOptions(.{}), + .optimize = b.standardOptimizeOption(.{}), + }); +} diff --git a/modules/virtual-io/build.zig.zon b/modules/virtual-io/build.zig.zon new file mode 100644 index 000000000..c760f07bf --- /dev/null +++ b/modules/virtual-io/build.zig.zon @@ -0,0 +1,11 @@ +.{ + .name = .virtual_io, + .fingerprint = 0x9ed0871d23642986, + .version = "0.0.1", + .paths = .{ + "src", + "build.zig", + "build.zig.zon", + "README.md", + }, +} diff --git a/modules/virtual-io/src/root.zig b/modules/virtual-io/src/root.zig new file mode 100644 index 000000000..abb3a75bc --- /dev/null +++ b/modules/virtual-io/src/root.zig @@ -0,0 +1,291 @@ +//! In-memory filesystem implementation +const std = @import("std"); +const builtin = @import("builtin"); + +const Allocator = std.mem.Allocator; +const assert = std.debug.assert; +const Io = std.Io; +const log = std.log.scoped(.vio); + +pub fn ResultID(T: type) type { + return switch (T) { + Dir, File => T.ID, + else => @compileError("Expected File or Dir, got " ++ @typeName(T)), + }; +} + +pub const Dir = struct { + pub const empty: Node = .{ .dir = .{ .inner = .empty } }; + pub const kind: Node.Kind = empty; + + pub const ID = enum(Node.ID) { + // Reserve first 256 file handles for os-specific values, such as sitdin/out/err + // on posix, cwd on wasm and the reserved NULL value on windows. + root = 0x100, + _, + + pub fn from_std(dir: Io.Dir) !ID { + return from_handle(ID, dir.handle); + } + + pub fn to_std(id: ID) Io.Dir { + return .{ .handle = to_handle(id) }; + } + + pub fn get(id: ID, vio: *const VirtualIo) !*Dir { + const node = vio.nodes.getPtr(@intFromEnum(id)) orelse + return error.Unexpected; + return switch (node.*) { + .dir => |*ret| ret, + else => error.NotDir, + }; + } + }; + + inner: std.StringHashMapUnmanaged(Node.ID) = .empty, + + pub fn open(parent: *Dir, vio: *const VirtualIo, sub_path: []const u8, T: type) !ResultID(T) { + var dir = parent; + var path_tail = sub_path; + while (std.mem.findScalar(u8, path_tail, '/')) |idx| { + const next = dir.inner.get(path_tail[0..idx]) orelse + return error.FileNotFound; + const node = vio.nodes.getPtr(next) orelse + return error.Unexpected; + switch (node.*) { + .dir => |*d| dir = d, + .file => return error.FileNotFound, + } + path_tail = path_tail[idx + 1 ..]; + } + const id = dir.inner.get(path_tail) orelse + return error.FileNotFound; + + // Check that node exists and is the right type + const node = vio.nodes.get(id); + if (node == null or node.? != T.kind) + return error.Unexpected; + + return @enumFromInt(id); + } + + pub fn create(dir: *Dir, vio: *VirtualIo, name: []const u8, T: type) !ResultID(T) { + if (std.mem.findScalar(u8, name, '/') != null) { + log.err("name includes '/': '{s}'", .{name}); + return error.BadPathName; + } + + const id = vio.last_id + 1; + vio.last_id = id; + + const name_owned = vio.gpa.dupe(u8, name) catch return error.NoSpaceLeft; + errdefer vio.gpa.free(name_owned); + + if (dir.inner.getOrPut(vio.gpa, name_owned)) |result| { + if (result.found_existing) + return error.PathAlreadyExists; + + result.value_ptr.* = id; + } else |_| return error.NoSpaceLeft; + + if (vio.nodes.getOrPut(vio.gpa, id)) |result| { + if (result.found_existing) + return error.PathAlreadyExists; + + result.value_ptr.* = T.empty; + } else |_| return error.NoSpaceLeft; + + return @enumFromInt(id); + } +}; + +pub const File = struct { + pub const empty: Node = .{ .file = .{ .inner = .empty } }; + pub const kind: Node.Kind = empty; + + pub const ID = enum(Node.ID) { + _, + + pub fn from_std(file: Io.File) !ID { + return from_handle(ID, file.handle); + } + + pub fn to_std(id: ID) Io.File { + return .{ + .handle = to_handle(id), + .flags = .{ .nonblocking = false }, + }; + } + + pub fn get(id: ID, vio: *const VirtualIo) !*File { + const node = vio.nodes.getPtr(@intFromEnum(id)) orelse + return error.Unexpected; + return switch (node.*) { + .file => |*ret| ret, + .dir => error.IsDir, + }; + } + }; + + inner: std.ArrayList(u8) = .empty, + + pub fn write_streaming( + vio: *const VirtualIo, + op: Io.Operation.FileWriteStreaming, + ) Io.Operation.FileWriteStreaming.Result { + const file = (try File.ID.from_std(op.file)).get(vio) catch + return error.Unexpected; + var allocating: Io.Writer.Allocating = .fromArrayList(vio.gpa, &file.inner); + defer file.inner = allocating.toArrayList(); + return allocating.writer.writeSplatHeader(op.header, op.data, op.splat) catch + error.NoSpaceLeft; + } +}; + +pub const Node = union(enum) { + pub const ID = u16; + pub const Kind = std.meta.Tag(Node); + pub const Map = std.AutoArrayHashMapUnmanaged(ID, Node); + + file: File, + dir: Dir, + + pub fn destroy(node: *Node, gpa: Allocator) void { + switch (node.*) { + .file => |*file| file.inner.deinit(gpa), + .dir => |*dir| { + var it = dir.inner.keyIterator(); + while (it.next()) |name| + gpa.free(name.*); + dir.inner.deinit(gpa); + }, + } + } +}; + +const VTable = struct { + fn operate(userdata: ?*anyopaque, op: Io.Operation) Io.Cancelable!Io.Operation.Result { + const vio: *VirtualIo = @ptrCast(@alignCast(userdata.?)); + return switch (op) { + .file_write_streaming => |write_op| .{ + .file_write_streaming = File.write_streaming(vio, write_op), + }, + .file_read_streaming => .{ .file_read_streaming = error.InputOutput }, + .device_io_control => unreachable, + .net_receive => .{ .net_receive = .{ error.NetworkDown, 0 } }, + .net_read => .{ .net_read = error.NetworkDown }, + }; + } + + fn create_dir_path_open( + userdata: ?*anyopaque, + dir: Io.Dir, + sub_path: []const u8, + _: Io.Dir.Permissions, + _: Io.Dir.OpenOptions, + ) Io.Dir.CreateDirPathOpenError!Io.Dir { + const vio: *VirtualIo = @ptrCast(@alignCast(userdata.?)); + const parent = try (try Dir.ID.from_std(dir)).get(vio); + return (try parent.create(vio, sub_path, Dir)).to_std(); + } + + fn dir_close(_: ?*anyopaque, _: []const Io.Dir) void {} + + fn dir_create_file( + userdata: ?*anyopaque, + dir: Io.Dir, + sub_path: []const u8, + _: Io.Dir.CreateFileOptions, + ) Io.File.OpenError!Io.File { + const vio: *VirtualIo = @ptrCast(@alignCast(userdata.?)); + const parent = try (try Dir.ID.from_std(dir)).get(vio); + return (try parent.create(vio, sub_path, File)).to_std(); + } + + fn dir_open_file( + userdata: ?*anyopaque, + dir: Io.Dir, + sub_path: []const u8, + _: Io.Dir.OpenFileOptions, + ) Io.File.OpenError!Io.File { + const vio: *VirtualIo = @ptrCast(@alignCast(userdata.?)); + const parent = try (try Dir.ID.from_std(dir)).get(vio); + return (try parent.open(vio, sub_path, File)).to_std(); + } + + fn file_close(_: ?*anyopaque, _: []const Io.File) void {} +}; + +pub const VirtualIo = struct { + pub const root_dir = Dir.ID.root.to_std(); + + pub const vtable: *const Io.VTable = blk: { + var ret = Io.failing.vtable.*; + ret.operate = VTable.operate; + ret.dirCreateDirPathOpen = VTable.create_dir_path_open; + ret.dirClose = VTable.dir_close; + ret.dirCreateFile = VTable.dir_create_file; + ret.dirOpenFile = VTable.dir_open_file; + ret.fileClose = VTable.file_close; + + const ret_const = ret; + break :blk &ret_const; + }; + + gpa: Allocator, + nodes: Node.Map, + last_id: Node.ID, + + pub fn io(vio: *VirtualIo) Io { + return .{ .userdata = vio, .vtable = vtable }; + } + + pub fn init(gpa: Allocator) !VirtualIo { + var ret: VirtualIo = .{ + .gpa = gpa, + .nodes = .empty, + .last_id = @intFromEnum(Dir.ID.root), + }; + try ret.nodes.put(gpa, ret.last_id, Dir.empty); + return ret; + } + + pub fn deinit(vio: *VirtualIo) void { + for (vio.nodes.values()) |*node| + node.destroy(vio.gpa); + vio.nodes.deinit(vio.gpa); + } + + pub fn total_file_count(vio: *const VirtualIo) usize { + var ret: usize = 0; + var it = vio.nodes.iterator(); + while (it.next()) |entry| { + if (entry.value_ptr.* == .file) + ret += 1; + } + return ret; + } + + pub fn file_contents(vio: *const VirtualIo, file: Io.File) !*std.ArrayList(u8) { + return &(try (try File.ID.from_std(file)).get(vio)).inner; + } +}; + +pub fn from_handle(T: type, handle: std.posix.fd_t) !T { + const Backing = @Int(.unsigned, @bitSizeOf(T)); + return if (std.math.cast(Backing, switch (builtin.os.tag) { + .windows => @intFromPtr(handle), + else => handle, + })) |int| + @enumFromInt(int) + else + error.Unexpected; +} + +pub fn to_handle(id: anytype) std.posix.fd_t { + // const ID = @TypeOf(id); + return switch (builtin.os.tag) { + .windows => @ptrFromInt(@intFromEnum(id)), + else => @intFromEnum(id), + }; +} diff --git a/tools/regz/build.zig b/tools/regz/build.zig index ab9f02247..14c30c77a 100644 --- a/tools/regz/build.zig +++ b/tools/regz/build.zig @@ -12,12 +12,15 @@ pub fn build(b: *Build) !void { .optimize = .ReleaseSafe, }); - const zqlite_dep = b.dependency("zqlite", .{ + const virtual_io = b.dependency("virtual_io", .{ .target = target, .optimize = optimize, - }); + }).module("virtual-io"); - const zqlite = zqlite_dep.module("zqlite"); + const zqlite = b.dependency("zqlite", .{ + .target = target, + .optimize = optimize, + }).module("zqlite"); const xml_module = b.createModule(.{ .root_source_file = b.path("src/xml.zig"), @@ -33,14 +36,9 @@ pub fn build(b: *Build) !void { .target = target, .optimize = optimize, .imports = &.{ - .{ - .name = "zqlite", - .module = zqlite, - }, - .{ - .name = "xml", - .module = xml_module, - }, + .{ .name = "virtual-io", .module = virtual_io }, + .{ .name = "xml", .module = xml_module }, + .{ .name = "zqlite", .module = zqlite }, }, }); regz_module.linkLibrary(libxml2_dep.artifact("xml")); @@ -52,14 +50,8 @@ pub fn build(b: *Build) !void { .target = target, .optimize = optimize, .imports = &.{ - .{ - .name = "regz", - .module = regz_module, - }, - .{ - .name = "xml", - .module = xml_module, - }, + .{ .name = "regz", .module = regz_module }, + .{ .name = "xml", .module = xml_module }, }, }), .use_llvm = true, diff --git a/tools/regz/build.zig.zon b/tools/regz/build.zig.zon index 8e1033808..81cdc6f64 100644 --- a/tools/regz/build.zig.zon +++ b/tools/regz/build.zig.zon @@ -13,6 +13,7 @@ .url = "git+https://github.com/allyourcodebase/libxml2.git#e2c881ccb72dc96b03bb80f1f4c4b386969b76f7", .hash = "libxml2-2.15.1-2-qHdjhjJXAAAF6fWNrfH_GFaXDHRNjlYQoeKF_RBnWtVu", }, + .virtual_io = .{ .path = "../../modules/virtual-io" }, .zqlite = .{ .url = "git+https://github.com/karlseguin/zqlite.zig#95054418207705ed9188b4d7467fec5136100f13", .hash = "zqlite-0.0.1-RWLaY9UynADU9w6axCjGV9--FpxxKO_qu1qmorhTj2D9", diff --git a/tools/regz/src/VirtualFilesystem.zig b/tools/regz/src/VirtualFilesystem.zig deleted file mode 100644 index 4b8cffa2b..000000000 --- a/tools/regz/src/VirtualFilesystem.zig +++ /dev/null @@ -1,392 +0,0 @@ -//! Filesystem to store generated files -gpa: Allocator, -directories: Map(ID, Dir) = .empty, -files: Map(ID, File) = .empty, -// child -> parent -hierarchy: Map(ID, ID) = .empty, -next_id: u16 = 2, - -const VirtualFilesystem = @This(); - -const std = @import("std"); -const Allocator = std.mem.Allocator; -const Map = std.AutoArrayHashMapUnmanaged; -const assert = std.debug.assert; -const log = std.log.scoped(.vfs); - -const builtin = @import("builtin"); - -fn id_from_handle(handle: std.posix.fd_t) ID { - return switch (builtin.os.tag) { - .windows => @enumFromInt(@intFromPtr(handle)), - else => @enumFromInt(handle), - }; -} - -fn handle_from_id(id: ID) std.posix.fd_t { - return switch (builtin.os.tag) { - .windows => @ptrFromInt(@intFromEnum(id)), - else => @intFromEnum(id), - }; -} - -pub const Kind = enum { - file, - directory, -}; - -pub const Dir = struct { - name: []const u8, - - pub fn deinit(d: *Dir, gpa: Allocator) void { - gpa.free(d.name); - } - - fn create_file(userdata: ?*anyopaque, dir: std.Io.Dir, sub_path: []const u8, _: std.Io.Dir.CreateFileOptions) std.Io.File.OpenError!std.Io.File { - const vfs: *VirtualFilesystem = @ptrCast(@alignCast(userdata.?)); - const dir_id = id_from_handle(dir.handle); - - if (std.mem.findScalar(u8, sub_path, '/') != null) { - log.err("path includes '/': '{s}'", .{sub_path}); - return error.BadPathName; - } - - const id = vfs.create_file(dir_id, sub_path) catch |err| switch (err) { - error.OutOfMemory => return error.NoSpaceLeft, - }; - return .{ - .handle = handle_from_id(id), - .flags = .{ - .nonblocking = false, - }, - }; - } - - fn create_dir_path_open( - userdata: ?*anyopaque, - parent_dir: std.Io.Dir, - sub_path: []const u8, - _: std.Io.Dir.Permissions, - _: std.Io.Dir.OpenOptions, - ) std.Io.Dir.CreateDirPathOpenError!std.Io.Dir { - const vfs: *VirtualFilesystem = @ptrCast(@alignCast(userdata.?)); - const parent = id_from_handle(parent_dir.handle); - const id = vfs.create_dir(parent, sub_path) catch return error.NoSpaceLeft; - - return .{ - .handle = handle_from_id(id), - }; - } - - fn close(_: ?*anyopaque, _: []const std.Io.Dir) void {} -}; - -pub const File = struct { - name: []const u8, - content: std.Io.Writer.Allocating, - - pub fn deinit(f: *File, gpa: Allocator) void { - gpa.free(f.name); - f.content.deinit(); - } - - pub fn close(_: ?*anyopaque, _: []const std.Io.File) void {} -}; - -fn operate(userdata: ?*anyopaque, op: std.Io.Operation) std.Io.Cancelable!std.Io.Operation.Result { - const vfs: *VirtualFilesystem = @ptrCast(@alignCast(userdata.?)); - return switch (op) { - .file_write_streaming => |write_op| blk: { - const file = vfs.files.getPtr(id_from_handle(write_op.file.handle)).?; - const header = write_op.header; - const data = write_op.data; - const splat = write_op.splat; - break :blk .{ - .file_write_streaming = file.content.writer.writeSplatHeader(header, data, splat) catch error.NoSpaceLeft, - }; - }, - .file_read_streaming => unreachable, - .device_io_control => unreachable, - .net_receive => unreachable, - .net_read => unreachable, - }; -} - -pub const ID = enum(u16) { - // Don't use this one, because on windows, fd_t is actually a *anyopaque, - // and setting that null under the hood is ILLEGAL, and I don't want to go - // to jail. - invalid = 0, - root = 1, - _, -}; - -pub fn init(gpa: Allocator) VirtualFilesystem { - return VirtualFilesystem{ - .gpa = gpa, - }; -} - -pub fn deinit(fs: *VirtualFilesystem) void { - for (fs.directories.values()) |*directory| directory.deinit(fs.gpa); - for (fs.files.values()) |*file| file.deinit(fs.gpa); - - fs.directories.deinit(fs.gpa); - fs.files.deinit(fs.gpa); - fs.hierarchy.deinit(fs.gpa); -} - -pub fn root_dir(fs: *VirtualFilesystem) std.Io.Dir { - _ = fs; - return .{ .handle = handle_from_id(ID.root) }; -} - -pub fn get_file(fs: *VirtualFilesystem, path: []const u8) !?ID { - var components: std.ArrayList([]const u8) = .empty; - defer components.deinit(fs.gpa); - - var it = std.mem.tokenizeScalar(u8, path, '/'); - while (it.next()) |component| - try components.append(fs.gpa, component); - - return fs.recursive_get_file(0, .root, components.items); -} - -fn recursive_get_file(fs: *VirtualFilesystem, depth: usize, dir_id: ID, components: []const []const u8) !?ID { - return switch (components.len) { - 0 => null, - 1 => blk: { - const children = try fs.get_children(fs.gpa, dir_id); - defer fs.gpa.free(children); - - break :blk for (children) |child| { - if (child.kind != .file) - continue; - - const name = fs.get_name(child.id); - if (std.mem.eql(u8, name, components[0])) - break child.id; - } else null; - }, - else => blk: { - const children = try fs.get_children(fs.gpa, dir_id); - defer fs.gpa.free(children); - - break :blk for (children) |child| { - if (child.kind != .directory) - continue; - - break try fs.recursive_get_file(depth + 1, child.id, components[1..]) orelse continue; - } else null; - }, - }; -} - -pub const Entry = struct { - id: ID, - kind: Kind, -}; - -pub fn get_children(fs: *VirtualFilesystem, allocator: Allocator, id: ID) ![]const Entry { - var ret: std.ArrayList(Entry) = .empty; - for (fs.hierarchy.keys(), fs.hierarchy.values()) |child_id, parent_id| { - if (parent_id == id) - try ret.append(allocator, .{ - .id = child_id, - .kind = fs.get_kind(child_id), - }); - } - return ret.toOwnedSlice(allocator); -} - -fn new_id(fs: *VirtualFilesystem) ID { - defer fs.next_id += 1; - return @enumFromInt(fs.next_id); -} - -fn create_dir(fs: *VirtualFilesystem, parent: ID, name: []const u8) !ID { - const id = fs.new_id(); - - const name_copy = try fs.gpa.dupe(u8, name); - try fs.directories.put(fs.gpa, id, .{ - .name = name_copy, - }); - - try fs.hierarchy.put(fs.gpa, id, parent); - - return id; -} - -fn create_file(fs: *VirtualFilesystem, parent: ID, name: []const u8) !ID { - const id = fs.new_id(); - - const name_copy = try fs.gpa.dupe(u8, name); - try fs.files.put(fs.gpa, id, .{ - .name = name_copy, - .content = .init(fs.gpa), - }); - - try fs.hierarchy.put(fs.gpa, id, parent); - - return id; -} - -pub fn get_kind(fs: *VirtualFilesystem, id: ID) Kind { - return if (fs.files.contains(id)) - .file - else if (fs.directories.contains(id)) - .directory - else - unreachable; -} - -pub fn get_name(fs: *VirtualFilesystem, id: ID) []const u8 { - return if (fs.files.get(id)) |f| - f.name - else if (fs.directories.get(id)) |d| - d.name - else - unreachable; -} - -pub fn get_content(fs: *VirtualFilesystem, id: ID) []const u8 { - assert(fs.get_kind(id) == .file); - return fs.files.get(id).?.content.writer.buffered(); -} - -fn get_child(fs: *VirtualFilesystem, parent: ID, component: []const u8) ?ID { - return for (fs.hierarchy.keys(), fs.hierarchy.values()) |child_id, entry_parent_id| { - if (entry_parent_id == parent and std.mem.eql(u8, component, fs.get_name(child_id))) - break child_id; - } else null; -} - -pub fn io(vfs: *VirtualFilesystem) std.Io { - return .{ - .userdata = vfs, - .vtable = &.{ - .dirCreateFile = Dir.create_file, - .operate = operate, - - // Default/failing/unimplemented handlers - .crashHandler = std.Io.noCrashHandler, - .async = std.Io.noAsync, - .concurrent = std.Io.failingConcurrent, - .await = std.Io.unreachableAwait, - .cancel = std.Io.unreachableCancel, - .groupAsync = std.Io.noGroupAsync, - .groupConcurrent = std.Io.failingGroupConcurrent, - .groupAwait = std.Io.unreachableGroupAwait, - .groupCancel = std.Io.unreachableGroupCancel, - - .recancel = std.Io.unreachableRecancel, - .swapCancelProtection = std.Io.unreachableSwapCancelProtection, - .checkCancel = std.Io.unreachableCheckCancel, - - .futexWait = std.Io.noFutexWait, - .futexWaitUncancelable = std.Io.noFutexWaitUncancelable, - .futexWake = std.Io.noFutexWake, - - .batchAwaitAsync = std.Io.unreachableBatchAwaitAsync, - .batchAwaitConcurrent = std.Io.unreachableBatchAwaitConcurrent, - .batchCancel = std.Io.unreachableBatchCancel, - - .dirCreateDir = std.Io.failingDirCreateDir, - .dirCreateDirPath = std.Io.failingDirCreateDirPath, - .dirCreateDirPathOpen = Dir.create_dir_path_open, - .dirOpenDir = std.Io.failingDirOpenDir, - .dirStat = std.Io.failingDirStat, - .dirStatFile = std.Io.failingDirStatFile, - .dirAccess = std.Io.failingDirAccess, - .dirCreateFileAtomic = std.Io.failingDirCreateFileAtomic, - .dirOpenFile = std.Io.failingDirOpenFile, - .dirClose = Dir.close, - .dirRead = std.Io.noDirRead, - .dirRealPath = std.Io.failingDirRealPath, - .dirRealPathFile = std.Io.failingDirRealPathFile, - .dirDeleteFile = std.Io.failingDirDeleteFile, - .dirDeleteDir = std.Io.failingDirDeleteDir, - .dirRename = std.Io.failingDirRename, - .dirRenamePreserve = std.Io.failingDirRenamePreserve, - .dirSymLink = std.Io.failingDirSymLink, - .dirReadLink = std.Io.failingDirReadLink, - .dirSetOwner = std.Io.failingDirSetOwner, - .dirSetFileOwner = std.Io.failingDirSetFileOwner, - .dirSetPermissions = std.Io.failingDirSetPermissions, - .dirSetFilePermissions = std.Io.failingDirSetFilePermissions, - .dirSetTimestamps = std.Io.noDirSetTimestamps, - .dirHardLink = std.Io.failingDirHardLink, - - .fileStat = std.Io.failingFileStat, - .fileLength = std.Io.failingFileLength, - .fileClose = File.close, - .fileWritePositional = std.Io.failingFileWritePositional, - .fileWriteFileStreaming = std.Io.noFileWriteFileStreaming, - .fileWriteFilePositional = std.Io.noFileWriteFilePositional, - .fileReadPositional = std.Io.failingFileReadPositional, - .fileSeekBy = std.Io.failingFileSeekBy, - .fileSeekTo = std.Io.failingFileSeekTo, - .fileSync = std.Io.failingFileSync, - .fileIsTty = std.Io.unreachableFileIsTty, - .fileEnableAnsiEscapeCodes = std.Io.unreachableFileEnableAnsiEscapeCodes, - .fileSupportsAnsiEscapeCodes = std.Io.unreachableFileSupportsAnsiEscapeCodes, - .fileSetLength = std.Io.failingFileSetLength, - .fileSetOwner = std.Io.failingFileSetOwner, - .fileSetPermissions = std.Io.failingFileSetPermissions, - .fileSetTimestamps = std.Io.noFileSetTimestamps, - .fileLock = std.Io.failingFileLock, - .fileTryLock = std.Io.failingFileTryLock, - .fileUnlock = std.Io.unreachableFileUnlock, - .fileDowngradeLock = std.Io.failingFileDowngradeLock, - .fileRealPath = std.Io.failingFileRealPath, - .fileHardLink = std.Io.failingFileHardLink, - - .fileMemoryMapCreate = std.Io.failingFileMemoryMapCreate, - .fileMemoryMapDestroy = std.Io.unreachableFileMemoryMapDestroy, - .fileMemoryMapSetLength = std.Io.unreachableFileMemoryMapSetLength, - .fileMemoryMapRead = std.Io.unreachableFileMemoryMapRead, - .fileMemoryMapWrite = std.Io.unreachableFileMemoryMapWrite, - - .processExecutableOpen = std.Io.failingProcessExecutableOpen, - .processExecutablePath = std.Io.failingProcessExecutablePath, - .lockStderr = std.Io.unreachableLockStderr, - .tryLockStderr = std.Io.noTryLockStderr, - .unlockStderr = std.Io.unreachableUnlockStderr, - .processCurrentPath = std.Io.failingProcessCurrentPath, - .processSetCurrentDir = std.Io.failingProcessSetCurrentDir, - .processSetCurrentPath = std.Io.failingProcessSetCurrentPath, - .processReplace = std.Io.failingProcessReplace, - .processReplacePath = std.Io.failingProcessReplacePath, - .processSpawn = std.Io.failingProcessSpawn, - .processSpawnPath = std.Io.failingProcessSpawnPath, - .childWait = std.Io.unreachableChildWait, - .childKill = std.Io.unreachableChildKill, - - .progressParentFile = std.Io.failingProgressParentFile, - - .now = std.Io.noNow, - .clockResolution = std.Io.failingClockResolution, - .sleep = std.Io.noSleep, - - .random = std.Io.noRandom, - .randomSecure = std.Io.failingRandomSecure, - - .netListenIp = std.Io.failingNetListenIp, - .netAccept = std.Io.failingNetAccept, - .netBindIp = std.Io.failingNetBindIp, - .netConnectIp = std.Io.failingNetConnectIp, - .netListenUnix = std.Io.failingNetListenUnix, - .netConnectUnix = std.Io.failingNetConnectUnix, - .netSocketCreatePair = std.Io.failingNetSocketCreatePair, - .netSend = std.Io.failingNetSend, - - .netWrite = std.Io.failingNetWrite, - .netWriteFile = std.Io.failingNetWriteFile, - .netClose = std.Io.unreachableNetClose, - .netShutdown = std.Io.failingNetShutdown, - .netInterfaceNameResolve = std.Io.failingNetInterfaceNameResolve, - .netInterfaceName = std.Io.unreachableNetInterfaceName, - .netLookup = std.Io.failingNetLookup, - }, - }; -} diff --git a/tools/regz/src/gen.zig b/tools/regz/src/gen.zig index 37b25a663..770f1d3dc 100644 --- a/tools/regz/src/gen.zig +++ b/tools/regz/src/gen.zig @@ -13,7 +13,7 @@ const DevicePeripheral = Database.DevicePeripheral; const EnumID = Database.EnumID; const StructID = Database.StructID; const NestedStructField = Database.NestedStructField; -const VirtualFilesystem = @import("VirtualFilesystem.zig"); +const VirtualIo = @import("virtual-io").VirtualIo; const Properties = @import("properties.zig").Properties; const arm = @import("arch/arm.zig"); @@ -1735,11 +1735,11 @@ const ExpectedOutput = struct { content: []const u8, }; -fn expect_output(expected_outputs: []const ExpectedOutput, vfs: *VirtualFilesystem) !void { - try std.testing.expectEqual(expected_outputs.len, vfs.files.count()); +fn expect_output(expected_outputs: []const ExpectedOutput, vio: *VirtualIo) !void { + try std.testing.expectEqual(expected_outputs.len, vio.total_file_count()); for (expected_outputs) |eo| { - const file_id = try vfs.get_file(eo.path) orelse unreachable; - try std.testing.expectEqualStrings(eo.content, vfs.get_content(file_id)); + const file = try VirtualIo.root_dir.openFile(vio.io(), eo.path, .{}); + try std.testing.expectEqualStrings(eo.content, (try vio.file_contents(file)).items); } } @@ -1780,10 +1780,10 @@ test "gen.peripheral instantiation" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "TEST_DEVICE.zig", @@ -1853,7 +1853,7 @@ test "gen.peripheral instantiation" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripherals with a shared type" { @@ -1903,10 +1903,10 @@ test "gen.peripherals with a shared type" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "TEST_DEVICE.zig", @@ -1977,7 +1977,7 @@ test "gen.peripherals with a shared type" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral with modes" { @@ -2022,10 +2022,10 @@ test "gen.peripheral with modes" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2098,7 +2098,7 @@ test "gen.peripheral with modes" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral with enum" { @@ -2128,10 +2128,10 @@ test "gen.peripheral with enum" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2168,7 +2168,7 @@ test "gen.peripheral with enum" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral with enum, enum is exhausted of values" { @@ -2197,10 +2197,10 @@ test "gen.peripheral with enum, enum is exhausted of values" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2236,7 +2236,7 @@ test "gen.peripheral with enum, enum is exhausted of values" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with named enum" { @@ -2272,10 +2272,10 @@ test "gen.field with named enum" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2315,7 +2315,7 @@ test "gen.field with named enum" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with named enum and named default" { @@ -2353,10 +2353,10 @@ test "gen.field with named enum and named default" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2396,7 +2396,7 @@ test "gen.field with named enum and named default" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with named enum and unnamed default" { @@ -2434,10 +2434,10 @@ test "gen.field with named enum and unnamed default" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2477,7 +2477,7 @@ test "gen.field with named enum and unnamed default" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with anonymous enum" { @@ -2512,10 +2512,10 @@ test "gen.field with anonymous enum" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2553,7 +2553,7 @@ test "gen.field with anonymous enum" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with anonymous enum and default" { @@ -2590,10 +2590,10 @@ test "gen.field with anonymous enum and default" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -2631,7 +2631,7 @@ test "gen.field with anonymous enum and default" { \\ , }, - }, &vfs); + }, &vio); } test "gen.namespaced register groups" { @@ -2675,10 +2675,10 @@ test "gen.namespaced register groups" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -2759,7 +2759,7 @@ test "gen.namespaced register groups" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral with reserved register" { @@ -2788,10 +2788,10 @@ test "gen.peripheral with reserved register" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -2862,7 +2862,7 @@ test "gen.peripheral with reserved register" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral with count" { @@ -2891,10 +2891,10 @@ test "gen.peripheral with count" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -2965,7 +2965,7 @@ test "gen.peripheral with count" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral with count, padding required" { @@ -2995,10 +2995,10 @@ test "gen.peripheral with count, padding required" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -3070,7 +3070,7 @@ test "gen.peripheral with count, padding required" { \\ , }, - }, &vfs); + }, &vio); } test "gen.register with count" { @@ -3100,10 +3100,10 @@ test "gen.register with count" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -3174,7 +3174,7 @@ test "gen.register with count" { \\ , }, - }, &vfs); + }, &vio); } test "gen.register with count and fields" { @@ -3217,10 +3217,10 @@ test "gen.register with count and fields" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -3294,7 +3294,7 @@ test "gen.register with count and fields" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with count, width of one, offset, and padding" { @@ -3325,10 +3325,10 @@ test "gen.field with count, width of one, offset, and padding" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -3367,7 +3367,7 @@ test "gen.field with count, width of one, offset, and padding" { \\ , }, - }, &vfs); + }, &vio); } test "gen.field with count, multi-bit width, offset, and padding" { @@ -3398,10 +3398,10 @@ test "gen.field with count, multi-bit width, offset, and padding" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -3437,7 +3437,7 @@ test "gen.field with count, multi-bit width, offset, and padding" { \\ , }, - }, &vfs); + }, &vio); } test "gen.interrupts.avr" { @@ -3462,10 +3462,10 @@ test "gen.interrupts.avr" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "ATmega328P.zig", @@ -3527,7 +3527,7 @@ test "gen.interrupts.avr" { \\ , }, - }, &vfs); + }, &vio); } test "gen.peripheral type with register and field" { @@ -3558,10 +3558,10 @@ test "gen.peripheral type with register and field" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -3598,7 +3598,7 @@ test "gen.peripheral type with register and field" { \\ , }, - }, &vfs); + }, &vio); } test "gen.name collisions in enum name cause them to be anonymous" { @@ -3648,10 +3648,10 @@ test "gen.name collisions in enum name cause them to be anonymous" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -3693,7 +3693,7 @@ test "gen.name collisions in enum name cause them to be anonymous" { \\ , }, - }, &vfs); + }, &vio); } test "gen.pick one enum field in value collisions" { @@ -3729,10 +3729,10 @@ test "gen.pick one enum field in value collisions" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -3769,7 +3769,7 @@ test "gen.pick one enum field in value collisions" { \\ , }, - }, &vfs); + }, &vio); } //test "gen.pick one enum field in name collisions" { @@ -3805,10 +3805,10 @@ test "gen.pick one enum field in value collisions" { // var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); // defer buffer.deinit(); // -// var vfs: VirtualFilesystem = .init(std.testing.allocator); -// defer vfs.deinit(); +// var vio: VirtualIo = try .init(std.testing.allocator); +// defer vio.deinit(); // -// try db.to_zig(vfs.io(), vfs.root_dir(), .{}); +// try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); // try expect_output(&.{ // .{ // .path = "types.zig", @@ -3845,7 +3845,7 @@ test "gen.pick one enum field in value collisions" { // \\ // , // }, -// }, &vfs); +// }, &vio); //} //test "gen.register fields with name collision" { @@ -3882,10 +3882,10 @@ test "gen.pick one enum field in value collisions" { // var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); // defer buffer.deinit(); // -// var vfs: VirtualFilesystem = .init(std.testing.allocator); -// defer vfs.deinit(); +// var vio: VirtualIo = try .init(std.testing.allocator); +// defer vio.deinit(); // -// try db.to_zig(vfs.io(), vfs.root_dir(), .{}); +// try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); // try expect_output(&.{ // .{ // .path = "types.zig", @@ -3921,7 +3921,7 @@ test "gen.pick one enum field in value collisions" { // \\ // , // }, -// }, &vfs); +// }, &vio); //} test "gen.nested struct field in a peripheral" { @@ -3960,10 +3960,10 @@ test "gen.nested struct field in a peripheral" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -4004,7 +4004,7 @@ test "gen.nested struct field in a peripheral" { \\ , }, - }, &vfs); + }, &vio); } test "gen.nested struct field in a peripheral that has a named type" { @@ -4045,10 +4045,10 @@ test "gen.nested struct field in a peripheral that has a named type" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -4091,7 +4091,7 @@ test "gen.nested struct field in a peripheral that has a named type" { \\ , }, - }, &vfs); + }, &vio); } test "gen.nested struct field in a peripheral with offset" { @@ -4130,10 +4130,10 @@ test "gen.nested struct field in a peripheral with offset" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -4176,7 +4176,7 @@ test "gen.nested struct field in a peripheral with offset" { \\ , }, - }, &vfs); + }, &vio); } test "gen.nested struct field in nested struct field" { @@ -4222,10 +4222,10 @@ test "gen.nested struct field in nested struct field" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -4269,7 +4269,7 @@ test "gen.nested struct field in nested struct field" { \\ , }, - }, &vfs); + }, &vio); } test "gen.nested struct field next to register" { @@ -4324,10 +4324,10 @@ test "gen.nested struct field next to register" { var buffer: std.Io.Writer.Allocating = .init(std.testing.allocator); defer buffer.deinit(); - var vfs: VirtualFilesystem = .init(std.testing.allocator); - defer vfs.deinit(); + var vio: VirtualIo = try .init(std.testing.allocator); + defer vio.deinit(); - try db.to_zig(vfs.io(), vfs.root_dir(), .{}); + try db.to_zig(vio.io(), VirtualIo.root_dir, .{}); try expect_output(&.{ .{ .path = "types.zig", @@ -4377,5 +4377,5 @@ test "gen.nested struct field next to register" { \\ , }, - }, &vfs); + }, &vio); }