authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-25 19:06:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-25 19:06:48-07:00
logc3d10dbda1fc133b7ca112787bbf0100b735ca36
tree9367d79b77d8910c1c538b84812c508e210ce88a
parent5b4885fe89939679ec2aa78f6bf16fe42faa781a

stage2 llvm backend: implement llvmType for error union and slices


2 files changed, 23 insertions(+), 4 deletions(-)

src/codegen/llvm.zig+17-3
......@@ -534,7 +534,14 @@ pub const DeclGen = struct {
534534 .Bool => return self.context.intType(1),
535535 .Pointer => {
536536 if (t.isSlice()) {
537 return self.todo("implement slices", .{});
537 var buf: Type.Payload.ElemType = undefined;
538 const ptr_type = t.slicePtrFieldType(&buf);
539
540 const fields: [2]*const llvm.Type = .{
541 try self.llvmType(ptr_type),
542 try self.llvmType(Type.initTag(.usize)),
543 };
544 return self.context.structType(&fields, 2, .False);
538545 } else {
539546 const elem_type = try self.llvmType(t.elemType());
540547 return elem_type.pointerType(0);
......@@ -549,7 +556,7 @@ pub const DeclGen = struct {
549556 var buf: Type.Payload.ElemType = undefined;
550557 const child_type = t.optionalChild(&buf);
551558
552 var optional_types: [2]*const llvm.Type = .{
559 const optional_types: [2]*const llvm.Type = .{
553560 try self.llvmType(child_type),
554561 self.context.intType(1),
555562 };
......@@ -559,8 +566,16 @@ pub const DeclGen = struct {
559566 }
560567 },
561568 .ErrorUnion => {
569 const error_type = t.errorUnionSet();
570 const payload_type = t.errorUnionPayload();
571 if (!payload_type.hasCodeGenBits()) {
572 return self.llvmType(error_type);
573 }
562574 return self.todo("implement llvmType for error unions", .{});
563575 },
576 .ErrorSet => {
577 return self.context.intType(16);
578 },
564579 .ComptimeInt => unreachable,
565580 .ComptimeFloat => unreachable,
566581 .Type => unreachable,
......@@ -572,7 +587,6 @@ pub const DeclGen = struct {
572587
573588 .Float,
574589 .Struct,
575 .ErrorSet,
576590 .Enum,
577591 .Union,
578592 .Fn,
src/codegen/llvm/bindings.zig+6-1
......@@ -35,7 +35,12 @@ pub const Context = opaque {
3535 extern fn LLVMVoidTypeInContext(C: *const Context) *const Type;
3636
3737 pub const structType = LLVMStructTypeInContext;
38 extern fn LLVMStructTypeInContext(C: *const Context, ElementTypes: [*]*const Type, ElementCount: c_uint, Packed: Bool) *const Type;
38 extern fn LLVMStructTypeInContext(
39 C: *const Context,
40 ElementTypes: [*]const *const Type,
41 ElementCount: c_uint,
42 Packed: Bool,
43 ) *const Type;
3944
4045 pub const constString = LLVMConstStringInContext;
4146 extern fn LLVMConstStringInContext(C: *const Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) *const Value;