authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-01-17 16:18:00+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-01-19 15:28:17+01:00
logab607d455e47c35b980c3281ef5c3fb433a770a7
tree061c85fb946c1dc9693c5912ae6336e27ffb58cc
parent9a6babf482047042d71d3d390933e08b7fb7c925

SPIR-V: Initial architecture definitions and setup


5 files changed, 35 insertions(+), 0 deletions(-)

lib/std/target.zig+23
......@@ -57,6 +57,7 @@ pub const Target = struct {
5757 wasi,
5858 emscripten,
5959 uefi,
60 opencl, // SPIR-V on OpenCL
6061 other,
6162
6263 pub fn isDarwin(tag: Tag) bool {
......@@ -248,6 +249,7 @@ pub const Target = struct {
248249 .wasi,
249250 .emscripten,
250251 .uefi,
252 .opencl,
251253 .other,
252254 => return .{ .none = {} },
253255
......@@ -403,6 +405,7 @@ pub const Target = struct {
403405 .wasi,
404406 .emscripten,
405407 .uefi,
408 .opencl,
406409 .other,
407410 => false,
408411 };
......@@ -421,6 +424,7 @@ pub const Target = struct {
421424 pub const powerpc = @import("target/powerpc.zig");
422425 pub const riscv = @import("target/riscv.zig");
423426 pub const sparc = @import("target/sparc.zig");
427 pub const spirv = @import("target/spirv.zig");
424428 pub const systemz = @import("target/systemz.zig");
425429 pub const wasm = @import("target/wasm.zig");
426430 pub const x86 = @import("target/x86.zig");
......@@ -493,6 +497,8 @@ pub const Target = struct {
493497 .wasi,
494498 .emscripten,
495499 => return .musl,
500 .opencl, // TODO: Where should this go?
501 => return .none,
496502 }
497503 }
498504
......@@ -528,6 +534,7 @@ pub const Target = struct {
528534 macho,
529535 wasm,
530536 c,
537 spirv,
531538 hex,
532539 raw,
533540 };
......@@ -744,6 +751,8 @@ pub const Target = struct {
744751 // Stage1 currently assumes that architectures above this comment
745752 // map one-to-one with the ZigLLVM_ArchType enum.
746753 spu_2,
754 spirv32,
755 spirv64,
747756
748757 pub fn isARM(arch: Arch) bool {
749758 return switch (arch) {
......@@ -857,6 +866,8 @@ pub const Target = struct {
857866 .s390x => ._S390,
858867 .ve => ._NONE,
859868 .spu_2 => ._SPU_2,
869 .spirv32 => ._NONE,
870 .spirv64 => ._NONE,
860871 };
861872 }
862873
......@@ -914,6 +925,8 @@ pub const Target = struct {
914925 .s390x => .Unknown,
915926 .ve => .Unknown,
916927 .spu_2 => .Unknown,
928 .spirv32 => .Unknown,
929 .spirv64 => .Unknown,
917930 };
918931 }
919932
......@@ -957,6 +970,9 @@ pub const Target = struct {
957970 .shave,
958971 .ve,
959972 .spu_2,
973 // GPU bitness is opaque. For now, assume little endian.
974 .spirv32,
975 .spirv64,
960976 => .Little,
961977
962978 .arc,
......@@ -1012,6 +1028,7 @@ pub const Target = struct {
10121028 .wasm32,
10131029 .renderscript32,
10141030 .aarch64_32,
1031 .spirv32,
10151032 => return 32,
10161033
10171034 .aarch64,
......@@ -1035,6 +1052,7 @@ pub const Target = struct {
10351052 .sparcv9,
10361053 .s390x,
10371054 .ve,
1055 .spirv64,
10381056 => return 64,
10391057 }
10401058 }
......@@ -1057,6 +1075,7 @@ pub const Target = struct {
10571075 .i386, .x86_64 => "x86",
10581076 .nvptx, .nvptx64 => "nvptx",
10591077 .wasm32, .wasm64 => "wasm",
1078 .spirv32, .spirv64 => "spir-v",
10601079 else => @tagName(arch),
10611080 };
10621081 }
......@@ -1347,6 +1366,7 @@ pub const Target = struct {
13471366 .uefi,
13481367 .windows,
13491368 .emscripten,
1369 .opencl,
13501370 .other,
13511371 => return false,
13521372 else => return true,
......@@ -1482,6 +1502,8 @@ pub const Target = struct {
14821502 .nvptx64,
14831503 .spu_2,
14841504 .avr,
1505 .spirv32,
1506 .spirv64,
14851507 => return result,
14861508
14871509 // TODO go over each item in this list and either move it to the above list, or
......@@ -1524,6 +1546,7 @@ pub const Target = struct {
15241546 .windows,
15251547 .emscripten,
15261548 .wasi,
1549 .opencl,
15271550 .other,
15281551 => return result,
15291552
lib/std/zig.zig+1
......@@ -141,6 +141,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
141141 .Lib => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}),
142142 },
143143 .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}),
144 .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}),
144145 .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}),
145146 .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}),
146147 }
lib/std/zig/cross_target.zig+2
......@@ -130,6 +130,7 @@ pub const CrossTarget = struct {
130130 .wasi,
131131 .emscripten,
132132 .uefi,
133 .opencl,
133134 .other,
134135 => {
135136 self.os_version_min = .{ .none = {} };
......@@ -730,6 +731,7 @@ pub const CrossTarget = struct {
730731 .wasi,
731732 .emscripten,
732733 .uefi,
734 .opencl,
733735 .other,
734736 => return error.InvalidOperatingSystemVersion,
735737
src/link.zig+8
......@@ -133,6 +133,7 @@ pub const File = struct {
133133 macho: MachO.TextBlock,
134134 c: C.DeclBlock,
135135 wasm: void,
136 spirv: void,
136137 };
137138
138139 pub const LinkFn = union {
......@@ -141,6 +142,7 @@ pub const File = struct {
141142 macho: MachO.SrcFn,
142143 c: C.FnBlock,
143144 wasm: ?Wasm.FnData,
145 spirv: void,
144146 };
145147
146148 pub const Export = union {
......@@ -149,6 +151,7 @@ pub const File = struct {
149151 macho: MachO.Export,
150152 c: void,
151153 wasm: void,
154 spirv: void,
152155 };
153156
154157 /// For DWARF .debug_info.
......@@ -177,6 +180,7 @@ pub const File = struct {
177180 .macho => &(try MachO.createEmpty(allocator, options)).base,
178181 .wasm => &(try Wasm.createEmpty(allocator, options)).base,
179182 .c => unreachable, // Reported error earlier.
183 .spirv => return error.SpirVObjectFormatUnimplemented,
180184 .hex => return error.HexObjectFormatUnimplemented,
181185 .raw => return error.RawObjectFormatUnimplemented,
182186 };
......@@ -192,6 +196,7 @@ pub const File = struct {
192196 .macho => &(try MachO.createEmpty(allocator, options)).base,
193197 .wasm => &(try Wasm.createEmpty(allocator, options)).base,
194198 .c => unreachable, // Reported error earlier.
199 .spirv => return error.SpirVObjectFormatUnimplemented,
195200 .hex => return error.HexObjectFormatUnimplemented,
196201 .raw => return error.RawObjectFormatUnimplemented,
197202 };
......@@ -207,6 +212,7 @@ pub const File = struct {
207212 .macho => &(try MachO.openPath(allocator, sub_path, options)).base,
208213 .wasm => &(try Wasm.openPath(allocator, sub_path, options)).base,
209214 .c => &(try C.openPath(allocator, sub_path, options)).base,
215 .spirv => return error.SpirVObjectFormatUnimplemented,
210216 .hex => return error.HexObjectFormatUnimplemented,
211217 .raw => return error.RawObjectFormatUnimplemented,
212218 };
......@@ -595,6 +601,7 @@ pub const File = struct {
595601 macho,
596602 c,
597603 wasm,
604 spirv,
598605 };
599606
600607 pub const ErrorFlags = struct {
......@@ -605,6 +612,7 @@ pub const File = struct {
605612 pub const Coff = @import("link/Coff.zig");
606613 pub const Elf = @import("link/Elf.zig");
607614 pub const MachO = @import("link/MachO.zig");
615 pub const SpirV = @import("link/SpirV.zig");
608616 pub const Wasm = @import("link/Wasm.zig");
609617};
610618
src/type.zig+1
......@@ -3597,6 +3597,7 @@ pub const CType = enum {
35973597 .amdpal,
35983598 .hermit,
35993599 .hurd,
3600 .opencl,
36003601 => @panic("TODO specify the C integer and float type sizes for this OS"),
36013602 }
36023603 }