authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2021-03-14 22:43:03-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2021-03-16 17:05:36-06:00
loge8aa6f90d6e8c69f3af32942d0ae2bdf44e34783
tree6a052e89591314fa58c1036c9b5d65c01d2b1285
parent277b01a089e059d63b6a01de011b666cc0702c38
signaturelock-open Commit is signed but in an unrecognized format.

stage2 llvm bindings: use correct type for LLVMBool for ABI compat


2 files changed, 25 insertions(+), 12 deletions(-)

src/codegen/llvm.zig+11-11
......@@ -219,7 +219,7 @@ pub const LLVMIRModule = struct {
219219
220220 var error_message: [*:0]const u8 = undefined;
221221 var target: *const llvm.Target = undefined;
222 if (llvm.Target.getFromTriple(llvm_target_triple.ptr, &target, &error_message)) {
222 if (llvm.Target.getFromTriple(llvm_target_triple.ptr, &target, &error_message).toBool()) {
223223 defer llvm.disposeMessage(error_message);
224224
225225 const stderr = std.io.getStdErr().writer();
......@@ -303,7 +303,7 @@ pub const LLVMIRModule = struct {
303303 // verifyModule always allocs the error_message even if there is no error
304304 defer llvm.disposeMessage(error_message);
305305
306 if (self.llvm_module.verify(.ReturnStatus, &error_message)) {
306 if (self.llvm_module.verify(.ReturnStatus, &error_message).toBool()) {
307307 const stderr = std.io.getStdErr().writer();
308308 try stderr.print("broken LLVM module found: {s}\nThis is a bug in the Zig compiler.", .{error_message});
309309 return error.BrokenLLVMModule;
......@@ -319,7 +319,7 @@ pub const LLVMIRModule = struct {
319319 object_pathZ.ptr,
320320 .ObjectFile,
321321 &error_message,
322 )) {
322 ).toBool()) {
323323 defer llvm.disposeMessage(error_message);
324324
325325 const stderr = std.io.getStdErr().writer();
......@@ -614,7 +614,7 @@ pub const LLVMIRModule = struct {
614614
615615 var indices: [2]*const llvm.Value = .{
616616 index_type.constNull(),
617 index_type.constInt(1, false),
617 index_type.constInt(1, .False),
618618 };
619619
620620 return self.builder.buildLoad(self.builder.buildInBoundsGEP(operand, &indices, 2, ""), "");
......@@ -676,7 +676,7 @@ pub const LLVMIRModule = struct {
676676 const signed = inst.base.ty.isSignedInt();
677677 // TODO: Should we use intcast here or just a simple bitcast?
678678 // LLVM does truncation vs bitcast (+signed extension) in the intcast depending on the sizes
679 return self.builder.buildIntCast2(val, try self.getLLVMType(inst.base.ty, inst.base.src), signed, "");
679 return self.builder.buildIntCast2(val, try self.getLLVMType(inst.base.ty, inst.base.src), llvm.Bool.fromBool(signed), "");
680680 }
681681
682682 fn genBitCast(self: *LLVMIRModule, inst: *Inst.UnOp) !?*const llvm.Value {
......@@ -782,7 +782,7 @@ pub const LLVMIRModule = struct {
782782 if (bigint.limbs.len != 1) {
783783 return self.fail(src, "TODO implement bigger bigint", .{});
784784 }
785 const llvm_int = llvm_type.constInt(bigint.limbs[0], false);
785 const llvm_int = llvm_type.constInt(bigint.limbs[0], .False);
786786 if (!bigint.positive) {
787787 return llvm.constNeg(llvm_int);
788788 }
......@@ -820,7 +820,7 @@ pub const LLVMIRModule = struct {
820820 return self.fail(src, "TODO handle other sentinel values", .{});
821821 } else false;
822822
823 return self.context.constString(payload.data.ptr, @intCast(c_uint, payload.data.len), !zero_sentinel);
823 return self.context.constString(payload.data.ptr, @intCast(c_uint, payload.data.len), llvm.Bool.fromBool(!zero_sentinel));
824824 } else {
825825 return self.fail(src, "TODO handle more array values", .{});
826826 }
......@@ -836,13 +836,13 @@ pub const LLVMIRModule = struct {
836836 llvm_child_type.constNull(),
837837 self.context.intType(1).constNull(),
838838 };
839 return self.context.constStruct(&optional_values, 2, false);
839 return self.context.constStruct(&optional_values, 2, .False);
840840 } else {
841841 var optional_values: [2]*const llvm.Value = .{
842842 try self.genTypedValue(src, .{ .ty = child_type, .val = tv.val }),
843843 self.context.intType(1).constAllOnes(),
844844 };
845 return self.context.constStruct(&optional_values, 2, false);
845 return self.context.constStruct(&optional_values, 2, .False);
846846 }
847847 } else {
848848 return self.fail(src, "TODO implement const of optional pointer", .{});
......@@ -882,7 +882,7 @@ pub const LLVMIRModule = struct {
882882 try self.getLLVMType(child_type, src),
883883 self.context.intType(1),
884884 };
885 return self.context.structType(&optional_types, 2, false);
885 return self.context.structType(&optional_types, 2, .False);
886886 } else {
887887 return self.fail(src, "TODO implement optional pointers as actual pointers", .{});
888888 }
......@@ -934,7 +934,7 @@ pub const LLVMIRModule = struct {
934934 try self.getLLVMType(return_type, src),
935935 if (fn_param_len == 0) null else llvm_param.ptr,
936936 @intCast(c_uint, fn_param_len),
937 false,
937 .False,
938938 );
939939 const llvm_fn = self.llvm_module.addFunction(func.name, fn_type);
940940
src/codegen/llvm/bindings.zig+14-1
......@@ -1,7 +1,20 @@
11//! We do this instead of @cImport because the self-hosted compiler is easier
22//! to bootstrap if it does not depend on translate-c.
33
4const Bool = bool;
4/// Do not compare directly to .True, use toBool() instead.
5pub const Bool = enum(c_int) {
6 False,
7 True,
8 _,
9
10 pub fn fromBool(b: bool) Bool {
11 return @intToEnum(Bool, @boolToInt(b));
12 }
13
14 pub fn toBool(b: Bool) bool {
15 return b != .False;
16 }
17};
518pub const AttributeIndex = c_uint;
619
720/// Make sure to use the *InContext functions instead of the global ones.