authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-25 03:04:33+01:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-25 03:16:52+01:00
log71d9f3a86b61c815031e42a24c3081e868870e46
treeb7761b0b9234319fccd6b75df9d1d4dca0667b7c
parent928914e25afce48f5b4abef7150f2c9242f29ba5

Builder: Fix llvm ir debug location output


1 files changed, 35 insertions(+), 10 deletions(-)

src/codegen/llvm/Builder.zig+35-10
......@@ -8026,7 +8026,10 @@ pub const Metadata = enum(u32) {
80268026 const Formatter = struct {
80278027 builder: *Builder,
80288028 need_comma: bool,
8029 map: std.AutoArrayHashMapUnmanaged(Metadata, void) = .{},
8029 map: std.AutoArrayHashMapUnmanaged(union(enum) {
8030 metadata: Metadata,
8031 debug_location: DebugLocation.Location,
8032 }, void) = .{},
80308033
80318034 const FormatData = struct {
80328035 formatter: *Formatter,
......@@ -8214,7 +8217,7 @@ pub const Metadata = enum(u32) {
82148217 .expression, .constant => return .{ .@"inline" = unwrapped_metadata },
82158218 else => {
82168219 assert(!tag.isInline());
8217 const gop = try formatter.map.getOrPutValue(builder.gpa, unwrapped_metadata, {});
8220 const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata });
82188221 return .{ .index = @intCast(gop.index) };
82198222 },
82208223 }
......@@ -9433,12 +9436,19 @@ pub fn printUnbuffered(
94339436 if (function.instructions.len > 0) {
94349437 var block_incoming_len: u32 = undefined;
94359438 try writer.writeAll(" {\n");
9436 var dbg: Metadata = .none;
9439 var maybe_dbg_index: ?u32 = null;
94379440 for (params_len..function.instructions.len) |instruction_i| {
94389441 const instruction_index: Function.Instruction.Index = @enumFromInt(instruction_i);
94399442 const instruction = function.instructions.get(@intFromEnum(instruction_index));
9440 if (function.debug_locations.get(instruction_index)) |debug_location|
9441 dbg = debug_location;
9443 if (function.debug_locations.get(instruction_index)) |debug_location| switch (debug_location) {
9444 .no_location => maybe_dbg_index = null,
9445 .location => |location| {
9446 const gop = try metadata_formatter.map.getOrPut(self.gpa, .{
9447 .debug_location = location,
9448 });
9449 maybe_dbg_index = @intCast(gop.index);
9450 },
9451 };
94429452 switch (instruction.tag) {
94439453 .add,
94449454 .@"add nsw",
......@@ -9870,9 +9880,10 @@ pub fn printUnbuffered(
98709880 });
98719881 },
98729882 }
9873 metadata_formatter.need_comma = true;
9874 defer metadata_formatter.need_comma = undefined;
9875 try writer.print("{}\n", .{try metadata_formatter.fmt("!dbg ", dbg)});
9883
9884 if (maybe_dbg_index) |dbg_index| {
9885 try writer.print(", !dbg !{}\n", .{dbg_index});
9886 } else try writer.writeByte('\n');
98769887 }
98779888 try writer.writeByte('}');
98789889 }
......@@ -9908,11 +9919,25 @@ pub fn printUnbuffered(
99089919 var metadata_index: usize = 0;
99099920 while (metadata_index < metadata_formatter.map.count()) : (metadata_index += 1) {
99109921 @setEvalBranchQuota(10_000);
9911 const metadata_item =
9912 self.metadata_items.get(@intFromEnum(metadata_formatter.map.keys()[metadata_index]));
99139922 try writer.print("!{} = ", .{metadata_index});
99149923 metadata_formatter.need_comma = false;
99159924 defer metadata_formatter.need_comma = undefined;
9925
9926 const key = metadata_formatter.map.keys()[metadata_index];
9927 const metadata_item = switch (key) {
9928 .debug_location => |location| {
9929 try metadata_formatter.specialized(.@"!", .DILocation, .{
9930 .line = location.line,
9931 .column = location.column,
9932 .scope = location.scope,
9933 .inlinedAt = location.inlined_at,
9934 .isImplicitCode = false,
9935 }, writer);
9936 continue;
9937 },
9938 .metadata => |metadata| self.metadata_items.get(@intFromEnum(metadata)),
9939 };
9940
99169941 switch (metadata_item.tag) {
99179942 .none, .expression, .constant => unreachable,
99189943 .file => {