adding msb, lsb and spec constants
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user