adding msb, lsb and spec constants
All checks were successful
Build / build (push) Successful in 2m3s
Test / build (push) Successful in 8m40s

This commit is contained in:
2026-03-30 01:00:00 +02:00
parent fbaf85a849
commit 6c8b364c7d
6 changed files with 431 additions and 243 deletions

View File

@@ -10,12 +10,14 @@ const Self = @This();
buffer: []const SpvWord,
index: usize,
did_jump: bool,
next_force_skip: ?usize,
pub fn init(buffer: []const SpvWord) Self {
return .{
.buffer = buffer,
.index = 0,
.did_jump = false,
.next_force_skip = null,
};
}
@@ -25,15 +27,37 @@ pub inline fn nextOrNull(self: *Self) ?SpvWord {
return word;
}
/// self.index + index will be automatically skipped
pub inline fn forceSkipIndex(self: *Self, index: SpvWord) void {
self.next_force_skip = self.index + index;
}
pub inline fn nextAsOrNull(self: *Self, comptime E: type) ?E {
if (self.next_force_skip) |skip_index| {
if (self.index == skip_index) {
_ = self.skip();
self.next_force_skip = null;
}
}
return if (self.nextOrNull()) |word| std.enums.fromInt(E, word) else null;
}
pub inline fn next(self: *Self) RuntimeError!SpvWord {
if (self.next_force_skip) |skip_index| {
if (self.index == skip_index) {
_ = self.skip();
self.next_force_skip = null;
}
}
return self.nextOrNull() orelse return RuntimeError.InvalidSpirV;
}
pub inline fn nextAs(self: *Self, comptime E: type) RuntimeError!E {
if (self.next_force_skip) |skip_index| {
if (self.index == skip_index) {
_ = self.skip();
}
}
return self.nextAsOrNull(E) orelse return RuntimeError.InvalidSpirV;
}
@@ -72,3 +96,10 @@ pub inline fn jumpToSourceLocation(self: *Self, source_location: usize) bool {
self.did_jump = true;
return true;
}
/// Like jumpToSourceLocation without toggling self.did_jump
pub inline fn goToSourceLocation(self: *Self, source_location: usize) bool {
if (source_location > self.buffer.len) return false;
self.index = source_location;
return true;
}