| ... | ... | @@ -137,6 +137,11 @@ pub fn loadInput(linker: *Linker, input: link.Input) !void { |
| 137 | 137 | if (n_read != bytes.len) |
| 138 | 138 | return diags.fail("SPIR-V object '{f}': incomplete read", .{obj.path}); |
| 139 | 139 | |
| 140 | const needs_swap = all_words[0] == @byteSwap(spec.magic_number); |
| 141 | if (needs_swap) { |
| 142 | for (all_words) |*w| w.* = @byteSwap(w.*); |
| 143 | } |
| 144 | |
| 140 | 145 | if (all_words[0] != spec.magic_number) |
| 141 | 146 | return diags.fail("SPIR-V object '{f}': invalid magic number", .{obj.path}); |
| 142 | 147 | |
| ... | ... | @@ -266,16 +271,6 @@ pub fn flush( |
| 266 | 271 | var binary = linkModule(arena, merged.words, merged.id_bound, sub_prog_node) catch |err| switch (err) { |
| 267 | 272 | error.OutOfMemory => |e| return e, |
| 268 | 273 | else => |other| { |
| 269 | | // Uncomment to write the pre-link merged module for debugging |
| 270 | | // const dbg_header = [_]Word{ |
| 271 | | // spec.magic_number, |
| 272 | | // merged.version.toWord(), |
| 273 | | // merged.generator_id, |
| 274 | | // merged.id_bound, |
| 275 | | // 0, |
| 276 | | // }; |
| 277 | | // linker.base.file.?.writeStreamingAll(io, @ptrCast(&dbg_header)) catch {}; |
| 278 | | // linker.base.file.?.writeStreamingAll(io, @ptrCast(merged.words)) catch {}; |
| 279 | 274 | return diags.fail("error while linking: {s}", .{@errorName(other)}); |
| 280 | 275 | }, |
| 281 | 276 | }; |
| ... | ... | @@ -289,10 +284,17 @@ pub fn flush( |
| 289 | 284 | 0, |
| 290 | 285 | }; |
| 291 | 286 | |
| 292 | | linker.base.file.?.writeStreamingAll(io, @ptrCast(&header)) catch |err| |
| 293 | | return diags.fail("failed to write: {t}", .{err}); |
| 294 | | linker.base.file.?.writeStreamingAll(io, @ptrCast(binary.instructions)) catch |err| |
| 295 | | return diags.fail("failed to write: {t}", .{err}); |
| 287 | var file_writer = linker.base.file.?.writer(io, &.{}); |
| 288 | file_writer.interface.writeSliceEndian(Word, &header, .little) catch |err| switch (err) { |
| 289 | error.WriteFailed => return diags.fail("failed to write: {t}", .{file_writer.err.?}), |
| 290 | }; |
| 291 | file_writer.interface.writeSliceEndian(Word, binary.instructions, .little) catch |err| switch (err) { |
| 292 | error.WriteFailed => return diags.fail("failed to write: {t}", .{file_writer.err.?}), |
| 293 | }; |
| 294 | file_writer.end() catch |err| switch (err) { |
| 295 | error.WriteFailed => return diags.fail("failed to write: {t}", .{file_writer.err.?}), |
| 296 | else => |e| return diags.fail("failed to write: {t}", .{e}), |
| 297 | }; |
| 296 | 298 | } |
| 297 | 299 | |
| 298 | 300 | fn linkModule(arena: Allocator, words: []const Word, id_bound: u32, progress: std.Progress.Node) !BinaryModule { |