|
1 | 1 | const std = @import("std");
|
| 2 | +const assert = std.debug.assert; |
2 | 3 | const Allocator = std.mem.Allocator;
|
3 | 4 | const Compilation = @import("Compilation.zig");
|
4 | 5 | const llvm = @import("llvm_bindings.zig");
|
@@ -433,15 +434,20 @@ pub const LLVMIRModule = struct {
|
433 | 434 | }
|
434 | 435 |
|
435 | 436 | fn genBreakpoint(self: *LLVMIRModule, inst: *Inst.NoOp) !?*const llvm.ValueRef {
|
436 |
| - // TODO: Store this function somewhere such that we dont have to add it again |
437 |
| - const fn_type = llvm.TypeRef.functionType(llvm.voidType(), null, 0, false); |
438 |
| - const func = self.llvm_module.addFunction("llvm.debugtrap", fn_type); |
439 |
| - |
440 |
| - // TODO: add assertion: LLVMGetIntrinsicID |
441 |
| - _ = self.builder.buildCall(func, null, 0, ""); |
| 437 | + const llvn_fn = self.getIntrinsic("llvm.debugtrap"); |
| 438 | + _ = self.builder.buildCall(llvn_fn, null, 0, ""); |
442 | 439 | return null;
|
443 | 440 | }
|
444 | 441 |
|
| 442 | + fn getIntrinsic(self: *LLVMIRModule, name: []const u8) *const llvm.ValueRef { |
| 443 | + const id = llvm.lookupIntrinsicID(name.ptr, name.len); |
| 444 | + assert(id != 0); |
| 445 | + // TODO: add support for overload intrinsics by passing the prefix of the intrinsic |
| 446 | + // to `lookupIntrinsicID` and then passing the correct types to |
| 447 | + // `getIntrinsicDeclaration` |
| 448 | + return self.llvm_module.getIntrinsicDeclaration(id, null, 0); |
| 449 | + } |
| 450 | + |
445 | 451 | fn resolveInst(self: *LLVMIRModule, inst: *ir.Inst) !*const llvm.ValueRef {
|
446 | 452 | if (inst.castTag(.constant)) |const_inst| {
|
447 | 453 | return self.genTypedValue(inst.src, .{ .ty = inst.ty, .val = const_inst.val });
|
@@ -514,7 +520,7 @@ pub const LLVMIRModule = struct {
|
514 | 520 |
|
515 | 521 | pub fn fail(self: *LLVMIRModule, src: usize, comptime format: []const u8, args: anytype) error{ OutOfMemory, CodegenFail } {
|
516 | 522 | @setCold(true);
|
517 |
| - std.debug.assert(self.err_msg == null); |
| 523 | + assert(self.err_msg == null); |
518 | 524 | self.err_msg = try Compilation.ErrorMsg.create(self.gpa, src, format, args);
|
519 | 525 | return error.CodegenFail;
|
520 | 526 | }
|
|
0 commit comments