aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-25 19:06:48 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-25 19:06:48 -0700
commitc3d10dbda1fc133b7ca112787bbf0100b735ca36 (patch)
tree9367d79b77d8910c1c538b84812c508e210ce88a /src/codegen
parent5b4885fe89939679ec2aa78f6bf16fe42faa781a (diff)
downloadzig-c3d10dbda1fc133b7ca112787bbf0100b735ca36.tar.gz
zig-c3d10dbda1fc133b7ca112787bbf0100b735ca36.zip
stage2 llvm backend: implement llvmType for error union and slices
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig20
-rw-r--r--src/codegen/llvm/bindings.zig7
2 files changed, 23 insertions, 4 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index b6855409b0..d6a4449616 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -534,7 +534,14 @@ pub const DeclGen = struct {
.Bool => return self.context.intType(1),
.Pointer => {
if (t.isSlice()) {
- return self.todo("implement slices", .{});
+ var buf: Type.Payload.ElemType = undefined;
+ const ptr_type = t.slicePtrFieldType(&buf);
+
+ const fields: [2]*const llvm.Type = .{
+ try self.llvmType(ptr_type),
+ try self.llvmType(Type.initTag(.usize)),
+ };
+ return self.context.structType(&fields, 2, .False);
} else {
const elem_type = try self.llvmType(t.elemType());
return elem_type.pointerType(0);
@@ -549,7 +556,7 @@ pub const DeclGen = struct {
var buf: Type.Payload.ElemType = undefined;
const child_type = t.optionalChild(&buf);
- var optional_types: [2]*const llvm.Type = .{
+ const optional_types: [2]*const llvm.Type = .{
try self.llvmType(child_type),
self.context.intType(1),
};
@@ -559,8 +566,16 @@ pub const DeclGen = struct {
}
},
.ErrorUnion => {
+ const error_type = t.errorUnionSet();
+ const payload_type = t.errorUnionPayload();
+ if (!payload_type.hasCodeGenBits()) {
+ return self.llvmType(error_type);
+ }
return self.todo("implement llvmType for error unions", .{});
},
+ .ErrorSet => {
+ return self.context.intType(16);
+ },
.ComptimeInt => unreachable,
.ComptimeFloat => unreachable,
.Type => unreachable,
@@ -572,7 +587,6 @@ pub const DeclGen = struct {
.Float,
.Struct,
- .ErrorSet,
.Enum,
.Union,
.Fn,
diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig
index 59c5b3dfe3..3d17172cfd 100644
--- a/src/codegen/llvm/bindings.zig
+++ b/src/codegen/llvm/bindings.zig
@@ -35,7 +35,12 @@ pub const Context = opaque {
extern fn LLVMVoidTypeInContext(C: *const Context) *const Type;
pub const structType = LLVMStructTypeInContext;
- extern fn LLVMStructTypeInContext(C: *const Context, ElementTypes: [*]*const Type, ElementCount: c_uint, Packed: Bool) *const Type;
+ extern fn LLVMStructTypeInContext(
+ C: *const Context,
+ ElementTypes: [*]const *const Type,
+ ElementCount: c_uint,
+ Packed: Bool,
+ ) *const Type;
pub const constString = LLVMConstStringInContext;
extern fn LLVMConstStringInContext(C: *const Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) *const Value;