| author | |
| committer | |
| log | 42c7e752e1eae7663068e9c52ad77f7383d977e9 |
| tree | a99443bbee26923de3fb0097b77b91e573232d33 |
| parent | 39420838061a9049fbc889212836a9d4d2ab9af4 |
| signature |
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.2 files changed, 21 insertions(+), 9 deletions(-)
src/codegen/spirv.zig+3-3| ... | ... | @@ -5440,7 +5440,7 @@ const DeclGen = struct { |
| 5440 | 5440 | }; |
| 5441 | 5441 | |
| 5442 | 5442 | // First, pre-allocate the labels for the cases. |
| 5443 | const first_case_label = self.spv.allocIds(num_cases); | |
| 5443 | const case_labels = self.spv.allocIds(num_cases); | |
| 5444 | 5444 | // We always need the default case - if zig has none, we will generate unreachable there. |
| 5445 | 5445 | const default = self.spv.allocId(); |
| 5446 | 5446 | |
| ... | ... | @@ -5471,7 +5471,7 @@ const DeclGen = struct { |
| 5471 | 5471 | const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len]; |
| 5472 | 5472 | extra_index = case.end + case.data.items_len + case_body.len; |
| 5473 | 5473 | |
| 5474 | const label: IdRef = @enumFromInt(@intFromEnum(first_case_label) + case_i); | |
| 5474 | const label = case_labels.at(case_i); | |
| 5475 | 5475 | |
| 5476 | 5476 | for (items) |item| { |
| 5477 | 5477 | const value = (try self.air.value(item, mod)) orelse unreachable; |
| ... | ... | @@ -5511,7 +5511,7 @@ const DeclGen = struct { |
| 5511 | 5511 | const case_body: []const Air.Inst.Index = @ptrCast(self.air.extra[case.end + items.len ..][0..case.data.body_len]); |
| 5512 | 5512 | extra_index = case.end + case.data.items_len + case_body.len; |
| 5513 | 5513 | |
| 5514 | const label: IdResult = @enumFromInt(@intFromEnum(first_case_label) + case_i); | |
| 5514 | const label = case_labels.at(case_i); | |
| 5515 | 5515 | |
| 5516 | 5516 | try self.beginSpvBlock(label); |
| 5517 | 5517 |
src/codegen/spirv/Module.zig+18-6| ... | ... | @@ -197,14 +197,26 @@ pub fn deinit(self: *Module) void { |
| 197 | 197 | self.* = undefined; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | pub fn allocId(self: *Module) spec.IdResult { | |
| 201 | defer self.next_result_id += 1; | |
| 202 | return @enumFromInt(self.next_result_id); | |
| 203 | } | |
| 200 | pub const IdRange = struct { | |
| 201 | base: u32, | |
| 202 | len: u32, | |
| 203 | ||
| 204 | pub fn at(range: IdRange, i: usize) IdResult { | |
| 205 | assert(i < range.len); | |
| 206 | return @enumFromInt(range.base + i); | |
| 207 | } | |
| 208 | }; | |
| 204 | 209 | |
| 205 | pub fn allocIds(self: *Module, n: u32) spec.IdResult { | |
| 210 | pub fn allocIds(self: *Module, n: u32) IdRange { | |
| 206 | 211 | defer self.next_result_id += n; |
| 207 | return @enumFromInt(self.next_result_id); | |
| 212 | return .{ | |
| 213 | .base = self.next_result_id, | |
| 214 | .len = n, | |
| 215 | }; | |
| 216 | } | |
| 217 | ||
| 218 | pub fn allocId(self: *Module) IdResult { | |
| 219 | return self.allocIds(1).at(0); | |
| 208 | 220 | } |
| 209 | 221 | |
| 210 | 222 | pub fn idBound(self: Module) Word { |