aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv/Module.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2024-03-31 19:05:54 +0200
committerRobin Voetter <robin@voetter.nl>2024-04-06 13:37:37 +0200
commit42c7e752e1eae7663068e9c52ad77f7383d977e9 (patch)
treea99443bbee26923de3fb0097b77b91e573232d33 /src/codegen/spirv/Module.zig
parent39420838061a9049fbc889212836a9d4d2ab9af4 (diff)
downloadzig-42c7e752e1eae7663068e9c52ad77f7383d977e9.tar.gz
zig-42c7e752e1eae7663068e9c52ad77f7383d977e9.zip
spirv: id range helper
This allows us to more sanely allocate a continuous range of result-ids, and avoids a bunch of nasty casting code in a few places. Its currently not used very often, but will be useful in the future.
Diffstat (limited to 'src/codegen/spirv/Module.zig')
-rw-r--r--src/codegen/spirv/Module.zig24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/codegen/spirv/Module.zig b/src/codegen/spirv/Module.zig
index 92b400d438..2d3a79ffc9 100644
--- a/src/codegen/spirv/Module.zig
+++ b/src/codegen/spirv/Module.zig
@@ -197,14 +197,26 @@ pub fn deinit(self: *Module) void {
self.* = undefined;
}
-pub fn allocId(self: *Module) spec.IdResult {
- defer self.next_result_id += 1;
- return @enumFromInt(self.next_result_id);
-}
+pub const IdRange = struct {
+ base: u32,
+ len: u32,
+
+ pub fn at(range: IdRange, i: usize) IdResult {
+ assert(i < range.len);
+ return @enumFromInt(range.base + i);
+ }
+};
-pub fn allocIds(self: *Module, n: u32) spec.IdResult {
+pub fn allocIds(self: *Module, n: u32) IdRange {
defer self.next_result_id += n;
- return @enumFromInt(self.next_result_id);
+ return .{
+ .base = self.next_result_id,
+ .len = n,
+ };
+}
+
+pub fn allocId(self: *Module) IdResult {
+ return self.allocIds(1).at(0);
}
pub fn idBound(self: Module) Word {