@@ -13853,16 +13853,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13853
13853
try constants_block.end();
13854
13854
}
13855
13855
13856
- const MetadataKind = enum(u8) {
13857
- dbg = 0,
13858
- };
13859
-
13860
13856
// METADATA_KIND_BLOCK
13861
13857
if (!self.strip) {
13862
13858
const MetadataKindBlock = ir.MetadataKindBlock;
13863
13859
var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock);
13864
13860
13865
- inline for (@typeInfo(MetadataKind).Enum.fields) |field| {
13861
+ inline for (@typeInfo(ir. MetadataKind).Enum.fields) |field| {
13866
13862
try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
13867
13863
.id = field.value,
13868
13864
.name = field.name,
@@ -14296,6 +14292,51 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14296
14292
});
14297
14293
}
14298
14294
14295
+ // Write global attached metadata
14296
+ {
14297
+ for (self.variables.items) |variable| {
14298
+ if (variable.global.getReplacement(self) != .none) continue;
14299
+
14300
+ const dbg = variable.global.ptrConst(self).dbg;
14301
+
14302
+ if (dbg == .none) continue;
14303
+
14304
+ try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
14305
+ .value = @enumFromInt(constant_adapter.getConstantIndex(variable.global.toConst())),
14306
+ .kind = ir.MetadataKind.dbg,
14307
+ .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14308
+ });
14309
+ }
14310
+
14311
+ for (self.functions.items) |func| {
14312
+ if (func.global.getReplacement(self) != .none) continue;
14313
+
14314
+ const dbg = func.global.ptrConst(self).dbg;
14315
+
14316
+ if (dbg == .none or func.instructions.len != 0) continue;
14317
+
14318
+ try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
14319
+ .value = @enumFromInt(constant_adapter.getConstantIndex(func.global.toConst())),
14320
+ .kind = ir.MetadataKind.dbg,
14321
+ .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14322
+ });
14323
+ }
14324
+
14325
+ for (self.aliases.items) |alias| {
14326
+ if (alias.global.getReplacement(self) != .none) continue;
14327
+
14328
+ const dbg = alias.global.ptrConst(self).dbg;
14329
+
14330
+ if (dbg == .none) continue;
14331
+
14332
+ try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{
14333
+ .value = @enumFromInt(constant_adapter.getConstantIndex(alias.global.toConst())),
14334
+ .kind = ir.MetadataKind.dbg,
14335
+ .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14336
+ });
14337
+ }
14338
+ }
14339
+
14299
14340
try metadata_block.end();
14300
14341
}
14301
14342
@@ -14909,7 +14950,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14909
14950
var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock);
14910
14951
14911
14952
try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentSingle{
14912
- .id = @intFromEnum( MetadataKind.dbg) ,
14953
+ .kind = ir. MetadataKind.dbg,
14913
14954
.metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1),
14914
14955
});
14915
14956
0 commit comments