mirror of
https://github.com/ziglang/zig.git
synced 2025-12-25 23:53:15 +00:00
stage2 llvm backend: implement llvmType for error union and slices
This commit is contained in:
parent
5b4885fe89
commit
c3d10dbda1
@ -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,
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user