| ... | ... | @@ -77,11 +77,11 @@ pub const String = enum(u32) { |
| 77 | 77 | return self.toIndex() == null; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | | pub fn slice(self: String, b: *const Builder) ?[:0]const u8 { |
| 80 | pub fn slice(self: String, builder: *const Builder) ?[:0]const u8 { |
| 81 | 81 | const index = self.toIndex() orelse return null; |
| 82 | | const start = b.string_indices.items[index]; |
| 83 | | const end = b.string_indices.items[index + 1]; |
| 84 | | return b.string_bytes.items[start .. end - 1 :0]; |
| 82 | const start = builder.string_indices.items[index]; |
| 83 | const end = builder.string_indices.items[index + 1]; |
| 84 | return builder.string_bytes.items[start .. end - 1 :0]; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | const FormatData = struct { |
| ... | ... | @@ -1124,7 +1124,8 @@ pub const Attribute = union(Kind) { |
| 1124 | 1124 | u32 => storage.value, |
| 1125 | 1125 | Alignment, String, Type, UwTable => @enumFromInt(storage.value), |
| 1126 | 1126 | AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value), |
| 1127 | | else => @compileError("bad payload type: " ++ @typeName(field.type)), |
| 1127 | else => @compileError("bad payload type: " ++ field.name ++ ": " ++ |
| 1128 | @typeName(field.type)), |
| 1128 | 1129 | }); |
| 1129 | 1130 | }, |
| 1130 | 1131 | .string, .none => unreachable, |
| ... | ... | @@ -1550,12 +1551,12 @@ pub const Attribute = union(Kind) { |
| 1550 | 1551 | |
| 1551 | 1552 | fn toStorage(self: Attribute) Storage { |
| 1552 | 1553 | return switch (self) { |
| 1553 | | inline else => |value| .{ .kind = @as(Kind, self), .value = switch (@TypeOf(value)) { |
| 1554 | inline else => |value, tag| .{ .kind = @as(Kind, self), .value = switch (@TypeOf(value)) { |
| 1554 | 1555 | void => 0, |
| 1555 | 1556 | u32 => value, |
| 1556 | 1557 | Alignment, String, Type, UwTable => @intFromEnum(value), |
| 1557 | 1558 | AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(value), |
| 1558 | | else => @compileError("bad payload type: " ++ @typeName(@TypeOf(value))), |
| 1559 | else => @compileError("bad payload type: " ++ @tagName(tag) ++ @typeName(@TypeOf(value))), |
| 1559 | 1560 | } }, |
| 1560 | 1561 | .string => |string_attr| .{ |
| 1561 | 1562 | .kind = Kind.fromString(string_attr.kind), |
| ... | ... | @@ -2130,6 +2131,7 @@ pub const Global = struct { |
| 2130 | 2131 | externally_initialized: ExternallyInitialized = .default, |
| 2131 | 2132 | type: Type, |
| 2132 | 2133 | partition: String = .none, |
| 2134 | dbg: Metadata = .none, |
| 2133 | 2135 | kind: union(enum) { |
| 2134 | 2136 | alias: Alias.Index, |
| 2135 | 2137 | variable: Variable.Index, |
| ... | ... | @@ -2204,6 +2206,10 @@ pub const Global = struct { |
| 2204 | 2206 | self.ptr(builder).unnamed_addr = unnamed_addr; |
| 2205 | 2207 | } |
| 2206 | 2208 | |
| 2209 | pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void { |
| 2210 | self.ptr(builder).dbg = dbg; |
| 2211 | } |
| 2212 | |
| 2207 | 2213 | const FormatData = struct { |
| 2208 | 2214 | global: Index, |
| 2209 | 2215 | builder: *const Builder, |
| ... | ... | @@ -2425,6 +2431,10 @@ pub const Variable = struct { |
| 2425 | 2431 | pub fn getAlignment(self: Index, builder: *Builder) Alignment { |
| 2426 | 2432 | return self.ptr(builder).alignment; |
| 2427 | 2433 | } |
| 2434 | |
| 2435 | pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void { |
| 2436 | self.ptrConst(builder).global.setDebugMetadata(expression, builder); |
| 2437 | } |
| 2428 | 2438 | }; |
| 2429 | 2439 | }; |
| 2430 | 2440 | |
| ... | ... | @@ -3772,8 +3782,7 @@ pub const Function = struct { |
| 3772 | 3782 | instructions: std.MultiArrayList(Instruction) = .{}, |
| 3773 | 3783 | names: [*]const String = &[0]String{}, |
| 3774 | 3784 | value_indices: [*]const u32 = &[0]u32{}, |
| 3775 | | metadata: ?[*]const Metadata = null, |
| 3776 | | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, ?DebugLocation) = .{}, |
| 3785 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{}, |
| 3777 | 3786 | debug_values: []const Instruction.Index = &.{}, |
| 3778 | 3787 | extra: []const u32 = &.{}, |
| 3779 | 3788 | |
| ... | ... | @@ -3836,6 +3845,10 @@ pub const Function = struct { |
| 3836 | 3845 | pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void { |
| 3837 | 3846 | self.ptr(builder).alignment = alignment; |
| 3838 | 3847 | } |
| 3848 | |
| 3849 | pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void { |
| 3850 | self.ptrConst(builder).global.setDebugMetadata(subprogram, builder); |
| 3851 | } |
| 3839 | 3852 | }; |
| 3840 | 3853 | |
| 3841 | 3854 | pub const Block = struct { |
| ... | ... | @@ -4823,7 +4836,7 @@ pub const Function = struct { |
| 4823 | 4836 | Instruction.Alloca.Info, |
| 4824 | 4837 | Instruction.Call.Info, |
| 4825 | 4838 | => @bitCast(value), |
| 4826 | | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 4839 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)), |
| 4827 | 4840 | }; |
| 4828 | 4841 | return .{ |
| 4829 | 4842 | .data = result, |
| ... | ... | @@ -4836,61 +4849,16 @@ pub const Function = struct { |
| 4836 | 4849 | } |
| 4837 | 4850 | }; |
| 4838 | 4851 | |
| 4839 | | pub const DebugLocation = struct { |
| 4840 | | line: u32, |
| 4841 | | column: u32, |
| 4842 | | scope: Metadata, |
| 4843 | | inlined_at: Metadata, |
| 4844 | | }; |
| 4845 | | |
| 4846 | | pub const DIFlags = opaque { |
| 4847 | | pub const Zero = 0; |
| 4848 | | pub const Private = 1; |
| 4849 | | pub const Protected = 2; |
| 4850 | | pub const Public = 3; |
| 4851 | | |
| 4852 | | pub const FwdDecl = 1 << 2; |
| 4853 | | pub const AppleBlock = 1 << 3; |
| 4854 | | pub const BlockByrefStruct = 1 << 4; |
| 4855 | | pub const Virtual = 1 << 5; |
| 4856 | | pub const Artificial = 1 << 6; |
| 4857 | | pub const Explicit = 1 << 7; |
| 4858 | | pub const Prototyped = 1 << 8; |
| 4859 | | pub const ObjcClassComplete = 1 << 9; |
| 4860 | | pub const ObjectPointer = 1 << 10; |
| 4861 | | pub const Vector = 1 << 11; |
| 4862 | | pub const StaticMember = 1 << 12; |
| 4863 | | pub const LValueReference = 1 << 13; |
| 4864 | | pub const RValueReference = 1 << 14; |
| 4865 | | pub const Reserved = 1 << 15; |
| 4866 | | |
| 4867 | | pub const SingleInheritance = 1 << 16; |
| 4868 | | pub const MultipleInheritance = 2 << 16; |
| 4869 | | pub const VirtualInheritance = 3 << 16; |
| 4870 | | |
| 4871 | | pub const IntroducedVirtual = 1 << 18; |
| 4872 | | pub const BitField = 1 << 19; |
| 4873 | | pub const NoReturn = 1 << 20; |
| 4874 | | pub const TypePassByValue = 1 << 22; |
| 4875 | | pub const TypePassByReference = 1 << 23; |
| 4876 | | pub const EnumClass = 1 << 24; |
| 4877 | | pub const Thunk = 1 << 25; |
| 4878 | | pub const NonTrivial = 1 << 26; |
| 4879 | | pub const BigEndian = 1 << 27; |
| 4880 | | pub const LittleEndian = 1 << 28; |
| 4881 | | pub const AllCallsDescribed = 1 << 29; |
| 4882 | | }; |
| 4883 | | |
| 4884 | 4852 | pub const WipFunction = struct { |
| 4885 | 4853 | builder: *Builder, |
| 4886 | 4854 | function: Function.Index, |
| 4887 | | last_debug_location: ?DebugLocation, |
| 4888 | | current_debug_location: ?DebugLocation, |
| 4855 | last_debug_location: Metadata, |
| 4856 | current_debug_location: Metadata, |
| 4889 | 4857 | cursor: Cursor, |
| 4890 | 4858 | blocks: std.ArrayListUnmanaged(Block), |
| 4891 | 4859 | instructions: std.MultiArrayList(Instruction), |
| 4892 | 4860 | names: std.ArrayListUnmanaged(String), |
| 4893 | | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, ?DebugLocation), |
| 4861 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, Metadata), |
| 4894 | 4862 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), |
| 4895 | 4863 | extra: std.ArrayListUnmanaged(u32), |
| 4896 | 4864 | |
| ... | ... | @@ -4923,9 +4891,11 @@ pub const WipFunction = struct { |
| 4923 | 4891 | pub const Instruction = Function.Instruction; |
| 4924 | 4892 | |
| 4925 | 4893 | pub fn init(builder: *Builder, function: Function.Index) Allocator.Error!WipFunction { |
| 4926 | | var self = WipFunction{ |
| 4894 | var self: WipFunction = .{ |
| 4927 | 4895 | .builder = builder, |
| 4928 | 4896 | .function = function, |
| 4897 | .last_debug_location = .none, |
| 4898 | .current_debug_location = .none, |
| 4929 | 4899 | .cursor = undefined, |
| 4930 | 4900 | .blocks = .{}, |
| 4931 | 4901 | .instructions = .{}, |
| ... | ... | @@ -4933,8 +4903,6 @@ pub const WipFunction = struct { |
| 4933 | 4903 | .debug_locations = .{}, |
| 4934 | 4904 | .debug_values = .{}, |
| 4935 | 4905 | .extra = .{}, |
| 4936 | | .current_debug_location = null, |
| 4937 | | .last_debug_location = null, |
| 4938 | 4906 | }; |
| 4939 | 4907 | errdefer self.deinit(); |
| 4940 | 4908 | |
| ... | ... | @@ -5874,7 +5842,7 @@ pub const WipFunction = struct { |
| 5874 | 5842 | const value_indices = try gpa.alloc(u32, final_instructions_len); |
| 5875 | 5843 | errdefer gpa.free(value_indices); |
| 5876 | 5844 | |
| 5877 | | var debug_locations = std.AutoHashMapUnmanaged(Instruction.Index, ?DebugLocation){}; |
| 5845 | var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, Metadata) = .{}; |
| 5878 | 5846 | errdefer debug_locations.deinit(gpa); |
| 5879 | 5847 | try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count())); |
| 5880 | 5848 | |
| ... | ... | @@ -5902,7 +5870,7 @@ pub const WipFunction = struct { |
| 5902 | 5870 | Instruction.Alloca.Info, |
| 5903 | 5871 | Instruction.Call.Info, |
| 5904 | 5872 | => @bitCast(value), |
| 5905 | | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 5873 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)), |
| 5906 | 5874 | }; |
| 5907 | 5875 | wip_extra.index += 1; |
| 5908 | 5876 | } |
| ... | ... | @@ -6472,13 +6440,7 @@ pub const WipFunction = struct { |
| 6472 | 6440 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6473 | 6441 | if (!self.builder.strip) { |
| 6474 | 6442 | try self.names.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6475 | | if (!std.mem.eql( |
| 6476 | | u8, |
| 6477 | | std.mem.asBytes(&self.current_debug_location), |
| 6478 | | std.mem.asBytes(&self.last_debug_location), |
| 6479 | | )) { |
| 6480 | | try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6481 | | } |
| 6443 | try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6482 | 6444 | } |
| 6483 | 6445 | try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6484 | 6446 | const final_name = if (name) |n| |
| ... | ... | @@ -6490,11 +6452,7 @@ pub const WipFunction = struct { |
| 6490 | 6452 | self.instructions.appendAssumeCapacity(instruction); |
| 6491 | 6453 | if (!self.builder.strip) { |
| 6492 | 6454 | self.names.appendAssumeCapacity(final_name); |
| 6493 | | if (!std.mem.eql( |
| 6494 | | u8, |
| 6495 | | std.mem.asBytes(&self.current_debug_location), |
| 6496 | | std.mem.asBytes(&self.last_debug_location), |
| 6497 | | )) { |
| 6455 | if (!std.meta.eql(self.current_debug_location, self.last_debug_location)) { |
| 6498 | 6456 | self.debug_locations.putAssumeCapacity(index, self.current_debug_location); |
| 6499 | 6457 | self.last_debug_location = self.current_debug_location; |
| 6500 | 6458 | } |
| ... | ... | @@ -6521,7 +6479,7 @@ pub const WipFunction = struct { |
| 6521 | 6479 | Instruction.Alloca.Info, |
| 6522 | 6480 | Instruction.Call.Info, |
| 6523 | 6481 | => @bitCast(value), |
| 6524 | | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 6482 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)), |
| 6525 | 6483 | }); |
| 6526 | 6484 | } |
| 6527 | 6485 | return result; |
| ... | ... | @@ -6569,7 +6527,7 @@ pub const WipFunction = struct { |
| 6569 | 6527 | Instruction.Alloca.Info, |
| 6570 | 6528 | Instruction.Call.Info, |
| 6571 | 6529 | => @bitCast(value), |
| 6572 | | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 6530 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)), |
| 6573 | 6531 | }; |
| 6574 | 6532 | return .{ |
| 6575 | 6533 | .data = result, |
| ... | ... | @@ -7194,7 +7152,7 @@ pub const Constant = enum(u32) { |
| 7194 | 7152 | @ptrCast(data.builder.constant_limbs.items[item.data..][0..Integer.limbs]); |
| 7195 | 7153 | const limbs = data.builder.constant_limbs |
| 7196 | 7154 | .items[item.data + Integer.limbs ..][0..extra.limbs_len]; |
| 7197 | | const bigint = std.math.big.int.Const{ |
| 7155 | const bigint: std.math.big.int.Const = .{ |
| 7198 | 7156 | .limbs = limbs, |
| 7199 | 7157 | .positive = tag == .positive_integer, |
| 7200 | 7158 | }; |
| ... | ... | @@ -7507,7 +7465,7 @@ pub const Value = enum(u32) { |
| 7507 | 7465 | return switch (self.unwrap()) { |
| 7508 | 7466 | .instruction => |instruction| instruction.typeOfWip(wip), |
| 7509 | 7467 | .constant => |constant| constant.typeOf(wip.builder), |
| 7510 | | .metadata => Type.metadata, |
| 7468 | .metadata => .metadata, |
| 7511 | 7469 | }; |
| 7512 | 7470 | } |
| 7513 | 7471 | |
| ... | ... | @@ -7515,7 +7473,7 @@ pub const Value = enum(u32) { |
| 7515 | 7473 | return switch (self.unwrap()) { |
| 7516 | 7474 | .instruction => |instruction| instruction.typeOf(function, builder), |
| 7517 | 7475 | .constant => |constant| constant.typeOf(builder), |
| 7518 | | .metadata => Type.metadata, |
| 7476 | .metadata => .metadata, |
| 7519 | 7477 | }; |
| 7520 | 7478 | } |
| 7521 | 7479 | |
| ... | ... | @@ -7559,11 +7517,11 @@ pub const MetadataString = enum(u32) { |
| 7559 | 7517 | none = 0, |
| 7560 | 7518 | _, |
| 7561 | 7519 | |
| 7562 | | pub fn slice(self: MetadataString, b: *const Builder) []const u8 { |
| 7520 | pub fn slice(self: MetadataString, builder: *const Builder) []const u8 { |
| 7563 | 7521 | const index = @intFromEnum(self); |
| 7564 | | const start = b.metadata_string_indices.items[index]; |
| 7565 | | const end = b.metadata_string_indices.items[index + 1]; |
| 7566 | | return b.metadata_string_bytes.items[start..end]; |
| 7522 | const start = builder.metadata_string_indices.items[index]; |
| 7523 | const end = builder.metadata_string_indices.items[index + 1]; |
| 7524 | return builder.metadata_string_bytes.items[start..end]; |
| 7567 | 7525 | } |
| 7568 | 7526 | |
| 7569 | 7527 | const Adapter = struct { |
| ... | ... | @@ -7576,6 +7534,22 @@ pub const MetadataString = enum(u32) { |
| 7576 | 7534 | return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder)); |
| 7577 | 7535 | } |
| 7578 | 7536 | }; |
| 7537 | |
| 7538 | const FormatData = struct { |
| 7539 | metadata_string: MetadataString, |
| 7540 | builder: *const Builder, |
| 7541 | }; |
| 7542 | fn format( |
| 7543 | data: FormatData, |
| 7544 | comptime _: []const u8, |
| 7545 | _: std.fmt.FormatOptions, |
| 7546 | writer: anytype, |
| 7547 | ) @TypeOf(writer).Error!void { |
| 7548 | try printEscapedString(data.metadata_string.slice(data.builder), .always_quote, writer); |
| 7549 | } |
| 7550 | fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Formatter(format) { |
| 7551 | return .{ .data = .{ .metadata_string = self, .builder = builder } }; |
| 7552 | } |
| 7579 | 7553 | }; |
| 7580 | 7554 | |
| 7581 | 7555 | pub const Metadata = enum(u32) { |
| ... | ... | @@ -7591,13 +7565,13 @@ pub const Metadata = enum(u32) { |
| 7591 | 7565 | compile_unit, |
| 7592 | 7566 | @"compile_unit optimized", |
| 7593 | 7567 | subprogram, |
| 7594 | | @"subprogram optimized", |
| 7595 | 7568 | @"subprogram local", |
| 7596 | 7569 | @"subprogram definition", |
| 7570 | @"subprogram local definition", |
| 7571 | @"subprogram optimized", |
| 7597 | 7572 | @"subprogram optimized local", |
| 7598 | 7573 | @"subprogram optimized definition", |
| 7599 | 7574 | @"subprogram optimized local definition", |
| 7600 | | @"subprogram local definition", |
| 7601 | 7575 | lexical_block, |
| 7602 | 7576 | location, |
| 7603 | 7577 | basic_bool_type, |
| ... | ... | @@ -7625,18 +7599,66 @@ pub const Metadata = enum(u32) { |
| 7625 | 7599 | @"global_var local", |
| 7626 | 7600 | global_var_expression, |
| 7627 | 7601 | constant, |
| 7602 | |
| 7603 | pub fn isInline(tag: Tag) bool { |
| 7604 | return switch (tag) { |
| 7605 | .none, |
| 7606 | .tuple, |
| 7607 | .expression, |
| 7608 | .constant, |
| 7609 | => true, |
| 7610 | .file, |
| 7611 | .compile_unit, |
| 7612 | .@"compile_unit optimized", |
| 7613 | .subprogram, |
| 7614 | .@"subprogram local", |
| 7615 | .@"subprogram definition", |
| 7616 | .@"subprogram local definition", |
| 7617 | .@"subprogram optimized", |
| 7618 | .@"subprogram optimized local", |
| 7619 | .@"subprogram optimized definition", |
| 7620 | .@"subprogram optimized local definition", |
| 7621 | .lexical_block, |
| 7622 | .location, |
| 7623 | .basic_bool_type, |
| 7624 | .basic_unsigned_type, |
| 7625 | .basic_signed_type, |
| 7626 | .basic_float_type, |
| 7627 | .composite_struct_type, |
| 7628 | .composite_union_type, |
| 7629 | .composite_enumeration_type, |
| 7630 | .composite_array_type, |
| 7631 | .composite_vector_type, |
| 7632 | .derived_pointer_type, |
| 7633 | .derived_member_type, |
| 7634 | .subroutine_type, |
| 7635 | .enumerator_unsigned, |
| 7636 | .enumerator_signed_positive, |
| 7637 | .enumerator_signed_negative, |
| 7638 | .subrange, |
| 7639 | .module_flag, |
| 7640 | .local_var, |
| 7641 | .parameter, |
| 7642 | .global_var, |
| 7643 | .@"global_var local", |
| 7644 | .global_var_expression, |
| 7645 | => false, |
| 7646 | }; |
| 7647 | } |
| 7628 | 7648 | }; |
| 7629 | 7649 | |
| 7650 | pub fn isInline(self: Metadata, builder: *const Builder) bool { |
| 7651 | return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline(); |
| 7652 | } |
| 7653 | |
| 7630 | 7654 | pub fn unwrap(self: Metadata, builder: *const Builder) Metadata { |
| 7631 | 7655 | var metadata = self; |
| 7632 | | var count: usize = 0; |
| 7633 | 7656 | while (@intFromEnum(metadata) >= Metadata.first_forward_reference and |
| 7634 | 7657 | @intFromEnum(metadata) < Metadata.first_local_metadata) |
| 7635 | 7658 | { |
| 7636 | 7659 | const index = @intFromEnum(metadata) - Metadata.first_forward_reference; |
| 7637 | 7660 | metadata = builder.metadata_forward_references.items[index]; |
| 7638 | 7661 | std.debug.assert(metadata != .none); |
| 7639 | | count += 1; |
| 7640 | 7662 | } |
| 7641 | 7663 | return metadata; |
| 7642 | 7664 | } |
| ... | ... | @@ -7648,13 +7670,75 @@ pub const Metadata = enum(u32) { |
| 7648 | 7670 | const ExtraIndex = u32; |
| 7649 | 7671 | }; |
| 7650 | 7672 | |
| 7673 | pub const DIFlags = packed struct(u32) { |
| 7674 | Visibility: enum(u2) { Zero, Private, Protected, Public } = .Zero, |
| 7675 | FwdDecl: bool = false, |
| 7676 | AppleBlock: bool = false, |
| 7677 | ReservedBit4: u1 = 0, |
| 7678 | Virtual: bool = false, |
| 7679 | Artificial: bool = false, |
| 7680 | Explicit: bool = false, |
| 7681 | Prototyped: bool = false, |
| 7682 | ObjcClassComplete: bool = false, |
| 7683 | ObjectPointer: bool = false, |
| 7684 | Vector: bool = false, |
| 7685 | StaticMember: bool = false, |
| 7686 | LValueReference: bool = false, |
| 7687 | RValueReference: bool = false, |
| 7688 | ExportSymbols: bool = false, |
| 7689 | Inheritance: enum(u2) { |
| 7690 | Zero, |
| 7691 | SingleInheritance, |
| 7692 | MultipleInheritance, |
| 7693 | VirtualInheritance, |
| 7694 | } = .Zero, |
| 7695 | IntroducedVirtual: bool = false, |
| 7696 | BitField: bool = false, |
| 7697 | NoReturn: bool = false, |
| 7698 | ReservedBit21: u1 = 0, |
| 7699 | TypePassbyValue: bool = false, |
| 7700 | TypePassbyReference: bool = false, |
| 7701 | EnumClass: bool = false, |
| 7702 | Thunk: bool = false, |
| 7703 | NonTrivial: bool = false, |
| 7704 | BigEndian: bool = false, |
| 7705 | LittleEndian: bool = false, |
| 7706 | AllCallsDescribed: bool = false, |
| 7707 | Unused: u2 = 0, |
| 7708 | |
| 7709 | pub fn format( |
| 7710 | self: DIFlags, |
| 7711 | comptime _: []const u8, |
| 7712 | _: std.fmt.FormatOptions, |
| 7713 | writer: anytype, |
| 7714 | ) @TypeOf(writer).Error!void { |
| 7715 | var need_pipe = false; |
| 7716 | inline for (@typeInfo(DIFlags).Struct.fields) |field| { |
| 7717 | switch (@typeInfo(field.type)) { |
| 7718 | .Bool => if (@field(self, field.name)) { |
| 7719 | if (need_pipe) try writer.writeAll(" | ") else need_pipe = true; |
| 7720 | try writer.print("DIFlag{s}", .{field.name}); |
| 7721 | }, |
| 7722 | .Enum => if (@field(self, field.name) != .Zero) { |
| 7723 | if (need_pipe) try writer.writeAll(" | ") else need_pipe = true; |
| 7724 | try writer.print("DIFlag{s}", .{@tagName(@field(self, field.name))}); |
| 7725 | }, |
| 7726 | .Int => assert(@field(self, field.name) == 0), |
| 7727 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ |
| 7728 | @typeName(field.type)), |
| 7729 | } |
| 7730 | } |
| 7731 | if (!need_pipe) try writer.writeByte('0'); |
| 7732 | } |
| 7733 | }; |
| 7734 | |
| 7651 | 7735 | pub const File = struct { |
| 7652 | | path: MetadataString, |
| 7653 | | name: MetadataString, |
| 7736 | filename: MetadataString, |
| 7737 | directory: MetadataString, |
| 7654 | 7738 | }; |
| 7655 | 7739 | |
| 7656 | 7740 | pub const CompileUnit = struct { |
| 7657 | | pub const Flags = struct { |
| 7741 | pub const Options = struct { |
| 7658 | 7742 | optimized: bool, |
| 7659 | 7743 | }; |
| 7660 | 7744 | |
| ... | ... | @@ -7665,11 +7749,49 @@ pub const Metadata = enum(u32) { |
| 7665 | 7749 | }; |
| 7666 | 7750 | |
| 7667 | 7751 | pub const Subprogram = struct { |
| 7668 | | pub const Flags = struct { |
| 7669 | | optimized: bool, |
| 7670 | | local: bool, |
| 7671 | | definition: bool, |
| 7672 | | debug_info_flags: u32, |
| 7752 | pub const Options = struct { |
| 7753 | di_flags: DIFlags, |
| 7754 | sp_flags: SPFlags, |
| 7755 | }; |
| 7756 | |
| 7757 | pub const SPFlags = packed struct(u32) { |
| 7758 | Virtuality: enum(u2) { Zero, Virtual, PureVirtual } = .Zero, |
| 7759 | LocalToUnit: bool = false, |
| 7760 | Definition: bool = false, |
| 7761 | Optimized: bool = false, |
| 7762 | Pure: bool = false, |
| 7763 | Elemental: bool = false, |
| 7764 | Recursive: bool = false, |
| 7765 | MainSubprogram: bool = false, |
| 7766 | Deleted: bool = false, |
| 7767 | ReservedBit10: u1 = 0, |
| 7768 | ObjCDirect: bool = false, |
| 7769 | Unused: u20 = 0, |
| 7770 | |
| 7771 | pub fn format( |
| 7772 | self: SPFlags, |
| 7773 | comptime _: []const u8, |
| 7774 | _: std.fmt.FormatOptions, |
| 7775 | writer: anytype, |
| 7776 | ) @TypeOf(writer).Error!void { |
| 7777 | var need_pipe = false; |
| 7778 | inline for (@typeInfo(SPFlags).Struct.fields) |field| { |
| 7779 | switch (@typeInfo(field.type)) { |
| 7780 | .Bool => if (@field(self, field.name)) { |
| 7781 | if (need_pipe) try writer.writeAll(" | ") else need_pipe = true; |
| 7782 | try writer.print("SPFlag{s}", .{field.name}); |
| 7783 | }, |
| 7784 | .Enum => if (@field(self, field.name) != .Zero) { |
| 7785 | if (need_pipe) try writer.writeAll(" | ") else need_pipe = true; |
| 7786 | try writer.print("SPFlag{s}", .{@tagName(@field(self, field.name))}); |
| 7787 | }, |
| 7788 | .Int => assert(@field(self, field.name) == 0), |
| 7789 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ |
| 7790 | @typeName(field.type)), |
| 7791 | } |
| 7792 | } |
| 7793 | if (!need_pipe) try writer.writeByte('0'); |
| 7794 | } |
| 7673 | 7795 | }; |
| 7674 | 7796 | |
| 7675 | 7797 | file: Metadata, |
| ... | ... | @@ -7678,21 +7800,21 @@ pub const Metadata = enum(u32) { |
| 7678 | 7800 | line: u32, |
| 7679 | 7801 | scope_line: u32, |
| 7680 | 7802 | ty: Metadata, |
| 7681 | | debug_info_flags: u32, |
| 7803 | di_flags: DIFlags, |
| 7682 | 7804 | compile_unit: Metadata, |
| 7683 | 7805 | }; |
| 7684 | 7806 | |
| 7685 | 7807 | pub const LexicalBlock = struct { |
| 7686 | | file: Metadata, |
| 7687 | 7808 | scope: Metadata, |
| 7809 | file: Metadata, |
| 7688 | 7810 | line: u32, |
| 7689 | 7811 | column: u32, |
| 7690 | 7812 | }; |
| 7691 | 7813 | |
| 7692 | 7814 | pub const Location = struct { |
| 7693 | | scope: Metadata, |
| 7694 | 7815 | line: u32, |
| 7695 | 7816 | column: u32, |
| 7817 | scope: Metadata, |
| 7696 | 7818 | inlined_at: Metadata, |
| 7697 | 7819 | }; |
| 7698 | 7820 | |
| ... | ... | @@ -7700,6 +7822,10 @@ pub const Metadata = enum(u32) { |
| 7700 | 7822 | name: MetadataString, |
| 7701 | 7823 | size_in_bits_lo: u32, |
| 7702 | 7824 | size_in_bits_hi: u32, |
| 7825 | |
| 7826 | pub fn bitSize(self: BasicType) u64 { |
| 7827 | return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo; |
| 7828 | } |
| 7703 | 7829 | }; |
| 7704 | 7830 | |
| 7705 | 7831 | pub const CompositeType = struct { |
| ... | ... | @@ -7713,6 +7839,13 @@ pub const Metadata = enum(u32) { |
| 7713 | 7839 | align_in_bits_lo: u32, |
| 7714 | 7840 | align_in_bits_hi: u32, |
| 7715 | 7841 | fields_tuple: Metadata, |
| 7842 | |
| 7843 | pub fn bitSize(self: CompositeType) u64 { |
| 7844 | return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo; |
| 7845 | } |
| 7846 | pub fn bitAlign(self: CompositeType) u64 { |
| 7847 | return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo; |
| 7848 | } |
| 7716 | 7849 | }; |
| 7717 | 7850 | |
| 7718 | 7851 | pub const DerivedType = struct { |
| ... | ... | @@ -7727,6 +7860,16 @@ pub const Metadata = enum(u32) { |
| 7727 | 7860 | align_in_bits_hi: u32, |
| 7728 | 7861 | offset_in_bits_lo: u32, |
| 7729 | 7862 | offset_in_bits_hi: u32, |
| 7863 | |
| 7864 | pub fn bitSize(self: DerivedType) u64 { |
| 7865 | return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo; |
| 7866 | } |
| 7867 | pub fn bitAlign(self: DerivedType) u64 { |
| 7868 | return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo; |
| 7869 | } |
| 7870 | pub fn bitOffset(self: DerivedType) u64 { |
| 7871 | return @as(u64, self.offset_in_bits_hi) << 32 | self.offset_in_bits_lo; |
| 7872 | } |
| 7730 | 7873 | }; |
| 7731 | 7874 | |
| 7732 | 7875 | pub const SubroutineType = struct { |
| ... | ... | @@ -7758,7 +7901,7 @@ pub const Metadata = enum(u32) { |
| 7758 | 7901 | }; |
| 7759 | 7902 | |
| 7760 | 7903 | pub const ModuleFlag = struct { |
| 7761 | | behaviour: Metadata, |
| 7904 | behavior: Metadata, |
| 7762 | 7905 | name: MetadataString, |
| 7763 | 7906 | constant: Metadata, |
| 7764 | 7907 | }; |
| ... | ... | @@ -7781,7 +7924,7 @@ pub const Metadata = enum(u32) { |
| 7781 | 7924 | }; |
| 7782 | 7925 | |
| 7783 | 7926 | pub const GlobalVar = struct { |
| 7784 | | pub const Flags = struct { |
| 7927 | pub const Options = struct { |
| 7785 | 7928 | local: bool, |
| 7786 | 7929 | }; |
| 7787 | 7930 | |
| ... | ... | @@ -7802,13 +7945,276 @@ pub const Metadata = enum(u32) { |
| 7802 | 7945 | pub fn toValue(self: Metadata) Value { |
| 7803 | 7946 | return @enumFromInt(Value.first_metadata + @intFromEnum(self)); |
| 7804 | 7947 | } |
| 7805 | | }; |
| 7806 | 7948 | |
| 7807 | | pub const InitError = error{ |
| 7808 | | InvalidLlvmTriple, |
| 7809 | | } || Allocator.Error; |
| 7949 | const Formatter = struct { |
| 7950 | builder: *Builder, |
| 7951 | need_comma: bool, |
| 7952 | map: std.AutoArrayHashMapUnmanaged(Metadata, void) = .{}, |
| 7953 | |
| 7954 | fn unwrapAssumeExists(formatter: *Formatter, item: Metadata) FormatData.Item { |
| 7955 | if (item == .none) return .none; |
| 7956 | const unwrapped_metadata = item.unwrap(formatter.builder); |
| 7957 | const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)]; |
| 7958 | return if (tag.isInline()) |
| 7959 | .{ .@"inline" = unwrapped_metadata } |
| 7960 | else |
| 7961 | .{ .index = @intCast(formatter.map.getIndex(unwrapped_metadata).?) }; |
| 7962 | } |
| 7963 | fn unwrap(formatter: *Formatter, item: Metadata) Allocator.Error!FormatData.Item { |
| 7964 | if (item == .none) return .none; |
| 7965 | const builder = formatter.builder; |
| 7966 | const unwrapped_metadata = item.unwrap(builder); |
| 7967 | const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)]; |
| 7968 | switch (tag) { |
| 7969 | .none => unreachable, |
| 7970 | .tuple => { |
| 7971 | var extra = builder.metadataExtraDataTrail( |
| 7972 | Metadata.Tuple, |
| 7973 | builder.metadata_items.items(.data)[@intFromEnum(unwrapped_metadata)], |
| 7974 | ); |
| 7975 | const elements = extra.trail.next(extra.data.elements_len, Metadata, builder); |
| 7976 | for (elements) |element| _ = try formatter.unwrap(element); |
| 7977 | }, |
| 7978 | .expression, .constant => {}, |
| 7979 | else => { |
| 7980 | assert(!tag.isInline()); |
| 7981 | const gop = try formatter.map.getOrPutValue(builder.gpa, unwrapped_metadata, {}); |
| 7982 | return .{ .index = @intCast(gop.index) }; |
| 7983 | }, |
| 7984 | } |
| 7985 | return .{ .@"inline" = unwrapped_metadata }; |
| 7986 | } |
| 7810 | 7987 | |
| 7811 | | pub fn init(options: Options) InitError!Builder { |
| 7988 | const FormatData = struct { |
| 7989 | formatter: *Formatter, |
| 7990 | prefix: []const u8 = "", |
| 7991 | item: FormatData.Item, |
| 7992 | |
| 7993 | const Item = union(enum) { |
| 7994 | none, |
| 7995 | @"inline": Metadata, |
| 7996 | index: u32, |
| 7997 | string: MetadataString, |
| 7998 | value: struct { |
| 7999 | value: Value, |
| 8000 | function: Function.Index, |
| 8001 | }, |
| 8002 | bool: bool, |
| 8003 | u32: u32, |
| 8004 | u64: u64, |
| 8005 | raw: []const u8, |
| 8006 | }; |
| 8007 | }; |
| 8008 | fn format( |
| 8009 | data: FormatData, |
| 8010 | comptime fmt_str: []const u8, |
| 8011 | fmt_opts: std.fmt.FormatOptions, |
| 8012 | writer: anytype, |
| 8013 | ) @TypeOf(writer).Error!void { |
| 8014 | if (data.item == .none) return; |
| 8015 | |
| 8016 | if (data.formatter.need_comma) try writer.writeAll(", "); |
| 8017 | defer data.formatter.need_comma = true; |
| 8018 | try writer.writeAll(data.prefix); |
| 8019 | |
| 8020 | const builder = data.formatter.builder; |
| 8021 | switch (data.item) { |
| 8022 | .none => unreachable, |
| 8023 | .@"inline" => |item| { |
| 8024 | const needed_comma = data.formatter.need_comma; |
| 8025 | defer data.formatter.need_comma = needed_comma; |
| 8026 | data.formatter.need_comma = false; |
| 8027 | |
| 8028 | const metadata_item = builder.metadata_items.get(@intFromEnum(item)); |
| 8029 | switch (metadata_item.tag) { |
| 8030 | .tuple => { |
| 8031 | var extra = |
| 8032 | builder.metadataExtraDataTrail(Metadata.Tuple, metadata_item.data); |
| 8033 | const elements = |
| 8034 | extra.trail.next(extra.data.elements_len, Metadata, builder); |
| 8035 | try writer.writeAll("!{"); |
| 8036 | for (elements) |element| try format(.{ |
| 8037 | .formatter = data.formatter, |
| 8038 | .item = data.formatter.unwrapAssumeExists(element), |
| 8039 | }, "%", fmt_opts, writer); |
| 8040 | try writer.writeByte('}'); |
| 8041 | }, |
| 8042 | .expression => { |
| 8043 | var extra = |
| 8044 | builder.metadataExtraDataTrail(Metadata.Expression, metadata_item.data); |
| 8045 | const elements = extra.trail.next(extra.data.elements_len, u32, builder); |
| 8046 | try writer.writeAll("!DIExpression("); |
| 8047 | for (elements) |element| try format(.{ |
| 8048 | .formatter = data.formatter, |
| 8049 | .item = .{ .u64 = element }, |
| 8050 | }, "%", fmt_opts, writer); |
| 8051 | try writer.writeByte(')'); |
| 8052 | }, |
| 8053 | .constant => try Constant.format(.{ |
| 8054 | .constant = @enumFromInt(metadata_item.data), |
| 8055 | .builder = builder, |
| 8056 | }, "%", fmt_opts, writer), |
| 8057 | else => unreachable, |
| 8058 | } |
| 8059 | }, |
| 8060 | .index => |item| try writer.print("!{d}", .{item}), |
| 8061 | .value => |item| try Value.format(.{ |
| 8062 | .value = switch (item.value.unwrap()) { |
| 8063 | .instruction, .constant => item.value, |
| 8064 | .metadata => |metadata| if (@intFromEnum(metadata) >= |
| 8065 | Metadata.first_local_metadata) |
| 8066 | item.function.ptrConst(builder).debug_values[ |
| 8067 | @intFromEnum(metadata) - Metadata.first_local_metadata |
| 8068 | ].toValue() |
| 8069 | else if (metadata != .none) { |
| 8070 | if (comptime std.mem.eql(u8, fmt_str, "%")) |
| 8071 | try writer.print("{%} ", .{Type.metadata.fmt(builder)}); |
| 8072 | try Metadata.Formatter.format(.{ |
| 8073 | .formatter = data.formatter, |
| 8074 | .item = data.formatter.unwrapAssumeExists(metadata), |
| 8075 | }, "", fmt_opts, writer); |
| 8076 | return; |
| 8077 | } else return, |
| 8078 | }, |
| 8079 | .function = item.function, |
| 8080 | .builder = builder, |
| 8081 | }, "%", fmt_opts, writer), |
| 8082 | .string => |item| try writer.print("{}", .{item.fmt(data.formatter.builder)}), |
| 8083 | inline .bool, .u32, .u64 => |item| try writer.print("{}", .{item}), |
| 8084 | .raw => |item| try writer.print("{s}", .{item}), |
| 8085 | } |
| 8086 | } |
| 8087 | inline fn fmt(formatter: *Formatter, prefix: []const u8, item: anytype) switch (@TypeOf(item)) { |
| 8088 | Metadata => Allocator.Error, |
| 8089 | else => error{}, |
| 8090 | }!std.fmt.Formatter(format) { |
| 8091 | return .{ .data = .{ |
| 8092 | .formatter = formatter, |
| 8093 | .prefix = prefix, |
| 8094 | .item = switch (@typeInfo(@TypeOf(item))) { |
| 8095 | .Null => .none, |
| 8096 | .Enum => |enum_info| switch (@TypeOf(item)) { |
| 8097 | Metadata => try formatter.unwrap(item), |
| 8098 | MetadataString => .{ .string = item }, |
| 8099 | else => if (enum_info.is_exhaustive) |
| 8100 | .{ .raw = @tagName(item) } |
| 8101 | else |
| 8102 | @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))), |
| 8103 | }, |
| 8104 | .EnumLiteral => .{ .raw = @tagName(item) }, |
| 8105 | .Bool => .{ .bool = item }, |
| 8106 | .Struct => .{ .u32 = @bitCast(item) }, |
| 8107 | .Int, .ComptimeInt => .{ .u64 = item }, |
| 8108 | .Pointer => .{ .raw = item }, |
| 8109 | .Optional => if (item) |some| switch (@typeInfo(@TypeOf(some))) { |
| 8110 | .Enum => |enum_info| switch (@TypeOf(some)) { |
| 8111 | Metadata => try formatter.unwrap(some), |
| 8112 | MetadataString => .{ .string = some }, |
| 8113 | else => if (enum_info.is_exhaustive) |
| 8114 | .{ .raw = @tagName(some) } |
| 8115 | else |
| 8116 | @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))), |
| 8117 | }, |
| 8118 | .Bool => .{ .bool = some }, |
| 8119 | .Struct => .{ .u32 = @bitCast(some) }, |
| 8120 | .Int => .{ .u64 = some }, |
| 8121 | .Pointer => .{ .raw = some }, |
| 8122 | else => @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))), |
| 8123 | } else .none, |
| 8124 | else => @compileError("unknown type to format: " ++ @typeName(@TypeOf(item))), |
| 8125 | }, |
| 8126 | } }; |
| 8127 | } |
| 8128 | inline fn fmtLocal( |
| 8129 | formatter: *Formatter, |
| 8130 | prefix: []const u8, |
| 8131 | item: Value, |
| 8132 | function: Function.Index, |
| 8133 | ) Allocator.Error!std.fmt.Formatter(format) { |
| 8134 | return .{ .data = .{ |
| 8135 | .formatter = formatter, |
| 8136 | .prefix = prefix, |
| 8137 | .item = .{ .value = .{ |
| 8138 | .value = switch (item.unwrap()) { |
| 8139 | .instruction, .constant => item, |
| 8140 | .metadata => |metadata| value: { |
| 8141 | const unwrapped_metadata = metadata.unwrap(formatter.builder); |
| 8142 | if (@intFromEnum(unwrapped_metadata) < Metadata.first_local_metadata) |
| 8143 | _ = try formatter.unwrap(unwrapped_metadata); |
| 8144 | break :value unwrapped_metadata.toValue(); |
| 8145 | }, |
| 8146 | }, |
| 8147 | .function = function, |
| 8148 | } }, |
| 8149 | } }; |
| 8150 | } |
| 8151 | |
| 8152 | inline fn specialized( |
| 8153 | formatter: *Formatter, |
| 8154 | distinct: enum { @"!", @"distinct !" }, |
| 8155 | node: enum { |
| 8156 | DIFile, |
| 8157 | DICompileUnit, |
| 8158 | DISubprogram, |
| 8159 | DILexicalBlock, |
| 8160 | DILocation, |
| 8161 | DIBasicType, |
| 8162 | DICompositeType, |
| 8163 | DIDerivedType, |
| 8164 | DISubroutineType, |
| 8165 | DIEnumerator, |
| 8166 | DISubrange, |
| 8167 | DILocalVariable, |
| 8168 | DIGlobalVariable, |
| 8169 | DIGlobalVariableExpression, |
| 8170 | }, |
| 8171 | items: anytype, |
| 8172 | writer: anytype, |
| 8173 | ) !void { |
| 8174 | comptime var fmt_str: []const u8 = ""; |
| 8175 | const names = comptime std.meta.fieldNames(@TypeOf(items)); |
| 8176 | comptime var fields: [2 + names.len]std.builtin.Type.StructField = undefined; |
| 8177 | inline for (fields[0..2], .{ "distinct", "node" }) |*field, name| { |
| 8178 | fmt_str = fmt_str ++ "{[" ++ name ++ "]s}"; |
| 8179 | field.* = .{ |
| 8180 | .name = name, |
| 8181 | .type = []const u8, |
| 8182 | .default_value = null, |
| 8183 | .is_comptime = false, |
| 8184 | .alignment = 0, |
| 8185 | }; |
| 8186 | } |
| 8187 | fmt_str = fmt_str ++ "("; |
| 8188 | inline for (fields[2..], names) |*field, name| { |
| 8189 | fmt_str = fmt_str ++ "{[" ++ name ++ "]}"; |
| 8190 | field.* = .{ |
| 8191 | .name = name ++ "", |
| 8192 | .type = std.fmt.Formatter(format), |
| 8193 | .default_value = null, |
| 8194 | .is_comptime = false, |
| 8195 | .alignment = 0, |
| 8196 | }; |
| 8197 | } |
| 8198 | fmt_str = fmt_str ++ ")\n"; |
| 8199 | |
| 8200 | var fmt_args: @Type(.{ .Struct = .{ |
| 8201 | .layout = .Auto, |
| 8202 | .fields = &fields, |
| 8203 | .decls = &.{}, |
| 8204 | .is_tuple = false, |
| 8205 | } }) = undefined; |
| 8206 | fmt_args.distinct = @tagName(distinct); |
| 8207 | fmt_args.node = @tagName(node); |
| 8208 | inline for (names) |name| @field(fmt_args, name) = try formatter.fmt( |
| 8209 | name ++ ": ", |
| 8210 | @field(items, name), |
| 8211 | ); |
| 8212 | try writer.print(fmt_str, fmt_args); |
| 8213 | } |
| 8214 | }; |
| 8215 | }; |
| 8216 | |
| 8217 | pub fn init(options: Options) Allocator.Error!Builder { |
| 7812 | 8218 | var self = Builder{ |
| 7813 | 8219 | .gpa = options.allocator, |
| 7814 | 8220 | .strip = options.strip, |
| ... | ... | @@ -8800,9 +9206,11 @@ pub fn printUnbuffered( |
| 8800 | 9206 | writer: anytype, |
| 8801 | 9207 | ) (@TypeOf(writer).Error || Allocator.Error)!void { |
| 8802 | 9208 | var need_newline = false; |
| 9209 | var metadata_formatter: Metadata.Formatter = .{ .builder = self, .need_comma = undefined }; |
| 9210 | defer metadata_formatter.map.deinit(self.gpa); |
| 8803 | 9211 | |
| 8804 | 9212 | if (self.source_filename != .none or self.data_layout != .none or self.target_triple != .none) { |
| 8805 | | if (need_newline) try writer.writeByte('\n'); |
| 9213 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 8806 | 9214 | if (self.source_filename != .none) try writer.print( |
| 8807 | 9215 | \\; ModuleID = '{s}' |
| 8808 | 9216 | \\source_filename = {"} |
| ... | ... | @@ -8816,36 +9224,35 @@ pub fn printUnbuffered( |
| 8816 | 9224 | \\target triple = {"} |
| 8817 | 9225 | \\ |
| 8818 | 9226 | , .{self.target_triple.fmt(self)}); |
| 8819 | | need_newline = true; |
| 8820 | 9227 | } |
| 8821 | 9228 | |
| 8822 | 9229 | if (self.module_asm.items.len > 0) { |
| 8823 | | if (need_newline) try writer.writeByte('\n'); |
| 9230 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 8824 | 9231 | var line_it = std.mem.tokenizeScalar(u8, self.module_asm.items, '\n'); |
| 8825 | 9232 | while (line_it.next()) |line| { |
| 8826 | 9233 | try writer.writeAll("module asm "); |
| 8827 | 9234 | try printEscapedString(line, .always_quote, writer); |
| 8828 | 9235 | try writer.writeByte('\n'); |
| 8829 | 9236 | } |
| 8830 | | need_newline = true; |
| 8831 | 9237 | } |
| 8832 | 9238 | |
| 8833 | 9239 | if (self.types.count() > 0) { |
| 8834 | | if (need_newline) try writer.writeByte('\n'); |
| 9240 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 8835 | 9241 | for (self.types.keys(), self.types.values()) |id, ty| try writer.print( |
| 8836 | 9242 | \\%{} = type {} |
| 8837 | 9243 | \\ |
| 8838 | 9244 | , .{ id.fmt(self), ty.fmt(self) }); |
| 8839 | | need_newline = true; |
| 8840 | 9245 | } |
| 8841 | 9246 | |
| 8842 | 9247 | if (self.variables.items.len > 0) { |
| 8843 | | if (need_newline) try writer.writeByte('\n'); |
| 9248 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 8844 | 9249 | for (self.variables.items) |variable| { |
| 8845 | 9250 | if (variable.global.getReplacement(self) != .none) continue; |
| 8846 | 9251 | const global = variable.global.ptrConst(self); |
| 9252 | metadata_formatter.need_comma = true; |
| 9253 | defer metadata_formatter.need_comma = undefined; |
| 8847 | 9254 | try writer.print( |
| 8848 | | \\{} ={}{}{}{}{ }{}{ }{} {s} {%}{ }{, } |
| 9255 | \\{} ={}{}{}{}{ }{}{ }{} {s} {%}{ }{, }{} |
| 8849 | 9256 | \\ |
| 8850 | 9257 | , .{ |
| 8851 | 9258 | variable.global.fmt(self), |
| ... | ... | @@ -8861,18 +9268,20 @@ pub fn printUnbuffered( |
| 8861 | 9268 | global.type.fmt(self), |
| 8862 | 9269 | variable.init.fmt(self), |
| 8863 | 9270 | variable.alignment, |
| 9271 | try metadata_formatter.fmt("!dbg ", global.dbg), |
| 8864 | 9272 | }); |
| 8865 | 9273 | } |
| 8866 | | need_newline = true; |
| 8867 | 9274 | } |
| 8868 | 9275 | |
| 8869 | 9276 | if (self.aliases.items.len > 0) { |
| 8870 | | if (need_newline) try writer.writeByte('\n'); |
| 9277 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 8871 | 9278 | for (self.aliases.items) |alias| { |
| 8872 | 9279 | if (alias.global.getReplacement(self) != .none) continue; |
| 8873 | 9280 | const global = alias.global.ptrConst(self); |
| 9281 | metadata_formatter.need_comma = true; |
| 9282 | defer metadata_formatter.need_comma = undefined; |
| 8874 | 9283 | try writer.print( |
| 8875 | | \\{} ={}{}{}{}{ }{} alias {%}, {%} |
| 9284 | \\{} ={}{}{}{}{ }{} alias {%}, {%}{} |
| 8876 | 9285 | \\ |
| 8877 | 9286 | , .{ |
| 8878 | 9287 | alias.global.fmt(self), |
| ... | ... | @@ -8884,9 +9293,9 @@ pub fn printUnbuffered( |
| 8884 | 9293 | global.unnamed_addr, |
| 8885 | 9294 | global.type.fmt(self), |
| 8886 | 9295 | alias.aliasee.fmt(self), |
| 9296 | try metadata_formatter.fmt("!dbg ", global.dbg), |
| 8887 | 9297 | }); |
| 8888 | 9298 | } |
| 8889 | | need_newline = true; |
| 8890 | 9299 | } |
| 8891 | 9300 | |
| 8892 | 9301 | var attribute_groups: std.AutoArrayHashMapUnmanaged(Attributes, void) = .{}; |
| ... | ... | @@ -8894,7 +9303,7 @@ pub fn printUnbuffered( |
| 8894 | 9303 | |
| 8895 | 9304 | for (0.., self.functions.items) |function_i, function| { |
| 8896 | 9305 | if (function.global.getReplacement(self) != .none) continue; |
| 8897 | | if (need_newline) try writer.writeByte('\n'); |
| 9306 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 8898 | 9307 | const function_index: Function.Index = @enumFromInt(function_i); |
| 8899 | 9308 | const global = function.global.ptrConst(self); |
| 8900 | 9309 | const params_len = global.type.functionParameters(self).len; |
| ... | ... | @@ -8940,13 +9349,23 @@ pub fn printUnbuffered( |
| 8940 | 9349 | if (function_attributes != .none) try writer.print(" #{d}", .{ |
| 8941 | 9350 | (try attribute_groups.getOrPutValue(self.gpa, function_attributes, {})).index, |
| 8942 | 9351 | }); |
| 8943 | | try writer.print("{ }", .{function.alignment}); |
| 9352 | { |
| 9353 | metadata_formatter.need_comma = false; |
| 9354 | defer metadata_formatter.need_comma = undefined; |
| 9355 | try writer.print("{ }{}", .{ |
| 9356 | function.alignment, |
| 9357 | try metadata_formatter.fmt("!dbg ", global.dbg), |
| 9358 | }); |
| 9359 | } |
| 8944 | 9360 | if (function.instructions.len > 0) { |
| 8945 | 9361 | var block_incoming_len: u32 = undefined; |
| 8946 | 9362 | try writer.writeAll(" {\n"); |
| 9363 | var dbg: Metadata = .none; |
| 8947 | 9364 | for (params_len..function.instructions.len) |instruction_i| { |
| 8948 | 9365 | const instruction_index: Function.Instruction.Index = @enumFromInt(instruction_i); |
| 8949 | 9366 | const instruction = function.instructions.get(@intFromEnum(instruction_index)); |
| 9367 | if (function.debug_locations.get(instruction_index)) |debug_location| |
| 9368 | dbg = debug_location; |
| 8950 | 9369 | switch (instruction.tag) { |
| 8951 | 9370 | .add, |
| 8952 | 9371 | .@"add nsw", |
| ... | ... | @@ -9031,7 +9450,7 @@ pub fn printUnbuffered( |
| 9031 | 9450 | .xor, |
| 9032 | 9451 | => |tag| { |
| 9033 | 9452 | const extra = function.extraData(Function.Instruction.Binary, instruction.data); |
| 9034 | | try writer.print(" %{} = {s} {%}, {}\n", .{ |
| 9453 | try writer.print(" %{} = {s} {%}, {}", .{ |
| 9035 | 9454 | instruction_index.name(&function).fmt(self), |
| 9036 | 9455 | @tagName(tag), |
| 9037 | 9456 | extra.lhs.fmt(function_index, self), |
| ... | ... | @@ -9053,7 +9472,7 @@ pub fn printUnbuffered( |
| 9053 | 9472 | .zext, |
| 9054 | 9473 | => |tag| { |
| 9055 | 9474 | const extra = function.extraData(Function.Instruction.Cast, instruction.data); |
| 9056 | | try writer.print(" %{} = {s} {%} to {%}\n", .{ |
| 9475 | try writer.print(" %{} = {s} {%} to {%}", .{ |
| 9057 | 9476 | instruction_index.name(&function).fmt(self), |
| 9058 | 9477 | @tagName(tag), |
| 9059 | 9478 | extra.val.fmt(function_index, self), |
| ... | ... | @@ -9064,7 +9483,7 @@ pub fn printUnbuffered( |
| 9064 | 9483 | .@"alloca inalloca", |
| 9065 | 9484 | => |tag| { |
| 9066 | 9485 | const extra = function.extraData(Function.Instruction.Alloca, instruction.data); |
| 9067 | | try writer.print(" %{} = {s} {%}{,%}{, }{, }\n", .{ |
| 9486 | try writer.print(" %{} = {s} {%}{,%}{, }{, }", .{ |
| 9068 | 9487 | instruction_index.name(&function).fmt(self), |
| 9069 | 9488 | @tagName(tag), |
| 9070 | 9489 | extra.type.fmt(self), |
| ... | ... | @@ -9077,7 +9496,7 @@ pub fn printUnbuffered( |
| 9077 | 9496 | .atomicrmw => |tag| { |
| 9078 | 9497 | const extra = |
| 9079 | 9498 | function.extraData(Function.Instruction.AtomicRmw, instruction.data); |
| 9080 | | try writer.print(" %{} = {s}{ } {s} {%}, {%}{ }{ }{, }\n", .{ |
| 9499 | try writer.print(" %{} = {s}{ } {s} {%}, {%}{ }{ }{, }", .{ |
| 9081 | 9500 | instruction_index.name(&function).fmt(self), |
| 9082 | 9501 | @tagName(tag), |
| 9083 | 9502 | extra.info.access_kind, |
| ... | ... | @@ -9094,17 +9513,17 @@ pub fn printUnbuffered( |
| 9094 | 9513 | const name = instruction_index.name(&function); |
| 9095 | 9514 | if (@intFromEnum(instruction_index) > params_len) |
| 9096 | 9515 | try writer.writeByte('\n'); |
| 9097 | | try writer.print("{}:\n", .{name.fmt(self)}); |
| 9516 | try writer.print("{}:", .{name.fmt(self)}); |
| 9098 | 9517 | }, |
| 9099 | 9518 | .br => |tag| { |
| 9100 | 9519 | const target: Function.Block.Index = @enumFromInt(instruction.data); |
| 9101 | | try writer.print(" {s} {%}\n", .{ |
| 9520 | try writer.print(" {s} {%}", .{ |
| 9102 | 9521 | @tagName(tag), target.toInst(&function).fmt(function_index, self), |
| 9103 | 9522 | }); |
| 9104 | 9523 | }, |
| 9105 | 9524 | .br_cond => { |
| 9106 | 9525 | const extra = function.extraData(Function.Instruction.BrCond, instruction.data); |
| 9107 | | try writer.print(" br {%}, {%}, {%}\n", .{ |
| 9526 | try writer.print(" br {%}, {%}, {%}", .{ |
| 9108 | 9527 | extra.cond.fmt(function_index, self), |
| 9109 | 9528 | extra.then.toInst(&function).fmt(function_index, self), |
| 9110 | 9529 | extra.@"else".toInst(&function).fmt(function_index, self), |
| ... | ... | @@ -9144,10 +9563,12 @@ pub fn printUnbuffered( |
| 9144 | 9563 | }); |
| 9145 | 9564 | for (0.., args) |arg_index, arg| { |
| 9146 | 9565 | if (arg_index > 0) try writer.writeAll(", "); |
| 9147 | | try writer.print("{%}{} {}", .{ |
| 9566 | metadata_formatter.need_comma = false; |
| 9567 | defer metadata_formatter.need_comma = undefined; |
| 9568 | try writer.print("{%}{}{}", .{ |
| 9148 | 9569 | arg.typeOf(function_index, self).fmt(self), |
| 9149 | 9570 | extra.data.attributes.param(arg_index, self).fmt(self), |
| 9150 | | arg.fmt(function_index, self), |
| 9571 | try metadata_formatter.fmtLocal(" ", arg, function_index), |
| 9151 | 9572 | }); |
| 9152 | 9573 | } |
| 9153 | 9574 | try writer.writeByte(')'); |
| ... | ... | @@ -9159,14 +9580,13 @@ pub fn printUnbuffered( |
| 9159 | 9580 | {}, |
| 9160 | 9581 | )).index, |
| 9161 | 9582 | }); |
| 9162 | | try writer.writeByte('\n'); |
| 9163 | 9583 | }, |
| 9164 | 9584 | .cmpxchg, |
| 9165 | 9585 | .@"cmpxchg weak", |
| 9166 | 9586 | => |tag| { |
| 9167 | 9587 | const extra = |
| 9168 | 9588 | function.extraData(Function.Instruction.CmpXchg, instruction.data); |
| 9169 | | try writer.print(" %{} = {s}{ } {%}, {%}, {%}{ }{ }{ }{, }\n", .{ |
| 9589 | try writer.print(" %{} = {s}{ } {%}, {%}, {%}{ }{ }{ }{, }", .{ |
| 9170 | 9590 | instruction_index.name(&function).fmt(self), |
| 9171 | 9591 | @tagName(tag), |
| 9172 | 9592 | extra.info.access_kind, |
| ... | ... | @@ -9182,7 +9602,7 @@ pub fn printUnbuffered( |
| 9182 | 9602 | .extractelement => |tag| { |
| 9183 | 9603 | const extra = |
| 9184 | 9604 | function.extraData(Function.Instruction.ExtractElement, instruction.data); |
| 9185 | | try writer.print(" %{} = {s} {%}, {%}\n", .{ |
| 9605 | try writer.print(" %{} = {s} {%}, {%}", .{ |
| 9186 | 9606 | instruction_index.name(&function).fmt(self), |
| 9187 | 9607 | @tagName(tag), |
| 9188 | 9608 | extra.val.fmt(function_index, self), |
| ... | ... | @@ -9201,7 +9621,6 @@ pub fn printUnbuffered( |
| 9201 | 9621 | extra.data.val.fmt(function_index, self), |
| 9202 | 9622 | }); |
| 9203 | 9623 | for (indices) |index| try writer.print(", {d}", .{index}); |
| 9204 | | try writer.writeByte('\n'); |
| 9205 | 9624 | }, |
| 9206 | 9625 | .fence => |tag| { |
| 9207 | 9626 | const info: MemoryAccessInfo = @bitCast(instruction.data); |
| ... | ... | @@ -9215,7 +9634,7 @@ pub fn printUnbuffered( |
| 9215 | 9634 | .@"fneg fast", |
| 9216 | 9635 | => |tag| { |
| 9217 | 9636 | const val: Value = @enumFromInt(instruction.data); |
| 9218 | | try writer.print(" %{} = {s} {%}\n", .{ |
| 9637 | try writer.print(" %{} = {s} {%}", .{ |
| 9219 | 9638 | instruction_index.name(&function).fmt(self), |
| 9220 | 9639 | @tagName(tag), |
| 9221 | 9640 | val.fmt(function_index, self), |
| ... | ... | @@ -9238,12 +9657,11 @@ pub fn printUnbuffered( |
| 9238 | 9657 | for (indices) |index| try writer.print(", {%}", .{ |
| 9239 | 9658 | index.fmt(function_index, self), |
| 9240 | 9659 | }); |
| 9241 | | try writer.writeByte('\n'); |
| 9242 | 9660 | }, |
| 9243 | 9661 | .insertelement => |tag| { |
| 9244 | 9662 | const extra = |
| 9245 | 9663 | function.extraData(Function.Instruction.InsertElement, instruction.data); |
| 9246 | | try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{ |
| 9664 | try writer.print(" %{} = {s} {%}, {%}, {%}", .{ |
| 9247 | 9665 | instruction_index.name(&function).fmt(self), |
| 9248 | 9666 | @tagName(tag), |
| 9249 | 9667 | extra.val.fmt(function_index, self), |
| ... | ... | @@ -9262,13 +9680,12 @@ pub fn printUnbuffered( |
| 9262 | 9680 | extra.data.elem.fmt(function_index, self), |
| 9263 | 9681 | }); |
| 9264 | 9682 | for (indices) |index| try writer.print(", {d}", .{index}); |
| 9265 | | try writer.writeByte('\n'); |
| 9266 | 9683 | }, |
| 9267 | 9684 | .load, |
| 9268 | 9685 | .@"load atomic", |
| 9269 | 9686 | => |tag| { |
| 9270 | 9687 | const extra = function.extraData(Function.Instruction.Load, instruction.data); |
| 9271 | | try writer.print(" %{} = {s}{ } {%}, {%}{ }{ }{, }\n", .{ |
| 9688 | try writer.print(" %{} = {s}{ } {%}, {%}{ }{ }{, }", .{ |
| 9272 | 9689 | instruction_index.name(&function).fmt(self), |
| 9273 | 9690 | @tagName(tag), |
| 9274 | 9691 | extra.info.access_kind, |
| ... | ... | @@ -9298,23 +9715,22 @@ pub fn printUnbuffered( |
| 9298 | 9715 | incoming_block.toInst(&function).fmt(function_index, self), |
| 9299 | 9716 | }); |
| 9300 | 9717 | } |
| 9301 | | try writer.writeByte('\n'); |
| 9302 | 9718 | }, |
| 9303 | 9719 | .ret => |tag| { |
| 9304 | 9720 | const val: Value = @enumFromInt(instruction.data); |
| 9305 | | try writer.print(" {s} {%}\n", .{ |
| 9721 | try writer.print(" {s} {%}", .{ |
| 9306 | 9722 | @tagName(tag), |
| 9307 | 9723 | val.fmt(function_index, self), |
| 9308 | 9724 | }); |
| 9309 | 9725 | }, |
| 9310 | 9726 | .@"ret void", |
| 9311 | 9727 | .@"unreachable", |
| 9312 | | => |tag| try writer.print(" {s}\n", .{@tagName(tag)}), |
| 9728 | => |tag| try writer.print(" {s}", .{@tagName(tag)}), |
| 9313 | 9729 | .select, |
| 9314 | 9730 | .@"select fast", |
| 9315 | 9731 | => |tag| { |
| 9316 | 9732 | const extra = function.extraData(Function.Instruction.Select, instruction.data); |
| 9317 | | try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{ |
| 9733 | try writer.print(" %{} = {s} {%}, {%}, {%}", .{ |
| 9318 | 9734 | instruction_index.name(&function).fmt(self), |
| 9319 | 9735 | @tagName(tag), |
| 9320 | 9736 | extra.cond.fmt(function_index, self), |
| ... | ... | @@ -9325,7 +9741,7 @@ pub fn printUnbuffered( |
| 9325 | 9741 | .shufflevector => |tag| { |
| 9326 | 9742 | const extra = |
| 9327 | 9743 | function.extraData(Function.Instruction.ShuffleVector, instruction.data); |
| 9328 | | try writer.print(" %{} = {s} {%}, {%}, {%}\n", .{ |
| 9744 | try writer.print(" %{} = {s} {%}, {%}, {%}", .{ |
| 9329 | 9745 | instruction_index.name(&function).fmt(self), |
| 9330 | 9746 | @tagName(tag), |
| 9331 | 9747 | extra.lhs.fmt(function_index, self), |
| ... | ... | @@ -9337,7 +9753,7 @@ pub fn printUnbuffered( |
| 9337 | 9753 | .@"store atomic", |
| 9338 | 9754 | => |tag| { |
| 9339 | 9755 | const extra = function.extraData(Function.Instruction.Store, instruction.data); |
| 9340 | | try writer.print(" {s}{ } {%}, {%}{ }{ }{, }\n", .{ |
| 9756 | try writer.print(" {s}{ } {%}, {%}{ }{ }{, }", .{ |
| 9341 | 9757 | @tagName(tag), |
| 9342 | 9758 | extra.info.access_kind, |
| 9343 | 9759 | extra.val.fmt(function_index, self), |
| ... | ... | @@ -9365,11 +9781,11 @@ pub fn printUnbuffered( |
| 9365 | 9781 | case_block.toInst(&function).fmt(function_index, self), |
| 9366 | 9782 | }, |
| 9367 | 9783 | ); |
| 9368 | | try writer.writeAll(" ]\n"); |
| 9784 | try writer.writeAll(" ]"); |
| 9369 | 9785 | }, |
| 9370 | 9786 | .va_arg => |tag| { |
| 9371 | 9787 | const extra = function.extraData(Function.Instruction.VaArg, instruction.data); |
| 9372 | | try writer.print(" %{} = {s} {%}, {%}\n", .{ |
| 9788 | try writer.print(" %{} = {s} {%}, {%}", .{ |
| 9373 | 9789 | instruction_index.name(&function).fmt(self), |
| 9374 | 9790 | @tagName(tag), |
| 9375 | 9791 | extra.list.fmt(function_index, self), |
| ... | ... | @@ -9377,11 +9793,13 @@ pub fn printUnbuffered( |
| 9377 | 9793 | }); |
| 9378 | 9794 | }, |
| 9379 | 9795 | } |
| 9796 | metadata_formatter.need_comma = true; |
| 9797 | defer metadata_formatter.need_comma = undefined; |
| 9798 | try writer.print("{}\n", .{try metadata_formatter.fmt("!dbg ", dbg)}); |
| 9380 | 9799 | } |
| 9381 | 9800 | try writer.writeByte('}'); |
| 9382 | 9801 | } |
| 9383 | 9802 | try writer.writeByte('\n'); |
| 9384 | | need_newline = true; |
| 9385 | 9803 | } |
| 9386 | 9804 | |
| 9387 | 9805 | if (attribute_groups.count() > 0) { |
| ... | ... | @@ -9391,7 +9809,367 @@ pub fn printUnbuffered( |
| 9391 | 9809 | \\attributes #{d} = {{{#"} }} |
| 9392 | 9810 | \\ |
| 9393 | 9811 | , .{ attribute_group_index, attribute_group.fmt(self) }); |
| 9394 | | need_newline = true; |
| 9812 | } |
| 9813 | |
| 9814 | if (self.metadata_named.count() > 0) { |
| 9815 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 9816 | for (self.metadata_named.keys(), self.metadata_named.values()) |name, data| { |
| 9817 | const elements: []const Metadata = |
| 9818 | @ptrCast(self.metadata_extra.items[data.index..][0..data.len]); |
| 9819 | try writer.writeByte('!'); |
| 9820 | try printEscapedString(name.slice(self), .quote_unless_valid_identifier, writer); |
| 9821 | try writer.writeAll(" = !{"); |
| 9822 | metadata_formatter.need_comma = false; |
| 9823 | defer metadata_formatter.need_comma = undefined; |
| 9824 | for (elements) |element| try writer.print("{}", .{try metadata_formatter.fmt("", element)}); |
| 9825 | try writer.writeAll("}\n"); |
| 9826 | } |
| 9827 | } |
| 9828 | |
| 9829 | if (metadata_formatter.map.count() > 0) { |
| 9830 | if (need_newline) try writer.writeByte('\n') else need_newline = true; |
| 9831 | var metadata_index: usize = 0; |
| 9832 | while (metadata_index < metadata_formatter.map.count()) : (metadata_index += 1) { |
| 9833 | @setEvalBranchQuota(10_000); |
| 9834 | const metadata_item = |
| 9835 | self.metadata_items.get(@intFromEnum(metadata_formatter.map.keys()[metadata_index])); |
| 9836 | try writer.print("!{} = ", .{metadata_index}); |
| 9837 | metadata_formatter.need_comma = false; |
| 9838 | defer metadata_formatter.need_comma = undefined; |
| 9839 | switch (metadata_item.tag) { |
| 9840 | .none, .tuple, .expression, .constant => unreachable, |
| 9841 | .file => { |
| 9842 | const extra = self.metadataExtraData(Metadata.File, metadata_item.data); |
| 9843 | try metadata_formatter.specialized(.@"distinct !", .DIFile, .{ |
| 9844 | .filename = extra.filename, |
| 9845 | .directory = extra.directory, |
| 9846 | .checksumkind = null, |
| 9847 | .checksum = null, |
| 9848 | .source = null, |
| 9849 | }, writer); |
| 9850 | }, |
| 9851 | .compile_unit, |
| 9852 | .@"compile_unit optimized", |
| 9853 | => |kind| { |
| 9854 | const extra = self.metadataExtraData(Metadata.CompileUnit, metadata_item.data); |
| 9855 | try metadata_formatter.specialized(.@"distinct !", .DICompileUnit, .{ |
| 9856 | .language = .DW_LANG_C99, |
| 9857 | .file = extra.file, |
| 9858 | .producer = extra.producer, |
| 9859 | .isOptimized = switch (kind) { |
| 9860 | .compile_unit => false, |
| 9861 | .@"compile_unit optimized" => true, |
| 9862 | else => unreachable, |
| 9863 | }, |
| 9864 | .flags = null, |
| 9865 | .runtimeVersion = 0, |
| 9866 | .splitDebugFilename = null, |
| 9867 | .emissionKind = .FullDebug, |
| 9868 | .enums = extra.enums, |
| 9869 | .retainedTypes = null, |
| 9870 | .globals = extra.globals, |
| 9871 | .imports = null, |
| 9872 | .macros = null, |
| 9873 | .dwoId = null, |
| 9874 | .splitDebugInlining = false, |
| 9875 | .debugInfoForProfiling = null, |
| 9876 | .nameTableKind = null, |
| 9877 | .rangesBaseAddress = null, |
| 9878 | .sysroot = null, |
| 9879 | .sdk = null, |
| 9880 | }, writer); |
| 9881 | }, |
| 9882 | .subprogram, |
| 9883 | .@"subprogram local", |
| 9884 | .@"subprogram definition", |
| 9885 | .@"subprogram local definition", |
| 9886 | .@"subprogram optimized", |
| 9887 | .@"subprogram optimized local", |
| 9888 | .@"subprogram optimized definition", |
| 9889 | .@"subprogram optimized local definition", |
| 9890 | => |kind| { |
| 9891 | const extra = self.metadataExtraData(Metadata.Subprogram, metadata_item.data); |
| 9892 | try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{ |
| 9893 | .name = extra.name, |
| 9894 | .linkageName = extra.linkage_name, |
| 9895 | .scope = extra.file, |
| 9896 | .file = extra.file, |
| 9897 | .line = extra.line, |
| 9898 | .type = null, |
| 9899 | .scopeLine = extra.scope_line, |
| 9900 | .containingType = null, |
| 9901 | .virtualIndex = null, |
| 9902 | .thisAdjustment = null, |
| 9903 | .flags = extra.di_flags, |
| 9904 | .spFlags = @as(Metadata.Subprogram.SPFlags, @bitCast(@as(u32, @as(u3, @intCast( |
| 9905 | @intFromEnum(kind) - @intFromEnum(Metadata.Tag.subprogram), |
| 9906 | ))) << 2)), |
| 9907 | .unit = extra.compile_unit, |
| 9908 | .templateParams = null, |
| 9909 | .declaration = null, |
| 9910 | .retainedNodes = null, |
| 9911 | .thrownTypes = null, |
| 9912 | .annotations = null, |
| 9913 | .targetFuncName = null, |
| 9914 | }, writer); |
| 9915 | }, |
| 9916 | .lexical_block => { |
| 9917 | const extra = self.metadataExtraData(Metadata.LexicalBlock, metadata_item.data); |
| 9918 | try metadata_formatter.specialized(.@"distinct !", .DILexicalBlock, .{ |
| 9919 | .scope = extra.scope, |
| 9920 | .file = extra.file, |
| 9921 | .line = extra.line, |
| 9922 | .column = extra.column, |
| 9923 | }, writer); |
| 9924 | }, |
| 9925 | .location => { |
| 9926 | const extra = self.metadataExtraData(Metadata.Location, metadata_item.data); |
| 9927 | try metadata_formatter.specialized(.@"!", .DILocation, .{ |
| 9928 | .line = extra.line, |
| 9929 | .column = extra.column, |
| 9930 | .scope = extra.scope, |
| 9931 | .inlinedAt = extra.inlined_at, |
| 9932 | .isImplicitCode = false, |
| 9933 | }, writer); |
| 9934 | }, |
| 9935 | .basic_bool_type, |
| 9936 | .basic_unsigned_type, |
| 9937 | .basic_signed_type, |
| 9938 | .basic_float_type, |
| 9939 | => |kind| { |
| 9940 | const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data); |
| 9941 | try metadata_formatter.specialized(.@"distinct !", .DIBasicType, .{ |
| 9942 | .tag = null, |
| 9943 | .name = switch (extra.name) { |
| 9944 | .none => null, |
| 9945 | else => extra.name, |
| 9946 | }, |
| 9947 | .size = extra.bitSize(), |
| 9948 | .@"align" = null, |
| 9949 | .encoding = @as(enum { |
| 9950 | DW_ATE_boolean, |
| 9951 | DW_ATE_unsigned, |
| 9952 | DW_ATE_signed, |
| 9953 | DW_ATE_float, |
| 9954 | }, switch (kind) { |
| 9955 | .basic_bool_type => .DW_ATE_boolean, |
| 9956 | .basic_unsigned_type => .DW_ATE_unsigned, |
| 9957 | .basic_signed_type => .DW_ATE_signed, |
| 9958 | .basic_float_type => .DW_ATE_float, |
| 9959 | else => unreachable, |
| 9960 | }), |
| 9961 | .flags = null, |
| 9962 | }, writer); |
| 9963 | }, |
| 9964 | .composite_struct_type, |
| 9965 | .composite_union_type, |
| 9966 | .composite_enumeration_type, |
| 9967 | .composite_array_type, |
| 9968 | => |kind| { |
| 9969 | const extra = self.metadataExtraData(Metadata.CompositeType, metadata_item.data); |
| 9970 | try metadata_formatter.specialized(.@"distinct !", .DICompositeType, .{ |
| 9971 | .tag = @as(enum { |
| 9972 | DW_TAG_structure_type, |
| 9973 | DW_TAG_union_type, |
| 9974 | DW_TAG_enumeration_type, |
| 9975 | DW_TAG_array_type, |
| 9976 | }, switch (kind) { |
| 9977 | .composite_struct_type => .DW_TAG_structure_type, |
| 9978 | .composite_union_type => .DW_TAG_union_type, |
| 9979 | .composite_enumeration_type => .DW_TAG_enumeration_type, |
| 9980 | .composite_array_type, .composite_vector_type => .DW_TAG_array_type, |
| 9981 | else => unreachable, |
| 9982 | }), |
| 9983 | .name = switch (extra.name) { |
| 9984 | .none => null, |
| 9985 | else => extra.name, |
| 9986 | }, |
| 9987 | .scope = extra.scope, |
| 9988 | .file = null, |
| 9989 | .line = null, |
| 9990 | .baseType = extra.underlying_type, |
| 9991 | .size = extra.bitSize(), |
| 9992 | .@"align" = extra.bitAlign(), |
| 9993 | .offset = null, |
| 9994 | .flags = null, |
| 9995 | .elements = extra.fields_tuple, |
| 9996 | .runtimeLang = null, |
| 9997 | .vtableHolder = null, |
| 9998 | .templateParams = null, |
| 9999 | .identifier = null, |
| 10000 | .discriminator = null, |
| 10001 | .dataLocation = null, |
| 10002 | .associated = null, |
| 10003 | .allocated = null, |
| 10004 | .rank = null, |
| 10005 | .annotations = null, |
| 10006 | }, writer); |
| 10007 | }, |
| 10008 | .derived_pointer_type, |
| 10009 | .derived_member_type, |
| 10010 | => |kind| { |
| 10011 | const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data); |
| 10012 | try metadata_formatter.specialized(.@"distinct !", .DIDerivedType, .{ |
| 10013 | .tag = @as(enum { |
| 10014 | DW_TAG_pointer_type, |
| 10015 | DW_TAG_member, |
| 10016 | }, switch (kind) { |
| 10017 | .derived_pointer_type => .DW_TAG_pointer_type, |
| 10018 | .derived_member_type => .DW_TAG_member, |
| 10019 | else => unreachable, |
| 10020 | }), |
| 10021 | .name = switch (extra.name) { |
| 10022 | .none => null, |
| 10023 | else => extra.name, |
| 10024 | }, |
| 10025 | .scope = extra.scope, |
| 10026 | .file = null, |
| 10027 | .line = null, |
| 10028 | .baseType = extra.underlying_type, |
| 10029 | .size = extra.bitSize(), |
| 10030 | .@"align" = extra.bitAlign(), |
| 10031 | .offset = switch (extra.bitOffset()) { |
| 10032 | 0 => null, |
| 10033 | else => |bit_offset| bit_offset, |
| 10034 | }, |
| 10035 | .flags = null, |
| 10036 | .extraData = null, |
| 10037 | .dwarfAddressSpace = null, |
| 10038 | .annotations = null, |
| 10039 | }, writer); |
| 10040 | }, |
| 10041 | .subroutine_type => { |
| 10042 | const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data); |
| 10043 | try metadata_formatter.specialized(.@"distinct !", .DISubroutineType, .{ |
| 10044 | .flags = null, |
| 10045 | .cc = null, |
| 10046 | .types = extra.types_tuple, |
| 10047 | }, writer); |
| 10048 | }, |
| 10049 | .enumerator_unsigned, |
| 10050 | .enumerator_signed_positive, |
| 10051 | .enumerator_signed_negative, |
| 10052 | => |kind| { |
| 10053 | const extra = self.metadataExtraData(Metadata.Enumerator, metadata_item.data); |
| 10054 | |
| 10055 | const ExpectedContents = extern struct { |
| 10056 | string: [(64 * 8 / std.math.log2(10)) + 2]u8, |
| 10057 | limbs: [ |
| 10058 | std.math.big.int.calcToStringLimbsBufferLen( |
| 10059 | 64 / @sizeOf(std.math.big.Limb), |
| 10060 | 10, |
| 10061 | ) |
| 10062 | ]std.math.big.Limb, |
| 10063 | }; |
| 10064 | var stack align(@alignOf(ExpectedContents)) = |
| 10065 | std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa); |
| 10066 | const allocator = stack.get(); |
| 10067 | |
| 10068 | const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len]; |
| 10069 | const bigint: std.math.big.int.Const = .{ |
| 10070 | .limbs = limbs, |
| 10071 | .positive = switch (kind) { |
| 10072 | .enumerator_unsigned, |
| 10073 | .enumerator_signed_positive, |
| 10074 | => true, |
| 10075 | .enumerator_signed_negative => false, |
| 10076 | else => unreachable, |
| 10077 | }, |
| 10078 | }; |
| 10079 | const str = try bigint.toStringAlloc(allocator, 10, undefined); |
| 10080 | defer allocator.free(str); |
| 10081 | |
| 10082 | try metadata_formatter.specialized(.@"distinct !", .DIEnumerator, .{ |
| 10083 | .name = extra.name, |
| 10084 | .value = str, |
| 10085 | .isUnsigned = switch (kind) { |
| 10086 | .enumerator_unsigned => true, |
| 10087 | .enumerator_signed_positive, .enumerator_signed_negative => false, |
| 10088 | else => unreachable, |
| 10089 | }, |
| 10090 | }, writer); |
| 10091 | }, |
| 10092 | .subrange => { |
| 10093 | const extra = self.metadataExtraData(Metadata.Subrange, metadata_item.data); |
| 10094 | try metadata_formatter.specialized(.@"!", .DISubrange, .{ |
| 10095 | .count = extra.count, |
| 10096 | .lowerBound = extra.lower_bound, |
| 10097 | .upperBound = null, |
| 10098 | .stride = null, |
| 10099 | }, writer); |
| 10100 | }, |
| 10101 | .module_flag => { |
| 10102 | const extra = self.metadataExtraData(Metadata.ModuleFlag, metadata_item.data); |
| 10103 | try writer.print("!{{{[behavior]}{[name]}{[constant]}}}\n", .{ |
| 10104 | .behavior = try metadata_formatter.fmt("", extra.behavior), |
| 10105 | .name = try metadata_formatter.fmt("!", extra.name), |
| 10106 | .constant = try metadata_formatter.fmt("", extra.constant), |
| 10107 | }); |
| 10108 | }, |
| 10109 | .local_var => { |
| 10110 | const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data); |
| 10111 | try metadata_formatter.specialized(.@"distinct !", .DILocalVariable, .{ |
| 10112 | .name = extra.name, |
| 10113 | .arg = null, |
| 10114 | .scope = extra.scope, |
| 10115 | .file = extra.file, |
| 10116 | .line = extra.line, |
| 10117 | .type = extra.ty, |
| 10118 | .flags = null, |
| 10119 | .@"align" = null, |
| 10120 | .annotations = null, |
| 10121 | }, writer); |
| 10122 | }, |
| 10123 | .parameter => { |
| 10124 | const extra = self.metadataExtraData(Metadata.Parameter, metadata_item.data); |
| 10125 | try metadata_formatter.specialized(.@"distinct !", .DILocalVariable, .{ |
| 10126 | .name = extra.name, |
| 10127 | .arg = extra.arg_no, |
| 10128 | .scope = extra.scope, |
| 10129 | .file = extra.file, |
| 10130 | .line = extra.line, |
| 10131 | .type = extra.ty, |
| 10132 | .flags = null, |
| 10133 | .@"align" = null, |
| 10134 | .annotations = null, |
| 10135 | }, writer); |
| 10136 | }, |
| 10137 | .global_var, |
| 10138 | .@"global_var local", |
| 10139 | => |kind| { |
| 10140 | const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data); |
| 10141 | try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{ |
| 10142 | .name = extra.name, |
| 10143 | .linkageName = extra.linkage_name, |
| 10144 | .scope = extra.scope, |
| 10145 | .file = extra.file, |
| 10146 | .line = extra.line, |
| 10147 | .type = extra.ty, |
| 10148 | .isLocal = switch (kind) { |
| 10149 | .global_var => false, |
| 10150 | .@"global_var local" => true, |
| 10151 | else => unreachable, |
| 10152 | }, |
| 10153 | .isDefinition = true, |
| 10154 | .declaration = null, |
| 10155 | .templateParams = null, |
| 10156 | .@"align" = null, |
| 10157 | .annotations = null, |
| 10158 | }, writer); |
| 10159 | }, |
| 10160 | .global_var_expression => { |
| 10161 | const extra = |
| 10162 | self.metadataExtraData(Metadata.GlobalVarExpression, metadata_item.data); |
| 10163 | try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariableExpression, .{ |
| 10164 | .@"var" = extra.variable, |
| 10165 | .expr = extra.expression, |
| 10166 | }, writer); |
| 10167 | }, |
| 10168 | else => { |
| 10169 | try writer.writeByte('\n'); |
| 10170 | }, |
| 10171 | } |
| 10172 | } |
| 9395 | 10173 | } |
| 9396 | 10174 | } |
| 9397 | 10175 | |
| ... | ... | @@ -9725,7 +10503,7 @@ fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraInd |
| 9725 | 10503 | self.type_extra.appendAssumeCapacity(switch (field.type) { |
| 9726 | 10504 | u32 => value, |
| 9727 | 10505 | String, Type => @intFromEnum(value), |
| 9728 | | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 10506 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)), |
| 9729 | 10507 | }); |
| 9730 | 10508 | } |
| 9731 | 10509 | return result; |
| ... | ... | @@ -10894,6 +11672,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item. |
| 10894 | 11672 | self.metadata_extra.appendAssumeCapacity(switch (field.type) { |
| 10895 | 11673 | u32 => value, |
| 10896 | 11674 | MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value), |
| 11675 | Metadata.DIFlags => @bitCast(value), |
| 10897 | 11676 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 10898 | 11677 | }); |
| 10899 | 11678 | } |
| ... | ... | @@ -10932,6 +11711,7 @@ fn metadataExtraDataTrail( |
| 10932 | 11711 | @field(result, field.name) = switch (field.type) { |
| 10933 | 11712 | u32 => value, |
| 10934 | 11713 | MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value), |
| 11714 | Metadata.DIFlags => @bitCast(value), |
| 10935 | 11715 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 10936 | 11716 | }; |
| 10937 | 11717 | return .{ |
| ... | ... | @@ -10989,10 +11769,7 @@ pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const |
| 10989 | 11769 | } |
| 10990 | 11770 | |
| 10991 | 11771 | pub fn debugNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void { |
| 10992 | | try self.metadata_extra.ensureUnusedCapacity( |
| 10993 | | self.gpa, |
| 10994 | | operands.len * @sizeOf(Metadata), |
| 10995 | | ); |
| 11772 | try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len); |
| 10996 | 11773 | try self.metadata_named.ensureUnusedCapacity(self.gpa, 1); |
| 10997 | 11774 | self.debugNamedAssumeCapacity(name, operands); |
| 10998 | 11775 | } |
| ... | ... | @@ -11002,9 +11779,13 @@ fn debugNone(self: *Builder) Allocator.Error!Metadata { |
| 11002 | 11779 | return self.debugNoneAssumeCapacity(); |
| 11003 | 11780 | } |
| 11004 | 11781 | |
| 11005 | | pub fn debugFile(self: *Builder, path: MetadataString, name: MetadataString) Allocator.Error!Metadata { |
| 11782 | pub fn debugFile( |
| 11783 | self: *Builder, |
| 11784 | filename: MetadataString, |
| 11785 | directory: MetadataString, |
| 11786 | ) Allocator.Error!Metadata { |
| 11006 | 11787 | try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0); |
| 11007 | | return self.debugFileAssumeCapacity(path, name); |
| 11788 | return self.debugFileAssumeCapacity(filename, directory); |
| 11008 | 11789 | } |
| 11009 | 11790 | |
| 11010 | 11791 | pub fn debugCompileUnit( |
| ... | ... | @@ -11013,10 +11794,10 @@ pub fn debugCompileUnit( |
| 11013 | 11794 | producer: MetadataString, |
| 11014 | 11795 | enums: Metadata, |
| 11015 | 11796 | globals: Metadata, |
| 11016 | | flags: Metadata.CompileUnit.Flags, |
| 11797 | options: Metadata.CompileUnit.Options, |
| 11017 | 11798 | ) Allocator.Error!Metadata { |
| 11018 | 11799 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0); |
| 11019 | | return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, flags); |
| 11800 | return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, options); |
| 11020 | 11801 | } |
| 11021 | 11802 | |
| 11022 | 11803 | pub fn debugSubprogram( |
| ... | ... | @@ -11027,7 +11808,7 @@ pub fn debugSubprogram( |
| 11027 | 11808 | line: u32, |
| 11028 | 11809 | scope_line: u32, |
| 11029 | 11810 | ty: Metadata, |
| 11030 | | flags: Metadata.Subprogram.Flags, |
| 11811 | options: Metadata.Subprogram.Options, |
| 11031 | 11812 | compile_unit: Metadata, |
| 11032 | 11813 | ) Allocator.Error!Metadata { |
| 11033 | 11814 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0); |
| ... | ... | @@ -11038,19 +11819,19 @@ pub fn debugSubprogram( |
| 11038 | 11819 | line, |
| 11039 | 11820 | scope_line, |
| 11040 | 11821 | ty, |
| 11041 | | flags, |
| 11822 | options, |
| 11042 | 11823 | compile_unit, |
| 11043 | 11824 | ); |
| 11044 | 11825 | } |
| 11045 | 11826 | |
| 11046 | | pub fn debugLexicalBlock(self: *Builder, file: Metadata, scope: Metadata, line: u32, column: u32) Allocator.Error!Metadata { |
| 11827 | pub fn debugLexicalBlock(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Allocator.Error!Metadata { |
| 11047 | 11828 | try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0); |
| 11048 | | return self.debugLexicalBlockAssumeCapacity(file, scope, line, column); |
| 11829 | return self.debugLexicalBlockAssumeCapacity(scope, file, line, column); |
| 11049 | 11830 | } |
| 11050 | 11831 | |
| 11051 | | pub fn debugLocation(self: *Builder, scope: Metadata, line: u32, column: u32, inlined_at: Metadata) Allocator.Error!Metadata { |
| 11832 | pub fn debugLocation(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Allocator.Error!Metadata { |
| 11052 | 11833 | try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0); |
| 11053 | | return self.debugLocationAssumeCapacity(scope, line, column, inlined_at); |
| 11834 | return self.debugLocationAssumeCapacity(line, column, scope, inlined_at); |
| 11054 | 11835 | } |
| 11055 | 11836 | |
| 11056 | 11837 | pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { |
| ... | ... | @@ -11294,12 +12075,12 @@ pub fn debugTuple( |
| 11294 | 12075 | |
| 11295 | 12076 | pub fn debugModuleFlag( |
| 11296 | 12077 | self: *Builder, |
| 11297 | | behaviour: Metadata, |
| 12078 | behavior: Metadata, |
| 11298 | 12079 | name: MetadataString, |
| 11299 | 12080 | constant: Metadata, |
| 11300 | 12081 | ) Allocator.Error!Metadata { |
| 11301 | 12082 | try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0); |
| 11302 | | return self.debugModuleFlagAssumeCapacity(behaviour, name, constant); |
| 12083 | return self.debugModuleFlagAssumeCapacity(behavior, name, constant); |
| 11303 | 12084 | } |
| 11304 | 12085 | |
| 11305 | 12086 | pub fn debugLocalVar( |
| ... | ... | @@ -11336,7 +12117,7 @@ pub fn debugGlobalVar( |
| 11336 | 12117 | line: u32, |
| 11337 | 12118 | ty: Metadata, |
| 11338 | 12119 | variable: Variable.Index, |
| 11339 | | flags: Metadata.GlobalVar.Flags, |
| 12120 | options: Metadata.GlobalVar.Options, |
| 11340 | 12121 | ) Allocator.Error!Metadata { |
| 11341 | 12122 | try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0); |
| 11342 | 12123 | return self.debugGlobalVarAssumeCapacity( |
| ... | ... | @@ -11347,7 +12128,7 @@ pub fn debugGlobalVar( |
| 11347 | 12128 | line, |
| 11348 | 12129 | ty, |
| 11349 | 12130 | variable, |
| 11350 | | flags, |
| 12131 | options, |
| 11351 | 12132 | ); |
| 11352 | 12133 | } |
| 11353 | 12134 | |
| ... | ... | @@ -11393,12 +12174,7 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp |
| 11393 | 12174 | if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false; |
| 11394 | 12175 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 11395 | 12176 | const rhs_extra = ctx.builder.metadataExtraData(@TypeOf(value), rhs_data); |
| 11396 | | inline for (std.meta.fields(@TypeOf(value))) |field| { |
| 11397 | | const lhs = @field(lhs_key.value, field.name); |
| 11398 | | const rhs = @field(rhs_extra, field.name); |
| 11399 | | if (lhs != rhs) return false; |
| 11400 | | } |
| 11401 | | return true; |
| 12177 | return std.meta.eql(lhs_key.value, rhs_extra); |
| 11402 | 12178 | } |
| 11403 | 12179 | }; |
| 11404 | 12180 | |
| ... | ... | @@ -11418,6 +12194,37 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp |
| 11418 | 12194 | return @enumFromInt(gop.index); |
| 11419 | 12195 | } |
| 11420 | 12196 | |
| 12197 | fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata { |
| 12198 | const Key = struct { tag: Metadata.Tag, index: Metadata }; |
| 12199 | const Adapter = struct { |
| 12200 | pub fn hash(_: @This(), key: Key) u32 { |
| 12201 | return @truncate(std.hash.Wyhash.hash( |
| 12202 | std.hash.uint32(@intFromEnum(key.tag)), |
| 12203 | std.mem.asBytes(&key.index), |
| 12204 | )); |
| 12205 | } |
| 12206 | |
| 12207 | pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { |
| 12208 | return @intFromEnum(lhs_key.index) == rhs_index; |
| 12209 | } |
| 12210 | }; |
| 12211 | |
| 12212 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( |
| 12213 | Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) }, |
| 12214 | Adapter{}, |
| 12215 | ); |
| 12216 | |
| 12217 | if (!gop.found_existing) { |
| 12218 | gop.key_ptr.* = {}; |
| 12219 | gop.value_ptr.* = {}; |
| 12220 | self.metadata_items.appendAssumeCapacity(.{ |
| 12221 | .tag = tag, |
| 12222 | .data = self.addMetadataExtraAssumeCapacity(value), |
| 12223 | }); |
| 12224 | } |
| 12225 | return @enumFromInt(gop.index); |
| 12226 | } |
| 12227 | |
| 11421 | 12228 | fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void { |
| 11422 | 12229 | std.debug.assert(name != .none); |
| 11423 | 12230 | const extra_index: u32 = @intCast(self.metadata_extra.items.len); |
| ... | ... | @@ -11434,10 +12241,14 @@ pub fn debugNoneAssumeCapacity(self: *Builder) Metadata { |
| 11434 | 12241 | return self.metadataSimpleAssumeCapacity(.none, .{}); |
| 11435 | 12242 | } |
| 11436 | 12243 | |
| 11437 | | fn debugFileAssumeCapacity(self: *Builder, path: MetadataString, name: MetadataString) Metadata { |
| 11438 | | return self.metadataSimpleAssumeCapacity(.file, Metadata.File{ |
| 11439 | | .path = path, |
| 11440 | | .name = name, |
| 12244 | fn debugFileAssumeCapacity( |
| 12245 | self: *Builder, |
| 12246 | filename: MetadataString, |
| 12247 | directory: MetadataString, |
| 12248 | ) Metadata { |
| 12249 | return self.metadataDistinctAssumeCapacity(.file, Metadata.File{ |
| 12250 | .filename = filename, |
| 12251 | .directory = directory, |
| 11441 | 12252 | }); |
| 11442 | 12253 | } |
| 11443 | 12254 | |
| ... | ... | @@ -11447,10 +12258,10 @@ pub fn debugCompileUnitAssumeCapacity( |
| 11447 | 12258 | producer: MetadataString, |
| 11448 | 12259 | enums: Metadata, |
| 11449 | 12260 | globals: Metadata, |
| 11450 | | flags: Metadata.CompileUnit.Flags, |
| 12261 | options: Metadata.CompileUnit.Options, |
| 11451 | 12262 | ) Metadata { |
| 11452 | | return self.metadataSimpleAssumeCapacity( |
| 11453 | | if (flags.optimized) .@"compile_unit optimized" else .compile_unit, |
| 12263 | return self.metadataDistinctAssumeCapacity( |
| 12264 | if (options.optimized) .@"compile_unit optimized" else .compile_unit, |
| 11454 | 12265 | Metadata.CompileUnit{ |
| 11455 | 12266 | .file = file, |
| 11456 | 12267 | .producer = producer, |
| ... | ... | @@ -11468,57 +12279,43 @@ fn debugSubprogramAssumeCapacity( |
| 11468 | 12279 | line: u32, |
| 11469 | 12280 | scope_line: u32, |
| 11470 | 12281 | ty: Metadata, |
| 11471 | | flags: Metadata.Subprogram.Flags, |
| 12282 | options: Metadata.Subprogram.Options, |
| 11472 | 12283 | compile_unit: Metadata, |
| 11473 | 12284 | ) Metadata { |
| 11474 | | const tag: Metadata.Tag = blk: { |
| 11475 | | var int: u3 = 0; |
| 11476 | | if (flags.optimized) int |= 0b1; |
| 11477 | | if (flags.local) int |= 0b10; |
| 11478 | | if (flags.definition) int |= 0b100; |
| 11479 | | break :blk switch (int) { |
| 11480 | | 0 => .subprogram, |
| 11481 | | 0b1 => .@"subprogram optimized", |
| 11482 | | 0b10 => .@"subprogram local", |
| 11483 | | 0b100 => .@"subprogram definition", |
| 11484 | | 0b011 => .@"subprogram optimized local", |
| 11485 | | 0b111 => .@"subprogram optimized local definition", |
| 11486 | | 0b101 => .@"subprogram optimized definition", |
| 11487 | | 0b110 => .@"subprogram local definition", |
| 11488 | | }; |
| 11489 | | }; |
| 11490 | | return self.metadataSimpleAssumeCapacity(tag, Metadata.Subprogram{ |
| 12285 | const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) + |
| 12286 | @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2))); |
| 12287 | return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{ |
| 11491 | 12288 | .file = file, |
| 11492 | 12289 | .name = name, |
| 11493 | 12290 | .linkage_name = linkage_name, |
| 11494 | 12291 | .line = line, |
| 11495 | 12292 | .scope_line = scope_line, |
| 11496 | 12293 | .ty = ty, |
| 11497 | | .debug_info_flags = flags.debug_info_flags, |
| 12294 | .di_flags = options.di_flags, |
| 11498 | 12295 | .compile_unit = compile_unit, |
| 11499 | 12296 | }); |
| 11500 | 12297 | } |
| 11501 | 12298 | |
| 11502 | | fn debugLexicalBlockAssumeCapacity(self: *Builder, file: Metadata, scope: Metadata, line: u32, column: u32) Metadata { |
| 11503 | | return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{ |
| 11504 | | .file = file, |
| 12299 | fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata { |
| 12300 | return self.metadataDistinctAssumeCapacity(.lexical_block, Metadata.LexicalBlock{ |
| 11505 | 12301 | .scope = scope, |
| 12302 | .file = file, |
| 11506 | 12303 | .line = line, |
| 11507 | 12304 | .column = column, |
| 11508 | 12305 | }); |
| 11509 | 12306 | } |
| 11510 | 12307 | |
| 11511 | | fn debugLocationAssumeCapacity(self: *Builder, scope: Metadata, line: u32, column: u32, inlined_at: Metadata) Metadata { |
| 12308 | fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata { |
| 11512 | 12309 | return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{ |
| 11513 | | .scope = scope, |
| 11514 | 12310 | .line = line, |
| 11515 | 12311 | .column = column, |
| 12312 | .scope = scope, |
| 11516 | 12313 | .inlined_at = inlined_at, |
| 11517 | 12314 | }); |
| 11518 | 12315 | } |
| 11519 | 12316 | |
| 11520 | 12317 | fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { |
| 11521 | | return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{ |
| 12318 | return self.metadataDistinctAssumeCapacity(.basic_bool_type, Metadata.BasicType{ |
| 11522 | 12319 | .name = name, |
| 11523 | 12320 | .size_in_bits_lo = @truncate(size_in_bits), |
| 11524 | 12321 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| ... | ... | @@ -11526,7 +12323,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit |
| 11526 | 12323 | } |
| 11527 | 12324 | |
| 11528 | 12325 | fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { |
| 11529 | | return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{ |
| 12326 | return self.metadataDistinctAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{ |
| 11530 | 12327 | .name = name, |
| 11531 | 12328 | .size_in_bits_lo = @truncate(size_in_bits), |
| 11532 | 12329 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| ... | ... | @@ -11534,7 +12331,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in |
| 11534 | 12331 | } |
| 11535 | 12332 | |
| 11536 | 12333 | fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { |
| 11537 | | return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{ |
| 12334 | return self.metadataDistinctAssumeCapacity(.basic_signed_type, Metadata.BasicType{ |
| 11538 | 12335 | .name = name, |
| 11539 | 12336 | .size_in_bits_lo = @truncate(size_in_bits), |
| 11540 | 12337 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| ... | ... | @@ -11542,7 +12339,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b |
| 11542 | 12339 | } |
| 11543 | 12340 | |
| 11544 | 12341 | fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { |
| 11545 | | return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{ |
| 12342 | return self.metadataDistinctAssumeCapacity(.basic_float_type, Metadata.BasicType{ |
| 11546 | 12343 | .name = name, |
| 11547 | 12344 | .size_in_bits_lo = @truncate(size_in_bits), |
| 11548 | 12345 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| ... | ... | @@ -11687,84 +12484,18 @@ fn debugCompositeTypeAssumeCapacity( |
| 11687 | 12484 | align_in_bits: u64, |
| 11688 | 12485 | fields_tuple: Metadata, |
| 11689 | 12486 | ) Metadata { |
| 11690 | | const Key = struct { |
| 11691 | | tag: Metadata.Tag, |
| 11692 | | name: MetadataString, |
| 11693 | | file: Metadata, |
| 11694 | | scope: Metadata, |
| 11695 | | line: u32, |
| 11696 | | underlying_type: Metadata, |
| 11697 | | size_in_bits: u64, |
| 11698 | | align_in_bits: u64, |
| 11699 | | fields_tuple: Metadata, |
| 11700 | | }; |
| 11701 | | const Adapter = struct { |
| 11702 | | builder: *const Builder, |
| 11703 | | pub fn hash(_: @This(), key: Key) u32 { |
| 11704 | | var hasher = std.hash.Wyhash.init(std.hash.uint32(@intFromEnum(key.tag))); |
| 11705 | | hasher.update(std.mem.asBytes(&key.name)); |
| 11706 | | hasher.update(std.mem.asBytes(&key.file)); |
| 11707 | | hasher.update(std.mem.asBytes(&key.scope)); |
| 11708 | | hasher.update(std.mem.asBytes(&key.line)); |
| 11709 | | hasher.update(std.mem.asBytes(&key.underlying_type)); |
| 11710 | | hasher.update(std.mem.asBytes(&key.size_in_bits)); |
| 11711 | | hasher.update(std.mem.asBytes(&key.align_in_bits)); |
| 11712 | | hasher.update(std.mem.asBytes(&key.fields_tuple)); |
| 11713 | | return @truncate(hasher.final()); |
| 11714 | | } |
| 11715 | | |
| 11716 | | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { |
| 11717 | | if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false; |
| 11718 | | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 11719 | | const rhs_extra = ctx.builder.metadataExtraData(Metadata.CompositeType, rhs_data); |
| 11720 | | const rhs_size_in_bits = @as(u64, rhs_extra.size_in_bits_lo) | @as(u64, rhs_extra.size_in_bits_hi) << 32; |
| 11721 | | const rhs_align_in_bits = @as(u64, rhs_extra.align_in_bits_lo) | @as(u64, rhs_extra.align_in_bits_hi) << 32; |
| 11722 | | return lhs_key.name == rhs_extra.name and |
| 11723 | | lhs_key.file == rhs_extra.file and |
| 11724 | | lhs_key.scope == rhs_extra.scope and |
| 11725 | | lhs_key.line == rhs_extra.line and |
| 11726 | | lhs_key.underlying_type == rhs_extra.underlying_type and |
| 11727 | | lhs_key.size_in_bits == rhs_size_in_bits and |
| 11728 | | lhs_key.align_in_bits == rhs_align_in_bits and |
| 11729 | | lhs_key.fields_tuple == rhs_extra.fields_tuple; |
| 11730 | | } |
| 11731 | | }; |
| 11732 | | |
| 11733 | | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( |
| 11734 | | Key{ |
| 11735 | | .tag = tag, |
| 11736 | | .name = name, |
| 11737 | | .file = file, |
| 11738 | | .scope = scope, |
| 11739 | | .line = line, |
| 11740 | | .underlying_type = underlying_type, |
| 11741 | | .size_in_bits = size_in_bits, |
| 11742 | | .align_in_bits = align_in_bits, |
| 11743 | | .fields_tuple = fields_tuple, |
| 11744 | | }, |
| 11745 | | Adapter{ .builder = self }, |
| 11746 | | ); |
| 11747 | | |
| 11748 | | if (!gop.found_existing) { |
| 11749 | | gop.key_ptr.* = {}; |
| 11750 | | gop.value_ptr.* = {}; |
| 11751 | | self.metadata_items.appendAssumeCapacity(.{ |
| 11752 | | .tag = tag, |
| 11753 | | .data = self.addMetadataExtraAssumeCapacity(Metadata.CompositeType{ |
| 11754 | | .name = name, |
| 11755 | | .file = file, |
| 11756 | | .scope = scope, |
| 11757 | | .line = line, |
| 11758 | | .underlying_type = underlying_type, |
| 11759 | | .size_in_bits_lo = @truncate(size_in_bits), |
| 11760 | | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 11761 | | .align_in_bits_lo = @truncate(align_in_bits), |
| 11762 | | .align_in_bits_hi = @truncate(align_in_bits >> 32), |
| 11763 | | .fields_tuple = fields_tuple, |
| 11764 | | }), |
| 11765 | | }); |
| 11766 | | } |
| 11767 | | return @enumFromInt(gop.index); |
| 12487 | return self.metadataDistinctAssumeCapacity(tag, Metadata.CompositeType{ |
| 12488 | .name = name, |
| 12489 | .file = file, |
| 12490 | .scope = scope, |
| 12491 | .line = line, |
| 12492 | .underlying_type = underlying_type, |
| 12493 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12494 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12495 | .align_in_bits_lo = @truncate(align_in_bits), |
| 12496 | .align_in_bits_hi = @truncate(align_in_bits >> 32), |
| 12497 | .fields_tuple = fields_tuple, |
| 12498 | }); |
| 11768 | 12499 | } |
| 11769 | 12500 | |
| 11770 | 12501 | fn debugPointerTypeAssumeCapacity( |
| ... | ... | @@ -11778,7 +12509,7 @@ fn debugPointerTypeAssumeCapacity( |
| 11778 | 12509 | align_in_bits: u64, |
| 11779 | 12510 | offset_in_bits: u64, |
| 11780 | 12511 | ) Metadata { |
| 11781 | | return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{ |
| 12512 | return self.metadataDistinctAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{ |
| 11782 | 12513 | .name = name, |
| 11783 | 12514 | .file = file, |
| 11784 | 12515 | .scope = scope, |
| ... | ... | @@ -11804,7 +12535,7 @@ fn debugMemberTypeAssumeCapacity( |
| 11804 | 12535 | align_in_bits: u64, |
| 11805 | 12536 | offset_in_bits: u64, |
| 11806 | 12537 | ) Metadata { |
| 11807 | | return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{ |
| 12538 | return self.metadataDistinctAssumeCapacity(.derived_member_type, Metadata.DerivedType{ |
| 11808 | 12539 | .name = name, |
| 11809 | 12540 | .file = file, |
| 11810 | 12541 | .scope = scope, |
| ... | ... | @@ -11823,7 +12554,7 @@ fn debugSubroutineTypeAssumeCapacity( |
| 11823 | 12554 | self: *Builder, |
| 11824 | 12555 | types_tuple: Metadata, |
| 11825 | 12556 | ) Metadata { |
| 11826 | | return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{ |
| 12557 | return self.metadataDistinctAssumeCapacity(.subroutine_type, Metadata.SubroutineType{ |
| 11827 | 12558 | .types_tuple = types_tuple, |
| 11828 | 12559 | }); |
| 11829 | 12560 | } |
| ... | ... | @@ -11835,52 +12566,32 @@ fn debugEnumeratorAssumeCapacity( |
| 11835 | 12566 | bit_width: u32, |
| 11836 | 12567 | value: std.math.big.int.Const, |
| 11837 | 12568 | ) Metadata { |
| 11838 | | const Key = struct { |
| 11839 | | tag: Metadata.Tag, |
| 11840 | | name: MetadataString, |
| 11841 | | bit_width: u32, |
| 11842 | | value: std.math.big.int.Const, |
| 11843 | | }; |
| 12569 | const Key = struct { tag: Metadata.Tag, index: Metadata }; |
| 11844 | 12570 | const Adapter = struct { |
| 11845 | | builder: *const Builder, |
| 11846 | 12571 | pub fn hash(_: @This(), key: Key) u32 { |
| 11847 | | var hasher = std.hash.Wyhash.init(std.hash.uint32(@intFromEnum(key.tag))); |
| 11848 | | hasher.update(std.mem.asBytes(&key.name)); |
| 11849 | | hasher.update(std.mem.asBytes(&key.bit_width)); |
| 11850 | | hasher.update(std.mem.sliceAsBytes(key.value.limbs)); |
| 11851 | | return @truncate(hasher.final()); |
| 12572 | return @truncate(std.hash.Wyhash.hash( |
| 12573 | std.hash.uint32(@intFromEnum(key.tag)), |
| 12574 | std.mem.asBytes(&key.index), |
| 12575 | )); |
| 11852 | 12576 | } |
| 11853 | 12577 | |
| 11854 | | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { |
| 11855 | | if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false; |
| 11856 | | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 11857 | | const rhs_extra = ctx.builder.metadataExtraData(Metadata.Enumerator, rhs_data); |
| 11858 | | const limbs = ctx.builder.metadata_limbs |
| 11859 | | .items[rhs_extra.limbs_index..][0..rhs_extra.limbs_len]; |
| 11860 | | const rhs_value = std.math.big.int.Const{ |
| 11861 | | .limbs = limbs, |
| 11862 | | .positive = lhs_key.value.positive, |
| 11863 | | }; |
| 11864 | | return lhs_key.name == rhs_extra.name and |
| 11865 | | lhs_key.bit_width == rhs_extra.bit_width and |
| 11866 | | lhs_key.value.eql(rhs_value); |
| 12578 | pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { |
| 12579 | return @intFromEnum(lhs_key.index) == rhs_index; |
| 11867 | 12580 | } |
| 11868 | 12581 | }; |
| 11869 | 12582 | |
| 11870 | 12583 | const tag: Metadata.Tag = if (unsigned) |
| 11871 | 12584 | .enumerator_unsigned |
| 11872 | | else if (value.positive) .enumerator_signed_positive else .enumerator_signed_negative; |
| 12585 | else if (value.positive) |
| 12586 | .enumerator_signed_positive |
| 12587 | else |
| 12588 | .enumerator_signed_negative; |
| 11873 | 12589 | |
| 11874 | 12590 | std.debug.assert(!(tag == .enumerator_unsigned and !value.positive)); |
| 11875 | 12591 | |
| 11876 | 12592 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( |
| 11877 | | Key{ |
| 11878 | | .tag = tag, |
| 11879 | | .name = name, |
| 11880 | | .bit_width = bit_width, |
| 11881 | | .value = value, |
| 11882 | | }, |
| 11883 | | Adapter{ .builder = self }, |
| 12593 | Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) }, |
| 12594 | Adapter{}, |
| 11884 | 12595 | ); |
| 11885 | 12596 | |
| 11886 | 12597 | if (!gop.found_existing) { |
| ... | ... | @@ -11905,7 +12616,7 @@ fn debugSubrangeAssumeCapacity( |
| 11905 | 12616 | lower_bound: Metadata, |
| 11906 | 12617 | count: Metadata, |
| 11907 | 12618 | ) Metadata { |
| 11908 | | return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{ |
| 12619 | return self.metadataDistinctAssumeCapacity(.subrange, Metadata.Subrange{ |
| 11909 | 12620 | .lower_bound = lower_bound, |
| 11910 | 12621 | .count = count, |
| 11911 | 12622 | }); |
| ... | ... | @@ -12005,12 +12716,12 @@ fn debugTupleAssumeCapacity( |
| 12005 | 12716 | |
| 12006 | 12717 | fn debugModuleFlagAssumeCapacity( |
| 12007 | 12718 | self: *Builder, |
| 12008 | | behaviour: Metadata, |
| 12719 | behavior: Metadata, |
| 12009 | 12720 | name: MetadataString, |
| 12010 | 12721 | constant: Metadata, |
| 12011 | 12722 | ) Metadata { |
| 12012 | 12723 | return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{ |
| 12013 | | .behaviour = behaviour, |
| 12724 | .behavior = behavior, |
| 12014 | 12725 | .name = name, |
| 12015 | 12726 | .constant = constant, |
| 12016 | 12727 | }); |
| ... | ... | @@ -12024,7 +12735,7 @@ fn debugLocalVarAssumeCapacity( |
| 12024 | 12735 | line: u32, |
| 12025 | 12736 | ty: Metadata, |
| 12026 | 12737 | ) Allocator.Error!Metadata { |
| 12027 | | return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{ |
| 12738 | return self.metadataDistinctAssumeCapacity(.local_var, Metadata.LocalVar{ |
| 12028 | 12739 | .name = name, |
| 12029 | 12740 | .file = file, |
| 12030 | 12741 | .scope = scope, |
| ... | ... | @@ -12042,7 +12753,7 @@ fn debugParameterAssumeCapacity( |
| 12042 | 12753 | ty: Metadata, |
| 12043 | 12754 | arg_no: u32, |
| 12044 | 12755 | ) Allocator.Error!Metadata { |
| 12045 | | return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{ |
| 12756 | return self.metadataDistinctAssumeCapacity(.parameter, Metadata.Parameter{ |
| 12046 | 12757 | .name = name, |
| 12047 | 12758 | .file = file, |
| 12048 | 12759 | .scope = scope, |
| ... | ... | @@ -12061,10 +12772,10 @@ fn debugGlobalVarAssumeCapacity( |
| 12061 | 12772 | line: u32, |
| 12062 | 12773 | ty: Metadata, |
| 12063 | 12774 | variable: Variable.Index, |
| 12064 | | flags: Metadata.GlobalVar.Flags, |
| 12775 | options: Metadata.GlobalVar.Options, |
| 12065 | 12776 | ) Allocator.Error!Metadata { |
| 12066 | | return self.metadataSimpleAssumeCapacity( |
| 12067 | | if (flags.local) .@"global_var local" else .global_var, |
| 12777 | return self.metadataDistinctAssumeCapacity( |
| 12778 | if (options.local) .@"global_var local" else .global_var, |
| 12068 | 12779 | Metadata.GlobalVar{ |
| 12069 | 12780 | .name = name, |
| 12070 | 12781 | .linkage_name = linkage_name, |
| ... | ... | @@ -12082,7 +12793,7 @@ fn debugGlobalVarExpressionAssumeCapacity( |
| 12082 | 12793 | variable: Metadata, |
| 12083 | 12794 | expression: Metadata, |
| 12084 | 12795 | ) Metadata { |
| 12085 | | return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{ |
| 12796 | return self.metadataDistinctAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{ |
| 12086 | 12797 | .variable = variable, |
| 12087 | 12798 | .expression = expression, |
| 12088 | 12799 | }); |
| ... | ... | @@ -12123,20 +12834,26 @@ fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata { |
| 12123 | 12834 | pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]const u32 { |
| 12124 | 12835 | const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes }); |
| 12125 | 12836 | var bitcode = BitcodeWriter.init(allocator, &.{ |
| 12126 | | std.math.log2_int_ceil(usize, self.type_items.items.len - 1), |
| 12127 | | std.math.log2_int_ceil(usize, self.function_attributes_set.count() - 1), |
| 12837 | if (self.type_items.items.len > 0) |
| 12838 | std.math.log2_int_ceil(usize, self.type_items.items.len) |
| 12839 | else |
| 12840 | undefined, |
| 12841 | if (self.type_items.items.len > 0) |
| 12842 | std.math.log2_int_ceil(usize, self.function_attributes_set.count()) |
| 12843 | else |
| 12844 | undefined, |
| 12128 | 12845 | }); |
| 12129 | 12846 | errdefer bitcode.deinit(); |
| 12130 | 12847 | |
| 12131 | 12848 | // Write LLVM IR magic |
| 12132 | | try bitcode.writeBits(IR.MAGIC, 32); |
| 12849 | try bitcode.writeBits(ir.MAGIC, 32); |
| 12133 | 12850 | |
| 12134 | | var record = std.ArrayListUnmanaged(u64){}; |
| 12851 | var record: std.ArrayListUnmanaged(u64) = .{}; |
| 12135 | 12852 | defer record.deinit(self.gpa); |
| 12136 | 12853 | |
| 12137 | 12854 | // IDENTIFICATION_BLOCK |
| 12138 | 12855 | { |
| 12139 | | const Identification = IR.Identification; |
| 12856 | const Identification = ir.Identification; |
| 12140 | 12857 | var identification_block = try bitcode.enterTopBlock(Identification); |
| 12141 | 12858 | |
| 12142 | 12859 | const producer = try std.fmt.allocPrint(self.gpa, "zig {d}.{d}.{d}", .{ |
| ... | ... | @@ -12154,7 +12871,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12154 | 12871 | |
| 12155 | 12872 | // MODULE_BLOCK |
| 12156 | 12873 | { |
| 12157 | | const Module = IR.Module; |
| 12874 | const Module = ir.Module; |
| 12158 | 12875 | var module_block = try bitcode.enterTopBlock(Module); |
| 12159 | 12876 | |
| 12160 | 12877 | try module_block.writeAbbrev(Module.Version{}); |
| ... | ... | @@ -12189,16 +12906,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12189 | 12906 | |
| 12190 | 12907 | // TYPE_BLOCK |
| 12191 | 12908 | { |
| 12192 | | var type_block = try module_block.enterSubBlock(IR.Type); |
| 12909 | var type_block = try module_block.enterSubBlock(ir.Type); |
| 12193 | 12910 | |
| 12194 | | try type_block.writeAbbrev(IR.Type.NumEntry{ .num = @intCast(self.type_items.items.len) }); |
| 12911 | try type_block.writeAbbrev(ir.Type.NumEntry{ .num = @intCast(self.type_items.items.len) }); |
| 12195 | 12912 | |
| 12196 | 12913 | for (self.type_items.items, 0..) |item, i| { |
| 12197 | 12914 | const ty: Type = @enumFromInt(i); |
| 12198 | 12915 | |
| 12199 | 12916 | switch (item.tag) { |
| 12200 | | .simple => try type_block.writeAbbrev(IR.Type.Simple{ .code = @truncate(item.data) }), |
| 12201 | | .integer => try type_block.writeAbbrev(IR.Type.Integer{ .width = item.data }), |
| 12917 | .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }), |
| 12918 | .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }), |
| 12202 | 12919 | .structure, |
| 12203 | 12920 | .packed_structure, |
| 12204 | 12921 | => |kind| { |
| ... | ... | @@ -12208,14 +12925,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12208 | 12925 | else => unreachable, |
| 12209 | 12926 | }; |
| 12210 | 12927 | var extra = self.typeExtraDataTrail(Type.Structure, item.data); |
| 12211 | | try type_block.writeAbbrev(IR.Type.StructAnon{ |
| 12928 | try type_block.writeAbbrev(ir.Type.StructAnon{ |
| 12212 | 12929 | .is_packed = is_packed, |
| 12213 | 12930 | .types = extra.trail.next(extra.data.fields_len, Type, self), |
| 12214 | 12931 | }); |
| 12215 | 12932 | }, |
| 12216 | 12933 | .named_structure => { |
| 12217 | 12934 | const extra = self.typeExtraData(Type.NamedStructure, item.data); |
| 12218 | | try type_block.writeAbbrev(IR.Type.StructName{ |
| 12935 | try type_block.writeAbbrev(ir.Type.StructName{ |
| 12219 | 12936 | .string = extra.id.slice(self).?, |
| 12220 | 12937 | }); |
| 12221 | 12938 | |
| ... | ... | @@ -12227,36 +12944,36 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12227 | 12944 | }; |
| 12228 | 12945 | |
| 12229 | 12946 | var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data); |
| 12230 | | try type_block.writeAbbrev(IR.Type.StructNamed{ |
| 12947 | try type_block.writeAbbrev(ir.Type.StructNamed{ |
| 12231 | 12948 | .is_packed = is_packed, |
| 12232 | 12949 | .types = real_extra.trail.next(real_extra.data.fields_len, Type, self), |
| 12233 | 12950 | }); |
| 12234 | 12951 | }, |
| 12235 | 12952 | .array, |
| 12236 | 12953 | .small_array, |
| 12237 | | => try type_block.writeAbbrev(IR.Type.Array{ |
| 12954 | => try type_block.writeAbbrev(ir.Type.Array{ |
| 12238 | 12955 | .len = ty.aggregateLen(self), |
| 12239 | 12956 | .child = ty.childType(self), |
| 12240 | 12957 | }), |
| 12241 | 12958 | .vector, |
| 12242 | 12959 | .scalable_vector, |
| 12243 | | => try type_block.writeAbbrev(IR.Type.Vector{ |
| 12960 | => try type_block.writeAbbrev(ir.Type.Vector{ |
| 12244 | 12961 | .len = ty.aggregateLen(self), |
| 12245 | 12962 | .child = ty.childType(self), |
| 12246 | 12963 | }), |
| 12247 | | .pointer => try type_block.writeAbbrev(IR.Type.Pointer{ |
| 12964 | .pointer => try type_block.writeAbbrev(ir.Type.Pointer{ |
| 12248 | 12965 | .addr_space = ty.pointerAddrSpace(self), |
| 12249 | 12966 | }), |
| 12250 | 12967 | .target => { |
| 12251 | 12968 | var extra = self.typeExtraDataTrail(Type.Target, item.data); |
| 12252 | | try type_block.writeAbbrev(IR.Type.StructName{ |
| 12969 | try type_block.writeAbbrev(ir.Type.StructName{ |
| 12253 | 12970 | .string = extra.data.name.slice(self).?, |
| 12254 | 12971 | }); |
| 12255 | 12972 | |
| 12256 | 12973 | const types = extra.trail.next(extra.data.types_len, Type, self); |
| 12257 | 12974 | const ints = extra.trail.next(extra.data.ints_len, u32, self); |
| 12258 | 12975 | |
| 12259 | | try type_block.writeAbbrev(IR.Type.Target{ |
| 12976 | try type_block.writeAbbrev(ir.Type.Target{ |
| 12260 | 12977 | .num_types = extra.data.types_len, |
| 12261 | 12978 | .types = types, |
| 12262 | 12979 | .ints = ints, |
| ... | ... | @@ -12269,7 +12986,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12269 | 12986 | else => unreachable, |
| 12270 | 12987 | }; |
| 12271 | 12988 | var extra = self.typeExtraDataTrail(Type.Function, item.data); |
| 12272 | | try type_block.writeAbbrev(IR.Type.Function{ |
| 12989 | try type_block.writeAbbrev(ir.Type.Function{ |
| 12273 | 12990 | .is_vararg = is_vararg, |
| 12274 | 12991 | .return_type = extra.data.ret, |
| 12275 | 12992 | .param_types = extra.trail.next(extra.data.params_len, Type, self), |
| ... | ... | @@ -12289,7 +13006,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12289 | 13006 | |
| 12290 | 13007 | // PARAMATTR_GROUP_BLOCK |
| 12291 | 13008 | { |
| 12292 | | const ParamattrGroup = IR.ParamattrGroup; |
| 13009 | const ParamattrGroup = ir.ParamattrGroup; |
| 12293 | 13010 | |
| 12294 | 13011 | var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroup); |
| 12295 | 13012 | |
| ... | ... | @@ -12493,7 +13210,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12493 | 13210 | |
| 12494 | 13211 | // PARAMATTR_BLOCK |
| 12495 | 13212 | { |
| 12496 | | const Paramattr = IR.Paramattr; |
| 13213 | const Paramattr = ir.Paramattr; |
| 12497 | 13214 | var paramattr_block = try module_block.enterSubBlock(Paramattr); |
| 12498 | 13215 | |
| 12499 | 13216 | for (self.function_attributes_set.keys()) |func_attributes| { |
| ... | ... | @@ -12517,7 +13234,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12517 | 13234 | try paramattr_block.end(); |
| 12518 | 13235 | } |
| 12519 | 13236 | |
| 12520 | | var globals = std.AutoArrayHashMapUnmanaged(Global.Index, void){}; |
| 13237 | var globals: std.AutoArrayHashMapUnmanaged(Global.Index, void) = .{}; |
| 12521 | 13238 | defer globals.deinit(self.gpa); |
| 12522 | 13239 | try globals.ensureUnusedCapacity( |
| 12523 | 13240 | self.gpa, |
| ... | ... | @@ -12696,7 +13413,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12696 | 13413 | |
| 12697 | 13414 | // CONSTANTS_BLOCK |
| 12698 | 13415 | { |
| 12699 | | const Constants = IR.Constants; |
| 13416 | const Constants = ir.Constants; |
| 12700 | 13417 | var constants_block = try module_block.enterSubBlock(Constants); |
| 12701 | 13418 | |
| 12702 | 13419 | var current_type: Type = .none; |
| ... | ... | @@ -12725,7 +13442,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 12725 | 13442 | @ptrCast(self.constant_limbs.items[data..][0..Constant.Integer.limbs]); |
| 12726 | 13443 | const limbs = self.constant_limbs |
| 12727 | 13444 | .items[data + Constant.Integer.limbs ..][0..extra.limbs_len]; |
| 12728 | | const bigint = std.math.big.int.Const{ |
| 13445 | const bigint: std.math.big.int.Const = .{ |
| 12729 | 13446 | .limbs = limbs, |
| 12730 | 13447 | .positive = tag == .positive_integer, |
| 12731 | 13448 | }; |
| ... | ... | @@ -13062,7 +13779,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13062 | 13779 | |
| 13063 | 13780 | // METADATA_BLOCK |
| 13064 | 13781 | if (!self.strip) { |
| 13065 | | const MetadataBlock = IR.MetadataBlock; |
| 13782 | const MetadataBlock = ir.MetadataBlock; |
| 13066 | 13783 | var metadata_block = try module_block.enterSubBlock(MetadataBlock); |
| 13067 | 13784 | |
| 13068 | 13785 | const MetadataBlockWriter = @TypeOf(metadata_block); |
| ... | ... | @@ -13115,50 +13832,45 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13115 | 13832 | try bitcode.alignTo32(); |
| 13116 | 13833 | } |
| 13117 | 13834 | |
| 13118 | | for (1..self.metadata_items.len) |metadata_index| { |
| 13119 | | const tag = self.metadata_items.items(.tag)[metadata_index]; |
| 13120 | | const data = self.metadata_items.items(.data)[metadata_index]; |
| 13835 | for ( |
| 13836 | self.metadata_items.items(.tag)[1..], |
| 13837 | self.metadata_items.items(.data)[1..], |
| 13838 | ) |tag, data| { |
| 13121 | 13839 | switch (tag) { |
| 13122 | 13840 | .none => unreachable, |
| 13123 | 13841 | .file => { |
| 13124 | 13842 | const extra = self.metadataExtraData(Metadata.File, data); |
| 13125 | 13843 | |
| 13126 | 13844 | try metadata_block.writeAbbrevAdapted(MetadataBlock.File{ |
| 13127 | | .name = extra.name, |
| 13128 | | .path = extra.path, |
| 13845 | .filename = extra.filename, |
| 13846 | .directory = extra.directory, |
| 13129 | 13847 | }, metadata_adapter); |
| 13130 | 13848 | }, |
| 13131 | | .compile_unit, .@"compile_unit optimized" => |kind| { |
| 13132 | | const is_optimized = kind == .@"compile_unit optimized"; |
| 13849 | .compile_unit, |
| 13850 | .@"compile_unit optimized", |
| 13851 | => |kind| { |
| 13133 | 13852 | const extra = self.metadataExtraData(Metadata.CompileUnit, data); |
| 13134 | 13853 | try metadata_block.writeAbbrevAdapted(MetadataBlock.CompileUnit{ |
| 13135 | 13854 | .file = extra.file, |
| 13136 | 13855 | .producer = extra.producer, |
| 13137 | | .is_optimized = is_optimized, |
| 13856 | .is_optimized = switch (kind) { |
| 13857 | .compile_unit => false, |
| 13858 | .@"compile_unit optimized" => true, |
| 13859 | else => unreachable, |
| 13860 | }, |
| 13138 | 13861 | .enums = extra.enums, |
| 13139 | 13862 | .globals = extra.globals, |
| 13140 | 13863 | }, metadata_adapter); |
| 13141 | 13864 | }, |
| 13142 | 13865 | .subprogram, |
| 13143 | | .@"subprogram optimized", |
| 13144 | 13866 | .@"subprogram local", |
| 13145 | 13867 | .@"subprogram definition", |
| 13868 | .@"subprogram local definition", |
| 13869 | .@"subprogram optimized", |
| 13146 | 13870 | .@"subprogram optimized local", |
| 13147 | 13871 | .@"subprogram optimized definition", |
| 13148 | 13872 | .@"subprogram optimized local definition", |
| 13149 | | .@"subprogram local definition", |
| 13150 | 13873 | => |kind| { |
| 13151 | | const sp_flags: u32 = switch (kind) { |
| 13152 | | .subprogram => 0, |
| 13153 | | .@"subprogram optimized" => 1 << 4, |
| 13154 | | .@"subprogram local" => 1 << 2, |
| 13155 | | .@"subprogram definition" => 1 << 3, |
| 13156 | | .@"subprogram optimized local" => (1 << 4) | (1 << 2), |
| 13157 | | .@"subprogram optimized definition" => (1 << 4) | (1 << 3), |
| 13158 | | .@"subprogram optimized local definition" => (1 << 4) | (1 << 2) | (1 << 3), |
| 13159 | | .@"subprogram local definition" => (1 << 2) | (1 << 3), |
| 13160 | | else => unreachable, |
| 13161 | | }; |
| 13162 | 13874 | const extra = self.metadataExtraData(Metadata.Subprogram, data); |
| 13163 | 13875 | |
| 13164 | 13876 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{ |
| ... | ... | @@ -13167,10 +13879,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13167 | 13879 | .linkage_name = extra.linkage_name, |
| 13168 | 13880 | .file = extra.file, |
| 13169 | 13881 | .line = extra.line, |
| 13170 | | .ty = Metadata.none, //extra.ty, |
| 13882 | .ty = .none, //extra.ty, |
| 13171 | 13883 | .scope_line = extra.scope_line, |
| 13172 | | .sp_flags = sp_flags, |
| 13173 | | .flags = extra.debug_info_flags, |
| 13884 | .sp_flags = @bitCast(@as(u32, @as(u3, @intCast( |
| 13885 | @intFromEnum(kind) - @intFromEnum(Metadata.Tag.subprogram), |
| 13886 | ))) << 2), |
| 13887 | .flags = extra.di_flags, |
| 13174 | 13888 | .compile_unit = extra.compile_unit, |
| 13175 | 13889 | }, metadata_adapter); |
| 13176 | 13890 | }, |
| ... | ... | @@ -13185,7 +13899,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13185 | 13899 | }, |
| 13186 | 13900 | .location => { |
| 13187 | 13901 | const extra = self.metadataExtraData(Metadata.Location, data); |
| 13188 | | std.debug.assert(extra.scope != Metadata.none); |
| 13902 | std.debug.assert(extra.scope != .none); |
| 13189 | 13903 | try metadata_block.writeAbbrev(MetadataBlock.Location{ |
| 13190 | 13904 | .line = extra.line, |
| 13191 | 13905 | .column = extra.column, |
| ... | ... | @@ -13201,12 +13915,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13201 | 13915 | const extra = self.metadataExtraData(Metadata.BasicType, data); |
| 13202 | 13916 | try metadata_block.writeAbbrevAdapted(MetadataBlock.BasicType{ |
| 13203 | 13917 | .name = extra.name, |
| 13204 | | .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32, |
| 13918 | .size_in_bits = extra.bitSize(), |
| 13205 | 13919 | .encoding = switch (kind) { |
| 13206 | | .basic_bool_type => std.dwarf.ATE.boolean, |
| 13207 | | .basic_unsigned_type => std.dwarf.ATE.unsigned, |
| 13208 | | .basic_signed_type => std.dwarf.ATE.signed, |
| 13209 | | .basic_float_type => std.dwarf.ATE.float, |
| 13920 | .basic_bool_type => DW.ATE.boolean, |
| 13921 | .basic_unsigned_type => DW.ATE.unsigned, |
| 13922 | .basic_signed_type => DW.ATE.signed, |
| 13923 | .basic_float_type => DW.ATE.float, |
| 13210 | 13924 | else => unreachable, |
| 13211 | 13925 | }, |
| 13212 | 13926 | }, metadata_adapter); |
| ... | ... | @@ -13221,12 +13935,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13221 | 13935 | |
| 13222 | 13936 | try metadata_block.writeAbbrevAdapted(MetadataBlock.CompositeType{ |
| 13223 | 13937 | .tag = switch (kind) { |
| 13224 | | .composite_struct_type => std.dwarf.TAG.structure_type, |
| 13225 | | .composite_union_type => std.dwarf.TAG.union_type, |
| 13226 | | .composite_enumeration_type => std.dwarf.TAG.enumeration_type, |
| 13227 | | .composite_array_type, |
| 13228 | | .composite_vector_type, |
| 13229 | | => std.dwarf.TAG.array_type, |
| 13938 | .composite_struct_type => DW.TAG.structure_type, |
| 13939 | .composite_union_type => DW.TAG.union_type, |
| 13940 | .composite_enumeration_type => DW.TAG.enumeration_type, |
| 13941 | .composite_array_type, .composite_vector_type => DW.TAG.array_type, |
| 13230 | 13942 | else => unreachable, |
| 13231 | 13943 | }, |
| 13232 | 13944 | .name = extra.name, |
| ... | ... | @@ -13234,9 +13946,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13234 | 13946 | .line = extra.line, |
| 13235 | 13947 | .scope = extra.scope, |
| 13236 | 13948 | .underlying_type = extra.underlying_type, |
| 13237 | | .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32, |
| 13238 | | .align_in_bits = @as(u64, extra.align_in_bits_lo) | @as(u64, extra.align_in_bits_hi) << 32, |
| 13239 | | .flags = if (kind == .composite_vector_type) DIFlags.Vector else 0, |
| 13949 | .size_in_bits = extra.bitSize(), |
| 13950 | .align_in_bits = extra.bitAlign(), |
| 13951 | .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{}, |
| 13240 | 13952 | .elements = extra.fields_tuple, |
| 13241 | 13953 | }, metadata_adapter); |
| 13242 | 13954 | }, |
| ... | ... | @@ -13246,8 +13958,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13246 | 13958 | const extra = self.metadataExtraData(Metadata.DerivedType, data); |
| 13247 | 13959 | try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{ |
| 13248 | 13960 | .tag = switch (kind) { |
| 13249 | | .derived_pointer_type => std.dwarf.TAG.pointer_type, |
| 13250 | | .derived_member_type => std.dwarf.TAG.member, |
| 13961 | .derived_pointer_type => DW.TAG.pointer_type, |
| 13962 | .derived_member_type => DW.TAG.member, |
| 13251 | 13963 | else => unreachable, |
| 13252 | 13964 | }, |
| 13253 | 13965 | .name = extra.name, |
| ... | ... | @@ -13255,9 +13967,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13255 | 13967 | .line = extra.line, |
| 13256 | 13968 | .scope = extra.scope, |
| 13257 | 13969 | .underlying_type = extra.underlying_type, |
| 13258 | | .size_in_bits = @as(u64, extra.size_in_bits_lo) | @as(u64, extra.size_in_bits_hi) << 32, |
| 13259 | | .align_in_bits = @as(u64, extra.align_in_bits_lo) | @as(u64, extra.align_in_bits_hi) << 32, |
| 13260 | | .offset_in_bits = @as(u64, extra.offset_in_bits_lo) | @as(u64, extra.offset_in_bits_hi) << 32, |
| 13970 | .size_in_bits = extra.bitSize(), |
| 13971 | .align_in_bits = extra.bitAlign(), |
| 13972 | .offset_in_bits = extra.bitOffset(), |
| 13261 | 13973 | }, metadata_adapter); |
| 13262 | 13974 | }, |
| 13263 | 13975 | .subroutine_type => { |
| ... | ... | @@ -13291,7 +14003,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13291 | 14003 | |
| 13292 | 14004 | const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len]; |
| 13293 | 14005 | |
| 13294 | | const bigint = std.math.big.int.Const{ |
| 14006 | const bigint: std.math.big.int.Const = .{ |
| 13295 | 14007 | .limbs = limbs, |
| 13296 | 14008 | .positive = positive, |
| 13297 | 14009 | }; |
| ... | ... | @@ -13315,7 +14027,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13315 | 14027 | const word_count = std.mem.alignForward(u32, extra.bit_width, 64) / 64; |
| 13316 | 14028 | try record.ensureUnusedCapacity(self.gpa, 3 + word_count); |
| 13317 | 14029 | |
| 13318 | | const flags = MetadataBlock.Enumerator.Flags{ |
| 14030 | const flags: MetadataBlock.Enumerator.Flags = .{ |
| 13319 | 14031 | .unsigned = unsigned, |
| 13320 | 14032 | .bigint = true, |
| 13321 | 14033 | }; |
| ... | ... | @@ -13375,7 +14087,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13375 | 14087 | const extra = self.metadataExtraData(Metadata.ModuleFlag, data); |
| 13376 | 14088 | try metadata_block.writeAbbrev(MetadataBlock.Node{ |
| 13377 | 14089 | .elements = &.{ |
| 13378 | | @enumFromInt(metadata_adapter.getMetadataIndex(extra.behaviour)), |
| 14090 | @enumFromInt(metadata_adapter.getMetadataIndex(extra.behavior)), |
| 13379 | 14091 | @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.name)), |
| 13380 | 14092 | @enumFromInt(metadata_adapter.getMetadataIndex(extra.constant)), |
| 13381 | 14093 | }, |
| ... | ... | @@ -13534,7 +14246,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13534 | 14246 | }; |
| 13535 | 14247 | |
| 13536 | 14248 | for (self.functions.items, 0..) |func, func_index| { |
| 13537 | | const FunctionBlock = IR.FunctionBlock; |
| 14249 | const FunctionBlock = ir.FunctionBlock; |
| 13538 | 14250 | if (func.global.getReplacement(self) != .none) continue; |
| 13539 | 14251 | |
| 13540 | 14252 | if (func.instructions.len == 0) continue; |
| ... | ... | @@ -13547,7 +14259,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13547 | 14259 | |
| 13548 | 14260 | // Emit function level metadata block |
| 13549 | 14261 | if (!self.strip and func.debug_values.len != 0) { |
| 13550 | | const MetadataBlock = IR.FunctionMetadataBlock; |
| 14262 | const MetadataBlock = ir.FunctionMetadataBlock; |
| 13551 | 14263 | var metadata_block = try function_block.enterSubBlock(MetadataBlock); |
| 13552 | 14264 | |
| 13553 | 14265 | for (func.debug_values) |value| { |
| ... | ... | @@ -13656,10 +14368,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13656 | 14368 | .srem, |
| 13657 | 14369 | .ashr, |
| 13658 | 14370 | .@"ashr exact", |
| 13659 | | => { |
| 14371 | => |kind| { |
| 13660 | 14372 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); |
| 13661 | 14373 | try function_block.writeAbbrev(FunctionBlock.Binary{ |
| 13662 | | .opcode = tag.toBinaryOpcode(), |
| 14374 | .opcode = kind.toBinaryOpcode(), |
| 13663 | 14375 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 13664 | 14376 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| 13665 | 14377 | }); |
| ... | ... | @@ -13669,10 +14381,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13669 | 14381 | .@"fmul fast", |
| 13670 | 14382 | .@"frem fast", |
| 13671 | 14383 | .@"fsub fast", |
| 13672 | | => { |
| 14384 | => |kind| { |
| 13673 | 14385 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); |
| 13674 | 14386 | try function_block.writeAbbrev(FunctionBlock.BinaryFast{ |
| 13675 | | .opcode = tag.toBinaryOpcode(), |
| 14387 | .opcode = kind.toBinaryOpcode(), |
| 13676 | 14388 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 13677 | 14389 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| 13678 | 14390 | .fast_math = .{}, |
| ... | ... | @@ -13709,12 +14421,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13709 | 14421 | .fpext, |
| 13710 | 14422 | .sext, |
| 13711 | 14423 | .zext, |
| 13712 | | => { |
| 14424 | => |kind| { |
| 13713 | 14425 | const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]); |
| 13714 | 14426 | try function_block.writeAbbrev(FunctionBlock.Cast{ |
| 13715 | 14427 | .val = adapter.getOffsetValueIndex(extra.val), |
| 13716 | 14428 | .type_index = extra.type, |
| 13717 | | .opcode = tag.toCastOpcode(), |
| 14429 | .opcode = kind.toCastOpcode(), |
| 13718 | 14430 | }); |
| 13719 | 14431 | }, |
| 13720 | 14432 | .@"fcmp false", |
| ... | ... | @@ -13743,12 +14455,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13743 | 14455 | .@"icmp ugt", |
| 13744 | 14456 | .@"icmp ule", |
| 13745 | 14457 | .@"icmp ult", |
| 13746 | | => { |
| 14458 | => |kind| { |
| 13747 | 14459 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); |
| 13748 | 14460 | try function_block.writeAbbrev(FunctionBlock.Cmp{ |
| 13749 | 14461 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 13750 | 14462 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| 13751 | | .pred = tag.toCmpPredicate(), |
| 14463 | .pred = kind.toCmpPredicate(), |
| 13752 | 14464 | }); |
| 13753 | 14465 | }, |
| 13754 | 14466 | .@"fcmp fast false", |
| ... | ... | @@ -13767,12 +14479,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13767 | 14479 | .@"fcmp fast ult", |
| 13768 | 14480 | .@"fcmp fast une", |
| 13769 | 14481 | .@"fcmp fast uno", |
| 13770 | | => { |
| 14482 | => |kind| { |
| 13771 | 14483 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); |
| 13772 | 14484 | try function_block.writeAbbrev(FunctionBlock.CmpFast{ |
| 13773 | 14485 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 13774 | 14486 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| 13775 | | .pred = tag.toCmpPredicate(), |
| 14487 | .pred = kind.toCmpPredicate(), |
| 13776 | 14488 | .fast_math = .{}, |
| 13777 | 14489 | }); |
| 13778 | 14490 | }, |
| ... | ... | @@ -13842,12 +14554,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13842 | 14554 | }, |
| 13843 | 14555 | .getelementptr, |
| 13844 | 14556 | .@"getelementptr inbounds", |
| 13845 | | => { |
| 14557 | => |kind| { |
| 13846 | 14558 | var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]); |
| 13847 | 14559 | const indices = extra.trail.next(extra.data.indices_len, Value, &func); |
| 13848 | 14560 | try function_block.writeAbbrevAdapted( |
| 13849 | 14561 | FunctionBlock.GetElementPtr{ |
| 13850 | | .is_inbounds = tag == .@"getelementptr inbounds", |
| 14562 | .is_inbounds = kind == .@"getelementptr inbounds", |
| 13851 | 14563 | .type_index = extra.data.type, |
| 13852 | 14564 | .base = extra.data.base, |
| 13853 | 14565 | .indices = indices, |
| ... | ... | @@ -14008,13 +14720,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14008 | 14720 | } |
| 14009 | 14721 | |
| 14010 | 14722 | if (!self.strip) { |
| 14011 | | if (func.debug_locations.get(@enumFromInt(instr_index))) |maybe_location| { |
| 14012 | | if (maybe_location) |location| { |
| 14723 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { |
| 14724 | if (debug_location != .none) { |
| 14725 | const location = self.metadata_items.get(@intFromEnum(debug_location)); |
| 14726 | assert(location.tag == .location); |
| 14727 | const extra = self.metadataExtraData(Metadata.Location, location.data); |
| 14013 | 14728 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ |
| 14014 | | .line = location.line, |
| 14015 | | .column = location.column, |
| 14016 | | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)), |
| 14017 | | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)), |
| 14729 | .line = extra.line, |
| 14730 | .column = extra.column, |
| 14731 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(extra.scope)), |
| 14732 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)), |
| 14018 | 14733 | .is_implicit = false, |
| 14019 | 14734 | }); |
| 14020 | 14735 | has_location = true; |
| ... | ... | @@ -14031,7 +14746,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14031 | 14746 | |
| 14032 | 14747 | // VALUE_SYMTAB |
| 14033 | 14748 | if (!self.strip) { |
| 14034 | | const ValueSymbolTable = IR.FunctionValueSymbolTable; |
| 14749 | const ValueSymbolTable = ir.FunctionValueSymbolTable; |
| 14035 | 14750 | |
| 14036 | 14751 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable); |
| 14037 | 14752 | |
| ... | ... | @@ -14060,7 +14775,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14060 | 14775 | |
| 14061 | 14776 | // STRTAB_BLOCK |
| 14062 | 14777 | { |
| 14063 | | const Strtab = IR.Strtab; |
| 14778 | const Strtab = ir.Strtab; |
| 14064 | 14779 | var strtab_block = try bitcode.enterTopBlock(Strtab); |
| 14065 | 14780 | |
| 14066 | 14781 | try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.string_bytes.items }); |
| ... | ... | @@ -14071,14 +14786,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14071 | 14786 | return bitcode.toSlice(); |
| 14072 | 14787 | } |
| 14073 | 14788 | |
| 14789 | const Allocator = std.mem.Allocator; |
| 14074 | 14790 | const assert = std.debug.assert; |
| 14791 | const bitcode_writer = @import("bitcode_writer.zig"); |
| 14075 | 14792 | const build_options = @import("build_options"); |
| 14793 | const Builder = @This(); |
| 14076 | 14794 | const builtin = @import("builtin"); |
| 14795 | const DW = std.dwarf; |
| 14796 | const ir = @import("ir.zig"); |
| 14077 | 14797 | const log = std.log.scoped(.llvm); |
| 14078 | 14798 | const std = @import("std"); |
| 14079 | | |
| 14080 | | const bitcode_writer = @import("bitcode_writer.zig"); |
| 14081 | | const IR = @import("IR.zig"); |
| 14082 | | |
| 14083 | | const Allocator = std.mem.Allocator; |
| 14084 | | const Builder = @This(); |