Implement bitfield

This commit is contained in:
David Gonzalez Martin 2024-06-08 23:43:48 -06:00
parent 2826a7d59a
commit fff62dd396
5 changed files with 745 additions and 209 deletions

View File

@ -1,3 +1,3 @@
struct
bitstruct
c abi
for loops

View File

@ -37,6 +37,7 @@ pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.D
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerator(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, value: u64, is_unsigned: bool) *LLVM.DebugInfo.Type.Enumerator;
pub extern fn NativityLLVMDebugInfoBuilderCreateReplaceableCompositeType(builder: *LLVM.DebugInfo.Builder, tag: c_uint, name_ptr: [*]const u8, name_len: usize, scope: ?*LLVM.DebugInfo.Scope, file: ?*LLVM.DebugInfo.File, line: c_uint) *LLVM.DebugInfo.Type.Composite;
pub extern fn NativityLLVMDebugInfoBuilderCreateMemberType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, alignment: u32, bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived;
pub extern fn NativityLLVMDebugInfoBuilderCreateBitfieldMemberType(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_pointer: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, bit_offset: u64, storage_bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived;
pub extern fn NativityLLVMDebugInfoBuilderCompositeTypeReplaceTypes(builder: *LLVM.DebugInfo.Builder, type: *LLVM.DebugInfo.Type.Composite, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize) void;
pub extern fn NativityLLLVMDITypeIsResolved(type: *LLVM.DebugInfo.Type) bool;
pub extern fn NativityLLVMDebugInfoBuilderFinalizeSubprogram(builder: *LLVM.DebugInfo.Builder, subprogram: *LLVM.DebugInfo.Subprogram, function: *LLVM.Value.Constant.Function) void;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
bitfield(s32) Bitfield{
a: u1,
b: u1,
c: u1,
d: u29,
}
fn[cc(.c)] main[export]() s32 {
>bf: Bitfield = {
.a = 0,
.b = 1,
.c = 1,
.d = 0,
};
>bf_int: s32 = #transmute(bf);
>bf_int2: s32 = 6;
>bf2: Bitfield = #transmute(bf_int2);
#assert(bf.a == bf2.a);
#assert(bf.b == bf2.b);
#assert(bf.c == bf2.c);
#assert(bf.d == bf2.d);
return bf_int - bf_int2;
}

View File

@ -234,6 +234,13 @@ extern "C" DIDerivedType* NativityLLVMDebugInfoBuilderCreateMemberType(DIBuilder
return member_type;
}
extern "C" DIDerivedType* NativityLLVMDebugInfoBuilderCreateBitfieldMemberType(DIBuilder& builder, DIScope *scope, const char* name_ptr, size_t name_len, DIFile* file, unsigned line_number, uint64_t bit_size, uint64_t bit_offset, uint64_t storage_bit_offset, DINode::DIFlags flags, DIType* type)
{
auto name = StringRef(name_ptr, name_len);
auto* member_type = builder.createBitFieldMemberType(scope, name, file, line_number, bit_size, bit_offset, storage_bit_offset, flags, type);
return member_type;
}
extern "C" bool NativityLLLVMDITypeIsResolved(DIType* type)
{
return type->isResolved();