authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-22 15:29:28+01:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-22 15:29:28+01:00
logde536e84739e949ed5bd85be9a263f74c70e7b94
tree8b7b2821b66dde4a3be8e0ccbd9aa3f52720c2ff
parent92eec8dfec6b02465cdf36cfcc594465623a5c65

LLVM Builder: Emit metadata kinds and function metadata attachments


2 files changed, 72 insertions(+), 0 deletions(-)

src/codegen/llvm/Builder.zig+36
...@@ -13739,6 +13739,25 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13739,6 +13739,25 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13739 try constants_block.end();13739 try constants_block.end();
13740 }13740 }
1374113741
13742 const MetadataKind = enum(u8) {
13743 dbg = 0,
13744 };
13745
13746 // METADATA_KIND_BLOCK
13747 if (!self.strip) {
13748 const MetadataKindBlock = ir.MetadataKindBlock;
13749 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock);
13750
13751 inline for (@typeInfo(MetadataKind).Enum.fields) |field| {
13752 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
13753 .id = field.value,
13754 .name = field.name,
13755 });
13756 }
13757
13758 try metadata_kind_block.end();
13759 }
13760
13742 const MetadataAdapter = struct {13761 const MetadataAdapter = struct {
13743 builder: *const Builder,13762 builder: *const Builder,
13744 constant_adapter: ConstantAdapter,13763 constant_adapter: ConstantAdapter,
...@@ -14766,6 +14785,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14766,6 +14785,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14766 try value_symtab_block.end();14785 try value_symtab_block.end();
14767 }14786 }
1476814787
14788 // METADATA_ATTACHMENT_BLOCK
14789 if (!self.strip) blk: {
14790 const dbg = func.global.ptrConst(self).dbg;
14791
14792 if (dbg == .none) break :blk;
14793
14794 const MetadataAttachmentBlock = ir.MetadataAttachmentBlock;
14795 var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock);
14796
14797 try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentSingle{
14798 .id = @intFromEnum(MetadataKind.dbg),
14799 .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14800 });
14801
14802 try metadata_attach_block.end();
14803 }
14804
14769 try function_block.end();14805 try function_block.end();
14770 }14806 }
14771 }14807 }
src/codegen/llvm/ir.zig+36
...@@ -580,6 +580,42 @@ pub const Constants = struct {...@@ -580,6 +580,42 @@ pub const Constants = struct {
580 };580 };
581};581};
582582
583pub const MetadataKindBlock = struct {
584 pub const id = 22;
585
586 pub const abbrevs = [_]type{
587 Kind,
588 };
589
590 pub const Kind = struct {
591 pub const ops = [_]AbbrevOp{
592 .{ .literal = 6 },
593 .{ .vbr = 4 },
594 .{ .array_fixed = 8 },
595 };
596 id: u32,
597 name: []const u8,
598 };
599};
600
601pub const MetadataAttachmentBlock = struct {
602 pub const id = 16;
603
604 pub const abbrevs = [_]type{
605 AttachmentSingle,
606 };
607
608 pub const AttachmentSingle = struct {
609 pub const ops = [_]AbbrevOp{
610 .{ .literal = 11 },
611 .{ .vbr = 4 },
612 MetadataAbbrev,
613 };
614 id: u32,
615 metadata: Builder.Metadata,
616 };
617};
618
583pub const MetadataBlock = struct {619pub const MetadataBlock = struct {
584 pub const id = 15;620 pub const id = 15;
585621