forked from mirror/vulkan-zig
Registry: Header revision
This commit is contained in:
@@ -17,7 +17,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
_ = try file.inStream().stream.read(source);
|
_ = try file.inStream().stream.read(source);
|
||||||
|
|
||||||
var spec = try xml.parse(std.heap.page_allocator, source);
|
const spec = try xml.parse(std.heap.page_allocator, source);
|
||||||
defer spec.deinit();
|
defer spec.deinit();
|
||||||
|
|
||||||
const registry = reg.generate(std.heap.page_allocator, spec.root);
|
const registry = reg.generate(std.heap.page_allocator, spec.root);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub const Registry = struct {
|
|||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: *Registry) void {
|
fn deinit(self: Registry) void {
|
||||||
self.declarations_by_name.deinit();
|
self.declarations_by_name.deinit();
|
||||||
|
|
||||||
// Copy to stack so that the arena doesn't destroy itself
|
// Copy to stack so that the arena doesn't destroy itself
|
||||||
@@ -467,6 +467,14 @@ const EnumInfo = struct {
|
|||||||
if (EnumInfo.isBackwardsCompatAlias(variant)) return;
|
if (EnumInfo.isBackwardsCompatAlias(variant)) return;
|
||||||
const name = variant.getAttribute("name").?;
|
const name = variant.getAttribute("name").?;
|
||||||
const value = blk: {
|
const value = blk: {
|
||||||
|
// An enum variant's value could be defined by any of the following attributes:
|
||||||
|
// - value: Straight up value of the enum variant, in either base 10 or 16 (prefixed with 0x).
|
||||||
|
// - bitpos: Used for bitmasks, and can also be set in extensions.
|
||||||
|
// - alias: The field is an alias of another variant within the same enum.
|
||||||
|
// - offset: Used with features and extensions, where a non-bitpos value is added to an enum.
|
||||||
|
// The value is given by `1e9 + (extr_nr - 1) * 1e3 + offset`, where `ext_nr` is either
|
||||||
|
// given by the `extnumber` field (in the case of a feature), or given in the parent <extension>
|
||||||
|
// tag. In the latter case its passed via the `ext_nr` parameter.
|
||||||
if (variant.getAttribute("value")) |value_str| {
|
if (variant.getAttribute("value")) |value_str| {
|
||||||
break :blk Value{.Value = parseInt(i32, value_str) catch unreachable};
|
break :blk Value{.Value = parseInt(i32, value_str) catch unreachable};
|
||||||
} else if (variant.getAttribute("bitpos")) |bitpos_str| {
|
} else if (variant.getAttribute("bitpos")) |bitpos_str| {
|
||||||
@@ -540,6 +548,8 @@ fn processTypes(registry: *Registry, root: *xml.Element) void {
|
|||||||
processFuncPointerType(registry, ty);
|
processFuncPointerType(registry, ty);
|
||||||
} else if (mem.eql(u8, category, "basetype")) {
|
} else if (mem.eql(u8, category, "basetype")) {
|
||||||
processBaseType(registry, ty);
|
processBaseType(registry, ty);
|
||||||
|
} else if (mem.eql(u8, category, "define")) {
|
||||||
|
processDefineType(registry, ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,6 +615,14 @@ fn processBaseType(registry: *Registry, ty: *xml.Element) void {
|
|||||||
registry.addDefinition(name, .{.BaseType = type_info});
|
registry.addDefinition(name, .{.BaseType = type_info});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn processDefineType(registry: *Registry, ty: *xml.Element) void {
|
||||||
|
if (ty.getCharData("name")) |name| {
|
||||||
|
if (mem.eql(u8, name, "VK_HEADER_VERSION")) {
|
||||||
|
registry.addApiConstant("VK_HEADER_VERSION", mem.trim(u8, ty.children.at(2).CharData, " "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn processEnums(registry: *Registry, root: *xml.Element) void {
|
fn processEnums(registry: *Registry, root: *xml.Element) void {
|
||||||
var it = root.findChildrenByTag("enums");
|
var it = root.findChildrenByTag("enums");
|
||||||
while (it.next()) |enums| {
|
while (it.next()) |enums| {
|
||||||
|
|||||||
@@ -95,8 +95,9 @@ pub const Document = struct {
|
|||||||
xml_decl: ?*XmlDecl,
|
xml_decl: ?*XmlDecl,
|
||||||
root: *Element,
|
root: *Element,
|
||||||
|
|
||||||
pub fn deinit(self: *Document) void {
|
pub fn deinit(self: Document) void {
|
||||||
self.arena.deinit();
|
var arena = self.arena; // Copy to stack so self can be taken by value.
|
||||||
|
arena.deinit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user