| ... | @@ -3797,7 +3797,7 @@ pub const Function = struct { | ... | @@ -3797,7 +3797,7 @@ pub const Function = struct { |
| 3797 | instructions: std.MultiArrayList(Instruction) = .{}, | 3797 | instructions: std.MultiArrayList(Instruction) = .{}, |
| 3798 | names: [*]const String = &[0]String{}, | 3798 | names: [*]const String = &[0]String{}, |
| 3799 | value_indices: [*]const u32 = &[0]u32{}, | 3799 | value_indices: [*]const u32 = &[0]u32{}, |
| 3800 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{}, | 3800 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, |
| 3801 | debug_values: []const Instruction.Index = &.{}, | 3801 | debug_values: []const Instruction.Index = &.{}, |
| 3802 | extra: []const u32 = &.{}, | 3802 | extra: []const u32 = &.{}, |
| 3803 | | 3803 | |
| ... | @@ -4857,16 +4857,40 @@ pub const Function = struct { | ... | @@ -4857,16 +4857,40 @@ pub const Function = struct { |
| 4857 | } | 4857 | } |
| 4858 | }; | 4858 | }; |
| 4859 | | 4859 | |
| | 4860 | pub const DebugLocation = union(enum) { |
| | 4861 | no_location: void, |
| | 4862 | location: Location, |
| | 4863 | |
| | 4864 | pub const Location = struct { |
| | 4865 | line: u32, |
| | 4866 | column: u32, |
| | 4867 | scope: Builder.Metadata, |
| | 4868 | inlined_at: Builder.Metadata, |
| | 4869 | }; |
| | 4870 | |
| | 4871 | pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata { |
| | 4872 | return switch (self) { |
| | 4873 | .no_location => .none, |
| | 4874 | .location => |location| try builder.debugLocation( |
| | 4875 | location.line, |
| | 4876 | location.column, |
| | 4877 | location.scope, |
| | 4878 | location.inlined_at, |
| | 4879 | ), |
| | 4880 | }; |
| | 4881 | } |
| | 4882 | }; |
| | 4883 | |
| 4860 | pub const WipFunction = struct { | 4884 | pub const WipFunction = struct { |
| 4861 | builder: *Builder, | 4885 | builder: *Builder, |
| 4862 | function: Function.Index, | 4886 | function: Function.Index, |
| 4863 | last_debug_location: Metadata, | 4887 | prev_debug_location: DebugLocation, |
| 4864 | current_debug_location: Metadata, | 4888 | debug_location: DebugLocation, |
| 4865 | cursor: Cursor, | 4889 | cursor: Cursor, |
| 4866 | blocks: std.ArrayListUnmanaged(Block), | 4890 | blocks: std.ArrayListUnmanaged(Block), |
| 4867 | instructions: std.MultiArrayList(Instruction), | 4891 | instructions: std.MultiArrayList(Instruction), |
| 4868 | names: std.ArrayListUnmanaged(String), | 4892 | names: std.ArrayListUnmanaged(String), |
| 4869 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, Metadata), | 4893 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), |
| 4870 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), | 4894 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), |
| 4871 | extra: std.ArrayListUnmanaged(u32), | 4895 | extra: std.ArrayListUnmanaged(u32), |
| 4872 | | 4896 | |
| ... | @@ -4902,8 +4926,8 @@ pub const WipFunction = struct { | ... | @@ -4902,8 +4926,8 @@ pub const WipFunction = struct { |
| 4902 | var self: WipFunction = .{ | 4926 | var self: WipFunction = .{ |
| 4903 | .builder = builder, | 4927 | .builder = builder, |
| 4904 | .function = function, | 4928 | .function = function, |
| 4905 | .last_debug_location = .none, | 4929 | .prev_debug_location = .no_location, |
| 4906 | .current_debug_location = .none, | 4930 | .debug_location = .no_location, |
| 4907 | .cursor = undefined, | 4931 | .cursor = undefined, |
| 4908 | .blocks = .{}, | 4932 | .blocks = .{}, |
| 4909 | .instructions = .{}, | 4933 | .instructions = .{}, |
| ... | @@ -5850,7 +5874,7 @@ pub const WipFunction = struct { | ... | @@ -5850,7 +5874,7 @@ pub const WipFunction = struct { |
| 5850 | const value_indices = try gpa.alloc(u32, final_instructions_len); | 5874 | const value_indices = try gpa.alloc(u32, final_instructions_len); |
| 5851 | errdefer gpa.free(value_indices); | 5875 | errdefer gpa.free(value_indices); |
| 5852 | | 5876 | |
| 5853 | var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{}; | 5877 | var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}; |
| 5854 | errdefer debug_locations.deinit(gpa); | 5878 | errdefer debug_locations.deinit(gpa); |
| 5855 | try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count())); | 5879 | try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count())); |
| 5856 | | 5880 | |
| ... | @@ -6494,10 +6518,10 @@ pub const WipFunction = struct { | ... | @@ -6494,10 +6518,10 @@ pub const WipFunction = struct { |
| 6494 | if (!self.builder.strip) { | 6518 | if (!self.builder.strip) { |
| 6495 | self.names.appendAssumeCapacity(final_name); | 6519 | self.names.appendAssumeCapacity(final_name); |
| 6496 | if (block_instructions.items.len == 0 or | 6520 | if (block_instructions.items.len == 0 or |
| 6497 | self.current_debug_location != self.last_debug_location) | 6521 | !std.meta.eql(self.debug_location, self.prev_debug_location)) |
| 6498 | { | 6522 | { |
| 6499 | self.debug_locations.putAssumeCapacity(index, self.current_debug_location); | 6523 | self.debug_locations.putAssumeCapacity(index, self.debug_location); |
| 6500 | self.last_debug_location = self.current_debug_location; | 6524 | self.prev_debug_location = self.debug_location; |
| 6501 | } | 6525 | } |
| 6502 | } | 6526 | } |
| 6503 | block_instructions.insertAssumeCapacity(self.cursor.instruction, index); | 6527 | block_instructions.insertAssumeCapacity(self.cursor.instruction, index); |
| ... | @@ -14866,20 +14890,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14866,20 +14890,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14866 | | 14890 | |
| 14867 | if (!self.strip) { | 14891 | if (!self.strip) { |
| 14868 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { | 14892 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { |
| 14869 | if (debug_location != .none) { | 14893 | switch (debug_location) { |
| 14870 | const location = self.metadata_items.get(@intFromEnum(debug_location)); | 14894 | .no_location => has_location = false, |
| 14871 | assert(location.tag == .location); | 14895 | .location => |location| { |
| 14872 | const extra = self.metadataExtraData(Metadata.Location, location.data); | 14896 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ |
| 14873 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ | 14897 | .line = location.line, |
| 14874 | .line = extra.line, | 14898 | .column = location.column, |
| 14875 | .column = extra.column, | 14899 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)), |
| 14876 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(extra.scope)), | 14900 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)), |
| 14877 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)), | 14901 | .is_implicit = false, |
| 14878 | .is_implicit = false, | 14902 | }); |
| 14879 | }); | 14903 | has_location = true; |
| 14880 | has_location = true; | 14904 | }, |
| 14881 | } else { | | |
| 14882 | has_location = false; | | |
| 14883 | } | 14905 | } |
| 14884 | } else if (has_location) { | 14906 | } else if (has_location) { |
| 14885 | try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{}); | 14907 | try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{}); |