import c
This commit is contained in:
@@ -8498,6 +8498,32 @@ pub const CodeGen = struct {
|
||||
return self.inferType(node).isFloat();
|
||||
}
|
||||
|
||||
/// Load LLVM bitcode from a file and merge it into the current module.
|
||||
pub fn mergeBitcodeFile(self: *CodeGen, bc_path: []const u8) !void {
|
||||
const bc_path_z = try self.allocator.dupeZ(u8, bc_path);
|
||||
var buf: c.LLVMMemoryBufferRef = null;
|
||||
var err_msg: [*c]u8 = null;
|
||||
|
||||
if (c.LLVMCreateMemoryBufferWithContentsOfFile(bc_path_z.ptr, &buf, &err_msg) != 0) {
|
||||
if (err_msg != null) {
|
||||
defer c.LLVMDisposeMessage(err_msg);
|
||||
const msg = std.mem.span(err_msg);
|
||||
return self.emitErrorFmt("failed to read bitcode '{s}': {s}", .{ bc_path, msg });
|
||||
}
|
||||
return error.CompileError;
|
||||
}
|
||||
|
||||
var bc_module: c.LLVMModuleRef = null;
|
||||
if (c.LLVMParseBitcodeInContext2(self.context, buf, &bc_module) != 0) {
|
||||
return self.emitErrorFmt("failed to parse bitcode '{s}'", .{bc_path});
|
||||
}
|
||||
|
||||
// LLVMLinkModules2 destroys bc_module on success
|
||||
if (c.LLVMLinkModules2(self.module, bc_module) != 0) {
|
||||
return self.emitErrorFmt("failed to link bitcode module '{s}'", .{bc_path});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify(self: *CodeGen) !void {
|
||||
var err_msg: [*c]u8 = null;
|
||||
if (c.LLVMVerifyModule(self.module, c.LLVMReturnStatusAction, &err_msg) != 0) {
|
||||
@@ -8602,13 +8628,14 @@ pub const CodeGen = struct {
|
||||
return if (result >= 0 and result <= 255) @intCast(result) else 1;
|
||||
}
|
||||
|
||||
pub fn link(allocator: std.mem.Allocator, io: std.Io, output_obj: []const u8, output_bin: []const u8, libraries: []const []const u8, target_config: TargetConfig) !void {
|
||||
pub fn link(allocator: std.mem.Allocator, io: std.Io, output_obj: []const u8, extra_objects: []const []const u8, output_bin: []const u8, libraries: []const []const u8, target_config: TargetConfig) !void {
|
||||
var argv = std.ArrayList([]const u8).empty;
|
||||
|
||||
if (target_config.isWindows()) {
|
||||
// Windows: MSVC-style linker flags
|
||||
const linker = target_config.linker orelse "link.exe";
|
||||
try argv.appendSlice(allocator, &.{ linker, output_obj });
|
||||
for (extra_objects) |eo| try argv.append(allocator, eo);
|
||||
try argv.append(allocator, try std.fmt.allocPrint(allocator, "/OUT:{s}", .{output_bin}));
|
||||
|
||||
for (target_config.lib_paths) |lp| {
|
||||
@@ -8620,6 +8647,7 @@ pub const CodeGen = struct {
|
||||
} else {
|
||||
// Unix: cc-style linker flags
|
||||
try argv.appendSlice(allocator, &.{ target_config.getLinker(), output_obj, "-o", output_bin });
|
||||
for (extra_objects) |eo| try argv.append(allocator, eo);
|
||||
|
||||
if (target_config.sysroot) |sr| {
|
||||
try argv.append(allocator, try std.fmt.allocPrint(allocator, "--sysroot={s}", .{sr}));
|
||||
|
||||
Reference in New Issue
Block a user