| ... | ... | @@ -58,3 +58,23 @@ pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void { |
| 58 | 58 | mir.* = undefined; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | /// Returns the requested data, as well as the new index which is at the start of the |
| 62 | /// trailers for the object. |
| 63 | pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } { |
| 64 | const fields = std.meta.fields(T); |
| 65 | var i: usize = index; |
| 66 | var result: T = undefined; |
| 67 | inline for (fields) |field| { |
| 68 | @field(result, field.name) = switch (field.field_type) { |
| 69 | u32 => mir.extra[i], |
| 70 | i32 => @bitCast(i32, mir.extra[i]), |
| 71 | else => @compileError("bad field type"), |
| 72 | }; |
| 73 | i += 1; |
| 74 | } |
| 75 | return .{ |
| 76 | .data = result, |
| 77 | .end = i, |
| 78 | }; |
| 79 | } |
| 80 | |