| author | |
| committer | |
| log | 4683de1e918c708ded3b111ae43fc702d28b1d52 |
| tree | 1d1eec82de669cc7f59a05db8069e78c509f61d7 |
| parent | c558a1ae26eaa8c59e97e80ec01990e35ef50f3a |
| parent | e8aa6f90d6e8c69f3af32942d0ae2bdf44e34783 |
| signature |
stage2 llvm bindings: use correct type for LLVMBool for ABI compat 2 files changed, 34 insertions(+), 21 deletions(-)
src/codegen/llvm.zig+11-11| ... | ... | @@ -219,7 +219,7 @@ pub const LLVMIRModule = struct { |
| 219 | 219 | |
| 220 | 220 | var error_message: [*:0]const u8 = undefined; |
| 221 | 221 | 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()) { | |
| 223 | 223 | defer llvm.disposeMessage(error_message); |
| 224 | 224 | |
| 225 | 225 | const stderr = std.io.getStdErr().writer(); |
| ... | ... | @@ -303,7 +303,7 @@ pub const LLVMIRModule = struct { |
| 303 | 303 | // verifyModule always allocs the error_message even if there is no error |
| 304 | 304 | defer llvm.disposeMessage(error_message); |
| 305 | 305 | |
| 306 | if (self.llvm_module.verify(.ReturnStatus, &error_message)) { | |
| 306 | if (self.llvm_module.verify(.ReturnStatus, &error_message).toBool()) { | |
| 307 | 307 | const stderr = std.io.getStdErr().writer(); |
| 308 | 308 | try stderr.print("broken LLVM module found: {s}\nThis is a bug in the Zig compiler.", .{error_message}); |
| 309 | 309 | return error.BrokenLLVMModule; |
| ... | ... | @@ -319,7 +319,7 @@ pub const LLVMIRModule = struct { |
| 319 | 319 | object_pathZ.ptr, |
| 320 | 320 | .ObjectFile, |
| 321 | 321 | &error_message, |
| 322 | )) { | |
| 322 | ).toBool()) { | |
| 323 | 323 | defer llvm.disposeMessage(error_message); |
| 324 | 324 | |
| 325 | 325 | const stderr = std.io.getStdErr().writer(); |
| ... | ... | @@ -614,7 +614,7 @@ pub const LLVMIRModule = struct { |
| 614 | 614 | |
| 615 | 615 | var indices: [2]*const llvm.Value = .{ |
| 616 | 616 | index_type.constNull(), |
| 617 | index_type.constInt(1, false), | |
| 617 | index_type.constInt(1, .False), | |
| 618 | 618 | }; |
| 619 | 619 | |
| 620 | 620 | return self.builder.buildLoad(self.builder.buildInBoundsGEP(operand, &indices, 2, ""), ""); |
| ... | ... | @@ -676,7 +676,7 @@ pub const LLVMIRModule = struct { |
| 676 | 676 | const signed = inst.base.ty.isSignedInt(); |
| 677 | 677 | // TODO: Should we use intcast here or just a simple bitcast? |
| 678 | 678 | // 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), ""); | |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | fn genBitCast(self: *LLVMIRModule, inst: *Inst.UnOp) !?*const llvm.Value { |
| ... | ... | @@ -782,7 +782,7 @@ pub const LLVMIRModule = struct { |
| 782 | 782 | if (bigint.limbs.len != 1) { |
| 783 | 783 | return self.fail(src, "TODO implement bigger bigint", .{}); |
| 784 | 784 | } |
| 785 | const llvm_int = llvm_type.constInt(bigint.limbs[0], false); | |
| 785 | const llvm_int = llvm_type.constInt(bigint.limbs[0], .False); | |
| 786 | 786 | if (!bigint.positive) { |
| 787 | 787 | return llvm.constNeg(llvm_int); |
| 788 | 788 | } |
| ... | ... | @@ -820,7 +820,7 @@ pub const LLVMIRModule = struct { |
| 820 | 820 | return self.fail(src, "TODO handle other sentinel values", .{}); |
| 821 | 821 | } else false; |
| 822 | 822 | |
| 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)); | |
| 824 | 824 | } else { |
| 825 | 825 | return self.fail(src, "TODO handle more array values", .{}); |
| 826 | 826 | } |
| ... | ... | @@ -836,13 +836,13 @@ pub const LLVMIRModule = struct { |
| 836 | 836 | llvm_child_type.constNull(), |
| 837 | 837 | self.context.intType(1).constNull(), |
| 838 | 838 | }; |
| 839 | return self.context.constStruct(&optional_values, 2, false); | |
| 839 | return self.context.constStruct(&optional_values, 2, .False); | |
| 840 | 840 | } else { |
| 841 | 841 | var optional_values: [2]*const llvm.Value = .{ |
| 842 | 842 | try self.genTypedValue(src, .{ .ty = child_type, .val = tv.val }), |
| 843 | 843 | self.context.intType(1).constAllOnes(), |
| 844 | 844 | }; |
| 845 | return self.context.constStruct(&optional_values, 2, false); | |
| 845 | return self.context.constStruct(&optional_values, 2, .False); | |
| 846 | 846 | } |
| 847 | 847 | } else { |
| 848 | 848 | return self.fail(src, "TODO implement const of optional pointer", .{}); |
| ... | ... | @@ -882,7 +882,7 @@ pub const LLVMIRModule = struct { |
| 882 | 882 | try self.getLLVMType(child_type, src), |
| 883 | 883 | self.context.intType(1), |
| 884 | 884 | }; |
| 885 | return self.context.structType(&optional_types, 2, false); | |
| 885 | return self.context.structType(&optional_types, 2, .False); | |
| 886 | 886 | } else { |
| 887 | 887 | return self.fail(src, "TODO implement optional pointers as actual pointers", .{}); |
| 888 | 888 | } |
| ... | ... | @@ -934,7 +934,7 @@ pub const LLVMIRModule = struct { |
| 934 | 934 | try self.getLLVMType(return_type, src), |
| 935 | 935 | if (fn_param_len == 0) null else llvm_param.ptr, |
| 936 | 936 | @intCast(c_uint, fn_param_len), |
| 937 | false, | |
| 937 | .False, | |
| 938 | 938 | ); |
| 939 | 939 | const llvm_fn = self.llvm_module.addFunction(func.name, fn_type); |
| 940 | 940 |
src/codegen/llvm/bindings.zig+23-10| ... | ... | @@ -1,7 +1,20 @@ |
| 1 | 1 | //! We do this instead of @cImport because the self-hosted compiler is easier |
| 2 | 2 | //! to bootstrap if it does not depend on translate-c. |
| 3 | 3 | |
| 4 | const LLVMBool = bool; | |
| 4 | /// Do not compare directly to .True, use toBool() instead. | |
| 5 | pub 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 | }; | |
| 5 | 18 | pub const AttributeIndex = c_uint; |
| 6 | 19 | |
| 7 | 20 | /// Make sure to use the *InContext functions instead of the global ones. |
| ... | ... | @@ -22,13 +35,13 @@ pub const Context = opaque { |
| 22 | 35 | extern fn LLVMVoidTypeInContext(C: *const Context) *const Type; |
| 23 | 36 | |
| 24 | 37 | pub const structType = LLVMStructTypeInContext; |
| 25 | extern fn LLVMStructTypeInContext(C: *const Context, ElementTypes: [*]*const Type, ElementCount: c_uint, Packed: LLVMBool) *const Type; | |
| 38 | extern fn LLVMStructTypeInContext(C: *const Context, ElementTypes: [*]*const Type, ElementCount: c_uint, Packed: Bool) *const Type; | |
| 26 | 39 | |
| 27 | 40 | pub const constString = LLVMConstStringInContext; |
| 28 | extern fn LLVMConstStringInContext(C: *const Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: LLVMBool) *const Value; | |
| 41 | extern fn LLVMConstStringInContext(C: *const Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) *const Value; | |
| 29 | 42 | |
| 30 | 43 | pub const constStruct = LLVMConstStructInContext; |
| 31 | extern fn LLVMConstStructInContext(C: *const Context, ConstantVals: [*]*const Value, Count: c_uint, Packed: LLVMBool) *const Value; | |
| 44 | extern fn LLVMConstStructInContext(C: *const Context, ConstantVals: [*]*const Value, Count: c_uint, Packed: Bool) *const Value; | |
| 32 | 45 | |
| 33 | 46 | pub const createBasicBlock = LLVMCreateBasicBlockInContext; |
| 34 | 47 | extern fn LLVMCreateBasicBlockInContext(C: *const Context, Name: [*:0]const u8) *const BasicBlock; |
| ... | ... | @@ -59,7 +72,7 @@ pub const Value = opaque { |
| 59 | 72 | |
| 60 | 73 | pub const Type = opaque { |
| 61 | 74 | pub const functionType = LLVMFunctionType; |
| 62 | extern fn LLVMFunctionType(ReturnType: *const Type, ParamTypes: ?[*]*const Type, ParamCount: c_uint, IsVarArg: LLVMBool) *const Type; | |
| 75 | extern fn LLVMFunctionType(ReturnType: *const Type, ParamTypes: ?[*]*const Type, ParamCount: c_uint, IsVarArg: Bool) *const Type; | |
| 63 | 76 | |
| 64 | 77 | pub const constNull = LLVMConstNull; |
| 65 | 78 | extern fn LLVMConstNull(Ty: *const Type) *const Value; |
| ... | ... | @@ -68,7 +81,7 @@ pub const Type = opaque { |
| 68 | 81 | extern fn LLVMConstAllOnes(Ty: *const Type) *const Value; |
| 69 | 82 | |
| 70 | 83 | pub const constInt = LLVMConstInt; |
| 71 | extern fn LLVMConstInt(IntTy: *const Type, N: c_ulonglong, SignExtend: LLVMBool) *const Value; | |
| 84 | extern fn LLVMConstInt(IntTy: *const Type, N: c_ulonglong, SignExtend: Bool) *const Value; | |
| 72 | 85 | |
| 73 | 86 | pub const constArray = LLVMConstArray; |
| 74 | 87 | extern fn LLVMConstArray(ElementTy: *const Type, ConstantVals: ?[*]*const Value, Length: c_uint) *const Value; |
| ... | ... | @@ -91,7 +104,7 @@ pub const Module = opaque { |
| 91 | 104 | extern fn LLVMDisposeModule(*const Module) void; |
| 92 | 105 | |
| 93 | 106 | pub const verify = LLVMVerifyModule; |
| 94 | extern fn LLVMVerifyModule(*const Module, Action: VerifierFailureAction, OutMessage: *[*:0]const u8) LLVMBool; | |
| 107 | extern fn LLVMVerifyModule(*const Module, Action: VerifierFailureAction, OutMessage: *[*:0]const u8) Bool; | |
| 95 | 108 | |
| 96 | 109 | pub const addFunction = LLVMAddFunction; |
| 97 | 110 | extern fn LLVMAddFunction(*const Module, Name: [*:0]const u8, FunctionTy: *const Type) *const Value; |
| ... | ... | @@ -191,7 +204,7 @@ pub const Builder = opaque { |
| 191 | 204 | extern fn LLVMBuildNUWSub(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value; |
| 192 | 205 | |
| 193 | 206 | pub const buildIntCast2 = LLVMBuildIntCast2; |
| 194 | extern fn LLVMBuildIntCast2(*const Builder, Val: *const Value, DestTy: *const Type, IsSigned: LLVMBool, Name: [*:0]const u8) *const Value; | |
| 207 | extern fn LLVMBuildIntCast2(*const Builder, Val: *const Value, DestTy: *const Type, IsSigned: Bool, Name: [*:0]const u8) *const Value; | |
| 195 | 208 | |
| 196 | 209 | pub const buildBitCast = LLVMBuildBitCast; |
| 197 | 210 | extern fn LLVMBuildBitCast(*const Builder, Val: *const Value, DestTy: *const Type, Name: [*:0]const u8) *const Value; |
| ... | ... | @@ -258,7 +271,7 @@ pub const TargetMachine = opaque { |
| 258 | 271 | Filename: [*:0]const u8, |
| 259 | 272 | codegen: CodeGenFileType, |
| 260 | 273 | ErrorMessage: *[*:0]const u8, |
| 261 | ) LLVMBool; | |
| 274 | ) Bool; | |
| 262 | 275 | }; |
| 263 | 276 | |
| 264 | 277 | pub const CodeMode = extern enum { |
| ... | ... | @@ -295,7 +308,7 @@ pub const CodeGenFileType = extern enum { |
| 295 | 308 | |
| 296 | 309 | pub const Target = opaque { |
| 297 | 310 | pub const getFromTriple = LLVMGetTargetFromTriple; |
| 298 | extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **const Target, ErrorMessage: *[*:0]const u8) LLVMBool; | |
| 311 | extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **const Target, ErrorMessage: *[*:0]const u8) Bool; | |
| 299 | 312 | }; |
| 300 | 313 | |
| 301 | 314 | extern fn LLVMInitializeAArch64TargetInfo() void; |