mirror of
https://github.com/ziglang/zig.git
synced 2026-01-09 08:55:36 +00:00
Builder: Emit metadata attachment for globals
This commit is contained in:
parent
ceb2c030c4
commit
9b39e824cd
@ -13853,16 +13853,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
|
||||
try constants_block.end();
|
||||
}
|
||||
|
||||
const MetadataKind = enum(u8) {
|
||||
dbg = 0,
|
||||
};
|
||||
|
||||
// METADATA_KIND_BLOCK
|
||||
if (!self.strip) {
|
||||
const MetadataKindBlock = ir.MetadataKindBlock;
|
||||
var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock);
|
||||
|
||||
inline for (@typeInfo(MetadataKind).Enum.fields) |field| {
|
||||
inline for (@typeInfo(ir.MetadataKind).Enum.fields) |field| {
|
||||
try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
|
||||
.id = field.value,
|
||||
.name = field.name,
|
||||
@ -14296,6 +14292,25 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
|
||||
});
|
||||
}
|
||||
|
||||
// Write global attached metadata
|
||||
{
|
||||
for (globals.keys()) |global| {
|
||||
const global_ptr = global.ptrConst(self);
|
||||
if (global_ptr.dbg == .none) continue;
|
||||
|
||||
switch (global_ptr.kind) {
|
||||
.function => |f| if (f.ptrConst(self).instructions.len != 0) continue,
|
||||
else => {},
|
||||
}
|
||||
|
||||
try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
|
||||
.value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())),
|
||||
.kind = ir.MetadataKind.dbg,
|
||||
.metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try metadata_block.end();
|
||||
}
|
||||
|
||||
@ -14909,7 +14924,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
|
||||
var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock);
|
||||
|
||||
try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentSingle{
|
||||
.id = @intFromEnum(MetadataKind.dbg),
|
||||
.kind = ir.MetadataKind.dbg,
|
||||
.metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,10 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 };
|
||||
|
||||
const BlockAbbrev = AbbrevOp{ .vbr = 6 };
|
||||
|
||||
pub const MetadataKind = enum(u1) {
|
||||
dbg = 0,
|
||||
};
|
||||
|
||||
pub const Identification = struct {
|
||||
pub const id = 13;
|
||||
|
||||
@ -616,10 +620,10 @@ pub const MetadataAttachmentBlock = struct {
|
||||
pub const AttachmentSingle = struct {
|
||||
pub const ops = [_]AbbrevOp{
|
||||
.{ .literal = 11 },
|
||||
.{ .vbr = 4 },
|
||||
.{ .fixed = 1 },
|
||||
MetadataAbbrev,
|
||||
};
|
||||
id: u32,
|
||||
kind: MetadataKind,
|
||||
metadata: Builder.Metadata,
|
||||
};
|
||||
};
|
||||
@ -649,6 +653,7 @@ pub const MetadataBlock = struct {
|
||||
Constant,
|
||||
Name,
|
||||
NamedNode,
|
||||
GlobalDeclAttachment,
|
||||
};
|
||||
|
||||
pub const Strings = struct {
|
||||
@ -1045,6 +1050,19 @@ pub const MetadataBlock = struct {
|
||||
|
||||
elements: []const Builder.Metadata,
|
||||
};
|
||||
|
||||
pub const GlobalDeclAttachment = struct {
|
||||
pub const ops = [_]AbbrevOp{
|
||||
.{ .literal = 36 },
|
||||
ValueAbbrev, // value id
|
||||
.{ .fixed = 1 }, // kind
|
||||
MetadataAbbrev, // elements
|
||||
};
|
||||
|
||||
value: Builder.Constant,
|
||||
kind: MetadataKind,
|
||||
metadata: Builder.Metadata,
|
||||
};
|
||||
};
|
||||
|
||||
pub const FunctionMetadataBlock = struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user