initial commit
This commit is contained in:
0
src/Image.zig
git.filemode.normal_file
0
src/Image.zig
git.filemode.normal_file
9
src/Interpreter.zig
git.filemode.normal_file
9
src/Interpreter.zig
git.filemode.normal_file
@@ -0,0 +1,9 @@
|
||||
const Self = @This();
|
||||
|
||||
pub fn init() !Self {
|
||||
return .{};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *const Self) void {
|
||||
_ = self;
|
||||
}
|
||||
58
src/Module.zig
git.filemode.normal_file
58
src/Module.zig
git.filemode.normal_file
@@ -0,0 +1,58 @@
|
||||
const std = @import("std");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const SpvVoid = lib.SpvVoid;
|
||||
const SpvByte = lib.SpvByte;
|
||||
const SpvWord = lib.SpvWord;
|
||||
const SpvBool = lib.SpvBool;
|
||||
const spv = lib.spv;
|
||||
|
||||
const Interpreter = @import("Interpreter.zig");
|
||||
const WordIterator = @import("WordIterator.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
const SpvEntryPoint = struct {
|
||||
exec_model: spv.SpvExecutionModel,
|
||||
id: SpvWord,
|
||||
name: []const u8,
|
||||
globals_count: SpvWord,
|
||||
globals: []const SpvWord,
|
||||
};
|
||||
|
||||
ctx: *const Interpreter,
|
||||
|
||||
it: WordIterator,
|
||||
|
||||
version_major: SpvByte,
|
||||
version_minor: SpvByte,
|
||||
generator_magic: SpvWord,
|
||||
|
||||
bound: SpvWord,
|
||||
|
||||
code: []const SpvWord,
|
||||
|
||||
addressing: spv.SpvAddressingModel,
|
||||
memory_model: spv.SpvMemoryModel,
|
||||
|
||||
entry_point_count: SpvWord,
|
||||
entry_points: []const SpvEntryPoint,
|
||||
|
||||
local_size_x: SpvWord,
|
||||
local_size_y: SpvWord,
|
||||
local_size_z: SpvWord,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, ctx: *const Interpreter, source: []const SpvWord) !Self {
|
||||
var self: Self = std.mem.zeroInit(Self, .{
|
||||
.ctx = ctx,
|
||||
.code = try allocator.dupe(SpvWord, source),
|
||||
});
|
||||
|
||||
self.it = WordIterator.init(self.code);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *const Self, allocator: std.mem.Allocator) void {
|
||||
allocator.free(self.code);
|
||||
}
|
||||
9
src/State.zig
git.filemode.normal_file
9
src/State.zig
git.filemode.normal_file
@@ -0,0 +1,9 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Interpreter = @import("Interpreter.zig");
|
||||
const Module = @import("Module.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
ctx: *Interpreter,
|
||||
owner: *Module,
|
||||
33
src/WordIterator.zig
git.filemode.normal_file
33
src/WordIterator.zig
git.filemode.normal_file
@@ -0,0 +1,33 @@
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const SpvWord = lib.SpvWord;
|
||||
|
||||
const Self = @This();
|
||||
|
||||
buffer: []const SpvWord,
|
||||
index: usize,
|
||||
|
||||
pub fn init(buffer: []const SpvWord) Self {
|
||||
return .{
|
||||
.buffer = buffer,
|
||||
.index = 0,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn next(self: *Self) ?SpvWord {
|
||||
const word = self.peek() orelse return null;
|
||||
self.index += 1;
|
||||
return word;
|
||||
}
|
||||
|
||||
pub fn peek(self: *const Self) ?SpvWord {
|
||||
return if (self.index >= self.buffer.len) null else self.buffer[self.index];
|
||||
}
|
||||
|
||||
pub fn skip(self: *Self) bool {
|
||||
if (self.index >= self.buffer.len) {
|
||||
return false;
|
||||
}
|
||||
self.index += 1;
|
||||
return true;
|
||||
}
|
||||
21
src/lib.zig
git.filemode.normal_file
21
src/lib.zig
git.filemode.normal_file
@@ -0,0 +1,21 @@
|
||||
const std = @import("std");
|
||||
pub const spv = @cImport(@cInclude("spirv.h"));
|
||||
|
||||
pub const Image = @import("Image.zig");
|
||||
pub const Interpreter = @import("Interpreter.zig");
|
||||
pub const Module = @import("Module.zig");
|
||||
pub const State = @import("State.zig");
|
||||
const opcode = @import("opcode.zig");
|
||||
|
||||
pub const SpvVoid = void;
|
||||
pub const SpvByte = u8;
|
||||
pub const SpvWord = u32;
|
||||
pub const SpvBool = bool;
|
||||
|
||||
test {
|
||||
std.testing.refAllDecls(Image);
|
||||
std.testing.refAllDecls(Interpreter);
|
||||
std.testing.refAllDecls(Module);
|
||||
std.testing.refAllDecls(State);
|
||||
std.testing.refAllDecls(opcode);
|
||||
}
|
||||
0
src/opcode.zig
git.filemode.normal_file
0
src/opcode.zig
git.filemode.normal_file
Reference in New Issue
Block a user