aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-01-18 23:47:25 +0100
committerRobin Voetter <robin@voetter.nl>2021-01-19 15:28:17 +0100
commit02c138fe7011346ebab5e4b24ba0f8575bb52173 (patch)
tree5f59ca5e6e25d700dd3aa9d1ea1f9be577bdb1a6 /src
parentb2b87b590011d8df52874e3f9bd1f88d1b0189d1 (diff)
downloadzig-02c138fe7011346ebab5e4b24ba0f8575bb52173.tar.gz
zig-02c138fe7011346ebab5e4b24ba0f8575bb52173.zip
SPIR-V: Add glsl450 and vulkan spir-v operating system definitions
Diffstat (limited to 'src')
-rw-r--r--src/codegen/llvm.zig5
-rw-r--r--src/link/SpirV.zig20
-rw-r--r--src/target.zig4
-rw-r--r--src/type.zig2
4 files changed, 29 insertions, 2 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 1edd466d54..df6a58b1e2 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -69,6 +69,8 @@ pub fn targetTriple(allocator: *Allocator, target: std.Target) ![:0]u8 {
.renderscript64 => "renderscript64",
.ve => "ve",
.spu_2 => return error.LLVMBackendDoesNotSupportSPUMarkII,
+ .spirv32 => return error.LLVMBackendDoesNotSupportSPIRV,
+ .spirv64 => return error.LLVMBackendDoesNotSupportSPIRV,
};
// TODO Add a sub-arch for some architectures depending on CPU features.
@@ -109,6 +111,9 @@ pub fn targetTriple(allocator: *Allocator, target: std.Target) ![:0]u8 {
.wasi => "wasi",
.emscripten => "emscripten",
.uefi => "windows",
+ .opencl => return error.LLVMBackendDoesNotSupportOpenCL,
+ .glsl450 => return error.LLVMBackendDoesNotSupportGLSL450,
+ .vulkan => return error.LLVMBackendDoesNotSupportVulkan,
.other => "unknown",
};
diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig
index 207e460174..68edfab845 100644
--- a/src/link/SpirV.zig
+++ b/src/link/SpirV.zig
@@ -12,6 +12,8 @@ const trace = @import("../tracy.zig").trace;
const build_options = @import("build_options");
const spec = @import("../codegen/spirv/spec.zig");
+//! SPIR-V Documentation: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html
+
pub const FnData = struct {
id: ?u32 = null,
code: std.ArrayListUnmanaged(u32) = .{},
@@ -32,6 +34,22 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV {
.allocator = gpa,
},
};
+
+ // TODO: Figure out where to put all of these
+ switch (options.target.cpu.arch) {
+ .spirv32, .spirv64 => {},
+ else => return error.TODOArchNotSupported,
+ }
+
+ switch (options.target.os.tag) {
+ .opencl, .glsl450, .vulkan => {},
+ else => return error.TODOOsNotSupported,
+ }
+
+ if (options.target.abi != .none) {
+ return error.TODOAbiNotSupported;
+ }
+
return spirv;
}
@@ -119,6 +137,8 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void {
switch (decl.typed_value) {
.most_recent => |tvm| {
const fn_data = &decl.fn_link.spirv;
+
+ // TODO: This could probably be more efficient.
for (fn_data.code.items) |word| {
try writer.writeIntLittle(u32, word);
}
diff --git a/src/target.zig b/src/target.zig
index c3df682ce0..e167520f89 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -189,7 +189,7 @@ pub fn supportsStackProbing(target: std.Target) bool {
pub fn osToLLVM(os_tag: std.Target.Os.Tag) llvm.OSType {
return switch (os_tag) {
- .freestanding, .other => .UnknownOS,
+ .freestanding, .other, .opencl, .glsl450, .vulkan => .UnknownOS,
.windows, .uefi => .Win32,
.ananas => .Ananas,
.cloudabi => .CloudABI,
@@ -280,7 +280,7 @@ pub fn archToLLVM(arch_tag: std.Target.Cpu.Arch) llvm.ArchType {
.renderscript32 => .renderscript32,
.renderscript64 => .renderscript64,
.ve => .ve,
- .spu_2 => .UnknownArch,
+ .spu_2, .spirv32, .spirv64 => .UnknownArch,
};
}
diff --git a/src/type.zig b/src/type.zig
index cb2448aa1a..e0190cdd37 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3598,6 +3598,8 @@ pub const CType = enum {
.hermit,
.hurd,
.opencl,
+ .glsl450,
+ .vulkan,
=> @panic("TODO specify the C integer and float type sizes for this OS"),
}
}