| ... | ... | @@ -486,11 +486,11 @@ pub const DeclGen = struct { |
| 486 | 486 | defer self.gpa.free(llvm_param); |
| 487 | 487 | |
| 488 | 488 | for (fn_param_types) |fn_param, i| { |
| 489 | | llvm_param[i] = try self.getLLVMType(fn_param); |
| 489 | llvm_param[i] = try self.llvmType(fn_param); |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | const fn_type = llvm.functionType( |
| 493 | | try self.getLLVMType(return_type), |
| 493 | try self.llvmType(return_type), |
| 494 | 494 | llvm_param.ptr, |
| 495 | 495 | @intCast(c_uint, fn_param_len), |
| 496 | 496 | .False, |
| ... | ... | @@ -510,8 +510,8 @@ pub const DeclGen = struct { |
| 510 | 510 | |
| 511 | 511 | assert(decl.has_tv); |
| 512 | 512 | |
| 513 | | // TODO: remove this redundant `getLLVMType`, it is also called in `genTypedValue`. |
| 514 | | const llvm_type = try self.getLLVMType(decl.ty); |
| 513 | // TODO: remove this redundant `llvmType`, it is also called in `genTypedValue`. |
| 514 | const llvm_type = try self.llvmType(decl.ty); |
| 515 | 515 | const val = try self.genTypedValue(.{ .ty = decl.ty, .val = decl.val }, null); |
| 516 | 516 | const global = self.llvmModule().addGlobal(llvm_type, decl.name); |
| 517 | 517 | llvm.setInitializer(global, val); |
| ... | ... | @@ -522,8 +522,8 @@ pub const DeclGen = struct { |
| 522 | 522 | return global; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | | fn getLLVMType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type { |
| 526 | | log.debug("getLLVMType for {}", .{t}); |
| 525 | fn llvmType(self: *DeclGen, t: Type) error{ OutOfMemory, CodegenFail }!*const llvm.Type { |
| 526 | log.debug("llvmType for {}", .{t}); |
| 527 | 527 | switch (t.zigTypeTag()) { |
| 528 | 528 | .Void => return self.context().voidType(), |
| 529 | 529 | .NoReturn => return self.context().voidType(), |
| ... | ... | @@ -536,12 +536,12 @@ pub const DeclGen = struct { |
| 536 | 536 | if (t.isSlice()) { |
| 537 | 537 | return self.todo("implement slices", .{}); |
| 538 | 538 | } else { |
| 539 | | const elem_type = try self.getLLVMType(t.elemType()); |
| 539 | const elem_type = try self.llvmType(t.elemType()); |
| 540 | 540 | return elem_type.pointerType(0); |
| 541 | 541 | } |
| 542 | 542 | }, |
| 543 | 543 | .Array => { |
| 544 | | const elem_type = try self.getLLVMType(t.elemType()); |
| 544 | const elem_type = try self.llvmType(t.elemType()); |
| 545 | 545 | return elem_type.arrayType(@intCast(c_uint, t.abiSize(self.module.getTarget()))); |
| 546 | 546 | }, |
| 547 | 547 | .Optional => { |
| ... | ... | @@ -550,7 +550,7 @@ pub const DeclGen = struct { |
| 550 | 550 | const child_type = t.optionalChild(&buf); |
| 551 | 551 | |
| 552 | 552 | var optional_types: [2]*const llvm.Type = .{ |
| 553 | | try self.getLLVMType(child_type), |
| 553 | try self.llvmType(child_type), |
| 554 | 554 | self.context().intType(1), |
| 555 | 555 | }; |
| 556 | 556 | return self.context().structType(&optional_types, 2, .False); |
| ... | ... | @@ -578,13 +578,13 @@ pub const DeclGen = struct { |
| 578 | 578 | .Frame, |
| 579 | 579 | .AnyFrame, |
| 580 | 580 | .Vector, |
| 581 | | => return self.todo("implement getLLVMType for type '{}'", .{t}), |
| 581 | => return self.todo("implement llvmType for type '{}'", .{t}), |
| 582 | 582 | } |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | // TODO: figure out a way to remove the FuncGen argument |
| 586 | 586 | fn genTypedValue(self: *DeclGen, tv: TypedValue, fg: ?*FuncGen) error{ OutOfMemory, CodegenFail }!*const llvm.Value { |
| 587 | | const llvm_type = try self.getLLVMType(tv.ty); |
| 587 | const llvm_type = try self.llvmType(tv.ty); |
| 588 | 588 | |
| 589 | 589 | if (tv.val.isUndef()) |
| 590 | 590 | return llvm_type.getUndef(); |
| ... | ... | @@ -611,7 +611,7 @@ pub const DeclGen = struct { |
| 611 | 611 | const decl = tv.val.castTag(.decl_ref).?.data; |
| 612 | 612 | const val = try self.resolveGlobalDecl(decl); |
| 613 | 613 | |
| 614 | | const usize_type = try self.getLLVMType(Type.initTag(.usize)); |
| 614 | const usize_type = try self.llvmType(Type.initTag(.usize)); |
| 615 | 615 | |
| 616 | 616 | // TODO: second index should be the index into the memory! |
| 617 | 617 | var indices: [2]*const llvm.Value = .{ |
| ... | ... | @@ -625,7 +625,7 @@ pub const DeclGen = struct { |
| 625 | 625 | .ref_val => { |
| 626 | 626 | const elem_value = tv.val.castTag(.ref_val).?.data; |
| 627 | 627 | const elem_type = tv.ty.castPointer().?.data; |
| 628 | | const alloca = fg.?.buildAlloca(try self.getLLVMType(elem_type)); |
| 628 | const alloca = fg.?.buildAlloca(try self.llvmType(elem_type)); |
| 629 | 629 | _ = fg.?.builder.buildStore(try self.genTypedValue(.{ .ty = elem_type, .val = elem_value }, fg), alloca); |
| 630 | 630 | return alloca; |
| 631 | 631 | }, |
| ... | ... | @@ -647,7 +647,7 @@ pub const DeclGen = struct { |
| 647 | 647 | if (!tv.ty.isPtrLikeOptional()) { |
| 648 | 648 | var buf: Type.Payload.ElemType = undefined; |
| 649 | 649 | const child_type = tv.ty.optionalChild(&buf); |
| 650 | | const llvm_child_type = try self.getLLVMType(child_type); |
| 650 | const llvm_child_type = try self.llvmType(child_type); |
| 651 | 651 | |
| 652 | 652 | if (tv.val.tag() == .null_value) { |
| 653 | 653 | var optional_values: [2]*const llvm.Value = .{ |
| ... | ... | @@ -909,7 +909,7 @@ pub const FuncGen = struct { |
| 909 | 909 | const inst_ty = self.air.typeOfIndex(inst); |
| 910 | 910 | if (!inst_ty.hasCodeGenBits()) return null; |
| 911 | 911 | |
| 912 | | const phi_node = self.builder.buildPhi(try self.dg.getLLVMType(inst_ty), ""); |
| 912 | const phi_node = self.builder.buildPhi(try self.dg.llvmType(inst_ty), ""); |
| 913 | 913 | phi_node.addIncoming( |
| 914 | 914 | break_vals.items.ptr, |
| 915 | 915 | break_bbs.items.ptr, |
| ... | ... | @@ -1086,7 +1086,7 @@ pub const FuncGen = struct { |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | const ret_ty = self.air.typeOfIndex(inst); |
| 1089 | | const ret_llvm_ty = try self.dg.getLLVMType(ret_ty); |
| 1089 | const ret_llvm_ty = try self.dg.llvmType(ret_ty); |
| 1090 | 1090 | const llvm_fn_ty = llvm.functionType( |
| 1091 | 1091 | ret_llvm_ty, |
| 1092 | 1092 | llvm_param_types.ptr, |
| ... | ... | @@ -1209,7 +1209,7 @@ pub const FuncGen = struct { |
| 1209 | 1209 | const signed = inst_ty.isSignedInt(); |
| 1210 | 1210 | // TODO: Should we use intcast here or just a simple bitcast? |
| 1211 | 1211 | // LLVM does truncation vs bitcast (+signed extension) in the intcast depending on the sizes |
| 1212 | | return self.builder.buildIntCast2(operand, try self.dg.getLLVMType(inst_ty), llvm.Bool.fromBool(signed), ""); |
| 1212 | return self.builder.buildIntCast2(operand, try self.dg.llvmType(inst_ty), llvm.Bool.fromBool(signed), ""); |
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | fn airPtrToInt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { |
| ... | ... | @@ -1218,7 +1218,7 @@ pub const FuncGen = struct { |
| 1218 | 1218 | |
| 1219 | 1219 | const un_op = self.air.instructions.items(.data)[inst].un_op; |
| 1220 | 1220 | const operand = try self.resolveInst(un_op); |
| 1221 | | const dest_llvm_ty = try self.dg.getLLVMType(self.air.typeOfIndex(inst)); |
| 1221 | const dest_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); |
| 1222 | 1222 | return self.builder.buildPtrToInt(operand, dest_llvm_ty, ""); |
| 1223 | 1223 | } |
| 1224 | 1224 | |
| ... | ... | @@ -1229,7 +1229,7 @@ pub const FuncGen = struct { |
| 1229 | 1229 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 1230 | 1230 | const operand = try self.resolveInst(ty_op.operand); |
| 1231 | 1231 | const inst_ty = self.air.typeOfIndex(inst); |
| 1232 | | const dest_type = try self.dg.getLLVMType(inst_ty); |
| 1232 | const dest_type = try self.dg.llvmType(inst_ty); |
| 1233 | 1233 | |
| 1234 | 1234 | return self.builder.buildBitCast(operand, dest_type, ""); |
| 1235 | 1235 | } |
| ... | ... | @@ -1239,7 +1239,7 @@ pub const FuncGen = struct { |
| 1239 | 1239 | self.arg_index += 1; |
| 1240 | 1240 | |
| 1241 | 1241 | const inst_ty = self.air.typeOfIndex(inst); |
| 1242 | | const ptr_val = self.buildAlloca(try self.dg.getLLVMType(inst_ty)); |
| 1242 | const ptr_val = self.buildAlloca(try self.dg.llvmType(inst_ty)); |
| 1243 | 1243 | _ = self.builder.buildStore(arg_val, ptr_val); |
| 1244 | 1244 | return self.builder.buildLoad(ptr_val, ""); |
| 1245 | 1245 | } |
| ... | ... | @@ -1254,7 +1254,7 @@ pub const FuncGen = struct { |
| 1254 | 1254 | |
| 1255 | 1255 | // TODO: figure out a way to get the name of the var decl. |
| 1256 | 1256 | // TODO: set alignment and volatile |
| 1257 | | return self.buildAlloca(try self.dg.getLLVMType(pointee_type)); |
| 1257 | return self.buildAlloca(try self.dg.llvmType(pointee_type)); |
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | /// Use this instead of builder.buildAlloca, because this function makes sure to |