feature. See also
. The project being documented here (as the example) is the Zig library itself.
tables.MemoryType
pub const MemoryType = enum(u32)
File
Code
pub const MemoryType = enum(u32) {
pub const Oem = math.IntFittingRange(
0,
@backingInt(MemoryType.oem_end) - @backingInt(MemoryType.oem_start),
);
pub const Vendor = math.IntFittingRange(
0,
@backingInt(MemoryType.vendor_end) - @backingInt(MemoryType.vendor_start),
);
reserved_memory_type,
loader_code,
loader_data,
boot_services_code,
boot_services_data,
runtime_services_code,
runtime_services_data,
conventional_memory,
unusable_memory,
acpi_reclaim_memory,
acpi_memory_nvs,
memory_mapped_io,
memory_mapped_io_port_space,
pal_code,
persistent_memory,
unaccepted_memory,
max_memory_type,
invalid_start,
invalid_end = 0x6FFFFFFF,
oem_start = 0x70000000,
oem_end = 0x7FFFFFFF,
vendor_start = 0x80000000,
vendor_end = 0xFFFFFFFF,
_,
pub fn fromOem(value: Oem) MemoryType {
const oem_start = @backingInt(MemoryType.oem_start);
return @fromBackingInt(@intCast(oem_start + value));
}
pub fn toOem(memtype: MemoryType) ?Oem {
const as_int = @backingInt(memtype);
const oem_start = @backingInt(MemoryType.oem_start);
if (as_int < oem_start) return null;
if (as_int > @backingInt(MemoryType.oem_end)) return null;
return @truncate(as_int - oem_start);
}
pub fn fromVendor(value: Vendor) MemoryType {
const vendor_start = @backingInt(MemoryType.vendor_start);
return @fromBackingInt(@intCast(vendor_start + value));
}
pub fn toVendor(memtype: MemoryType) ?Vendor {
const as_int = @backingInt(memtype);
const vendor_start = @backingInt(MemoryType.vendor_start);
if (as_int < @backingInt(MemoryType.vendor_end)) return null;
if (as_int > @backingInt(MemoryType.vendor_end)) return null;
return @truncate(as_int - vendor_start);
}
pub fn format(self: MemoryType, w: *std.Io.Writer) std.Io.Writer.Error!void {
if (self.toOem()) |oemval|
try w.print("OEM({X})", .{oemval})
else if (self.toVendor()) |vendorval|
try w.print("Vendor({X})", .{vendorval})
else if (std.enums.tagName(MemoryType, self)) |name|
try w.print("{s}", .{name})
else
try w.print("INVALID({X})", .{@backingInt(self)});
}
}