authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2023-08-13 16:11:33+02:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-21 16:24:59+01:00
logd3055480ec27de9107678fc9e2ac9075633f1384
tree1b30f33c3b13d8b441e9e47c1cdfba985b24367a
parent049cad44113ad8851be95f691188402456551e3a

LLVM: Emit bitcode even if libllvm is not present


1 files changed, 20 insertions(+), 1 deletions(-)

src/codegen/llvm.zig+20-1
...@@ -1238,7 +1238,26 @@ pub const Object = struct {...@@ -1238,7 +1238,26 @@ pub const Object = struct {
1238 if (options.asm_path == null and options.bin_path == null and1238 if (options.asm_path == null and options.bin_path == null and
1239 options.post_ir_path == null and options.post_bc_path == null) return;1239 options.post_ir_path == null and options.post_bc_path == null) return;
12401240
1241 if (!self.builder.useLibLlvm()) unreachable; // caught in Compilation.Config.resolve1241 if (options.post_bc_path) |path| {
1242 if (!self.builder.useLibLlvm()) {
1243 var arena_allocator = std.heap.ArenaAllocator.init(self.gpa);
1244 defer arena_allocator.deinit();
1245 const arena = arena_allocator.allocator();
1246
1247 var file = try std.fs.cwd().createFileZ(path, .{});
1248 defer file.close();
1249 const bitcode = try self.builder.toBitcode(arena);
1250
1251 const ptr: [*]const u8 = @ptrCast(bitcode.ptr);
1252 try file.writeAll(ptr[0..(bitcode.len * 4)]);
1253 return;
1254 }
1255 }
1256
1257 if (!self.builder.useLibLlvm()) {
1258 log.err("emitting without libllvm not implemented", .{});
1259 return error.FailedToEmit;
1260 }
12421261
1243 // Unfortunately, LLVM shits the bed when we ask for both binary and assembly.1262 // Unfortunately, LLVM shits the bed when we ask for both binary and assembly.
1244 // So we call the entire pipeline multiple times if this is requested.1263 // So we call the entire pipeline multiple times if this is requested.