Make SPIR-V registry parse-able by std.json.parse

This commit is contained in:
Robin Voetter
2020-08-12 02:20:07 +02:00
parent c708f01e3a
commit c761d8e635
3 changed files with 63 additions and 41 deletions

View File

@@ -0,0 +1,14 @@
const std = @import("std");
const reg = @import("registry.zig");
const Allocator = std.mem.Allocator;
pub fn generate(allocator: *Allocator, spec_jsons: []const []const u8, writer: anytype) !void {
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
const registries = try arena.allocator.alloc(reg.Registry, spec_jsons.len);
for (registries) |*registry, i| {
var tokens = std.json.TokenStream.init(spec_jsons[i]);
registry.* = try std.json.parse(reg.Registry, &tokens, .{.allocator = &arena.allocator});
}
}