| ... | @@ -56,8 +56,8 @@ metadata_map: std.AutoArrayHashMapUnmanaged(void, void), | ... | @@ -56,8 +56,8 @@ metadata_map: std.AutoArrayHashMapUnmanaged(void, void), |
| 56 | metadata_items: std.MultiArrayList(Metadata.Item), | 56 | metadata_items: std.MultiArrayList(Metadata.Item), |
| 57 | metadata_extra: std.ArrayListUnmanaged(u32), | 57 | metadata_extra: std.ArrayListUnmanaged(u32), |
| 58 | metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb), | 58 | metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb), |
| 59 | metadata_forward_references: std.ArrayListUnmanaged(Metadata), | 59 | metadata_forward_references: std.ArrayListUnmanaged(Metadata.Optional), |
| 60 | metadata_named: std.AutoArrayHashMapUnmanaged(MetadataString, struct { | 60 | metadata_named: std.AutoArrayHashMapUnmanaged(String, struct { |
| 61 | len: u32, | 61 | len: u32, |
| 62 | index: Metadata.Item.ExtraIndex, | 62 | index: Metadata.Item.ExtraIndex, |
| 63 | }), | 63 | }), |
| ... | @@ -265,19 +265,20 @@ pub const Type = enum(u32) { | ... | @@ -265,19 +265,20 @@ pub const Type = enum(u32) { |
| 265 | }; | 265 | }; |
| 266 | | 266 | |
| 267 | pub const Simple = enum(u5) { | 267 | pub const Simple = enum(u5) { |
| 268 | void = 2, | 268 | const Code = ir.ModuleBlock.TypeBlock.Code; |
| 269 | half = 10, | 269 | void = @intFromEnum(Code.VOID), |
| 270 | bfloat = 23, | 270 | half = @intFromEnum(Code.HALF), |
| 271 | float = 3, | 271 | bfloat = @intFromEnum(Code.BFLOAT), |
| 272 | double = 4, | 272 | float = @intFromEnum(Code.FLOAT), |
| 273 | fp128 = 14, | 273 | double = @intFromEnum(Code.DOUBLE), |
| 274 | x86_fp80 = 13, | 274 | fp128 = @intFromEnum(Code.FP128), |
| 275 | ppc_fp128 = 15, | 275 | x86_fp80 = @intFromEnum(Code.X86_FP80), |
| 276 | x86_amx = 24, | 276 | ppc_fp128 = @intFromEnum(Code.PPC_FP128), |
| 277 | x86_mmx = 17, | 277 | x86_amx = @intFromEnum(Code.X86_AMX), |
| 278 | label = 5, | 278 | x86_mmx = @intFromEnum(Code.X86_MMX), |
| 279 | token = 22, | 279 | label = @intFromEnum(Code.LABEL), |
| 280 | metadata = 16, | 280 | token = @intFromEnum(Code.TOKEN), |
| | 281 | metadata = @intFromEnum(Code.METADATA), |
| 281 | }; | 282 | }; |
| 282 | | 283 | |
| 283 | pub const Function = struct { | 284 | pub const Function = struct { |
| ... | @@ -1325,8 +1326,8 @@ pub const Attribute = union(Kind) { | ... | @@ -1325,8 +1326,8 @@ pub const Attribute = union(Kind) { |
| 1325 | .none => unreachable, | 1326 | .none => unreachable, |
| 1326 | } | 1327 | } |
| 1327 | } | 1328 | } |
| 1328 | pub fn fmt(self: Index, builder: *const Builder, mode: FormatData.mode) std.fmt.Alt(FormatData, format) { | 1329 | pub fn fmt(self: Index, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) { |
| 1329 | return .{ .data = .{ .attribute_index = self, .builder = builder, .mode = mode } }; | 1330 | return .{ .data = .{ .attribute_index = self, .builder = builder, .flags = flags } }; |
| 1330 | } | 1331 | } |
| 1331 | | 1332 | |
| 1332 | fn toStorage(self: Index, builder: *const Builder) Storage { | 1333 | fn toStorage(self: Index, builder: *const Builder) Storage { |
| ... | @@ -2295,7 +2296,7 @@ pub const Global = struct { | ... | @@ -2295,7 +2296,7 @@ pub const Global = struct { |
| 2295 | externally_initialized: ExternallyInitialized = .default, | 2296 | externally_initialized: ExternallyInitialized = .default, |
| 2296 | type: Type, | 2297 | type: Type, |
| 2297 | partition: String = .none, | 2298 | partition: String = .none, |
| 2298 | dbg: Metadata = .none, | 2299 | dbg: Metadata.Optional = .none, |
| 2299 | kind: union(enum) { | 2300 | kind: union(enum) { |
| 2300 | alias: Alias.Index, | 2301 | alias: Alias.Index, |
| 2301 | variable: Variable.Index, | 2302 | variable: Variable.Index, |
| ... | @@ -2375,7 +2376,11 @@ pub const Global = struct { | ... | @@ -2375,7 +2376,11 @@ pub const Global = struct { |
| 2375 | } | 2376 | } |
| 2376 | | 2377 | |
| 2377 | pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void { | 2378 | pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void { |
| 2378 | self.ptr(builder).dbg = dbg; | 2379 | self.ptr(builder).dbg = dbg.toOptional(); |
| | 2380 | } |
| | 2381 | |
| | 2382 | pub fn getDebugMetadata(self: Index, builder: *const Builder) Metadata.Optional { |
| | 2383 | return self.ptrConst(builder).dbg; |
| 2379 | } | 2384 | } |
| 2380 | | 2385 | |
| 2381 | const FormatData = struct { | 2386 | const FormatData = struct { |
| ... | @@ -2606,6 +2611,10 @@ pub const Variable = struct { | ... | @@ -2606,6 +2611,10 @@ pub const Variable = struct { |
| 2606 | pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void { | 2611 | pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void { |
| 2607 | self.ptrConst(builder).global.setDebugMetadata(expression, builder); | 2612 | self.ptrConst(builder).global.setDebugMetadata(expression, builder); |
| 2608 | } | 2613 | } |
| | 2614 | |
| | 2615 | pub fn getGlobalVariableExpression(self: Index, builder: *Builder) Metadata.Optional { |
| | 2616 | return self.ptrConst(builder).global.getDebugMetadata(builder); |
| | 2617 | } |
| 2609 | }; | 2618 | }; |
| 2610 | }; | 2619 | }; |
| 2611 | | 2620 | |
| ... | @@ -4107,6 +4116,10 @@ pub const Function = struct { | ... | @@ -4107,6 +4116,10 @@ pub const Function = struct { |
| 4107 | pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void { | 4116 | pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void { |
| 4108 | self.ptrConst(builder).global.setDebugMetadata(subprogram, builder); | 4117 | self.ptrConst(builder).global.setDebugMetadata(subprogram, builder); |
| 4109 | } | 4118 | } |
| | 4119 | |
| | 4120 | pub fn getSubprogram(self: Index, builder: *const Builder) Metadata.Optional { |
| | 4121 | return self.ptrConst(builder).global.getDebugMetadata(builder); |
| | 4122 | } |
| 4110 | }; | 4123 | }; |
| 4111 | | 4124 | |
| 4112 | pub const Block = struct { | 4125 | pub const Block = struct { |
| ... | @@ -4869,13 +4882,20 @@ pub const Function = struct { | ... | @@ -4869,13 +4882,20 @@ pub const Function = struct { |
| 4869 | then: Block.Index, | 4882 | then: Block.Index, |
| 4870 | @"else": Block.Index, | 4883 | @"else": Block.Index, |
| 4871 | weights: Weights, | 4884 | weights: Weights, |
| | 4885 | |
| 4872 | pub const Weights = enum(u32) { | 4886 | pub const Weights = enum(u32) { |
| 4873 | // We can do this as metadata indices 0 and 1 are reserved. | 4887 | none = @bitCast(Metadata.Optional.none), |
| 4874 | none = 0, | 4888 | unpredictable, |
| 4875 | unpredictable = 1, | | |
| 4876 | /// These values should be converted to `Metadata` to be used | | |
| 4877 | /// in a `prof` annotation providing branch weights. | | |
| 4878 | _, | 4889 | _, |
| | 4890 | |
| | 4891 | pub fn fromMetadata(metadata: Metadata) Weights { |
| | 4892 | assert(metadata.kind == .node); |
| | 4893 | return @enumFromInt(metadata.index); |
| | 4894 | } |
| | 4895 | |
| | 4896 | pub fn toMetadata(weights: Weights) Metadata { |
| | 4897 | return .{ .index = @intCast(@intFromEnum(weights)), .kind = .node }; |
| | 4898 | } |
| 4879 | }; | 4899 | }; |
| 4880 | }; | 4900 | }; |
| 4881 | | 4901 | |
| ... | @@ -5130,19 +5150,19 @@ pub const DebugLocation = union(enum) { | ... | @@ -5130,19 +5150,19 @@ pub const DebugLocation = union(enum) { |
| 5130 | pub const Location = struct { | 5150 | pub const Location = struct { |
| 5131 | line: u32, | 5151 | line: u32, |
| 5132 | column: u32, | 5152 | column: u32, |
| 5133 | scope: Builder.Metadata, | 5153 | scope: Builder.Metadata.Optional, |
| 5134 | inlined_at: Builder.Metadata, | 5154 | inlined_at: Builder.Metadata.Optional, |
| 5135 | }; | 5155 | }; |
| 5136 | | 5156 | |
| 5137 | pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata { | 5157 | pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata.Optional { |
| 5138 | return switch (self) { | 5158 | return switch (self) { |
| 5139 | .no_location => .none, | 5159 | .no_location => .none, |
| 5140 | .location => |location| try builder.debugLocation( | 5160 | .location => |location| (try builder.debugLocation( |
| 5141 | location.line, | 5161 | location.line, |
| 5142 | location.column, | 5162 | location.column, |
| 5143 | location.scope, | 5163 | location.scope.unwrap().?, |
| 5144 | location.inlined_at, | 5164 | location.inlined_at.unwrap(), |
| 5145 | ), | 5165 | )).toOptional(), |
| 5146 | }; | 5166 | }; |
| 5147 | } | 5167 | } |
| 5148 | }; | 5168 | }; |
| ... | @@ -5280,20 +5300,19 @@ pub const WipFunction = struct { | ... | @@ -5280,20 +5300,19 @@ pub const WipFunction = struct { |
| 5280 | .cond = cond, | 5300 | .cond = cond, |
| 5281 | .then = then, | 5301 | .then = then, |
| 5282 | .@"else" = @"else", | 5302 | .@"else" = @"else", |
| 5283 | .weights = switch (weights) { | 5303 | .weights = weights: switch (weights) { |
| 5284 | .none => .none, | 5304 | .none => .none, |
| 5285 | .unpredictable => .unpredictable, | 5305 | .unpredictable => .unpredictable, |
| 5286 | .then_likely, .else_likely => w: { | 5306 | .then_likely, .else_likely => { |
| 5287 | const branch_weights_str = try self.builder.metadataString("branch_weights"); | 5307 | const branch_weights_str = try self.builder.metadataString("branch_weights"); |
| 5288 | const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1)); | 5308 | const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1)); |
| 5289 | const likely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 2000)); | 5309 | const likely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 2000)); |
| 5290 | const weight_vals: [2]Metadata = switch (weights) { | 5310 | const weight_vals: [3]Metadata = switch (weights) { |
| 5291 | .none, .unpredictable => unreachable, | 5311 | .none, .unpredictable => unreachable, |
| 5292 | .then_likely => .{ likely_const, unlikely_const }, | 5312 | .then_likely => .{ branch_weights_str.toMetadata(), likely_const, unlikely_const }, |
| 5293 | .else_likely => .{ unlikely_const, likely_const }, | 5313 | .else_likely => .{ branch_weights_str.toMetadata(), unlikely_const, likely_const }, |
| 5294 | }; | 5314 | }; |
| 5295 | const tuple = try self.builder.strTuple(branch_weights_str, &weight_vals); | 5315 | break :weights .fromMetadata(try self.builder.metadataTuple(&weight_vals)); |
| 5296 | break :w @enumFromInt(@intFromEnum(tuple)); | | |
| 5297 | }, | 5316 | }, |
| 5298 | }, | 5317 | }, |
| 5299 | }), | 5318 | }), |
| ... | @@ -6197,20 +6216,18 @@ pub const WipFunction = struct { | ... | @@ -6197,20 +6216,18 @@ pub const WipFunction = struct { |
| 6197 | return instruction.toValue(); | 6216 | return instruction.toValue(); |
| 6198 | } | 6217 | } |
| 6199 | | 6218 | |
| 6200 | pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata { | 6219 | pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata.Optional { |
| 6201 | if (self.strip) return .none; | 6220 | if (self.strip) return .none; |
| 6202 | return switch (value.unwrap()) { | 6221 | const metadata: Metadata = metadata: switch (value.unwrap()) { |
| 6203 | .instruction => |instr_index| blk: { | 6222 | .instruction => |instr_index| { |
| 6204 | const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index); | 6223 | const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index); |
| 6205 | | | |
| 6206 | const metadata: Metadata = @enumFromInt(Metadata.first_local_metadata + gop.index); | | |
| 6207 | if (!gop.found_existing) gop.key_ptr.* = instr_index; | 6224 | if (!gop.found_existing) gop.key_ptr.* = instr_index; |
| 6208 | | 6225 | break :metadata .{ .index = @intCast(gop.index), .kind = .local }; |
| 6209 | break :blk metadata; | | |
| 6210 | }, | 6226 | }, |
| 6211 | .constant => |constant| try self.builder.metadataConstant(constant), | 6227 | .constant => |constant| try self.builder.metadataConstant(constant), |
| 6212 | .metadata => |metadata| metadata, | 6228 | .metadata => |metadata| metadata, |
| 6213 | }; | 6229 | }; |
| | 6230 | return metadata.toOptional(); |
| 6214 | } | 6231 | } |
| 6215 | | 6232 | |
| 6216 | pub fn finish(self: *WipFunction) Allocator.Error!void { | 6233 | pub fn finish(self: *WipFunction) Allocator.Error!void { |
| ... | @@ -7820,7 +7837,7 @@ pub const Value = enum(u32) { | ... | @@ -7820,7 +7837,7 @@ pub const Value = enum(u32) { |
| 7820 | else if (@intFromEnum(self) < first_metadata) | 7837 | else if (@intFromEnum(self) < first_metadata) |
| 7821 | .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) } | 7838 | .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) } |
| 7822 | else | 7839 | else |
| 7823 | .{ .metadata = @enumFromInt(@intFromEnum(self) - first_metadata) }; | 7840 | .{ .metadata = @bitCast(@intFromEnum(self) - first_metadata) }; |
| 7824 | } | 7841 | } |
| 7825 | | 7842 | |
| 7826 | pub fn typeOfWip(self: Value, wip: *const WipFunction) Type { | 7843 | pub fn typeOfWip(self: Value, wip: *const WipFunction) Type { |
| ... | @@ -7873,50 +7890,110 @@ pub const Value = enum(u32) { | ... | @@ -7873,50 +7890,110 @@ pub const Value = enum(u32) { |
| 7873 | } | 7890 | } |
| 7874 | }; | 7891 | }; |
| 7875 | | 7892 | |
| 7876 | pub const MetadataString = enum(u32) { | 7893 | pub const Metadata = packed struct(u32) { |
| 7877 | none = 0, | 7894 | index: u29, |
| 7878 | _, | 7895 | kind: Kind, |
| | 7896 | unused: enum(u1) { unused = 0 } = .unused, |
| 7879 | | 7897 | |
| 7880 | pub fn slice(self: MetadataString, builder: *const Builder) []const u8 { | 7898 | pub const Kind = enum(u2) { |
| 7881 | const index = @intFromEnum(self); | 7899 | string, |
| 7882 | const start = builder.metadata_string_indices.items[index]; | 7900 | node, |
| 7883 | const end = builder.metadata_string_indices.items[index + 1]; | 7901 | forward, |
| 7884 | return builder.metadata_string_bytes.items[start..end]; | 7902 | local, |
| 7885 | } | 7903 | }; |
| 7886 | | 7904 | |
| 7887 | const Adapter = struct { | 7905 | pub const empty_tuple: Metadata = .{ .kind = .node, .index = 0 }; |
| 7888 | builder: *const Builder, | 7906 | |
| 7889 | pub fn hash(_: Adapter, key: []const u8) u32 { | 7907 | pub const Optional = packed struct(u32) { |
| 7890 | return @truncate(std.hash.Wyhash.hash(0, key)); | 7908 | index: u29, |
| | 7909 | kind: Metadata.Kind, |
| | 7910 | is_none: bool, |
| | 7911 | |
| | 7912 | pub const none: Metadata.Optional = .{ .index = 0, .kind = .string, .is_none = true }; |
| | 7913 | pub const empty_tuple: Metadata.Optional = Metadata.empty_tuple.toOptional(); |
| | 7914 | |
| | 7915 | pub fn wrap(metadata: ?Metadata) Metadata.Optional { |
| | 7916 | return (metadata orelse return .none).toOptional(); |
| 7891 | } | 7917 | } |
| 7892 | pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool { | 7918 | pub fn unwrap(metadata: Metadata.Optional) ?Metadata { |
| 7893 | const rhs_metadata_string: MetadataString = @enumFromInt(rhs_index); | 7919 | return if (metadata.is_none) null else .{ .index = metadata.index, .kind = metadata.kind }; |
| 7894 | return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder)); | 7920 | } |
| | 7921 | pub fn toValue(metadata: Metadata.Optional) Value { |
| | 7922 | return if (metadata.unwrap()) |m| m.toValue() else .none; |
| | 7923 | } |
| | 7924 | pub fn toString(metadata: Metadata.Optional) Metadata.String.Optional { |
| | 7925 | return if (metadata.unwrap()) |m| m.toString().toOptional() else .none; |
| 7895 | } | 7926 | } |
| 7896 | }; | 7927 | }; |
| 7897 | | 7928 | pub fn toOptional(metadata: Metadata) Metadata.Optional { |
| 7898 | const FormatData = struct { | 7929 | return .{ .index = metadata.index, .kind = metadata.kind, .is_none = false }; |
| 7899 | metadata_string: MetadataString, | | |
| 7900 | builder: *const Builder, | | |
| 7901 | }; | | |
| 7902 | fn format(data: FormatData, w: *Writer) Writer.Error!void { | | |
| 7903 | try printEscapedString(data.metadata_string.slice(data.builder), .always_quote, w); | | |
| 7904 | } | 7930 | } |
| 7905 | fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Alt(FormatData, format) { | 7931 | pub fn toValue(metadata: Metadata) Value { |
| 7906 | return .{ .data = .{ .metadata_string = self, .builder = builder } }; | 7932 | return @enumFromInt(Value.first_metadata + @as(u32, @bitCast(metadata))); |
| 7907 | } | 7933 | } |
| 7908 | }; | | |
| 7909 | | 7934 | |
| 7910 | pub const Metadata = enum(u32) { | 7935 | pub const String = enum(u32) { |
| 7911 | none = 0, | 7936 | _, |
| 7912 | empty_tuple = 1, | 7937 | |
| 7913 | _, | 7938 | pub const Optional = enum(u32) { |
| | 7939 | none = @bitCast(Metadata.Optional.none), |
| | 7940 | _, |
| | 7941 | |
| | 7942 | pub fn wrap(metadata: ?Metadata.String) Metadata.String.Optional { |
| | 7943 | return (metadata orelse return .none).toOptional(); |
| | 7944 | } |
| | 7945 | pub fn unwrap(metadata: Metadata.String.Optional) ?Metadata.String { |
| | 7946 | return switch (metadata) { |
| | 7947 | .none => null, |
| | 7948 | else => @enumFromInt(@intFromEnum(metadata)), |
| | 7949 | }; |
| | 7950 | } |
| | 7951 | pub fn toMetadata(metadata: Metadata.String.Optional) Metadata.Optional { |
| | 7952 | return if (metadata.unwrap()) |m| m.toMetadata().toOptional() else .none; |
| | 7953 | } |
| | 7954 | }; |
| | 7955 | pub fn toOptional(metadata: Metadata.String) Metadata.String.Optional { |
| | 7956 | return @enumFromInt(@intFromEnum(metadata)); |
| | 7957 | } |
| | 7958 | pub fn toMetadata(metadata: Metadata.String) Metadata { |
| | 7959 | return .{ .index = @intCast(@intFromEnum(metadata)), .kind = .string }; |
| | 7960 | } |
| 7914 | | 7961 | |
| 7915 | const first_forward_reference = 1 << 29; | 7962 | pub fn slice(metadata: Metadata.String, builder: *const Builder) []const u8 { |
| 7916 | const first_local_metadata = 1 << 30; | 7963 | const index = @intFromEnum(metadata); |
| | 7964 | const start = builder.metadata_string_indices.items[index]; |
| | 7965 | const end = builder.metadata_string_indices.items[index + 1]; |
| | 7966 | return builder.metadata_string_bytes.items[start..end]; |
| | 7967 | } |
| | 7968 | |
| | 7969 | const Adapter = struct { |
| | 7970 | builder: *const Builder, |
| | 7971 | pub fn hash(_: Adapter, key: []const u8) u32 { |
| | 7972 | return @truncate(std.hash.Wyhash.hash(0, key)); |
| | 7973 | } |
| | 7974 | pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool { |
| | 7975 | const rhs_metadata: Metadata.String = @enumFromInt(rhs_index); |
| | 7976 | return std.mem.eql(u8, lhs_key, rhs_metadata.slice(ctx.builder)); |
| | 7977 | } |
| | 7978 | }; |
| | 7979 | |
| | 7980 | const FormatData = struct { |
| | 7981 | metadata: Metadata.String, |
| | 7982 | builder: *const Builder, |
| | 7983 | }; |
| | 7984 | fn format(data: FormatData, w: *Writer) Writer.Error!void { |
| | 7985 | try printEscapedString(data.metadata.slice(data.builder), .always_quote, w); |
| | 7986 | } |
| | 7987 | fn fmt(self: Metadata.String, builder: *const Builder) std.fmt.Alt(FormatData, format) { |
| | 7988 | return .{ .data = .{ .metadata = self, .builder = builder } }; |
| | 7989 | } |
| | 7990 | }; |
| | 7991 | pub fn toString(metadata: Metadata) Metadata.String { |
| | 7992 | assert(metadata.kind == .string); |
| | 7993 | return @enumFromInt(metadata.index); |
| | 7994 | } |
| 7917 | | 7995 | |
| 7918 | pub const Tag = enum(u6) { | 7996 | pub const Tag = enum(u6) { |
| 7919 | none, | | |
| 7920 | file, | 7997 | file, |
| 7921 | compile_unit, | 7998 | compile_unit, |
| 7922 | @"compile_unit optimized", | 7999 | @"compile_unit optimized", |
| ... | @@ -7947,8 +8024,6 @@ pub const Metadata = enum(u32) { | ... | @@ -7947,8 +8024,6 @@ pub const Metadata = enum(u32) { |
| 7947 | enumerator_signed_negative, | 8024 | enumerator_signed_negative, |
| 7948 | subrange, | 8025 | subrange, |
| 7949 | tuple, | 8026 | tuple, |
| 7950 | str_tuple, | | |
| 7951 | module_flag, | | |
| 7952 | expression, | 8027 | expression, |
| 7953 | local_var, | 8028 | local_var, |
| 7954 | parameter, | 8029 | parameter, |
| ... | @@ -7957,9 +8032,8 @@ pub const Metadata = enum(u32) { | ... | @@ -7957,9 +8032,8 @@ pub const Metadata = enum(u32) { |
| 7957 | global_var_expression, | 8032 | global_var_expression, |
| 7958 | constant, | 8033 | constant, |
| 7959 | | 8034 | |
| 7960 | pub fn isInline(tag: Tag) bool { | 8035 | pub fn isInline(metadata_tag: Metadata.Tag) bool { |
| 7961 | return switch (tag) { | 8036 | return switch (metadata_tag) { |
| 7962 | .none, | | |
| 7963 | .expression, | 8037 | .expression, |
| 7964 | .constant, | 8038 | .constant, |
| 7965 | => true, | 8039 | => true, |
| ... | @@ -7993,8 +8067,6 @@ pub const Metadata = enum(u32) { | ... | @@ -7993,8 +8067,6 @@ pub const Metadata = enum(u32) { |
| 7993 | .enumerator_signed_negative, | 8067 | .enumerator_signed_negative, |
| 7994 | .subrange, | 8068 | .subrange, |
| 7995 | .tuple, | 8069 | .tuple, |
| 7996 | .str_tuple, | | |
| 7997 | .module_flag, | | |
| 7998 | .local_var, | 8070 | .local_var, |
| 7999 | .parameter, | 8071 | .parameter, |
| 8000 | .global_var, | 8072 | .global_var, |
| ... | @@ -8005,20 +8077,31 @@ pub const Metadata = enum(u32) { | ... | @@ -8005,20 +8077,31 @@ pub const Metadata = enum(u32) { |
| 8005 | } | 8077 | } |
| 8006 | }; | 8078 | }; |
| 8007 | | 8079 | |
| 8008 | pub fn isInline(self: Metadata, builder: *const Builder) bool { | 8080 | pub fn tag(metadata: Metadata, builder: *const Builder) Tag { |
| 8009 | return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline(); | 8081 | assert(metadata.kind == .node); |
| | 8082 | return builder.metadata_items.items(.tag)[metadata.index]; |
| 8010 | } | 8083 | } |
| 8011 | | 8084 | |
| 8012 | pub fn unwrap(self: Metadata, builder: *const Builder) Metadata { | 8085 | pub fn item(metadata: Metadata, builder: *const Builder) Item { |
| 8013 | var metadata = self; | 8086 | assert(metadata.kind == .node); |
| 8014 | while (@intFromEnum(metadata) >= Metadata.first_forward_reference and | 8087 | return builder.metadata_items.get(metadata.index); |
| 8015 | @intFromEnum(metadata) < Metadata.first_local_metadata) | 8088 | } |
| 8016 | { | 8089 | |
| 8017 | const index = @intFromEnum(metadata) - Metadata.first_forward_reference; | 8090 | pub fn isInline(metadata: Metadata, builder: *const Builder) bool { |
| 8018 | metadata = builder.metadata_forward_references.items[index]; | 8091 | return metadata.tag(builder).isInline(); |
| 8019 | assert(metadata != .none); | 8092 | } |
| | 8093 | |
| | 8094 | pub fn unwrap(metadata: Metadata, builder: *const Builder) Metadata { |
| | 8095 | switch (metadata.kind) { |
| | 8096 | .string, .node, .local => return metadata, |
| | 8097 | .forward => { |
| | 8098 | const referenced = builder.metadata_forward_references.items[metadata.index].unwrap().?; |
| | 8099 | switch (referenced.kind) { |
| | 8100 | .string, .node => return referenced, |
| | 8101 | .forward, .local => unreachable, |
| | 8102 | } |
| | 8103 | }, |
| 8020 | } | 8104 | } |
| 8021 | return metadata; | | |
| 8022 | } | 8105 | } |
| 8023 | | 8106 | |
| 8024 | pub const Item = struct { | 8107 | pub const Item = struct { |
| ... | @@ -8086,8 +8169,8 @@ pub const Metadata = enum(u32) { | ... | @@ -8086,8 +8169,8 @@ pub const Metadata = enum(u32) { |
| 8086 | }; | 8169 | }; |
| 8087 | | 8170 | |
| 8088 | pub const File = struct { | 8171 | pub const File = struct { |
| 8089 | filename: MetadataString, | 8172 | filename: Metadata.String.Optional, |
| 8090 | directory: MetadataString, | 8173 | directory: Metadata.String.Optional, |
| 8091 | }; | 8174 | }; |
| 8092 | | 8175 | |
| 8093 | pub const CompileUnit = struct { | 8176 | pub const CompileUnit = struct { |
| ... | @@ -8095,10 +8178,10 @@ pub const Metadata = enum(u32) { | ... | @@ -8095,10 +8178,10 @@ pub const Metadata = enum(u32) { |
| 8095 | optimized: bool, | 8178 | optimized: bool, |
| 8096 | }; | 8179 | }; |
| 8097 | | 8180 | |
| 8098 | file: Metadata, | 8181 | file: Metadata.Optional, |
| 8099 | producer: MetadataString, | 8182 | producer: Metadata.String.Optional, |
| 8100 | enums: Metadata, | 8183 | enums: Metadata.Optional, |
| 8101 | globals: Metadata, | 8184 | globals: Metadata.Optional, |
| 8102 | }; | 8185 | }; |
| 8103 | | 8186 | |
| 8104 | pub const Subprogram = struct { | 8187 | pub const Subprogram = struct { |
| ... | @@ -8142,19 +8225,34 @@ pub const Metadata = enum(u32) { | ... | @@ -8142,19 +8225,34 @@ pub const Metadata = enum(u32) { |
| 8142 | } | 8225 | } |
| 8143 | }; | 8226 | }; |
| 8144 | | 8227 | |
| 8145 | file: Metadata, | 8228 | file: Metadata.Optional, |
| 8146 | name: MetadataString, | 8229 | name: Metadata.String.Optional, |
| 8147 | linkage_name: MetadataString, | 8230 | linkage_name: Metadata.String.Optional, |
| 8148 | line: u32, | 8231 | line: u32, |
| 8149 | scope_line: u32, | 8232 | scope_line: u32, |
| 8150 | ty: Metadata, | 8233 | ty: Metadata.Optional, |
| 8151 | di_flags: DIFlags, | 8234 | di_flags: DIFlags, |
| 8152 | compile_unit: Metadata, | 8235 | compile_unit: Metadata.Optional, |
| 8153 | }; | 8236 | }; |
| | 8237 | pub fn getSubprogram(metadata: Metadata, builder: *const Builder) Subprogram { |
| | 8238 | const metadata_item = metadata.item(builder); |
| | 8239 | switch (metadata_item.tag) { |
| | 8240 | else => unreachable, |
| | 8241 | .subprogram, |
| | 8242 | .@"subprogram local", |
| | 8243 | .@"subprogram definition", |
| | 8244 | .@"subprogram local definition", |
| | 8245 | .@"subprogram optimized", |
| | 8246 | .@"subprogram optimized local", |
| | 8247 | .@"subprogram optimized definition", |
| | 8248 | .@"subprogram optimized local definition", |
| | 8249 | => return builder.metadataExtraData(Metadata.Subprogram, metadata_item.data), |
| | 8250 | } |
| | 8251 | } |
| 8154 | | 8252 | |
| 8155 | pub const LexicalBlock = struct { | 8253 | pub const LexicalBlock = struct { |
| 8156 | scope: Metadata, | 8254 | scope: Metadata.Optional, |
| 8157 | file: Metadata, | 8255 | file: Metadata.Optional, |
| 8158 | line: u32, | 8256 | line: u32, |
| 8159 | column: u32, | 8257 | column: u32, |
| 8160 | }; | 8258 | }; |
| ... | @@ -8163,11 +8261,11 @@ pub const Metadata = enum(u32) { | ... | @@ -8163,11 +8261,11 @@ pub const Metadata = enum(u32) { |
| 8163 | line: u32, | 8261 | line: u32, |
| 8164 | column: u32, | 8262 | column: u32, |
| 8165 | scope: Metadata, | 8263 | scope: Metadata, |
| 8166 | inlined_at: Metadata, | 8264 | inlined_at: Metadata.Optional, |
| 8167 | }; | 8265 | }; |
| 8168 | | 8266 | |
| 8169 | pub const BasicType = struct { | 8267 | pub const BasicType = struct { |
| 8170 | name: MetadataString, | 8268 | name: Metadata.String.Optional, |
| 8171 | size_in_bits_lo: u32, | 8269 | size_in_bits_lo: u32, |
| 8172 | size_in_bits_hi: u32, | 8270 | size_in_bits_hi: u32, |
| 8173 | | 8271 | |
| ... | @@ -8177,16 +8275,16 @@ pub const Metadata = enum(u32) { | ... | @@ -8177,16 +8275,16 @@ pub const Metadata = enum(u32) { |
| 8177 | }; | 8275 | }; |
| 8178 | | 8276 | |
| 8179 | pub const CompositeType = struct { | 8277 | pub const CompositeType = struct { |
| 8180 | name: MetadataString, | 8278 | name: Metadata.String.Optional, |
| 8181 | file: Metadata, | 8279 | file: Metadata.Optional, |
| 8182 | scope: Metadata, | 8280 | scope: Metadata.Optional, |
| 8183 | line: u32, | 8281 | line: u32, |
| 8184 | underlying_type: Metadata, | 8282 | underlying_type: Metadata.Optional, |
| 8185 | size_in_bits_lo: u32, | 8283 | size_in_bits_lo: u32, |
| 8186 | size_in_bits_hi: u32, | 8284 | size_in_bits_hi: u32, |
| 8187 | align_in_bits_lo: u32, | 8285 | align_in_bits_lo: u32, |
| 8188 | align_in_bits_hi: u32, | 8286 | align_in_bits_hi: u32, |
| 8189 | fields_tuple: Metadata, | 8287 | fields_tuple: Metadata.Optional, |
| 8190 | | 8288 | |
| 8191 | pub fn bitSize(self: CompositeType) u64 { | 8289 | pub fn bitSize(self: CompositeType) u64 { |
| 8192 | return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo; | 8290 | return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo; |
| ... | @@ -8197,11 +8295,11 @@ pub const Metadata = enum(u32) { | ... | @@ -8197,11 +8295,11 @@ pub const Metadata = enum(u32) { |
| 8197 | }; | 8295 | }; |
| 8198 | | 8296 | |
| 8199 | pub const DerivedType = struct { | 8297 | pub const DerivedType = struct { |
| 8200 | name: MetadataString, | 8298 | name: Metadata.String.Optional, |
| 8201 | file: Metadata, | 8299 | file: Metadata.Optional, |
| 8202 | scope: Metadata, | 8300 | scope: Metadata.Optional, |
| 8203 | line: u32, | 8301 | line: u32, |
| 8204 | underlying_type: Metadata, | 8302 | underlying_type: Metadata.Optional, |
| 8205 | size_in_bits_lo: u32, | 8303 | size_in_bits_lo: u32, |
| 8206 | size_in_bits_hi: u32, | 8304 | size_in_bits_hi: u32, |
| 8207 | align_in_bits_lo: u32, | 8305 | align_in_bits_lo: u32, |
| ... | @@ -8221,19 +8319,19 @@ pub const Metadata = enum(u32) { | ... | @@ -8221,19 +8319,19 @@ pub const Metadata = enum(u32) { |
| 8221 | }; | 8319 | }; |
| 8222 | | 8320 | |
| 8223 | pub const SubroutineType = struct { | 8321 | pub const SubroutineType = struct { |
| 8224 | types_tuple: Metadata, | 8322 | types_tuple: Metadata.Optional, |
| 8225 | }; | 8323 | }; |
| 8226 | | 8324 | |
| 8227 | pub const Enumerator = struct { | 8325 | pub const Enumerator = struct { |
| 8228 | name: MetadataString, | 8326 | name: Metadata.String.Optional, |
| 8229 | bit_width: u32, | 8327 | bit_width: u32, |
| 8230 | limbs_index: u32, | 8328 | limbs_index: u32, |
| 8231 | limbs_len: u32, | 8329 | limbs_len: u32, |
| 8232 | }; | 8330 | }; |
| 8233 | | 8331 | |
| 8234 | pub const Subrange = struct { | 8332 | pub const Subrange = struct { |
| 8235 | lower_bound: Metadata, | 8333 | lower_bound: Metadata.Optional, |
| 8236 | count: Metadata, | 8334 | count: Metadata.Optional, |
| 8237 | }; | 8335 | }; |
| 8238 | | 8336 | |
| 8239 | pub const Expression = struct { | 8337 | pub const Expression = struct { |
| ... | @@ -8248,33 +8346,20 @@ pub const Metadata = enum(u32) { | ... | @@ -8248,33 +8346,20 @@ pub const Metadata = enum(u32) { |
| 8248 | // elements: [elements_len]Metadata | 8346 | // elements: [elements_len]Metadata |
| 8249 | }; | 8347 | }; |
| 8250 | | 8348 | |
| 8251 | pub const StrTuple = struct { | | |
| 8252 | str: MetadataString, | | |
| 8253 | elements_len: u32, | | |
| 8254 | | | |
| 8255 | // elements: [elements_len]Metadata | | |
| 8256 | }; | | |
| 8257 | | | |
| 8258 | pub const ModuleFlag = struct { | | |
| 8259 | behavior: Metadata, | | |
| 8260 | name: MetadataString, | | |
| 8261 | constant: Metadata, | | |
| 8262 | }; | | |
| 8263 | | | |
| 8264 | pub const LocalVar = struct { | 8349 | pub const LocalVar = struct { |
| 8265 | name: MetadataString, | 8350 | name: Metadata.String.Optional, |
| 8266 | file: Metadata, | 8351 | file: Metadata.Optional, |
| 8267 | scope: Metadata, | 8352 | scope: Metadata.Optional, |
| 8268 | line: u32, | 8353 | line: u32, |
| 8269 | ty: Metadata, | 8354 | ty: Metadata.Optional, |
| 8270 | }; | 8355 | }; |
| 8271 | | 8356 | |
| 8272 | pub const Parameter = struct { | 8357 | pub const Parameter = struct { |
| 8273 | name: MetadataString, | 8358 | name: Metadata.String.Optional, |
| 8274 | file: Metadata, | 8359 | file: Metadata.Optional, |
| 8275 | scope: Metadata, | 8360 | scope: Metadata.Optional, |
| 8276 | line: u32, | 8361 | line: u32, |
| 8277 | ty: Metadata, | 8362 | ty: Metadata.Optional, |
| 8278 | arg_no: u32, | 8363 | arg_no: u32, |
| 8279 | }; | 8364 | }; |
| 8280 | | 8365 | |
| ... | @@ -8283,24 +8368,20 @@ pub const Metadata = enum(u32) { | ... | @@ -8283,24 +8368,20 @@ pub const Metadata = enum(u32) { |
| 8283 | local: bool, | 8368 | local: bool, |
| 8284 | }; | 8369 | }; |
| 8285 | | 8370 | |
| 8286 | name: MetadataString, | 8371 | name: Metadata.String.Optional, |
| 8287 | linkage_name: MetadataString, | 8372 | linkage_name: Metadata.String.Optional, |
| 8288 | file: Metadata, | 8373 | file: Metadata.Optional, |
| 8289 | scope: Metadata, | 8374 | scope: Metadata.Optional, |
| 8290 | line: u32, | 8375 | line: u32, |
| 8291 | ty: Metadata, | 8376 | ty: Metadata.Optional, |
| 8292 | variable: Variable.Index, | 8377 | variable: Variable.Index, |
| 8293 | }; | 8378 | }; |
| 8294 | | 8379 | |
| 8295 | pub const GlobalVarExpression = struct { | 8380 | pub const GlobalVarExpression = struct { |
| 8296 | variable: Metadata, | 8381 | variable: Metadata.Optional, |
| 8297 | expression: Metadata, | 8382 | expression: Metadata.Optional, |
| 8298 | }; | 8383 | }; |
| 8299 | | 8384 | |
| 8300 | pub fn toValue(self: Metadata) Value { | | |
| 8301 | return @enumFromInt(Value.first_metadata + @intFromEnum(self)); | | |
| 8302 | } | | |
| 8303 | | | |
| 8304 | const Formatter = struct { | 8385 | const Formatter = struct { |
| 8305 | builder: *Builder, | 8386 | builder: *Builder, |
| 8306 | need_comma: bool, | 8387 | need_comma: bool, |
| ... | @@ -8325,7 +8406,7 @@ pub const Metadata = enum(u32) { | ... | @@ -8325,7 +8406,7 @@ pub const Metadata = enum(u32) { |
| 8325 | local_inline: Metadata, | 8406 | local_inline: Metadata, |
| 8326 | local_index: u32, | 8407 | local_index: u32, |
| 8327 | | 8408 | |
| 8328 | string: MetadataString, | 8409 | string: Metadata.String, |
| 8329 | bool: bool, | 8410 | bool: bool, |
| 8330 | u32: u32, | 8411 | u32: u32, |
| 8331 | u64: u64, | 8412 | u64: u64, |
| ... | @@ -8356,10 +8437,10 @@ pub const Metadata = enum(u32) { | ... | @@ -8356,10 +8437,10 @@ pub const Metadata = enum(u32) { |
| 8356 | defer data.formatter.need_comma = needed_comma; | 8437 | defer data.formatter.need_comma = needed_comma; |
| 8357 | data.formatter.need_comma = false; | 8438 | data.formatter.need_comma = false; |
| 8358 | | 8439 | |
| 8359 | const item = builder.metadata_items.get(@intFromEnum(node)); | 8440 | const node_item = node.item(builder); |
| 8360 | switch (item.tag) { | 8441 | switch (node_item.tag) { |
| 8361 | .expression => { | 8442 | .expression => { |
| 8362 | var extra = builder.metadataExtraDataTrail(Expression, item.data); | 8443 | var extra = builder.metadataExtraDataTrail(Expression, node_item.data); |
| 8363 | const elements = extra.trail.next(extra.data.elements_len, u32, builder); | 8444 | const elements = extra.trail.next(extra.data.elements_len, u32, builder); |
| 8364 | try w.writeAll("!DIExpression("); | 8445 | try w.writeAll("!DIExpression("); |
| 8365 | for (elements) |element| try format(.{ | 8446 | for (elements) |element| try format(.{ |
| ... | @@ -8370,7 +8451,7 @@ pub const Metadata = enum(u32) { | ... | @@ -8370,7 +8451,7 @@ pub const Metadata = enum(u32) { |
| 8370 | try w.writeByte(')'); | 8451 | try w.writeByte(')'); |
| 8371 | }, | 8452 | }, |
| 8372 | .constant => try Constant.format(.{ | 8453 | .constant => try Constant.format(.{ |
| 8373 | .constant = @enumFromInt(item.data), | 8454 | .constant = @enumFromInt(node_item.data), |
| 8374 | .builder = builder, | 8455 | .builder = builder, |
| 8375 | .flags = data.specialized orelse .{}, | 8456 | .flags = data.specialized orelse .{}, |
| 8376 | }, w), | 8457 | }, w), |
| ... | @@ -8378,17 +8459,17 @@ pub const Metadata = enum(u32) { | ... | @@ -8378,17 +8459,17 @@ pub const Metadata = enum(u32) { |
| 8378 | } | 8459 | } |
| 8379 | }, | 8460 | }, |
| 8380 | .index => |node| try w.print("!{d}", .{node}), | 8461 | .index => |node| try w.print("!{d}", .{node}), |
| 8381 | inline .local_value, .local_metadata => |node, tag| try Value.format(.{ | 8462 | inline .local_value, .local_metadata => |node, node_tag| try Value.format(.{ |
| 8382 | .value = node.value, | 8463 | .value = node.value, |
| 8383 | .function = node.function, | 8464 | .function = node.function, |
| 8384 | .builder = builder, | 8465 | .builder = builder, |
| 8385 | .flags = switch (tag) { | 8466 | .flags = switch (node_tag) { |
| 8386 | .local_value => data.specialized orelse .{}, | 8467 | .local_value => data.specialized orelse .{}, |
| 8387 | .local_metadata => .{ .percent = true }, | 8468 | .local_metadata => .{ .percent = true }, |
| 8388 | else => unreachable, | 8469 | else => unreachable, |
| 8389 | }, | 8470 | }, |
| 8390 | }, w), | 8471 | }, w), |
| 8391 | inline .local_inline, .local_index => |node, tag| { | 8472 | inline .local_inline, .local_index => |node, node_tag| { |
| 8392 | if (data.specialized) |flags| { | 8473 | if (data.specialized) |flags| { |
| 8393 | if (flags.onlyPercent()) { | 8474 | if (flags.onlyPercent()) { |
| 8394 | try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)}); | 8475 | try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)}); |
| ... | @@ -8396,39 +8477,43 @@ pub const Metadata = enum(u32) { | ... | @@ -8396,39 +8477,43 @@ pub const Metadata = enum(u32) { |
| 8396 | } | 8477 | } |
| 8397 | try format(.{ | 8478 | try format(.{ |
| 8398 | .formatter = data.formatter, | 8479 | .formatter = data.formatter, |
| 8399 | .node = @unionInit(FormatData.Node, @tagName(tag)["local_".len..], node), | 8480 | .node = @unionInit(FormatData.Node, @tagName(node_tag)["local_".len..], node), |
| 8400 | .specialized = .{ .percent = true }, | 8481 | .specialized = .{ .percent = true }, |
| 8401 | }, w); | 8482 | }, w); |
| 8402 | }, | 8483 | }, |
| 8403 | .string => |node| try w.print("{s}{f}", .{ | 8484 | .string => |s| { |
| 8404 | @as([]const u8, if (is_specialized) "!" else ""), node.fmt(builder), | 8485 | if (is_specialized) try w.writeByte('!'); |
| 8405 | }), | 8486 | try w.print("{f}", .{s.fmt(builder)}); |
| | 8487 | }, |
| 8406 | inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}), | 8488 | inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}), |
| 8407 | inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}), | 8489 | inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}), |
| 8408 | .raw => |node| try w.writeAll(node), | 8490 | .raw => |node| try w.writeAll(node), |
| 8409 | } | 8491 | } |
| 8410 | } | 8492 | } |
| 8411 | inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) { | 8493 | inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) { |
| 8412 | Metadata => Allocator.Error, | 8494 | Metadata, Metadata.Optional, ?Metadata => Allocator.Error, |
| 8413 | else => error{}, | 8495 | else => error{}, |
| 8414 | }!std.fmt.Alt(FormatData, format) { | 8496 | }!std.fmt.Alt(FormatData, format) { |
| 8415 | const Node = @TypeOf(node); | 8497 | const Node = @TypeOf(node); |
| 8416 | const MaybeNode = switch (@typeInfo(Node)) { | 8498 | const MaybeNode = switch (Node) { |
| 8417 | .optional => Node, | 8499 | Metadata.Optional => ?Metadata, |
| 8418 | .null => ?noreturn, | 8500 | Metadata.String.Optional => ?Metadata.String, |
| 8419 | else => ?Node, | 8501 | else => switch (@typeInfo(Node)) { |
| | 8502 | .optional => Node, |
| | 8503 | .null => ?noreturn, |
| | 8504 | else => ?Node, |
| | 8505 | }, |
| 8420 | }; | 8506 | }; |
| 8421 | const Some = @typeInfo(MaybeNode).optional.child; | 8507 | const Some = @typeInfo(MaybeNode).optional.child; |
| 8422 | return .{ .data = .{ | 8508 | return .{ .data = .{ |
| 8423 | .formatter = formatter, | 8509 | .formatter = formatter, |
| 8424 | .prefix = prefix, | 8510 | .prefix = prefix, |
| 8425 | .node = if (@as(MaybeNode, node)) |some| switch (@typeInfo(Some)) { | 8511 | .node = if (@as(MaybeNode, switch (Node) { |
| | 8512 | Metadata.Optional, Metadata.String.Optional => node.unwrap(), |
| | 8513 | else => node, |
| | 8514 | })) |some| switch (@typeInfo(Some)) { |
| 8426 | .@"enum" => |enum_info| switch (Some) { | 8515 | .@"enum" => |enum_info| switch (Some) { |
| 8427 | Metadata => switch (some) { | 8516 | Metadata.String => .{ .string = some }, |
| 8428 | .none => .none, | | |
| 8429 | else => try formatter.refUnwrapped(some.unwrap(formatter.builder)), | | |
| 8430 | }, | | |
| 8431 | MetadataString => .{ .string = some }, | | |
| 8432 | else => if (enum_info.is_exhaustive) | 8517 | else => if (enum_info.is_exhaustive) |
| 8433 | .{ .raw = @tagName(some) } | 8518 | .{ .raw = @tagName(some) } |
| 8434 | else | 8519 | else |
| ... | @@ -8438,15 +8523,23 @@ pub const Metadata = enum(u32) { | ... | @@ -8438,15 +8523,23 @@ pub const Metadata = enum(u32) { |
| 8438 | .bool => .{ .bool = some }, | 8523 | .bool => .{ .bool = some }, |
| 8439 | .@"struct" => switch (Some) { | 8524 | .@"struct" => switch (Some) { |
| 8440 | DIFlags => .{ .di_flags = some }, | 8525 | DIFlags => .{ .di_flags = some }, |
| | 8526 | Metadata => switch (some.kind) { |
| | 8527 | .string => .{ .string = some.toString() }, |
| | 8528 | .node, .forward => try formatter.refUnwrapped(some.unwrap(formatter.builder)), |
| | 8529 | .local => unreachable, |
| | 8530 | }, |
| 8441 | Subprogram.DISPFlags => .{ .sp_flags = some }, | 8531 | Subprogram.DISPFlags => .{ .sp_flags = some }, |
| 8442 | else => @compileError("unknown type to format: " ++ @typeName(Node)), | 8532 | else => @compileError("unknown type to format: " ++ @typeName(Node)), |
| 8443 | }, | 8533 | }, |
| 8444 | .int, .comptime_int => .{ .u64 = some }, | 8534 | .int, .comptime_int => .{ .u64 = some }, |
| 8445 | .pointer => .{ .raw = some }, | 8535 | .pointer => .{ .raw = some }, |
| 8446 | else => @compileError("unknown type to format: " ++ @typeName(Node)), | 8536 | else => @compileError("unknown type to format: " ++ @typeName(Node)), |
| 8447 | } else switch (@typeInfo(Node)) { | 8537 | } else switch (Node) { |
| 8448 | .optional, .null => .none, | 8538 | Metadata.Optional, Metadata.String.Optional => .none, |
| 8449 | else => unreachable, | 8539 | else => switch (@typeInfo(Node)) { |
| | 8540 | .optional, .null => .none, |
| | 8541 | else => unreachable, |
| | 8542 | }, |
| 8450 | }, | 8543 | }, |
| 8451 | .specialized = special, | 8544 | .specialized = special, |
| 8452 | } }; | 8545 | } }; |
| ... | @@ -8460,24 +8553,26 @@ pub const Metadata = enum(u32) { | ... | @@ -8460,24 +8553,26 @@ pub const Metadata = enum(u32) { |
| 8460 | return .{ .data = .{ | 8553 | return .{ .data = .{ |
| 8461 | .formatter = formatter, | 8554 | .formatter = formatter, |
| 8462 | .prefix = prefix, | 8555 | .prefix = prefix, |
| 8463 | .node = switch (value.unwrap()) { | 8556 | .node = node: switch (value.unwrap()) { |
| 8464 | .instruction, .constant => .{ .local_value = .{ | 8557 | .instruction, .constant => .{ .local_value = .{ |
| 8465 | .value = value, | 8558 | .value = value, |
| 8466 | .function = function, | 8559 | .function = function, |
| 8467 | } }, | 8560 | } }, |
| 8468 | .metadata => |metadata| if (value == .none) .none else node: { | 8561 | .metadata => |metadata| if (value == .none) .none else { |
| 8469 | const unwrapped = metadata.unwrap(formatter.builder); | 8562 | const unwrapped = metadata.unwrap(formatter.builder); |
| 8470 | break :node if (@intFromEnum(unwrapped) >= first_local_metadata) | 8563 | break :node switch (unwrapped.kind) { |
| 8471 | .{ .local_metadata = .{ | 8564 | .string, .node => switch (try formatter.refUnwrapped(unwrapped)) { |
| | 8565 | .@"inline" => |node| .{ .local_inline = node }, |
| | 8566 | .index => |node| .{ .local_index = node }, |
| | 8567 | else => unreachable, |
| | 8568 | }, |
| | 8569 | .forward => unreachable, |
| | 8570 | .local => .{ .local_metadata = .{ |
| 8472 | .value = function.ptrConst(formatter.builder).debug_values[ | 8571 | .value = function.ptrConst(formatter.builder).debug_values[ |
| 8473 | @intFromEnum(unwrapped) - first_local_metadata | 8572 | unwrapped.index |
| 8474 | ].toValue(), | 8573 | ].toValue(), |
| 8475 | .function = function, | 8574 | .function = function, |
| 8476 | } } | 8575 | } }, |
| 8477 | else switch (try formatter.refUnwrapped(unwrapped)) { | | |
| 8478 | .@"inline" => |node| .{ .local_inline = node }, | | |
| 8479 | .index => |node| .{ .local_index = node }, | | |
| 8480 | else => unreachable, | | |
| 8481 | }; | 8576 | }; |
| 8482 | }, | 8577 | }, |
| 8483 | }, | 8578 | }, |
| ... | @@ -8485,16 +8580,12 @@ pub const Metadata = enum(u32) { | ... | @@ -8485,16 +8580,12 @@ pub const Metadata = enum(u32) { |
| 8485 | } }; | 8580 | } }; |
| 8486 | } | 8581 | } |
| 8487 | fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node { | 8582 | fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node { |
| 8488 | assert(node != .none); | | |
| 8489 | assert(@intFromEnum(node) < first_forward_reference); | | |
| 8490 | const builder = formatter.builder; | 8583 | const builder = formatter.builder; |
| 8491 | const unwrapped_metadata = node.unwrap(builder); | 8584 | const unwrapped_metadata = node.unwrap(builder); |
| 8492 | const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)]; | 8585 | switch (unwrapped_metadata.tag(builder)) { |
| 8493 | switch (tag) { | | |
| 8494 | .none => unreachable, | | |
| 8495 | .expression, .constant => return .{ .@"inline" = unwrapped_metadata }, | 8586 | .expression, .constant => return .{ .@"inline" = unwrapped_metadata }, |
| 8496 | else => { | 8587 | else => |metadata_tag| { |
| 8497 | assert(!tag.isInline()); | 8588 | assert(!metadata_tag.isInline()); |
| 8498 | const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata }); | 8589 | const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata }); |
| 8499 | return .{ .index = @intCast(gop.index) }; | 8590 | return .{ .index = @intCast(gop.index) }; |
| 8500 | }, | 8591 | }, |
| ... | @@ -8669,11 +8760,9 @@ pub fn init(options: Options) Allocator.Error!Builder { | ... | @@ -8669,11 +8760,9 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8669 | assert(try self.intConst(.i32, 1) == .@"1"); | 8760 | assert(try self.intConst(.i32, 1) == .@"1"); |
| 8670 | assert(try self.noneConst(.token) == .none); | 8761 | assert(try self.noneConst(.token) == .none); |
| 8671 | | 8762 | |
| 8672 | assert(try self.metadataNone() == .none); | 8763 | assert(try self.metadataTuple(&.{}) == Metadata.empty_tuple); |
| 8673 | assert(try self.metadataTuple(&.{}) == .empty_tuple); | | |
| 8674 | | 8764 | |
| 8675 | try self.metadata_string_indices.append(self.gpa, 0); | 8765 | try self.metadata_string_indices.append(self.gpa, 0); |
| 8676 | assert(try self.metadataString("") == .none); | | |
| 8677 | | 8766 | |
| 8678 | return self; | 8767 | return self; |
| 8679 | } | 8768 | } |
| ... | @@ -9232,8 +9321,8 @@ pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant { | ... | @@ -9232,8 +9321,8 @@ pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant { |
| 9232 | return self.halfConstAssumeCapacity(val); | 9321 | return self.halfConstAssumeCapacity(val); |
| 9233 | } | 9322 | } |
| 9234 | | 9323 | |
| 9235 | pub fn halfValue(self: *Builder, ty: Type, value: f16) Allocator.Error!Value { | 9324 | pub fn halfValue(self: *Builder, value: f16) Allocator.Error!Value { |
| 9236 | return (try self.halfConst(ty, value)).toValue(); | 9325 | return (try self.halfConst(value)).toValue(); |
| 9237 | } | 9326 | } |
| 9238 | | 9327 | |
| 9239 | pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant { | 9328 | pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant { |
| ... | @@ -9241,8 +9330,8 @@ pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant { | ... | @@ -9241,8 +9330,8 @@ pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant { |
| 9241 | return self.bfloatConstAssumeCapacity(val); | 9330 | return self.bfloatConstAssumeCapacity(val); |
| 9242 | } | 9331 | } |
| 9243 | | 9332 | |
| 9244 | pub fn bfloatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value { | 9333 | pub fn bfloatValue(self: *Builder, value: f32) Allocator.Error!Value { |
| 9245 | return (try self.bfloatConst(ty, value)).toValue(); | 9334 | return (try self.bfloatConst(value)).toValue(); |
| 9246 | } | 9335 | } |
| 9247 | | 9336 | |
| 9248 | pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant { | 9337 | pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant { |
| ... | @@ -9250,8 +9339,8 @@ pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant { | ... | @@ -9250,8 +9339,8 @@ pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant { |
| 9250 | return self.floatConstAssumeCapacity(val); | 9339 | return self.floatConstAssumeCapacity(val); |
| 9251 | } | 9340 | } |
| 9252 | | 9341 | |
| 9253 | pub fn floatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value { | 9342 | pub fn floatValue(self: *Builder, value: f32) Allocator.Error!Value { |
| 9254 | return (try self.floatConst(ty, value)).toValue(); | 9343 | return (try self.floatConst(value)).toValue(); |
| 9255 | } | 9344 | } |
| 9256 | | 9345 | |
| 9257 | pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant { | 9346 | pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant { |
| ... | @@ -9259,8 +9348,8 @@ pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant { | ... | @@ -9259,8 +9348,8 @@ pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant { |
| 9259 | return self.doubleConstAssumeCapacity(val); | 9348 | return self.doubleConstAssumeCapacity(val); |
| 9260 | } | 9349 | } |
| 9261 | | 9350 | |
| 9262 | pub fn doubleValue(self: *Builder, ty: Type, value: f64) Allocator.Error!Value { | 9351 | pub fn doubleValue(self: *Builder, value: f64) Allocator.Error!Value { |
| 9263 | return (try self.doubleConst(ty, value)).toValue(); | 9352 | return (try self.doubleConst(value)).toValue(); |
| 9264 | } | 9353 | } |
| 9265 | | 9354 | |
| 9266 | pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant { | 9355 | pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant { |
| ... | @@ -9268,8 +9357,8 @@ pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant { | ... | @@ -9268,8 +9357,8 @@ pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant { |
| 9268 | return self.fp128ConstAssumeCapacity(val); | 9357 | return self.fp128ConstAssumeCapacity(val); |
| 9269 | } | 9358 | } |
| 9270 | | 9359 | |
| 9271 | pub fn fp128Value(self: *Builder, ty: Type, value: f128) Allocator.Error!Value { | 9360 | pub fn fp128Value(self: *Builder, value: f128) Allocator.Error!Value { |
| 9272 | return (try self.fp128Const(ty, value)).toValue(); | 9361 | return (try self.fp128Const(value)).toValue(); |
| 9273 | } | 9362 | } |
| 9274 | | 9363 | |
| 9275 | pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant { | 9364 | pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant { |
| ... | @@ -9277,8 +9366,8 @@ pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant { | ... | @@ -9277,8 +9366,8 @@ pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant { |
| 9277 | return self.x86_fp80ConstAssumeCapacity(val); | 9366 | return self.x86_fp80ConstAssumeCapacity(val); |
| 9278 | } | 9367 | } |
| 9279 | | 9368 | |
| 9280 | pub fn x86_fp80Value(self: *Builder, ty: Type, value: f80) Allocator.Error!Value { | 9369 | pub fn x86_fp80Value(self: *Builder, value: f80) Allocator.Error!Value { |
| 9281 | return (try self.x86_fp80Const(ty, value)).toValue(); | 9370 | return (try self.x86_fp80Const(value)).toValue(); |
| 9282 | } | 9371 | } |
| 9283 | | 9372 | |
| 9284 | pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant { | 9373 | pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant { |
| ... | @@ -9286,8 +9375,8 @@ pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant { | ... | @@ -9286,8 +9375,8 @@ pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant { |
| 9286 | return self.ppc_fp128ConstAssumeCapacity(val); | 9375 | return self.ppc_fp128ConstAssumeCapacity(val); |
| 9287 | } | 9376 | } |
| 9288 | | 9377 | |
| 9289 | pub fn ppc_fp128Value(self: *Builder, ty: Type, value: [2]f64) Allocator.Error!Value { | 9378 | pub fn ppc_fp128Value(self: *Builder, value: [2]f64) Allocator.Error!Value { |
| 9290 | return (try self.ppc_fp128Const(ty, value)).toValue(); | 9379 | return (try self.ppc_fp128Const(value)).toValue(); |
| 9291 | } | 9380 | } |
| 9292 | | 9381 | |
| 9293 | pub fn nullConst(self: *Builder, ty: Type) Allocator.Error!Constant { | 9382 | pub fn nullConst(self: *Builder, ty: Type) Allocator.Error!Constant { |
| ... | @@ -9870,7 +9959,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -9870,7 +9959,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 9870 | .none => {}, | 9959 | .none => {}, |
| 9871 | .unpredictable => try w.writeAll("!unpredictable !{}"), | 9960 | .unpredictable => try w.writeAll("!unpredictable !{}"), |
| 9872 | _ => try w.print("{f}", .{ | 9961 | _ => try w.print("{f}", .{ |
| 9873 | try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.weights))), null), | 9962 | try metadata_formatter.fmt("!prof ", extra.weights.toMetadata(), null), |
| 9874 | }), | 9963 | }), |
| 9875 | } | 9964 | } |
| 9876 | }, | 9965 | }, |
| ... | @@ -10153,7 +10242,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10153,7 +10242,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10153 | .none => {}, | 10242 | .none => {}, |
| 10154 | .unpredictable => try w.writeAll("!unpredictable !{}"), | 10243 | .unpredictable => try w.writeAll("!unpredictable !{}"), |
| 10155 | _ => try w.print("{f}", .{ | 10244 | _ => try w.print("{f}", .{ |
| 10156 | try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.data.weights))), null), | 10245 | try metadata_formatter.fmt("!prof ", extra.data.weights.toMetadata(), null), |
| 10157 | }), | 10246 | }), |
| 10158 | } | 10247 | } |
| 10159 | }, | 10248 | }, |
| ... | @@ -10193,7 +10282,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10193,7 +10282,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10193 | const elements: []const Metadata = | 10282 | const elements: []const Metadata = |
| 10194 | @ptrCast(self.metadata_extra.items[data.index..][0..data.len]); | 10283 | @ptrCast(self.metadata_extra.items[data.index..][0..data.len]); |
| 10195 | try w.writeByte('!'); | 10284 | try w.writeByte('!'); |
| 10196 | try printEscapedString(name.slice(self), .quote_unless_valid_identifier, w); | 10285 | try printEscapedString(name.slice(self).?, .quote_unless_valid_identifier, w); |
| 10197 | try w.writeAll(" = !{"); | 10286 | try w.writeAll(" = !{"); |
| 10198 | metadata_formatter.need_comma = false; | 10287 | metadata_formatter.need_comma = false; |
| 10199 | defer metadata_formatter.need_comma = undefined; | 10288 | defer metadata_formatter.need_comma = undefined; |
| ... | @@ -10223,11 +10312,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10223,11 +10312,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10223 | }, w); | 10312 | }, w); |
| 10224 | continue; | 10313 | continue; |
| 10225 | }, | 10314 | }, |
| 10226 | .metadata => |metadata| self.metadata_items.get(@intFromEnum(metadata)), | 10315 | .metadata => |metadata| metadata.item(self), |
| 10227 | }; | 10316 | }; |
| 10228 | | 10317 | |
| 10229 | switch (metadata_item.tag) { | 10318 | switch (metadata_item.tag) { |
| 10230 | .none, .expression, .constant => unreachable, | 10319 | .expression, .constant => unreachable, |
| 10231 | .file => { | 10320 | .file => { |
| 10232 | const extra = self.metadataExtraData(Metadata.File, metadata_item.data); | 10321 | const extra = self.metadataExtraData(Metadata.File, metadata_item.data); |
| 10233 | try metadata_formatter.specialized(.@"!", .DIFile, .{ | 10322 | try metadata_formatter.specialized(.@"!", .DIFile, .{ |
| ... | @@ -10330,10 +10419,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10330,10 +10419,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10330 | const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data); | 10419 | const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data); |
| 10331 | try metadata_formatter.specialized(.@"!", .DIBasicType, .{ | 10420 | try metadata_formatter.specialized(.@"!", .DIBasicType, .{ |
| 10332 | .tag = null, | 10421 | .tag = null, |
| 10333 | .name = switch (extra.name) { | 10422 | .name = extra.name, |
| 10334 | .none => null, | | |
| 10335 | else => extra.name, | | |
| 10336 | }, | | |
| 10337 | .size = extra.bitSize(), | 10423 | .size = extra.bitSize(), |
| 10338 | .@"align" = null, | 10424 | .@"align" = null, |
| 10339 | .encoding = @as(enum { | 10425 | .encoding = @as(enum { |
| ... | @@ -10371,10 +10457,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10371,10 +10457,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10371 | .composite_array_type, .composite_vector_type => .DW_TAG_array_type, | 10457 | .composite_array_type, .composite_vector_type => .DW_TAG_array_type, |
| 10372 | else => unreachable, | 10458 | else => unreachable, |
| 10373 | }), | 10459 | }), |
| 10374 | .name = switch (extra.name) { | 10460 | .name = extra.name, |
| 10375 | .none => null, | | |
| 10376 | else => extra.name, | | |
| 10377 | }, | | |
| 10378 | .scope = extra.scope, | 10461 | .scope = extra.scope, |
| 10379 | .file = null, | 10462 | .file = null, |
| 10380 | .line = null, | 10463 | .line = null, |
| ... | @@ -10409,10 +10492,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10409,10 +10492,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10409 | .derived_member_type => .DW_TAG_member, | 10492 | .derived_member_type => .DW_TAG_member, |
| 10410 | else => unreachable, | 10493 | else => unreachable, |
| 10411 | }), | 10494 | }), |
| 10412 | .name = switch (extra.name) { | 10495 | .name = extra.name, |
| 10413 | .none => null, | | |
| 10414 | else => extra.name, | | |
| 10415 | }, | | |
| 10416 | .scope = extra.scope, | 10496 | .scope = extra.scope, |
| 10417 | .file = null, | 10497 | .file = null, |
| 10418 | .line = null, | 10498 | .line = null, |
| ... | @@ -10505,25 +10585,6 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10505,25 +10585,6 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10505 | }); | 10585 | }); |
| 10506 | try w.writeAll("}\n"); | 10586 | try w.writeAll("}\n"); |
| 10507 | }, | 10587 | }, |
| 10508 | .str_tuple => { | | |
| 10509 | var extra = self.metadataExtraDataTrail(Metadata.StrTuple, metadata_item.data); | | |
| 10510 | const elements = extra.trail.next(extra.data.elements_len, Metadata, self); | | |
| 10511 | try w.print("!{{{[str]f}", .{ | | |
| 10512 | .str = try metadata_formatter.fmt("", extra.data.str, .{ .percent = true }), | | |
| 10513 | }); | | |
| 10514 | for (elements) |element| try w.print("{[element]f}", .{ | | |
| 10515 | .element = try metadata_formatter.fmt("", element, .{ .percent = true }), | | |
| 10516 | }); | | |
| 10517 | try w.writeAll("}\n"); | | |
| 10518 | }, | | |
| 10519 | .module_flag => { | | |
| 10520 | const extra = self.metadataExtraData(Metadata.ModuleFlag, metadata_item.data); | | |
| 10521 | try w.print("!{{{[behavior]f}{[name]f}{[constant]f}}}\n", .{ | | |
| 10522 | .behavior = try metadata_formatter.fmt("", extra.behavior, .{ .percent = true }), | | |
| 10523 | .name = try metadata_formatter.fmt("", extra.name, .{ .percent = true }), | | |
| 10524 | .constant = try metadata_formatter.fmt("", extra.constant, .{ .percent = true }), | | |
| 10525 | }); | | |
| 10526 | }, | | |
| 10527 | .local_var => { | 10588 | .local_var => { |
| 10528 | const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data); | 10589 | const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data); |
| 10529 | try metadata_formatter.specialized(.@"!", .DILocalVariable, .{ | 10590 | try metadata_formatter.specialized(.@"!", .DILocalVariable, .{ |
| ... | @@ -11914,8 +11975,8 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item. | ... | @@ -11914,8 +11975,8 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item. |
| 11914 | const value = @field(extra, field.name); | 11975 | const value = @field(extra, field.name); |
| 11915 | self.metadata_extra.appendAssumeCapacity(switch (field.type) { | 11976 | self.metadata_extra.appendAssumeCapacity(switch (field.type) { |
| 11916 | u32 => value, | 11977 | u32 => value, |
| 11917 | MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value), | 11978 | Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value), |
| 11918 | Metadata.DIFlags => @bitCast(value), | 11979 | Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value), |
| 11919 | else => @compileError("bad field type: " ++ @typeName(field.type)), | 11980 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 11920 | }); | 11981 | }); |
| 11921 | } | 11982 | } |
| ... | @@ -11953,8 +12014,8 @@ fn metadataExtraDataTrail( | ... | @@ -11953,8 +12014,8 @@ fn metadataExtraDataTrail( |
| 11953 | inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value| | 12014 | inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value| |
| 11954 | @field(result, field.name) = switch (field.type) { | 12015 | @field(result, field.name) = switch (field.type) { |
| 11955 | u32 => value, | 12016 | u32 => value, |
| 11956 | MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value), | 12017 | Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value), |
| 11957 | Metadata.DIFlags => @bitCast(value), | 12018 | Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value), |
| 11958 | else => @compileError("bad field type: " ++ @typeName(field.type)), | 12019 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 11959 | }; | 12020 | }; |
| 11960 | return .{ | 12021 | return .{ |
| ... | @@ -11967,48 +12028,65 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite | ... | @@ -11967,48 +12028,65 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite |
| 11967 | return self.metadataExtraDataTrail(T, index).data; | 12028 | return self.metadataExtraDataTrail(T, index).data; |
| 11968 | } | 12029 | } |
| 11969 | | 12030 | |
| 11970 | pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!MetadataString { | 12031 | pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!Metadata.String { |
| | 12032 | assert(bytes.len > 0); |
| 11971 | try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len); | 12033 | try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len); |
| 11972 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); | 12034 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 11973 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); | 12035 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 11974 | | 12036 | |
| 11975 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted( | 12037 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted( |
| 11976 | bytes, | 12038 | bytes, |
| 11977 | MetadataString.Adapter{ .builder = self }, | 12039 | Metadata.String.Adapter{ .builder = self }, |
| 11978 | ); | 12040 | ); |
| 11979 | if (!gop.found_existing) { | 12041 | if (!gop.found_existing) { |
| 11980 | self.metadata_string_bytes.appendSliceAssumeCapacity(bytes); | 12042 | self.metadata_string_bytes.appendSliceAssumeCapacity(bytes); |
| 11981 | self.metadata_string_indices.appendAssumeCapacity(@intCast(self.metadata_string_bytes.items.len)); | 12043 | self.metadata_string_indices.appendAssumeCapacity( |
| | 12044 | @intCast(self.metadata_string_bytes.items.len), |
| | 12045 | ); |
| 11982 | } | 12046 | } |
| 11983 | return @enumFromInt(gop.index); | 12047 | return @enumFromInt(gop.index); |
| 11984 | } | 12048 | } |
| 11985 | | 12049 | |
| 11986 | pub fn metadataStringFromStrtabString(self: *Builder, str: StrtabString) Allocator.Error!MetadataString { | 12050 | pub fn metadataStringFromStrtabString( |
| 11987 | if (str == .none or str == .empty) return MetadataString.none; | 12051 | self: *Builder, |
| | 12052 | str: StrtabString, |
| | 12053 | ) Allocator.Error!Metadata.String { |
| 11988 | return try self.metadataString(str.slice(self).?); | 12054 | return try self.metadataString(str.slice(self).?); |
| 11989 | } | 12055 | } |
| 11990 | | 12056 | |
| 11991 | pub fn metadataStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!MetadataString { | 12057 | pub fn metadataStringFmt( |
| | 12058 | self: *Builder, |
| | 12059 | comptime fmt_str: []const u8, |
| | 12060 | fmt_args: anytype, |
| | 12061 | ) Allocator.Error!Metadata.String { |
| 11992 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); | 12062 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 11993 | try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args))); | 12063 | try self.metadata_string_bytes.ensureUnusedCapacity( |
| | 12064 | self.gpa, |
| | 12065 | @intCast(std.fmt.count(fmt_str, fmt_args)), |
| | 12066 | ); |
| 11994 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); | 12067 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 11995 | return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args); | 12068 | return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args); |
| 11996 | } | 12069 | } |
| 11997 | | 12070 | |
| 11998 | pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) MetadataString { | 12071 | pub fn metadataStringFmtAssumeCapacity( |
| | 12072 | self: *Builder, |
| | 12073 | comptime fmt_str: []const u8, |
| | 12074 | fmt_args: anytype, |
| | 12075 | ) Metadata.String { |
| 11999 | self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args); | 12076 | self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args); |
| 12000 | return self.trailingMetadataStringAssumeCapacity(); | 12077 | return self.trailingMetadataStringAssumeCapacity(); |
| 12001 | } | 12078 | } |
| 12002 | | 12079 | |
| 12003 | pub fn trailingMetadataString(self: *Builder) Allocator.Error!MetadataString { | 12080 | pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String { |
| 12004 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); | 12081 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 12005 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); | 12082 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 12006 | return self.trailingMetadataStringAssumeCapacity(); | 12083 | return self.trailingMetadataStringAssumeCapacity(); |
| 12007 | } | 12084 | } |
| 12008 | | 12085 | |
| 12009 | pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString { | 12086 | pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String { |
| 12010 | const start = self.metadata_string_indices.getLast(); | 12087 | const start = self.metadata_string_indices.getLast(); |
| 12011 | const bytes: []const u8 = self.metadata_string_bytes.items[start..]; | 12088 | const bytes: []const u8 = self.metadata_string_bytes.items[start..]; |
| | 12089 | assert(bytes.len > 0); |
| 12012 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self }); | 12090 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self }); |
| 12013 | if (gop.found_existing) { | 12091 | if (gop.found_existing) { |
| 12014 | self.metadata_string_bytes.shrinkRetainingCapacity(start); | 12092 | self.metadata_string_bytes.shrinkRetainingCapacity(start); |
| ... | @@ -12018,21 +12096,16 @@ pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString { | ... | @@ -12018,21 +12096,16 @@ pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString { |
| 12018 | return @enumFromInt(gop.index); | 12096 | return @enumFromInt(gop.index); |
| 12019 | } | 12097 | } |
| 12020 | | 12098 | |
| 12021 | pub fn metadataNamed(self: *Builder, name: MetadataString, operands: []const Metadata) Allocator.Error!void { | 12099 | pub fn addNamedMetadata(self: *Builder, name: String, operands: []const Metadata) Allocator.Error!void { |
| 12022 | try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len); | 12100 | try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len); |
| 12023 | try self.metadata_named.ensureUnusedCapacity(self.gpa, 1); | 12101 | try self.metadata_named.ensureUnusedCapacity(self.gpa, 1); |
| 12024 | self.metadataNamedAssumeCapacity(name, operands); | 12102 | self.addNamedMetadataAssumeCapacity(name, operands); |
| 12025 | } | | |
| 12026 | | | |
| 12027 | fn metadataNone(self: *Builder) Allocator.Error!Metadata { | | |
| 12028 | try self.ensureUnusedMetadataCapacity(1, NoExtra, 0); | | |
| 12029 | return self.metadataNoneAssumeCapacity(); | | |
| 12030 | } | 12103 | } |
| 12031 | | 12104 | |
| 12032 | pub fn debugFile( | 12105 | pub fn debugFile( |
| 12033 | self: *Builder, | 12106 | self: *Builder, |
| 12034 | filename: MetadataString, | 12107 | filename: ?Metadata.String, |
| 12035 | directory: MetadataString, | 12108 | directory: ?Metadata.String, |
| 12036 | ) Allocator.Error!Metadata { | 12109 | ) Allocator.Error!Metadata { |
| 12037 | try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0); | 12110 | try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0); |
| 12038 | return self.debugFileAssumeCapacity(filename, directory); | 12111 | return self.debugFileAssumeCapacity(filename, directory); |
| ... | @@ -12040,10 +12113,10 @@ pub fn debugFile( | ... | @@ -12040,10 +12113,10 @@ pub fn debugFile( |
| 12040 | | 12113 | |
| 12041 | pub fn debugCompileUnit( | 12114 | pub fn debugCompileUnit( |
| 12042 | self: *Builder, | 12115 | self: *Builder, |
| 12043 | file: Metadata, | 12116 | file: ?Metadata, |
| 12044 | producer: MetadataString, | 12117 | producer: ?Metadata.String, |
| 12045 | enums: Metadata, | 12118 | enums: ?Metadata, |
| 12046 | globals: Metadata, | 12119 | globals: ?Metadata, |
| 12047 | options: Metadata.CompileUnit.Options, | 12120 | options: Metadata.CompileUnit.Options, |
| 12048 | ) Allocator.Error!Metadata { | 12121 | ) Allocator.Error!Metadata { |
| 12049 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0); | 12122 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0); |
| ... | @@ -12052,14 +12125,14 @@ pub fn debugCompileUnit( | ... | @@ -12052,14 +12125,14 @@ pub fn debugCompileUnit( |
| 12052 | | 12125 | |
| 12053 | pub fn debugSubprogram( | 12126 | pub fn debugSubprogram( |
| 12054 | self: *Builder, | 12127 | self: *Builder, |
| 12055 | file: Metadata, | 12128 | file: ?Metadata, |
| 12056 | name: MetadataString, | 12129 | name: ?Metadata.String, |
| 12057 | linkage_name: MetadataString, | 12130 | linkage_name: ?Metadata.String, |
| 12058 | line: u32, | 12131 | line: u32, |
| 12059 | scope_line: u32, | 12132 | scope_line: u32, |
| 12060 | ty: Metadata, | 12133 | ty: ?Metadata, |
| 12061 | options: Metadata.Subprogram.Options, | 12134 | options: Metadata.Subprogram.Options, |
| 12062 | compile_unit: Metadata, | 12135 | compile_unit: ?Metadata, |
| 12063 | ) Allocator.Error!Metadata { | 12136 | ) Allocator.Error!Metadata { |
| 12064 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0); | 12137 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0); |
| 12065 | return self.debugSubprogramAssumeCapacity( | 12138 | return self.debugSubprogramAssumeCapacity( |
| ... | @@ -12074,32 +12147,60 @@ pub fn debugSubprogram( | ... | @@ -12074,32 +12147,60 @@ pub fn debugSubprogram( |
| 12074 | ); | 12147 | ); |
| 12075 | } | 12148 | } |
| 12076 | | 12149 | |
| 12077 | pub fn debugLexicalBlock(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Allocator.Error!Metadata { | 12150 | pub fn debugLexicalBlock( |
| | 12151 | self: *Builder, |
| | 12152 | scope: ?Metadata, |
| | 12153 | file: ?Metadata, |
| | 12154 | line: u32, |
| | 12155 | column: u32, |
| | 12156 | ) Allocator.Error!Metadata { |
| 12078 | try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0); | 12157 | try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0); |
| 12079 | return self.debugLexicalBlockAssumeCapacity(scope, file, line, column); | 12158 | return self.debugLexicalBlockAssumeCapacity(scope, file, line, column); |
| 12080 | } | 12159 | } |
| 12081 | | 12160 | |
| 12082 | pub fn debugLocation(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Allocator.Error!Metadata { | 12161 | pub fn debugLocation( |
| | 12162 | self: *Builder, |
| | 12163 | line: u32, |
| | 12164 | column: u32, |
| | 12165 | scope: Metadata, |
| | 12166 | inlined_at: ?Metadata, |
| | 12167 | ) Allocator.Error!Metadata { |
| 12083 | try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0); | 12168 | try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0); |
| 12084 | return self.debugLocationAssumeCapacity(line, column, scope, inlined_at); | 12169 | return self.debugLocationAssumeCapacity(line, column, scope, inlined_at); |
| 12085 | } | 12170 | } |
| 12086 | | 12171 | |
| 12087 | pub fn debugBoolType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { | 12172 | pub fn debugBoolType( |
| | 12173 | self: *Builder, |
| | 12174 | name: ?Metadata.String, |
| | 12175 | size_in_bits: u64, |
| | 12176 | ) Allocator.Error!Metadata { |
| 12088 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 12177 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12089 | return self.debugBoolTypeAssumeCapacity(name, size_in_bits); | 12178 | return self.debugBoolTypeAssumeCapacity(name, size_in_bits); |
| 12090 | } | 12179 | } |
| 12091 | | 12180 | |
| 12092 | pub fn debugUnsignedType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { | 12181 | pub fn debugUnsignedType( |
| | 12182 | self: *Builder, |
| | 12183 | name: ?Metadata.String, |
| | 12184 | size_in_bits: u64, |
| | 12185 | ) Allocator.Error!Metadata { |
| 12093 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 12186 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12094 | return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits); | 12187 | return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits); |
| 12095 | } | 12188 | } |
| 12096 | | 12189 | |
| 12097 | pub fn debugSignedType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { | 12190 | pub fn debugSignedType( |
| | 12191 | self: *Builder, |
| | 12192 | name: ?Metadata.String, |
| | 12193 | size_in_bits: u64, |
| | 12194 | ) Allocator.Error!Metadata { |
| 12098 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 12195 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12099 | return self.debugSignedTypeAssumeCapacity(name, size_in_bits); | 12196 | return self.debugSignedTypeAssumeCapacity(name, size_in_bits); |
| 12100 | } | 12197 | } |
| 12101 | | 12198 | |
| 12102 | pub fn debugFloatType(self: *Builder, name: MetadataString, size_in_bits: u64) Allocator.Error!Metadata { | 12199 | pub fn debugFloatType( |
| | 12200 | self: *Builder, |
| | 12201 | name: ?Metadata.String, |
| | 12202 | size_in_bits: u64, |
| | 12203 | ) Allocator.Error!Metadata { |
| 12103 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); | 12204 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12104 | return self.debugFloatTypeAssumeCapacity(name, size_in_bits); | 12205 | return self.debugFloatTypeAssumeCapacity(name, size_in_bits); |
| 12105 | } | 12206 | } |
| ... | @@ -12111,14 +12212,14 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { | ... | @@ -12111,14 +12212,14 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { |
| 12111 | | 12212 | |
| 12112 | pub fn debugStructType( | 12213 | pub fn debugStructType( |
| 12113 | self: *Builder, | 12214 | self: *Builder, |
| 12114 | name: MetadataString, | 12215 | name: ?Metadata.String, |
| 12115 | file: Metadata, | 12216 | file: ?Metadata, |
| 12116 | scope: Metadata, | 12217 | scope: ?Metadata, |
| 12117 | line: u32, | 12218 | line: u32, |
| 12118 | underlying_type: Metadata, | 12219 | underlying_type: ?Metadata, |
| 12119 | size_in_bits: u64, | 12220 | size_in_bits: u64, |
| 12120 | align_in_bits: u64, | 12221 | align_in_bits: u64, |
| 12121 | fields_tuple: Metadata, | 12222 | fields_tuple: ?Metadata, |
| 12122 | ) Allocator.Error!Metadata { | 12223 | ) Allocator.Error!Metadata { |
| 12123 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 12224 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12124 | return self.debugStructTypeAssumeCapacity( | 12225 | return self.debugStructTypeAssumeCapacity( |
| ... | @@ -12135,14 +12236,14 @@ pub fn debugStructType( | ... | @@ -12135,14 +12236,14 @@ pub fn debugStructType( |
| 12135 | | 12236 | |
| 12136 | pub fn debugUnionType( | 12237 | pub fn debugUnionType( |
| 12137 | self: *Builder, | 12238 | self: *Builder, |
| 12138 | name: MetadataString, | 12239 | name: ?Metadata.String, |
| 12139 | file: Metadata, | 12240 | file: ?Metadata, |
| 12140 | scope: Metadata, | 12241 | scope: ?Metadata, |
| 12141 | line: u32, | 12242 | line: u32, |
| 12142 | underlying_type: Metadata, | 12243 | underlying_type: ?Metadata, |
| 12143 | size_in_bits: u64, | 12244 | size_in_bits: u64, |
| 12144 | align_in_bits: u64, | 12245 | align_in_bits: u64, |
| 12145 | fields_tuple: Metadata, | 12246 | fields_tuple: ?Metadata, |
| 12146 | ) Allocator.Error!Metadata { | 12247 | ) Allocator.Error!Metadata { |
| 12147 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 12248 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12148 | return self.debugUnionTypeAssumeCapacity( | 12249 | return self.debugUnionTypeAssumeCapacity( |
| ... | @@ -12159,14 +12260,14 @@ pub fn debugUnionType( | ... | @@ -12159,14 +12260,14 @@ pub fn debugUnionType( |
| 12159 | | 12260 | |
| 12160 | pub fn debugEnumerationType( | 12261 | pub fn debugEnumerationType( |
| 12161 | self: *Builder, | 12262 | self: *Builder, |
| 12162 | name: MetadataString, | 12263 | name: ?Metadata.String, |
| 12163 | file: Metadata, | 12264 | file: ?Metadata, |
| 12164 | scope: Metadata, | 12265 | scope: ?Metadata, |
| 12165 | line: u32, | 12266 | line: u32, |
| 12166 | underlying_type: Metadata, | 12267 | underlying_type: ?Metadata, |
| 12167 | size_in_bits: u64, | 12268 | size_in_bits: u64, |
| 12168 | align_in_bits: u64, | 12269 | align_in_bits: u64, |
| 12169 | fields_tuple: Metadata, | 12270 | fields_tuple: ?Metadata, |
| 12170 | ) Allocator.Error!Metadata { | 12271 | ) Allocator.Error!Metadata { |
| 12171 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 12272 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12172 | return self.debugEnumerationTypeAssumeCapacity( | 12273 | return self.debugEnumerationTypeAssumeCapacity( |
| ... | @@ -12183,14 +12284,14 @@ pub fn debugEnumerationType( | ... | @@ -12183,14 +12284,14 @@ pub fn debugEnumerationType( |
| 12183 | | 12284 | |
| 12184 | pub fn debugArrayType( | 12285 | pub fn debugArrayType( |
| 12185 | self: *Builder, | 12286 | self: *Builder, |
| 12186 | name: MetadataString, | 12287 | name: ?Metadata.String, |
| 12187 | file: Metadata, | 12288 | file: ?Metadata, |
| 12188 | scope: Metadata, | 12289 | scope: ?Metadata, |
| 12189 | line: u32, | 12290 | line: u32, |
| 12190 | underlying_type: Metadata, | 12291 | underlying_type: ?Metadata, |
| 12191 | size_in_bits: u64, | 12292 | size_in_bits: u64, |
| 12192 | align_in_bits: u64, | 12293 | align_in_bits: u64, |
| 12193 | fields_tuple: Metadata, | 12294 | fields_tuple: ?Metadata, |
| 12194 | ) Allocator.Error!Metadata { | 12295 | ) Allocator.Error!Metadata { |
| 12195 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 12296 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12196 | return self.debugArrayTypeAssumeCapacity( | 12297 | return self.debugArrayTypeAssumeCapacity( |
| ... | @@ -12207,14 +12308,14 @@ pub fn debugArrayType( | ... | @@ -12207,14 +12308,14 @@ pub fn debugArrayType( |
| 12207 | | 12308 | |
| 12208 | pub fn debugVectorType( | 12309 | pub fn debugVectorType( |
| 12209 | self: *Builder, | 12310 | self: *Builder, |
| 12210 | name: MetadataString, | 12311 | name: ?Metadata.String, |
| 12211 | file: Metadata, | 12312 | file: ?Metadata, |
| 12212 | scope: Metadata, | 12313 | scope: ?Metadata, |
| 12213 | line: u32, | 12314 | line: u32, |
| 12214 | underlying_type: Metadata, | 12315 | underlying_type: ?Metadata, |
| 12215 | size_in_bits: u64, | 12316 | size_in_bits: u64, |
| 12216 | align_in_bits: u64, | 12317 | align_in_bits: u64, |
| 12217 | fields_tuple: Metadata, | 12318 | fields_tuple: ?Metadata, |
| 12218 | ) Allocator.Error!Metadata { | 12319 | ) Allocator.Error!Metadata { |
| 12219 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); | 12320 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12220 | return self.debugVectorTypeAssumeCapacity( | 12321 | return self.debugVectorTypeAssumeCapacity( |
| ... | @@ -12231,11 +12332,11 @@ pub fn debugVectorType( | ... | @@ -12231,11 +12332,11 @@ pub fn debugVectorType( |
| 12231 | | 12332 | |
| 12232 | pub fn debugPointerType( | 12333 | pub fn debugPointerType( |
| 12233 | self: *Builder, | 12334 | self: *Builder, |
| 12234 | name: MetadataString, | 12335 | name: ?Metadata.String, |
| 12235 | file: Metadata, | 12336 | file: ?Metadata, |
| 12236 | scope: Metadata, | 12337 | scope: ?Metadata, |
| 12237 | line: u32, | 12338 | line: u32, |
| 12238 | underlying_type: Metadata, | 12339 | underlying_type: ?Metadata, |
| 12239 | size_in_bits: u64, | 12340 | size_in_bits: u64, |
| 12240 | align_in_bits: u64, | 12341 | align_in_bits: u64, |
| 12241 | offset_in_bits: u64, | 12342 | offset_in_bits: u64, |
| ... | @@ -12255,11 +12356,11 @@ pub fn debugPointerType( | ... | @@ -12255,11 +12356,11 @@ pub fn debugPointerType( |
| 12255 | | 12356 | |
| 12256 | pub fn debugMemberType( | 12357 | pub fn debugMemberType( |
| 12257 | self: *Builder, | 12358 | self: *Builder, |
| 12258 | name: MetadataString, | 12359 | name: ?Metadata.String, |
| 12259 | file: Metadata, | 12360 | file: ?Metadata, |
| 12260 | scope: Metadata, | 12361 | scope: ?Metadata, |
| 12261 | line: u32, | 12362 | line: u32, |
| 12262 | underlying_type: Metadata, | 12363 | underlying_type: ?Metadata, |
| 12263 | size_in_bits: u64, | 12364 | size_in_bits: u64, |
| 12264 | align_in_bits: u64, | 12365 | align_in_bits: u64, |
| 12265 | offset_in_bits: u64, | 12366 | offset_in_bits: u64, |
| ... | @@ -12277,17 +12378,14 @@ pub fn debugMemberType( | ... | @@ -12277,17 +12378,14 @@ pub fn debugMemberType( |
| 12277 | ); | 12378 | ); |
| 12278 | } | 12379 | } |
| 12279 | | 12380 | |
| 12280 | pub fn debugSubroutineType( | 12381 | pub fn debugSubroutineType(self: *Builder, types_tuple: ?Metadata) Allocator.Error!Metadata { |
| 12281 | self: *Builder, | | |
| 12282 | types_tuple: Metadata, | | |
| 12283 | ) Allocator.Error!Metadata { | | |
| 12284 | try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0); | 12382 | try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0); |
| 12285 | return self.debugSubroutineTypeAssumeCapacity(types_tuple); | 12383 | return self.debugSubroutineTypeAssumeCapacity(types_tuple); |
| 12286 | } | 12384 | } |
| 12287 | | 12385 | |
| 12288 | pub fn debugEnumerator( | 12386 | pub fn debugEnumerator( |
| 12289 | self: *Builder, | 12387 | self: *Builder, |
| 12290 | name: MetadataString, | 12388 | name: ?Metadata.String, |
| 12291 | unsigned: bool, | 12389 | unsigned: bool, |
| 12292 | bit_width: u32, | 12390 | bit_width: u32, |
| 12293 | value: std.math.big.int.Const, | 12391 | value: std.math.big.int.Const, |
| ... | @@ -12300,55 +12398,37 @@ pub fn debugEnumerator( | ... | @@ -12300,55 +12398,37 @@ pub fn debugEnumerator( |
| 12300 | | 12398 | |
| 12301 | pub fn debugSubrange( | 12399 | pub fn debugSubrange( |
| 12302 | self: *Builder, | 12400 | self: *Builder, |
| 12303 | lower_bound: Metadata, | 12401 | lower_bound: ?Metadata, |
| 12304 | count: Metadata, | 12402 | count: ?Metadata, |
| 12305 | ) Allocator.Error!Metadata { | 12403 | ) Allocator.Error!Metadata { |
| 12306 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0); | 12404 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0); |
| 12307 | return self.debugSubrangeAssumeCapacity(lower_bound, count); | 12405 | return self.debugSubrangeAssumeCapacity(lower_bound, count); |
| 12308 | } | 12406 | } |
| 12309 | | 12407 | |
| 12310 | pub fn debugExpression( | 12408 | pub fn debugExpression(self: *Builder, elements: []const u32) Allocator.Error!Metadata { |
| 12311 | self: *Builder, | | |
| 12312 | elements: []const u32, | | |
| 12313 | ) Allocator.Error!Metadata { | | |
| 12314 | try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len); | 12409 | try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len); |
| 12315 | return self.debugExpressionAssumeCapacity(elements); | 12410 | return self.debugExpressionAssumeCapacity(elements); |
| 12316 | } | 12411 | } |
| 12317 | | 12412 | |
| 12318 | pub fn metadataTuple( | 12413 | pub fn metadataTuple(self: *Builder, elements: []const Metadata) Allocator.Error!Metadata { |
| 12319 | self: *Builder, | 12414 | return self.metadataTupleOptionals(@ptrCast(elements)); |
| 12320 | elements: []const Metadata, | | |
| 12321 | ) Allocator.Error!Metadata { | | |
| 12322 | try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len); | | |
| 12323 | return self.metadataTupleAssumeCapacity(elements); | | |
| 12324 | } | | |
| 12325 | | | |
| 12326 | pub fn strTuple( | | |
| 12327 | self: *Builder, | | |
| 12328 | str: MetadataString, | | |
| 12329 | elements: []const Metadata, | | |
| 12330 | ) Allocator.Error!Metadata { | | |
| 12331 | try self.ensureUnusedMetadataCapacity(1, Metadata.StrTuple, elements.len); | | |
| 12332 | return self.strTupleAssumeCapacity(str, elements); | | |
| 12333 | } | 12415 | } |
| 12334 | | 12416 | |
| 12335 | pub fn metadataModuleFlag( | 12417 | pub fn metadataTupleOptionals( |
| 12336 | self: *Builder, | 12418 | self: *Builder, |
| 12337 | behavior: Metadata, | 12419 | elements: []const Metadata.Optional, |
| 12338 | name: MetadataString, | | |
| 12339 | constant: Metadata, | | |
| 12340 | ) Allocator.Error!Metadata { | 12420 | ) Allocator.Error!Metadata { |
| 12341 | try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0); | 12421 | try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len); |
| 12342 | return self.metadataModuleFlagAssumeCapacity(behavior, name, constant); | 12422 | return self.metadataTupleOptionalsAssumeCapacity(elements); |
| 12343 | } | 12423 | } |
| 12344 | | 12424 | |
| 12345 | pub fn debugLocalVar( | 12425 | pub fn debugLocalVar( |
| 12346 | self: *Builder, | 12426 | self: *Builder, |
| 12347 | name: MetadataString, | 12427 | name: ?Metadata.String, |
| 12348 | file: Metadata, | 12428 | file: ?Metadata, |
| 12349 | scope: Metadata, | 12429 | scope: ?Metadata, |
| 12350 | line: u32, | 12430 | line: u32, |
| 12351 | ty: Metadata, | 12431 | ty: ?Metadata, |
| 12352 | ) Allocator.Error!Metadata { | 12432 | ) Allocator.Error!Metadata { |
| 12353 | try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0); | 12433 | try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0); |
| 12354 | return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty); | 12434 | return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty); |
| ... | @@ -12356,11 +12436,11 @@ pub fn debugLocalVar( | ... | @@ -12356,11 +12436,11 @@ pub fn debugLocalVar( |
| 12356 | | 12436 | |
| 12357 | pub fn debugParameter( | 12437 | pub fn debugParameter( |
| 12358 | self: *Builder, | 12438 | self: *Builder, |
| 12359 | name: MetadataString, | 12439 | name: ?Metadata.String, |
| 12360 | file: Metadata, | 12440 | file: ?Metadata, |
| 12361 | scope: Metadata, | 12441 | scope: ?Metadata, |
| 12362 | line: u32, | 12442 | line: u32, |
| 12363 | ty: Metadata, | 12443 | ty: ?Metadata, |
| 12364 | arg_no: u32, | 12444 | arg_no: u32, |
| 12365 | ) Allocator.Error!Metadata { | 12445 | ) Allocator.Error!Metadata { |
| 12366 | try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0); | 12446 | try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0); |
| ... | @@ -12369,12 +12449,12 @@ pub fn debugParameter( | ... | @@ -12369,12 +12449,12 @@ pub fn debugParameter( |
| 12369 | | 12449 | |
| 12370 | pub fn debugGlobalVar( | 12450 | pub fn debugGlobalVar( |
| 12371 | self: *Builder, | 12451 | self: *Builder, |
| 12372 | name: MetadataString, | 12452 | name: ?Metadata.String, |
| 12373 | linkage_name: MetadataString, | 12453 | linkage_name: ?Metadata.String, |
| 12374 | file: Metadata, | 12454 | file: ?Metadata, |
| 12375 | scope: Metadata, | 12455 | scope: ?Metadata, |
| 12376 | line: u32, | 12456 | line: u32, |
| 12377 | ty: Metadata, | 12457 | ty: ?Metadata, |
| 12378 | variable: Variable.Index, | 12458 | variable: Variable.Index, |
| 12379 | options: Metadata.GlobalVar.Options, | 12459 | options: Metadata.GlobalVar.Options, |
| 12380 | ) Allocator.Error!Metadata { | 12460 | ) Allocator.Error!Metadata { |
| ... | @@ -12393,8 +12473,8 @@ pub fn debugGlobalVar( | ... | @@ -12393,8 +12473,8 @@ pub fn debugGlobalVar( |
| 12393 | | 12473 | |
| 12394 | pub fn debugGlobalVarExpression( | 12474 | pub fn debugGlobalVarExpression( |
| 12395 | self: *Builder, | 12475 | self: *Builder, |
| 12396 | variable: Metadata, | 12476 | variable: ?Metadata, |
| 12397 | expression: Metadata, | 12477 | expression: ?Metadata, |
| 12398 | ) Allocator.Error!Metadata { | 12478 | ) Allocator.Error!Metadata { |
| 12399 | try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0); | 12479 | try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0); |
| 12400 | return self.debugGlobalVarExpressionAssumeCapacity(variable, expression); | 12480 | return self.debugGlobalVarExpressionAssumeCapacity(variable, expression); |
| ... | @@ -12405,13 +12485,11 @@ pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadat | ... | @@ -12405,13 +12485,11 @@ pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadat |
| 12405 | return self.metadataConstantAssumeCapacity(value); | 12485 | return self.metadataConstantAssumeCapacity(value); |
| 12406 | } | 12486 | } |
| 12407 | | 12487 | |
| 12408 | pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void { | 12488 | pub fn resolveDebugForwardReference(self: *Builder, fwd_ref: Metadata, value: Metadata) void { |
| 12409 | assert( | 12489 | assert(fwd_ref.kind == .forward); |
| 12410 | @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and | 12490 | const resolved = &self.metadata_forward_references.items[fwd_ref.index]; |
| 12411 | @intFromEnum(fwd_ref) <= Metadata.first_local_metadata, | 12491 | assert(resolved.is_none); |
| 12412 | ); | 12492 | resolved.* = value.toOptional(); |
| 12413 | const index = @intFromEnum(fwd_ref) - Metadata.first_forward_reference; | | |
| 12414 | self.metadata_forward_references.items[index] = ty; | | |
| 12415 | } | 12493 | } |
| 12416 | | 12494 | |
| 12417 | fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata { | 12495 | fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata { |
| ... | @@ -12450,41 +12528,20 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp | ... | @@ -12450,41 +12528,20 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp |
| 12450 | .data = self.addMetadataExtraAssumeCapacity(value), | 12528 | .data = self.addMetadataExtraAssumeCapacity(value), |
| 12451 | }); | 12529 | }); |
| 12452 | } | 12530 | } |
| 12453 | return @enumFromInt(gop.index); | 12531 | return .{ .index = @intCast(gop.index), .kind = .node }; |
| 12454 | } | 12532 | } |
| 12455 | | 12533 | |
| 12456 | fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata { | 12534 | fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata { |
| 12457 | const Key = struct { tag: Metadata.Tag, index: Metadata }; | 12535 | const index = self.metadata_items.len; |
| 12458 | const Adapter = struct { | 12536 | _ = self.metadata_map.entries.addOneAssumeCapacity(); |
| 12459 | pub fn hash(_: @This(), key: Key) u32 { | 12537 | self.metadata_items.appendAssumeCapacity(.{ |
| 12460 | return @truncate(std.hash.Wyhash.hash( | 12538 | .tag = tag, |
| 12461 | std.hash.int(@intFromEnum(key.tag)), | 12539 | .data = self.addMetadataExtraAssumeCapacity(value), |
| 12462 | std.mem.asBytes(&key.index), | 12540 | }); |
| 12463 | )); | 12541 | return .{ .index = @intCast(index), .kind = .node }; |
| 12464 | } | | |
| 12465 | | | |
| 12466 | pub fn eql(_: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { | | |
| 12467 | return @intFromEnum(lhs_key.index) == rhs_index; | | |
| 12468 | } | | |
| 12469 | }; | | |
| 12470 | | | |
| 12471 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( | | |
| 12472 | Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) }, | | |
| 12473 | Adapter{}, | | |
| 12474 | ); | | |
| 12475 | | | |
| 12476 | if (!gop.found_existing) { | | |
| 12477 | gop.key_ptr.* = {}; | | |
| 12478 | gop.value_ptr.* = {}; | | |
| 12479 | self.metadata_items.appendAssumeCapacity(.{ | | |
| 12480 | .tag = tag, | | |
| 12481 | .data = self.addMetadataExtraAssumeCapacity(value), | | |
| 12482 | }); | | |
| 12483 | } | | |
| 12484 | return @enumFromInt(gop.index); | | |
| 12485 | } | 12542 | } |
| 12486 | | 12543 | |
| 12487 | fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void { | 12544 | fn addNamedMetadataAssumeCapacity(self: *Builder, name: String, operands: []const Metadata) void { |
| 12488 | assert(name != .none); | 12545 | assert(name != .none); |
| 12489 | const extra_index: u32 = @intCast(self.metadata_extra.items.len); | 12546 | const extra_index: u32 = @intCast(self.metadata_extra.items.len); |
| 12490 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands)); | 12547 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands)); |
| ... | @@ -12496,119 +12553,127 @@ fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: [ | ... | @@ -12496,119 +12553,127 @@ fn metadataNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: [ |
| 12496 | }; | 12553 | }; |
| 12497 | } | 12554 | } |
| 12498 | | 12555 | |
| 12499 | pub fn metadataNoneAssumeCapacity(self: *Builder) Metadata { | | |
| 12500 | return self.metadataSimpleAssumeCapacity(.none, .{}); | | |
| 12501 | } | | |
| 12502 | | | |
| 12503 | fn debugFileAssumeCapacity( | 12556 | fn debugFileAssumeCapacity( |
| 12504 | self: *Builder, | 12557 | self: *Builder, |
| 12505 | filename: MetadataString, | 12558 | filename: ?Metadata.String, |
| 12506 | directory: MetadataString, | 12559 | directory: ?Metadata.String, |
| 12507 | ) Metadata { | 12560 | ) Metadata { |
| 12508 | assert(!self.strip); | 12561 | assert(!self.strip); |
| 12509 | return self.metadataSimpleAssumeCapacity(.file, Metadata.File{ | 12562 | return self.metadataSimpleAssumeCapacity(.file, Metadata.File{ |
| 12510 | .filename = filename, | 12563 | .filename = .wrap(filename), |
| 12511 | .directory = directory, | 12564 | .directory = .wrap(directory), |
| 12512 | }); | 12565 | }); |
| 12513 | } | 12566 | } |
| 12514 | | 12567 | |
| 12515 | pub fn debugCompileUnitAssumeCapacity( | 12568 | pub fn debugCompileUnitAssumeCapacity( |
| 12516 | self: *Builder, | 12569 | self: *Builder, |
| 12517 | file: Metadata, | 12570 | file: ?Metadata, |
| 12518 | producer: MetadataString, | 12571 | producer: ?Metadata.String, |
| 12519 | enums: Metadata, | 12572 | enums: ?Metadata, |
| 12520 | globals: Metadata, | 12573 | globals: ?Metadata, |
| 12521 | options: Metadata.CompileUnit.Options, | 12574 | options: Metadata.CompileUnit.Options, |
| 12522 | ) Metadata { | 12575 | ) Metadata { |
| 12523 | assert(!self.strip); | 12576 | assert(!self.strip); |
| 12524 | return self.metadataDistinctAssumeCapacity( | 12577 | return self.metadataDistinctAssumeCapacity( |
| 12525 | if (options.optimized) .@"compile_unit optimized" else .compile_unit, | 12578 | if (options.optimized) .@"compile_unit optimized" else .compile_unit, |
| 12526 | Metadata.CompileUnit{ | 12579 | Metadata.CompileUnit{ |
| 12527 | .file = file, | 12580 | .file = .wrap(file), |
| 12528 | .producer = producer, | 12581 | .producer = .wrap(producer), |
| 12529 | .enums = enums, | 12582 | .enums = .wrap(enums), |
| 12530 | .globals = globals, | 12583 | .globals = .wrap(globals), |
| 12531 | }, | 12584 | }, |
| 12532 | ); | 12585 | ); |
| 12533 | } | 12586 | } |
| 12534 | | 12587 | |
| 12535 | fn debugSubprogramAssumeCapacity( | 12588 | fn debugSubprogramAssumeCapacity( |
| 12536 | self: *Builder, | 12589 | self: *Builder, |
| 12537 | file: Metadata, | 12590 | file: ?Metadata, |
| 12538 | name: MetadataString, | 12591 | name: ?Metadata.String, |
| 12539 | linkage_name: MetadataString, | 12592 | linkage_name: ?Metadata.String, |
| 12540 | line: u32, | 12593 | line: u32, |
| 12541 | scope_line: u32, | 12594 | scope_line: u32, |
| 12542 | ty: Metadata, | 12595 | ty: ?Metadata, |
| 12543 | options: Metadata.Subprogram.Options, | 12596 | options: Metadata.Subprogram.Options, |
| 12544 | compile_unit: Metadata, | 12597 | compile_unit: ?Metadata, |
| 12545 | ) Metadata { | 12598 | ) Metadata { |
| 12546 | assert(!self.strip); | 12599 | assert(!self.strip); |
| 12547 | const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) + | 12600 | const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) + |
| 12548 | @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2))); | 12601 | @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2))); |
| 12549 | return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{ | 12602 | return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{ |
| 12550 | .file = file, | 12603 | .file = .wrap(file), |
| 12551 | .name = name, | 12604 | .name = .wrap(name), |
| 12552 | .linkage_name = linkage_name, | 12605 | .linkage_name = .wrap(linkage_name), |
| 12553 | .line = line, | 12606 | .line = line, |
| 12554 | .scope_line = scope_line, | 12607 | .scope_line = scope_line, |
| 12555 | .ty = ty, | 12608 | .ty = .wrap(ty), |
| 12556 | .di_flags = options.di_flags, | 12609 | .di_flags = options.di_flags, |
| 12557 | .compile_unit = compile_unit, | 12610 | .compile_unit = .wrap(compile_unit), |
| 12558 | }); | 12611 | }); |
| 12559 | } | 12612 | } |
| 12560 | | 12613 | |
| 12561 | fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata { | 12614 | fn debugLexicalBlockAssumeCapacity( |
| | 12615 | self: *Builder, |
| | 12616 | scope: ?Metadata, |
| | 12617 | file: ?Metadata, |
| | 12618 | line: u32, |
| | 12619 | column: u32, |
| | 12620 | ) Metadata { |
| 12562 | assert(!self.strip); | 12621 | assert(!self.strip); |
| 12563 | return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{ | 12622 | return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{ |
| 12564 | .scope = scope, | 12623 | .scope = .wrap(scope), |
| 12565 | .file = file, | 12624 | .file = .wrap(file), |
| 12566 | .line = line, | 12625 | .line = line, |
| 12567 | .column = column, | 12626 | .column = column, |
| 12568 | }); | 12627 | }); |
| 12569 | } | 12628 | } |
| 12570 | | 12629 | |
| 12571 | fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata { | 12630 | fn debugLocationAssumeCapacity( |
| | 12631 | self: *Builder, |
| | 12632 | line: u32, |
| | 12633 | column: u32, |
| | 12634 | scope: Metadata, |
| | 12635 | inlined_at: ?Metadata, |
| | 12636 | ) Metadata { |
| 12572 | assert(!self.strip); | 12637 | assert(!self.strip); |
| 12573 | return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{ | 12638 | return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{ |
| 12574 | .line = line, | 12639 | .line = line, |
| 12575 | .column = column, | 12640 | .column = column, |
| 12576 | .scope = scope, | 12641 | .scope = scope, |
| 12577 | .inlined_at = inlined_at, | 12642 | .inlined_at = .wrap(inlined_at), |
| 12578 | }); | 12643 | }); |
| 12579 | } | 12644 | } |
| 12580 | | 12645 | |
| 12581 | fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { | 12646 | fn debugBoolTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata { |
| 12582 | assert(!self.strip); | 12647 | assert(!self.strip); |
| 12583 | return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{ | 12648 | return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{ |
| 12584 | .name = name, | 12649 | .name = .wrap(name), |
| 12585 | .size_in_bits_lo = @truncate(size_in_bits), | 12650 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12586 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12651 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12587 | }); | 12652 | }); |
| 12588 | } | 12653 | } |
| 12589 | | 12654 | |
| 12590 | fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { | 12655 | fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata { |
| 12591 | assert(!self.strip); | 12656 | assert(!self.strip); |
| 12592 | return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{ | 12657 | return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{ |
| 12593 | .name = name, | 12658 | .name = .wrap(name), |
| 12594 | .size_in_bits_lo = @truncate(size_in_bits), | 12659 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12595 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12660 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12596 | }); | 12661 | }); |
| 12597 | } | 12662 | } |
| 12598 | | 12663 | |
| 12599 | fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { | 12664 | fn debugSignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata { |
| 12600 | assert(!self.strip); | 12665 | assert(!self.strip); |
| 12601 | return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{ | 12666 | return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{ |
| 12602 | .name = name, | 12667 | .name = .wrap(name), |
| 12603 | .size_in_bits_lo = @truncate(size_in_bits), | 12668 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12604 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12669 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12605 | }); | 12670 | }); |
| 12606 | } | 12671 | } |
| 12607 | | 12672 | |
| 12608 | fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata { | 12673 | fn debugFloatTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata { |
| 12609 | assert(!self.strip); | 12674 | assert(!self.strip); |
| 12610 | return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{ | 12675 | return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{ |
| 12611 | .name = name, | 12676 | .name = .wrap(name), |
| 12612 | .size_in_bits_lo = @truncate(size_in_bits), | 12677 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12613 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12678 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12614 | }); | 12679 | }); |
| ... | @@ -12616,21 +12681,21 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi | ... | @@ -12616,21 +12681,21 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi |
| 12616 | | 12681 | |
| 12617 | fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata { | 12682 | fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata { |
| 12618 | assert(!self.strip); | 12683 | assert(!self.strip); |
| 12619 | const index = Metadata.first_forward_reference + self.metadata_forward_references.items.len; | 12684 | const index = self.metadata_forward_references.items.len; |
| 12620 | self.metadata_forward_references.appendAssumeCapacity(.none); | 12685 | self.metadata_forward_references.appendAssumeCapacity(.none); |
| 12621 | return @enumFromInt(index); | 12686 | return .{ .index = @intCast(index), .kind = .forward }; |
| 12622 | } | 12687 | } |
| 12623 | | 12688 | |
| 12624 | fn debugStructTypeAssumeCapacity( | 12689 | fn debugStructTypeAssumeCapacity( |
| 12625 | self: *Builder, | 12690 | self: *Builder, |
| 12626 | name: MetadataString, | 12691 | name: ?Metadata.String, |
| 12627 | file: Metadata, | 12692 | file: ?Metadata, |
| 12628 | scope: Metadata, | 12693 | scope: ?Metadata, |
| 12629 | line: u32, | 12694 | line: u32, |
| 12630 | underlying_type: Metadata, | 12695 | underlying_type: ?Metadata, |
| 12631 | size_in_bits: u64, | 12696 | size_in_bits: u64, |
| 12632 | align_in_bits: u64, | 12697 | align_in_bits: u64, |
| 12633 | fields_tuple: Metadata, | 12698 | fields_tuple: ?Metadata, |
| 12634 | ) Metadata { | 12699 | ) Metadata { |
| 12635 | assert(!self.strip); | 12700 | assert(!self.strip); |
| 12636 | return self.debugCompositeTypeAssumeCapacity( | 12701 | return self.debugCompositeTypeAssumeCapacity( |
| ... | @@ -12648,14 +12713,14 @@ fn debugStructTypeAssumeCapacity( | ... | @@ -12648,14 +12713,14 @@ fn debugStructTypeAssumeCapacity( |
| 12648 | | 12713 | |
| 12649 | fn debugUnionTypeAssumeCapacity( | 12714 | fn debugUnionTypeAssumeCapacity( |
| 12650 | self: *Builder, | 12715 | self: *Builder, |
| 12651 | name: MetadataString, | 12716 | name: ?Metadata.String, |
| 12652 | file: Metadata, | 12717 | file: ?Metadata, |
| 12653 | scope: Metadata, | 12718 | scope: ?Metadata, |
| 12654 | line: u32, | 12719 | line: u32, |
| 12655 | underlying_type: Metadata, | 12720 | underlying_type: ?Metadata, |
| 12656 | size_in_bits: u64, | 12721 | size_in_bits: u64, |
| 12657 | align_in_bits: u64, | 12722 | align_in_bits: u64, |
| 12658 | fields_tuple: Metadata, | 12723 | fields_tuple: ?Metadata, |
| 12659 | ) Metadata { | 12724 | ) Metadata { |
| 12660 | assert(!self.strip); | 12725 | assert(!self.strip); |
| 12661 | return self.debugCompositeTypeAssumeCapacity( | 12726 | return self.debugCompositeTypeAssumeCapacity( |
| ... | @@ -12673,14 +12738,14 @@ fn debugUnionTypeAssumeCapacity( | ... | @@ -12673,14 +12738,14 @@ fn debugUnionTypeAssumeCapacity( |
| 12673 | | 12738 | |
| 12674 | fn debugEnumerationTypeAssumeCapacity( | 12739 | fn debugEnumerationTypeAssumeCapacity( |
| 12675 | self: *Builder, | 12740 | self: *Builder, |
| 12676 | name: MetadataString, | 12741 | name: ?Metadata.String, |
| 12677 | file: Metadata, | 12742 | file: ?Metadata, |
| 12678 | scope: Metadata, | 12743 | scope: ?Metadata, |
| 12679 | line: u32, | 12744 | line: u32, |
| 12680 | underlying_type: Metadata, | 12745 | underlying_type: ?Metadata, |
| 12681 | size_in_bits: u64, | 12746 | size_in_bits: u64, |
| 12682 | align_in_bits: u64, | 12747 | align_in_bits: u64, |
| 12683 | fields_tuple: Metadata, | 12748 | fields_tuple: ?Metadata, |
| 12684 | ) Metadata { | 12749 | ) Metadata { |
| 12685 | assert(!self.strip); | 12750 | assert(!self.strip); |
| 12686 | return self.debugCompositeTypeAssumeCapacity( | 12751 | return self.debugCompositeTypeAssumeCapacity( |
| ... | @@ -12698,14 +12763,14 @@ fn debugEnumerationTypeAssumeCapacity( | ... | @@ -12698,14 +12763,14 @@ fn debugEnumerationTypeAssumeCapacity( |
| 12698 | | 12763 | |
| 12699 | fn debugArrayTypeAssumeCapacity( | 12764 | fn debugArrayTypeAssumeCapacity( |
| 12700 | self: *Builder, | 12765 | self: *Builder, |
| 12701 | name: MetadataString, | 12766 | name: ?Metadata.String, |
| 12702 | file: Metadata, | 12767 | file: ?Metadata, |
| 12703 | scope: Metadata, | 12768 | scope: ?Metadata, |
| 12704 | line: u32, | 12769 | line: u32, |
| 12705 | underlying_type: Metadata, | 12770 | underlying_type: ?Metadata, |
| 12706 | size_in_bits: u64, | 12771 | size_in_bits: u64, |
| 12707 | align_in_bits: u64, | 12772 | align_in_bits: u64, |
| 12708 | fields_tuple: Metadata, | 12773 | fields_tuple: ?Metadata, |
| 12709 | ) Metadata { | 12774 | ) Metadata { |
| 12710 | assert(!self.strip); | 12775 | assert(!self.strip); |
| 12711 | return self.debugCompositeTypeAssumeCapacity( | 12776 | return self.debugCompositeTypeAssumeCapacity( |
| ... | @@ -12723,14 +12788,14 @@ fn debugArrayTypeAssumeCapacity( | ... | @@ -12723,14 +12788,14 @@ fn debugArrayTypeAssumeCapacity( |
| 12723 | | 12788 | |
| 12724 | fn debugVectorTypeAssumeCapacity( | 12789 | fn debugVectorTypeAssumeCapacity( |
| 12725 | self: *Builder, | 12790 | self: *Builder, |
| 12726 | name: MetadataString, | 12791 | name: ?Metadata.String, |
| 12727 | file: Metadata, | 12792 | file: ?Metadata, |
| 12728 | scope: Metadata, | 12793 | scope: ?Metadata, |
| 12729 | line: u32, | 12794 | line: u32, |
| 12730 | underlying_type: Metadata, | 12795 | underlying_type: ?Metadata, |
| 12731 | size_in_bits: u64, | 12796 | size_in_bits: u64, |
| 12732 | align_in_bits: u64, | 12797 | align_in_bits: u64, |
| 12733 | fields_tuple: Metadata, | 12798 | fields_tuple: ?Metadata, |
| 12734 | ) Metadata { | 12799 | ) Metadata { |
| 12735 | assert(!self.strip); | 12800 | assert(!self.strip); |
| 12736 | return self.debugCompositeTypeAssumeCapacity( | 12801 | return self.debugCompositeTypeAssumeCapacity( |
| ... | @@ -12749,48 +12814,48 @@ fn debugVectorTypeAssumeCapacity( | ... | @@ -12749,48 +12814,48 @@ fn debugVectorTypeAssumeCapacity( |
| 12749 | fn debugCompositeTypeAssumeCapacity( | 12814 | fn debugCompositeTypeAssumeCapacity( |
| 12750 | self: *Builder, | 12815 | self: *Builder, |
| 12751 | tag: Metadata.Tag, | 12816 | tag: Metadata.Tag, |
| 12752 | name: MetadataString, | 12817 | name: ?Metadata.String, |
| 12753 | file: Metadata, | 12818 | file: ?Metadata, |
| 12754 | scope: Metadata, | 12819 | scope: ?Metadata, |
| 12755 | line: u32, | 12820 | line: u32, |
| 12756 | underlying_type: Metadata, | 12821 | underlying_type: ?Metadata, |
| 12757 | size_in_bits: u64, | 12822 | size_in_bits: u64, |
| 12758 | align_in_bits: u64, | 12823 | align_in_bits: u64, |
| 12759 | fields_tuple: Metadata, | 12824 | fields_tuple: ?Metadata, |
| 12760 | ) Metadata { | 12825 | ) Metadata { |
| 12761 | assert(!self.strip); | 12826 | assert(!self.strip); |
| 12762 | return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{ | 12827 | return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{ |
| 12763 | .name = name, | 12828 | .name = .wrap(name), |
| 12764 | .file = file, | 12829 | .file = .wrap(file), |
| 12765 | .scope = scope, | 12830 | .scope = .wrap(scope), |
| 12766 | .line = line, | 12831 | .line = line, |
| 12767 | .underlying_type = underlying_type, | 12832 | .underlying_type = .wrap(underlying_type), |
| 12768 | .size_in_bits_lo = @truncate(size_in_bits), | 12833 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12769 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12834 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12770 | .align_in_bits_lo = @truncate(align_in_bits), | 12835 | .align_in_bits_lo = @truncate(align_in_bits), |
| 12771 | .align_in_bits_hi = @truncate(align_in_bits >> 32), | 12836 | .align_in_bits_hi = @truncate(align_in_bits >> 32), |
| 12772 | .fields_tuple = fields_tuple, | 12837 | .fields_tuple = .wrap(fields_tuple), |
| 12773 | }); | 12838 | }); |
| 12774 | } | 12839 | } |
| 12775 | | 12840 | |
| 12776 | fn debugPointerTypeAssumeCapacity( | 12841 | fn debugPointerTypeAssumeCapacity( |
| 12777 | self: *Builder, | 12842 | self: *Builder, |
| 12778 | name: MetadataString, | 12843 | name: ?Metadata.String, |
| 12779 | file: Metadata, | 12844 | file: ?Metadata, |
| 12780 | scope: Metadata, | 12845 | scope: ?Metadata, |
| 12781 | line: u32, | 12846 | line: u32, |
| 12782 | underlying_type: Metadata, | 12847 | underlying_type: ?Metadata, |
| 12783 | size_in_bits: u64, | 12848 | size_in_bits: u64, |
| 12784 | align_in_bits: u64, | 12849 | align_in_bits: u64, |
| 12785 | offset_in_bits: u64, | 12850 | offset_in_bits: u64, |
| 12786 | ) Metadata { | 12851 | ) Metadata { |
| 12787 | assert(!self.strip); | 12852 | assert(!self.strip); |
| 12788 | return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{ | 12853 | return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{ |
| 12789 | .name = name, | 12854 | .name = .wrap(name), |
| 12790 | .file = file, | 12855 | .file = .wrap(file), |
| 12791 | .scope = scope, | 12856 | .scope = .wrap(scope), |
| 12792 | .line = line, | 12857 | .line = line, |
| 12793 | .underlying_type = underlying_type, | 12858 | .underlying_type = .wrap(underlying_type), |
| 12794 | .size_in_bits_lo = @truncate(size_in_bits), | 12859 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12795 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12860 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12796 | .align_in_bits_lo = @truncate(align_in_bits), | 12861 | .align_in_bits_lo = @truncate(align_in_bits), |
| ... | @@ -12802,22 +12867,22 @@ fn debugPointerTypeAssumeCapacity( | ... | @@ -12802,22 +12867,22 @@ fn debugPointerTypeAssumeCapacity( |
| 12802 | | 12867 | |
| 12803 | fn debugMemberTypeAssumeCapacity( | 12868 | fn debugMemberTypeAssumeCapacity( |
| 12804 | self: *Builder, | 12869 | self: *Builder, |
| 12805 | name: MetadataString, | 12870 | name: ?Metadata.String, |
| 12806 | file: Metadata, | 12871 | file: ?Metadata, |
| 12807 | scope: Metadata, | 12872 | scope: ?Metadata, |
| 12808 | line: u32, | 12873 | line: u32, |
| 12809 | underlying_type: Metadata, | 12874 | underlying_type: ?Metadata, |
| 12810 | size_in_bits: u64, | 12875 | size_in_bits: u64, |
| 12811 | align_in_bits: u64, | 12876 | align_in_bits: u64, |
| 12812 | offset_in_bits: u64, | 12877 | offset_in_bits: u64, |
| 12813 | ) Metadata { | 12878 | ) Metadata { |
| 12814 | assert(!self.strip); | 12879 | assert(!self.strip); |
| 12815 | return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{ | 12880 | return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{ |
| 12816 | .name = name, | 12881 | .name = .wrap(name), |
| 12817 | .file = file, | 12882 | .file = .wrap(file), |
| 12818 | .scope = scope, | 12883 | .scope = .wrap(scope), |
| 12819 | .line = line, | 12884 | .line = line, |
| 12820 | .underlying_type = underlying_type, | 12885 | .underlying_type = .wrap(underlying_type), |
| 12821 | .size_in_bits_lo = @truncate(size_in_bits), | 12886 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12822 | .size_in_bits_hi = @truncate(size_in_bits >> 32), | 12887 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12823 | .align_in_bits_lo = @truncate(align_in_bits), | 12888 | .align_in_bits_lo = @truncate(align_in_bits), |
| ... | @@ -12827,19 +12892,16 @@ fn debugMemberTypeAssumeCapacity( | ... | @@ -12827,19 +12892,16 @@ fn debugMemberTypeAssumeCapacity( |
| 12827 | }); | 12892 | }); |
| 12828 | } | 12893 | } |
| 12829 | | 12894 | |
| 12830 | fn debugSubroutineTypeAssumeCapacity( | 12895 | fn debugSubroutineTypeAssumeCapacity(self: *Builder, types_tuple: ?Metadata) Metadata { |
| 12831 | self: *Builder, | | |
| 12832 | types_tuple: Metadata, | | |
| 12833 | ) Metadata { | | |
| 12834 | assert(!self.strip); | 12896 | assert(!self.strip); |
| 12835 | return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{ | 12897 | return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{ |
| 12836 | .types_tuple = types_tuple, | 12898 | .types_tuple = .wrap(types_tuple), |
| 12837 | }); | 12899 | }); |
| 12838 | } | 12900 | } |
| 12839 | | 12901 | |
| 12840 | fn debugEnumeratorAssumeCapacity( | 12902 | fn debugEnumeratorAssumeCapacity( |
| 12841 | self: *Builder, | 12903 | self: *Builder, |
| 12842 | name: MetadataString, | 12904 | name: ?Metadata.String, |
| 12843 | unsigned: bool, | 12905 | unsigned: bool, |
| 12844 | bit_width: u32, | 12906 | bit_width: u32, |
| 12845 | value: std.math.big.int.Const, | 12907 | value: std.math.big.int.Const, |
| ... | @@ -12847,7 +12909,7 @@ fn debugEnumeratorAssumeCapacity( | ... | @@ -12847,7 +12909,7 @@ fn debugEnumeratorAssumeCapacity( |
| 12847 | assert(!self.strip); | 12909 | assert(!self.strip); |
| 12848 | const Key = struct { | 12910 | const Key = struct { |
| 12849 | tag: Metadata.Tag, | 12911 | tag: Metadata.Tag, |
| 12850 | name: MetadataString, | 12912 | name: Metadata.String.Optional, |
| 12851 | bit_width: u32, | 12913 | bit_width: u32, |
| 12852 | value: std.math.big.int.Const, | 12914 | value: std.math.big.int.Const, |
| 12853 | }; | 12915 | }; |
| ... | @@ -12886,15 +12948,12 @@ fn debugEnumeratorAssumeCapacity( | ... | @@ -12886,15 +12948,12 @@ fn debugEnumeratorAssumeCapacity( |
| 12886 | | 12948 | |
| 12887 | assert(!(tag == .enumerator_unsigned and !value.positive)); | 12949 | assert(!(tag == .enumerator_unsigned and !value.positive)); |
| 12888 | | 12950 | |
| 12889 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( | 12951 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(Key{ |
| 12890 | Key{ | 12952 | .tag = tag, |
| 12891 | .tag = tag, | 12953 | .name = .wrap(name), |
| 12892 | .name = name, | 12954 | .bit_width = bit_width, |
| 12893 | .bit_width = bit_width, | 12955 | .value = value, |
| 12894 | .value = value, | 12956 | }, Adapter{ .builder = self }); |
| 12895 | }, | | |
| 12896 | Adapter{ .builder = self }, | | |
| 12897 | ); | | |
| 12898 | | 12957 | |
| 12899 | if (!gop.found_existing) { | 12958 | if (!gop.found_existing) { |
| 12900 | gop.key_ptr.* = {}; | 12959 | gop.key_ptr.* = {}; |
| ... | @@ -12902,7 +12961,7 @@ fn debugEnumeratorAssumeCapacity( | ... | @@ -12902,7 +12961,7 @@ fn debugEnumeratorAssumeCapacity( |
| 12902 | self.metadata_items.appendAssumeCapacity(.{ | 12961 | self.metadata_items.appendAssumeCapacity(.{ |
| 12903 | .tag = tag, | 12962 | .tag = tag, |
| 12904 | .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{ | 12963 | .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{ |
| 12905 | .name = name, | 12964 | .name = .wrap(name), |
| 12906 | .bit_width = bit_width, | 12965 | .bit_width = bit_width, |
| 12907 | .limbs_index = @intCast(self.metadata_limbs.items.len), | 12966 | .limbs_index = @intCast(self.metadata_limbs.items.len), |
| 12908 | .limbs_len = @intCast(value.limbs.len), | 12967 | .limbs_len = @intCast(value.limbs.len), |
| ... | @@ -12910,25 +12969,18 @@ fn debugEnumeratorAssumeCapacity( | ... | @@ -12910,25 +12969,18 @@ fn debugEnumeratorAssumeCapacity( |
| 12910 | }); | 12969 | }); |
| 12911 | self.metadata_limbs.appendSliceAssumeCapacity(value.limbs); | 12970 | self.metadata_limbs.appendSliceAssumeCapacity(value.limbs); |
| 12912 | } | 12971 | } |
| 12913 | return @enumFromInt(gop.index); | 12972 | return .{ .index = @intCast(gop.index), .kind = .node }; |
| 12914 | } | 12973 | } |
| 12915 | | 12974 | |
| 12916 | fn debugSubrangeAssumeCapacity( | 12975 | fn debugSubrangeAssumeCapacity(self: *Builder, lower_bound: ?Metadata, count: ?Metadata) Metadata { |
| 12917 | self: *Builder, | | |
| 12918 | lower_bound: Metadata, | | |
| 12919 | count: Metadata, | | |
| 12920 | ) Metadata { | | |
| 12921 | assert(!self.strip); | 12976 | assert(!self.strip); |
| 12922 | return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{ | 12977 | return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{ |
| 12923 | .lower_bound = lower_bound, | 12978 | .lower_bound = .wrap(lower_bound), |
| 12924 | .count = count, | 12979 | .count = .wrap(count), |
| 12925 | }); | 12980 | }); |
| 12926 | } | 12981 | } |
| 12927 | | 12982 | |
| 12928 | fn debugExpressionAssumeCapacity( | 12983 | fn debugExpressionAssumeCapacity(self: *Builder, elements: []const u32) Metadata { |
| 12929 | self: *Builder, | | |
| 12930 | elements: []const u32, | | |
| 12931 | ) Metadata { | | |
| 12932 | assert(!self.strip); | 12984 | assert(!self.strip); |
| 12933 | const Key = struct { | 12985 | const Key = struct { |
| 12934 | elements: []const u32, | 12986 | elements: []const u32, |
| ... | @@ -12936,13 +12988,15 @@ fn debugExpressionAssumeCapacity( | ... | @@ -12936,13 +12988,15 @@ fn debugExpressionAssumeCapacity( |
| 12936 | const Adapter = struct { | 12988 | const Adapter = struct { |
| 12937 | builder: *const Builder, | 12989 | builder: *const Builder, |
| 12938 | pub fn hash(_: @This(), key: Key) u32 { | 12990 | pub fn hash(_: @This(), key: Key) u32 { |
| 12939 | var hasher = comptime std.hash.Wyhash.init(std.hash.int(@intFromEnum(Metadata.Tag.expression))); | 12991 | var hasher = |
| | 12992 | comptime std.hash.Wyhash.init(std.hash.int(@intFromEnum(Metadata.Tag.expression))); |
| 12940 | hasher.update(std.mem.sliceAsBytes(key.elements)); | 12993 | hasher.update(std.mem.sliceAsBytes(key.elements)); |
| 12941 | return @truncate(hasher.final()); | 12994 | return @truncate(hasher.final()); |
| 12942 | } | 12995 | } |
| 12943 | | 12996 | |
| 12944 | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { | 12997 | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { |
| 12945 | if (Metadata.Tag.expression != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false; | 12998 | if (Metadata.Tag.expression != ctx.builder.metadata_items.items(.tag)[rhs_index]) |
| | 12999 | return false; |
| 12946 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; | 13000 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 12947 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data); | 13001 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data); |
| 12948 | return std.mem.eql( | 13002 | return std.mem.eql( |
| ... | @@ -12969,15 +13023,12 @@ fn debugExpressionAssumeCapacity( | ... | @@ -12969,15 +13023,12 @@ fn debugExpressionAssumeCapacity( |
| 12969 | }); | 13023 | }); |
| 12970 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements)); | 13024 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements)); |
| 12971 | } | 13025 | } |
| 12972 | return @enumFromInt(gop.index); | 13026 | return .{ .index = @intCast(gop.index), .kind = .node }; |
| 12973 | } | 13027 | } |
| 12974 | | 13028 | |
| 12975 | fn metadataTupleAssumeCapacity( | 13029 | fn metadataTupleOptionalsAssumeCapacity(self: *Builder, elements: []const Metadata.Optional) Metadata { |
| 12976 | self: *Builder, | | |
| 12977 | elements: []const Metadata, | | |
| 12978 | ) Metadata { | | |
| 12979 | const Key = struct { | 13030 | const Key = struct { |
| 12980 | elements: []const Metadata, | 13031 | elements: []const Metadata.Optional, |
| 12981 | }; | 13032 | }; |
| 12982 | const Adapter = struct { | 13033 | const Adapter = struct { |
| 12983 | builder: *const Builder, | 13034 | builder: *const Builder, |
| ... | @@ -12992,9 +13043,9 @@ fn metadataTupleAssumeCapacity( | ... | @@ -12992,9 +13043,9 @@ fn metadataTupleAssumeCapacity( |
| 12992 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; | 13043 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 12993 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data); | 13044 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data); |
| 12994 | return std.mem.eql( | 13045 | return std.mem.eql( |
| 12995 | Metadata, | 13046 | Metadata.Optional, |
| 12996 | lhs_key.elements, | 13047 | lhs_key.elements, |
| 12997 | rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata, ctx.builder), | 13048 | rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata.Optional, ctx.builder), |
| 12998 | ); | 13049 | ); |
| 12999 | } | 13050 | } |
| 13000 | }; | 13051 | }; |
| ... | @@ -13015,117 +13066,55 @@ fn metadataTupleAssumeCapacity( | ... | @@ -13015,117 +13066,55 @@ fn metadataTupleAssumeCapacity( |
| 13015 | }); | 13066 | }); |
| 13016 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements)); | 13067 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements)); |
| 13017 | } | 13068 | } |
| 13018 | return @enumFromInt(gop.index); | 13069 | return .{ .index = @intCast(gop.index), .kind = .node }; |
| 13019 | } | | |
| 13020 | | | |
| 13021 | fn strTupleAssumeCapacity( | | |
| 13022 | self: *Builder, | | |
| 13023 | str: MetadataString, | | |
| 13024 | elements: []const Metadata, | | |
| 13025 | ) Metadata { | | |
| 13026 | const Key = struct { | | |
| 13027 | str: MetadataString, | | |
| 13028 | elements: []const Metadata, | | |
| 13029 | }; | | |
| 13030 | const Adapter = struct { | | |
| 13031 | builder: *const Builder, | | |
| 13032 | pub fn hash(_: @This(), key: Key) u32 { | | |
| 13033 | var hasher = comptime std.hash.Wyhash.init(std.hash.int(@intFromEnum(Metadata.Tag.tuple))); | | |
| 13034 | hasher.update(std.mem.sliceAsBytes(key.elements)); | | |
| 13035 | return @truncate(hasher.final()); | | |
| 13036 | } | | |
| 13037 | | | |
| 13038 | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { | | |
| 13039 | if (.str_tuple != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false; | | |
| 13040 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; | | |
| 13041 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.StrTuple, rhs_data); | | |
| 13042 | return rhs_extra.data.str == lhs_key.str and std.mem.eql( | | |
| 13043 | Metadata, | | |
| 13044 | lhs_key.elements, | | |
| 13045 | rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata, ctx.builder), | | |
| 13046 | ); | | |
| 13047 | } | | |
| 13048 | }; | | |
| 13049 | | | |
| 13050 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( | | |
| 13051 | Key{ .str = str, .elements = elements }, | | |
| 13052 | Adapter{ .builder = self }, | | |
| 13053 | ); | | |
| 13054 | | | |
| 13055 | if (!gop.found_existing) { | | |
| 13056 | gop.key_ptr.* = {}; | | |
| 13057 | gop.value_ptr.* = {}; | | |
| 13058 | self.metadata_items.appendAssumeCapacity(.{ | | |
| 13059 | .tag = .str_tuple, | | |
| 13060 | .data = self.addMetadataExtraAssumeCapacity(Metadata.StrTuple{ | | |
| 13061 | .str = str, | | |
| 13062 | .elements_len = @intCast(elements.len), | | |
| 13063 | }), | | |
| 13064 | }); | | |
| 13065 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements)); | | |
| 13066 | } | | |
| 13067 | return @enumFromInt(gop.index); | | |
| 13068 | } | | |
| 13069 | | | |
| 13070 | fn metadataModuleFlagAssumeCapacity( | | |
| 13071 | self: *Builder, | | |
| 13072 | behavior: Metadata, | | |
| 13073 | name: MetadataString, | | |
| 13074 | constant: Metadata, | | |
| 13075 | ) Metadata { | | |
| 13076 | return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{ | | |
| 13077 | .behavior = behavior, | | |
| 13078 | .name = name, | | |
| 13079 | .constant = constant, | | |
| 13080 | }); | | |
| 13081 | } | 13070 | } |
| 13082 | | 13071 | |
| 13083 | fn debugLocalVarAssumeCapacity( | 13072 | fn debugLocalVarAssumeCapacity( |
| 13084 | self: *Builder, | 13073 | self: *Builder, |
| 13085 | name: MetadataString, | 13074 | name: ?Metadata.String, |
| 13086 | file: Metadata, | 13075 | file: ?Metadata, |
| 13087 | scope: Metadata, | 13076 | scope: ?Metadata, |
| 13088 | line: u32, | 13077 | line: u32, |
| 13089 | ty: Metadata, | 13078 | ty: ?Metadata, |
| 13090 | ) Metadata { | 13079 | ) Metadata { |
| 13091 | assert(!self.strip); | 13080 | assert(!self.strip); |
| 13092 | return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{ | 13081 | return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{ |
| 13093 | .name = name, | 13082 | .name = .wrap(name), |
| 13094 | .file = file, | 13083 | .file = .wrap(file), |
| 13095 | .scope = scope, | 13084 | .scope = .wrap(scope), |
| 13096 | .line = line, | 13085 | .line = line, |
| 13097 | .ty = ty, | 13086 | .ty = .wrap(ty), |
| 13098 | }); | 13087 | }); |
| 13099 | } | 13088 | } |
| 13100 | | 13089 | |
| 13101 | fn debugParameterAssumeCapacity( | 13090 | fn debugParameterAssumeCapacity( |
| 13102 | self: *Builder, | 13091 | self: *Builder, |
| 13103 | name: MetadataString, | 13092 | name: ?Metadata.String, |
| 13104 | file: Metadata, | 13093 | file: ?Metadata, |
| 13105 | scope: Metadata, | 13094 | scope: ?Metadata, |
| 13106 | line: u32, | 13095 | line: u32, |
| 13107 | ty: Metadata, | 13096 | ty: ?Metadata, |
| 13108 | arg_no: u32, | 13097 | arg_no: u32, |
| 13109 | ) Metadata { | 13098 | ) Metadata { |
| 13110 | assert(!self.strip); | 13099 | assert(!self.strip); |
| 13111 | return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{ | 13100 | return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{ |
| 13112 | .name = name, | 13101 | .name = .wrap(name), |
| 13113 | .file = file, | 13102 | .file = .wrap(file), |
| 13114 | .scope = scope, | 13103 | .scope = .wrap(scope), |
| 13115 | .line = line, | 13104 | .line = line, |
| 13116 | .ty = ty, | 13105 | .ty = .wrap(ty), |
| 13117 | .arg_no = arg_no, | 13106 | .arg_no = arg_no, |
| 13118 | }); | 13107 | }); |
| 13119 | } | 13108 | } |
| 13120 | | 13109 | |
| 13121 | fn debugGlobalVarAssumeCapacity( | 13110 | fn debugGlobalVarAssumeCapacity( |
| 13122 | self: *Builder, | 13111 | self: *Builder, |
| 13123 | name: MetadataString, | 13112 | name: ?Metadata.String, |
| 13124 | linkage_name: MetadataString, | 13113 | linkage_name: ?Metadata.String, |
| 13125 | file: Metadata, | 13114 | file: ?Metadata, |
| 13126 | scope: Metadata, | 13115 | scope: ?Metadata, |
| 13127 | line: u32, | 13116 | line: u32, |
| 13128 | ty: Metadata, | 13117 | ty: ?Metadata, |
| 13129 | variable: Variable.Index, | 13118 | variable: Variable.Index, |
| 13130 | options: Metadata.GlobalVar.Options, | 13119 | options: Metadata.GlobalVar.Options, |
| 13131 | ) Metadata { | 13120 | ) Metadata { |
| ... | @@ -13133,12 +13122,12 @@ fn debugGlobalVarAssumeCapacity( | ... | @@ -13133,12 +13122,12 @@ fn debugGlobalVarAssumeCapacity( |
| 13133 | return self.metadataDistinctAssumeCapacity( | 13122 | return self.metadataDistinctAssumeCapacity( |
| 13134 | if (options.local) .@"global_var local" else .global_var, | 13123 | if (options.local) .@"global_var local" else .global_var, |
| 13135 | Metadata.GlobalVar{ | 13124 | Metadata.GlobalVar{ |
| 13136 | .name = name, | 13125 | .name = .wrap(name), |
| 13137 | .linkage_name = linkage_name, | 13126 | .linkage_name = .wrap(linkage_name), |
| 13138 | .file = file, | 13127 | .file = .wrap(file), |
| 13139 | .scope = scope, | 13128 | .scope = .wrap(scope), |
| 13140 | .line = line, | 13129 | .line = line, |
| 13141 | .ty = ty, | 13130 | .ty = .wrap(ty), |
| 13142 | .variable = variable, | 13131 | .variable = variable, |
| 13143 | }, | 13132 | }, |
| 13144 | ); | 13133 | ); |
| ... | @@ -13146,13 +13135,13 @@ fn debugGlobalVarAssumeCapacity( | ... | @@ -13146,13 +13135,13 @@ fn debugGlobalVarAssumeCapacity( |
| 13146 | | 13135 | |
| 13147 | fn debugGlobalVarExpressionAssumeCapacity( | 13136 | fn debugGlobalVarExpressionAssumeCapacity( |
| 13148 | self: *Builder, | 13137 | self: *Builder, |
| 13149 | variable: Metadata, | 13138 | variable: ?Metadata, |
| 13150 | expression: Metadata, | 13139 | expression: ?Metadata, |
| 13151 | ) Metadata { | 13140 | ) Metadata { |
| 13152 | assert(!self.strip); | 13141 | assert(!self.strip); |
| 13153 | return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{ | 13142 | return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{ |
| 13154 | .variable = variable, | 13143 | .variable = .wrap(variable), |
| 13155 | .expression = expression, | 13144 | .expression = .wrap(expression), |
| 13156 | }); | 13145 | }); |
| 13157 | } | 13146 | } |
| 13158 | | 13147 | |
| ... | @@ -13185,7 +13174,7 @@ fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata { | ... | @@ -13185,7 +13174,7 @@ fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata { |
| 13185 | .data = @intFromEnum(constant), | 13174 | .data = @intFromEnum(constant), |
| 13186 | }); | 13175 | }); |
| 13187 | } | 13176 | } |
| 13188 | return @enumFromInt(gop.index); | 13177 | return .{ .index = @intCast(gop.index), .kind = .node }; |
| 13189 | } | 13178 | } |
| 13190 | | 13179 | |
| 13191 | pub const Producer = struct { | 13180 | pub const Producer = struct { |
| ... | @@ -13209,8 +13198,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13209,8 +13198,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13209 | | 13198 | |
| 13210 | // IDENTIFICATION_BLOCK | 13199 | // IDENTIFICATION_BLOCK |
| 13211 | { | 13200 | { |
| 13212 | const Identification = ir.Identification; | 13201 | const IdentificationBlock = ir.IdentificationBlock; |
| 13213 | var identification_block = try bitcode.enterTopBlock(Identification); | 13202 | var identification_block = try bitcode.enterTopBlock(IdentificationBlock); |
| 13214 | | 13203 | |
| 13215 | const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{ | 13204 | const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{ |
| 13216 | producer.name, | 13205 | producer.name, |
| ... | @@ -13220,42 +13209,42 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13220,42 +13209,42 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13220 | }); | 13209 | }); |
| 13221 | defer self.gpa.free(producer_str); | 13210 | defer self.gpa.free(producer_str); |
| 13222 | | 13211 | |
| 13223 | try identification_block.writeAbbrev(Identification.Version{ .string = producer_str }); | 13212 | try identification_block.writeAbbrev(IdentificationBlock.Version{ .string = producer_str }); |
| 13224 | try identification_block.writeAbbrev(Identification.Epoch{ .epoch = 0 }); | 13213 | try identification_block.writeAbbrev(IdentificationBlock.Epoch{ .epoch = 0 }); |
| 13225 | | 13214 | |
| 13226 | try identification_block.end(); | 13215 | try identification_block.end(); |
| 13227 | } | 13216 | } |
| 13228 | | 13217 | |
| 13229 | // MODULE_BLOCK | 13218 | // MODULE_BLOCK |
| 13230 | { | 13219 | { |
| 13231 | const Module = ir.Module; | 13220 | const ModuleBlock = ir.ModuleBlock; |
| 13232 | var module_block = try bitcode.enterTopBlock(Module); | 13221 | var module_block = try bitcode.enterTopBlock(ModuleBlock); |
| 13233 | | 13222 | |
| 13234 | try module_block.writeAbbrev(Module.Version{}); | 13223 | try module_block.writeAbbrev(ModuleBlock.Version{}); |
| 13235 | | 13224 | |
| 13236 | if (self.target_triple.slice(self)) |triple| { | 13225 | if (self.target_triple.slice(self)) |triple| { |
| 13237 | try module_block.writeAbbrev(Module.String{ | 13226 | try module_block.writeAbbrev(ModuleBlock.String{ |
| 13238 | .code = 2, | 13227 | .code = 2, |
| 13239 | .string = triple, | 13228 | .string = triple, |
| 13240 | }); | 13229 | }); |
| 13241 | } | 13230 | } |
| 13242 | | 13231 | |
| 13243 | if (self.data_layout.slice(self)) |data_layout| { | 13232 | if (self.data_layout.slice(self)) |data_layout| { |
| 13244 | try module_block.writeAbbrev(Module.String{ | 13233 | try module_block.writeAbbrev(ModuleBlock.String{ |
| 13245 | .code = 3, | 13234 | .code = 3, |
| 13246 | .string = data_layout, | 13235 | .string = data_layout, |
| 13247 | }); | 13236 | }); |
| 13248 | } | 13237 | } |
| 13249 | | 13238 | |
| 13250 | if (self.source_filename.slice(self)) |source_filename| { | 13239 | if (self.source_filename.slice(self)) |source_filename| { |
| 13251 | try module_block.writeAbbrev(Module.String{ | 13240 | try module_block.writeAbbrev(ModuleBlock.String{ |
| 13252 | .code = 16, | 13241 | .code = 16, |
| 13253 | .string = source_filename, | 13242 | .string = source_filename, |
| 13254 | }); | 13243 | }); |
| 13255 | } | 13244 | } |
| 13256 | | 13245 | |
| 13257 | if (self.module_asm.items.len != 0) { | 13246 | if (self.module_asm.items.len != 0) { |
| 13258 | try module_block.writeAbbrev(Module.String{ | 13247 | try module_block.writeAbbrev(ModuleBlock.String{ |
| 13259 | .code = 4, | 13248 | .code = 4, |
| 13260 | .string = self.module_asm.items, | 13249 | .string = self.module_asm.items, |
| 13261 | }); | 13250 | }); |
| ... | @@ -13263,16 +13252,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13263,16 +13252,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13263 | | 13252 | |
| 13264 | // TYPE_BLOCK | 13253 | // TYPE_BLOCK |
| 13265 | { | 13254 | { |
| 13266 | var type_block = try module_block.enterSubBlock(ir.Type, true); | 13255 | const TypeBlock = ir.ModuleBlock.TypeBlock; |
| | 13256 | var type_block = try module_block.enterSubBlock(TypeBlock, true); |
| 13267 | | 13257 | |
| 13268 | try type_block.writeAbbrev(ir.Type.NumEntry{ .num = @intCast(self.type_items.items.len) }); | 13258 | try type_block.writeAbbrev(TypeBlock.NumEntry{ .num = @intCast(self.type_items.items.len) }); |
| 13269 | | 13259 | |
| 13270 | for (self.type_items.items, 0..) |item, i| { | 13260 | for (self.type_items.items, 0..) |item, i| { |
| 13271 | const ty: Type = @enumFromInt(i); | 13261 | const ty: Type = @enumFromInt(i); |
| 13272 | | 13262 | |
| 13273 | switch (item.tag) { | 13263 | switch (item.tag) { |
| 13274 | .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }), | 13264 | .simple => try type_block.writeAbbrev(TypeBlock.Simple{ .code = @enumFromInt(item.data) }), |
| 13275 | .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }), | 13265 | .integer => try type_block.writeAbbrev(TypeBlock.Integer{ .width = item.data }), |
| 13276 | .structure, | 13266 | .structure, |
| 13277 | .packed_structure, | 13267 | .packed_structure, |
| 13278 | => |kind| { | 13268 | => |kind| { |
| ... | @@ -13282,19 +13272,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13282,19 +13272,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13282 | else => unreachable, | 13272 | else => unreachable, |
| 13283 | }; | 13273 | }; |
| 13284 | var extra = self.typeExtraDataTrail(Type.Structure, item.data); | 13274 | var extra = self.typeExtraDataTrail(Type.Structure, item.data); |
| 13285 | try type_block.writeAbbrev(ir.Type.StructAnon{ | 13275 | try type_block.writeAbbrev(TypeBlock.StructAnon{ |
| 13286 | .is_packed = is_packed, | 13276 | .is_packed = is_packed, |
| 13287 | .types = extra.trail.next(extra.data.fields_len, Type, self), | 13277 | .types = extra.trail.next(extra.data.fields_len, Type, self), |
| 13288 | }); | 13278 | }); |
| 13289 | }, | 13279 | }, |
| 13290 | .named_structure => { | 13280 | .named_structure => { |
| 13291 | const extra = self.typeExtraData(Type.NamedStructure, item.data); | 13281 | const extra = self.typeExtraData(Type.NamedStructure, item.data); |
| 13292 | try type_block.writeAbbrev(ir.Type.StructName{ | 13282 | try type_block.writeAbbrev(TypeBlock.StructName{ |
| 13293 | .string = extra.id.slice(self).?, | 13283 | .string = extra.id.slice(self).?, |
| 13294 | }); | 13284 | }); |
| 13295 | | 13285 | |
| 13296 | switch (extra.body) { | 13286 | switch (extra.body) { |
| 13297 | .none => try type_block.writeAbbrev(ir.Type.Opaque{}), | 13287 | .none => try type_block.writeAbbrev(TypeBlock.Opaque{}), |
| 13298 | else => { | 13288 | else => { |
| 13299 | const real_struct = self.type_items.items[@intFromEnum(extra.body)]; | 13289 | const real_struct = self.type_items.items[@intFromEnum(extra.body)]; |
| 13300 | const is_packed: bool = switch (real_struct.tag) { | 13290 | const is_packed: bool = switch (real_struct.tag) { |
| ... | @@ -13304,7 +13294,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13304,7 +13294,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13304 | }; | 13294 | }; |
| 13305 | | 13295 | |
| 13306 | var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data); | 13296 | var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data); |
| 13307 | try type_block.writeAbbrev(ir.Type.StructNamed{ | 13297 | try type_block.writeAbbrev(TypeBlock.StructNamed{ |
| 13308 | .is_packed = is_packed, | 13298 | .is_packed = is_packed, |
| 13309 | .types = real_extra.trail.next(real_extra.data.fields_len, Type, self), | 13299 | .types = real_extra.trail.next(real_extra.data.fields_len, Type, self), |
| 13310 | }); | 13300 | }); |
| ... | @@ -13313,29 +13303,29 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13313,29 +13303,29 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13313 | }, | 13303 | }, |
| 13314 | .array, | 13304 | .array, |
| 13315 | .small_array, | 13305 | .small_array, |
| 13316 | => try type_block.writeAbbrev(ir.Type.Array{ | 13306 | => try type_block.writeAbbrev(TypeBlock.Array{ |
| 13317 | .len = ty.aggregateLen(self), | 13307 | .len = ty.aggregateLen(self), |
| 13318 | .child = ty.childType(self), | 13308 | .child = ty.childType(self), |
| 13319 | }), | 13309 | }), |
| 13320 | .vector, | 13310 | .vector, |
| 13321 | .scalable_vector, | 13311 | .scalable_vector, |
| 13322 | => try type_block.writeAbbrev(ir.Type.Vector{ | 13312 | => try type_block.writeAbbrev(TypeBlock.Vector{ |
| 13323 | .len = ty.aggregateLen(self), | 13313 | .len = ty.aggregateLen(self), |
| 13324 | .child = ty.childType(self), | 13314 | .child = ty.childType(self), |
| 13325 | }), | 13315 | }), |
| 13326 | .pointer => try type_block.writeAbbrev(ir.Type.Pointer{ | 13316 | .pointer => try type_block.writeAbbrev(TypeBlock.Pointer{ |
| 13327 | .addr_space = ty.pointerAddrSpace(self), | 13317 | .addr_space = ty.pointerAddrSpace(self), |
| 13328 | }), | 13318 | }), |
| 13329 | .target => { | 13319 | .target => { |
| 13330 | var extra = self.typeExtraDataTrail(Type.Target, item.data); | 13320 | var extra = self.typeExtraDataTrail(Type.Target, item.data); |
| 13331 | try type_block.writeAbbrev(ir.Type.StructName{ | 13321 | try type_block.writeAbbrev(TypeBlock.StructName{ |
| 13332 | .string = extra.data.name.slice(self).?, | 13322 | .string = extra.data.name.slice(self).?, |
| 13333 | }); | 13323 | }); |
| 13334 | | 13324 | |
| 13335 | const types = extra.trail.next(extra.data.types_len, Type, self); | 13325 | const types = extra.trail.next(extra.data.types_len, Type, self); |
| 13336 | const ints = extra.trail.next(extra.data.ints_len, u32, self); | 13326 | const ints = extra.trail.next(extra.data.ints_len, u32, self); |
| 13337 | | 13327 | |
| 13338 | try type_block.writeAbbrev(ir.Type.Target{ | 13328 | try type_block.writeAbbrev(TypeBlock.Target{ |
| 13339 | .num_types = extra.data.types_len, | 13329 | .num_types = extra.data.types_len, |
| 13340 | .types = types, | 13330 | .types = types, |
| 13341 | .ints = ints, | 13331 | .ints = ints, |
| ... | @@ -13348,7 +13338,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13348,7 +13338,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13348 | else => unreachable, | 13338 | else => unreachable, |
| 13349 | }; | 13339 | }; |
| 13350 | var extra = self.typeExtraDataTrail(Type.Function, item.data); | 13340 | var extra = self.typeExtraDataTrail(Type.Function, item.data); |
| 13351 | try type_block.writeAbbrev(ir.Type.Function{ | 13341 | try type_block.writeAbbrev(TypeBlock.Function{ |
| 13352 | .is_vararg = is_vararg, | 13342 | .is_vararg = is_vararg, |
| 13353 | .return_type = extra.data.ret, | 13343 | .return_type = extra.data.ret, |
| 13354 | .param_types = extra.trail.next(extra.data.params_len, Type, self), | 13344 | .param_types = extra.trail.next(extra.data.params_len, Type, self), |
| ... | @@ -13368,9 +13358,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13368,9 +13358,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13368 | | 13358 | |
| 13369 | // PARAMATTR_GROUP_BLOCK | 13359 | // PARAMATTR_GROUP_BLOCK |
| 13370 | { | 13360 | { |
| 13371 | const ParamattrGroup = ir.ParamattrGroup; | 13361 | const ParamattrGroupBlock = ir.ModuleBlock.ParamattrGroupBlock; |
| 13372 | | 13362 | |
| 13373 | var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroup, true); | 13363 | var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroupBlock, true); |
| 13374 | | 13364 | |
| 13375 | for (self.function_attributes_set.keys()) |func_attributes| { | 13365 | for (self.function_attributes_set.keys()) |func_attributes| { |
| 13376 | for (func_attributes.slice(self), 0..) |attributes, i| { | 13366 | for (func_attributes.slice(self), 0..) |attributes, i| { |
| ... | @@ -13572,8 +13562,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13572,8 +13562,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13572 | | 13562 | |
| 13573 | // PARAMATTR_BLOCK | 13563 | // PARAMATTR_BLOCK |
| 13574 | { | 13564 | { |
| 13575 | const Paramattr = ir.Paramattr; | 13565 | const ParamattrBlock = ir.ModuleBlock.ParamattrBlock; |
| 13576 | var paramattr_block = try module_block.enterSubBlock(Paramattr, true); | 13566 | var paramattr_block = try module_block.enterSubBlock(ParamattrBlock, true); |
| 13577 | | 13567 | |
| 13578 | for (self.function_attributes_set.keys()) |func_attributes| { | 13568 | for (self.function_attributes_set.keys()) |func_attributes| { |
| 13579 | const func_attributes_slice = func_attributes.slice(self); | 13569 | const func_attributes_slice = func_attributes.slice(self); |
| ... | @@ -13590,7 +13580,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13590,7 +13580,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13590 | record.appendAssumeCapacity(@intCast(group_index)); | 13580 | record.appendAssumeCapacity(@intCast(group_index)); |
| 13591 | } | 13581 | } |
| 13592 | | 13582 | |
| 13593 | try paramattr_block.writeAbbrev(Paramattr.Entry{ .group_indices = record.items }); | 13583 | try paramattr_block.writeAbbrev(ParamattrBlock.Entry{ .group_indices = record.items }); |
| 13594 | } | 13584 | } |
| 13595 | | 13585 | |
| 13596 | try paramattr_block.end(); | 13586 | try paramattr_block.end(); |
| ... | @@ -13624,38 +13614,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13624,38 +13614,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13624 | } | 13614 | } |
| 13625 | | 13615 | |
| 13626 | const ConstantAdapter = struct { | 13616 | const ConstantAdapter = struct { |
| 13627 | const ConstantAdapter = @This(); | | |
| 13628 | builder: *const Builder, | 13617 | builder: *const Builder, |
| 13629 | globals: *const std.AutoArrayHashMapUnmanaged(Global.Index, void), | 13618 | globals: *const std.AutoArrayHashMapUnmanaged(Global.Index, void), |
| 13630 | | 13619 | |
| 13631 | pub fn get(adapter: @This(), param: anytype, comptime field_name: []const u8) @TypeOf(param) { | 13620 | pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { |
| 13632 | _ = field_name; | 13621 | Constant => u32, |
| | 13622 | else => |Param| Param, |
| | 13623 | } { |
| 13633 | return switch (@TypeOf(param)) { | 13624 | return switch (@TypeOf(param)) { |
| 13634 | Constant => @enumFromInt(adapter.getConstantIndex(param)), | 13625 | Constant => adapter.getConstantIndex(param), |
| 13635 | else => param, | 13626 | else => param, |
| 13636 | }; | 13627 | }; |
| 13637 | } | 13628 | } |
| 13638 | | 13629 | |
| 13639 | pub fn getConstantIndex(adapter: ConstantAdapter, constant: Constant) u32 { | 13630 | pub fn getConstantIndex(adapter: @This(), constant: Constant) u32 { |
| 13640 | return switch (constant.unwrap()) { | 13631 | return switch (constant.unwrap()) { |
| 13641 | .constant => |c| c + adapter.numGlobals(), | 13632 | .constant => |c| c + adapter.numGlobals(), |
| 13642 | .global => |global| @intCast(adapter.globals.getIndex(global.unwrap(adapter.builder)).?), | 13633 | .global => |global| @intCast(adapter.globals.getIndex(global.unwrap(adapter.builder)).?), |
| 13643 | }; | 13634 | }; |
| 13644 | } | 13635 | } |
| 13645 | | 13636 | |
| 13646 | pub fn numConstants(adapter: ConstantAdapter) u32 { | 13637 | pub fn numConstants(adapter: @This()) u32 { |
| 13647 | return @intCast(adapter.globals.count() + adapter.builder.constant_items.len); | 13638 | return @intCast(adapter.globals.count() + adapter.builder.constant_items.len); |
| 13648 | } | 13639 | } |
| 13649 | | 13640 | |
| 13650 | pub fn numGlobals(adapter: ConstantAdapter) u32 { | 13641 | pub fn numGlobals(adapter: @This()) u32 { |
| 13651 | return @intCast(adapter.globals.count()); | 13642 | return @intCast(adapter.globals.count()); |
| 13652 | } | 13643 | } |
| 13653 | }; | 13644 | }; |
| 13654 | | 13645 | const constant_adapter: ConstantAdapter = .{ .builder = self, .globals = &globals }; |
| 13655 | const constant_adapter = ConstantAdapter{ | | |
| 13656 | .builder = self, | | |
| 13657 | .globals = &globals, | | |
| 13658 | }; | | |
| 13659 | | 13646 | |
| 13660 | // Globals | 13647 | // Globals |
| 13661 | { | 13648 | { |
| ... | @@ -13670,7 +13657,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13670,7 +13657,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13670 | if (variable.section == .none) break :blk 0; | 13657 | if (variable.section == .none) break :blk 0; |
| 13671 | const gop = section_map.getOrPutAssumeCapacity(variable.section); | 13658 | const gop = section_map.getOrPutAssumeCapacity(variable.section); |
| 13672 | if (!gop.found_existing) { | 13659 | if (!gop.found_existing) { |
| 13673 | try module_block.writeAbbrev(Module.String{ | 13660 | try module_block.writeAbbrev(ModuleBlock.String{ |
| 13674 | .code = 5, | 13661 | .code = 5, |
| 13675 | .string = variable.section.slice(self).?, | 13662 | .string = variable.section.slice(self).?, |
| 13676 | }); | 13663 | }); |
| ... | @@ -13686,7 +13673,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13686,7 +13673,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13686 | const strtab = variable.global.strtab(self); | 13673 | const strtab = variable.global.strtab(self); |
| 13687 | | 13674 | |
| 13688 | const global = variable.global.ptrConst(self); | 13675 | const global = variable.global.ptrConst(self); |
| 13689 | try module_block.writeAbbrev(Module.Variable{ | 13676 | try module_block.writeAbbrev(ModuleBlock.Variable{ |
| 13690 | .strtab_offset = strtab.offset, | 13677 | .strtab_offset = strtab.offset, |
| 13691 | .strtab_size = strtab.size, | 13678 | .strtab_size = strtab.size, |
| 13692 | .type_index = global.type, | 13679 | .type_index = global.type, |
| ... | @@ -13717,7 +13704,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13717,7 +13704,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13717 | if (func.section == .none) break :blk 0; | 13704 | if (func.section == .none) break :blk 0; |
| 13718 | const gop = section_map.getOrPutAssumeCapacity(func.section); | 13705 | const gop = section_map.getOrPutAssumeCapacity(func.section); |
| 13719 | if (!gop.found_existing) { | 13706 | if (!gop.found_existing) { |
| 13720 | try module_block.writeAbbrev(Module.String{ | 13707 | try module_block.writeAbbrev(ModuleBlock.String{ |
| 13721 | .code = 5, | 13708 | .code = 5, |
| 13722 | .string = func.section.slice(self).?, | 13709 | .string = func.section.slice(self).?, |
| 13723 | }); | 13710 | }); |
| ... | @@ -13733,7 +13720,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13733,7 +13720,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13733 | const strtab = func.global.strtab(self); | 13720 | const strtab = func.global.strtab(self); |
| 13734 | | 13721 | |
| 13735 | const global = func.global.ptrConst(self); | 13722 | const global = func.global.ptrConst(self); |
| 13736 | try module_block.writeAbbrev(Module.Function{ | 13723 | try module_block.writeAbbrev(ModuleBlock.Function{ |
| 13737 | .strtab_offset = strtab.offset, | 13724 | .strtab_offset = strtab.offset, |
| 13738 | .strtab_size = strtab.size, | 13725 | .strtab_size = strtab.size, |
| 13739 | .type_index = global.type, | 13726 | .type_index = global.type, |
| ... | @@ -13757,7 +13744,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13757,7 +13744,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13757 | const strtab = alias.global.strtab(self); | 13744 | const strtab = alias.global.strtab(self); |
| 13758 | | 13745 | |
| 13759 | const global = alias.global.ptrConst(self); | 13746 | const global = alias.global.ptrConst(self); |
| 13760 | try module_block.writeAbbrev(Module.Alias{ | 13747 | try module_block.writeAbbrev(ModuleBlock.Alias{ |
| 13761 | .strtab_offset = strtab.offset, | 13748 | .strtab_offset = strtab.offset, |
| 13762 | .strtab_size = strtab.size, | 13749 | .strtab_size = strtab.size, |
| 13763 | .type_index = global.type, | 13750 | .type_index = global.type, |
| ... | @@ -13775,8 +13762,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13775,8 +13762,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13775 | | 13762 | |
| 13776 | // CONSTANTS_BLOCK | 13763 | // CONSTANTS_BLOCK |
| 13777 | { | 13764 | { |
| 13778 | const Constants = ir.Constants; | 13765 | const ConstantsBlock = ir.ModuleBlock.ConstantsBlock; |
| 13779 | var constants_block = try module_block.enterSubBlock(Constants, true); | 13766 | var constants_block = try module_block.enterSubBlock(ConstantsBlock, true); |
| 13780 | | 13767 | |
| 13781 | var current_type: Type = .none; | 13768 | var current_type: Type = .none; |
| 13782 | const tags = self.constant_items.items(.tag); | 13769 | const tags = self.constant_items.items(.tag); |
| ... | @@ -13786,7 +13773,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13786,7 +13773,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13786 | const constant: Constant = @enumFromInt(index); | 13773 | const constant: Constant = @enumFromInt(index); |
| 13787 | const constant_type = constant.typeOf(self); | 13774 | const constant_type = constant.typeOf(self); |
| 13788 | if (constant_type != current_type) { | 13775 | if (constant_type != current_type) { |
| 13789 | try constants_block.writeAbbrev(Constants.SetType{ .type_id = constant_type }); | 13776 | try constants_block.writeAbbrev(ConstantsBlock.SetType{ .type_id = constant_type }); |
| 13790 | current_type = constant_type; | 13777 | current_type = constant_type; |
| 13791 | } | 13778 | } |
| 13792 | const data = datas[index]; | 13779 | const data = datas[index]; |
| ... | @@ -13794,9 +13781,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13794,9 +13781,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13794 | .null, | 13781 | .null, |
| 13795 | .zeroinitializer, | 13782 | .zeroinitializer, |
| 13796 | .none, | 13783 | .none, |
| 13797 | => try constants_block.writeAbbrev(Constants.Null{}), | 13784 | => try constants_block.writeAbbrev(ConstantsBlock.Null{}), |
| 13798 | .undef => try constants_block.writeAbbrev(Constants.Undef{}), | 13785 | .undef => try constants_block.writeAbbrev(ConstantsBlock.Undef{}), |
| 13799 | .poison => try constants_block.writeAbbrev(Constants.Poison{}), | 13786 | .poison => try constants_block.writeAbbrev(ConstantsBlock.Poison{}), |
| 13800 | .positive_integer, | 13787 | .positive_integer, |
| 13801 | .negative_integer, | 13788 | .negative_integer, |
| 13802 | => |tag| { | 13789 | => |tag| { |
| ... | @@ -13832,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13832,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13832 | try constants_block.writeUnabbrev(5, record.items); | 13819 | try constants_block.writeUnabbrev(5, record.items); |
| 13833 | continue; | 13820 | continue; |
| 13834 | }; | 13821 | }; |
| 13835 | try constants_block.writeAbbrev(Constants.Integer{ | 13822 | try constants_block.writeAbbrev(ConstantsBlock.Integer{ |
| 13836 | .value = @bitCast(if (val >= 0) | 13823 | .value = @bitCast(if (val >= 0) |
| 13837 | val << 1 | 0 | 13824 | val << 1 | 0 |
| 13838 | else | 13825 | else |
| ... | @@ -13841,17 +13828,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13841,17 +13828,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13841 | }, | 13828 | }, |
| 13842 | .half, | 13829 | .half, |
| 13843 | .bfloat, | 13830 | .bfloat, |
| 13844 | => try constants_block.writeAbbrev(Constants.Half{ .value = @truncate(data) }), | 13831 | => try constants_block.writeAbbrev(ConstantsBlock.Half{ .value = @truncate(data) }), |
| 13845 | .float => try constants_block.writeAbbrev(Constants.Float{ .value = data }), | 13832 | .float => try constants_block.writeAbbrev(ConstantsBlock.Float{ .value = data }), |
| 13846 | .double => { | 13833 | .double => { |
| 13847 | const extra = self.constantExtraData(Constant.Double, data); | 13834 | const extra = self.constantExtraData(Constant.Double, data); |
| 13848 | try constants_block.writeAbbrev(Constants.Double{ | 13835 | try constants_block.writeAbbrev(ConstantsBlock.Double{ |
| 13849 | .value = (@as(u64, extra.hi) << 32) | extra.lo, | 13836 | .value = (@as(u64, extra.hi) << 32) | extra.lo, |
| 13850 | }); | 13837 | }); |
| 13851 | }, | 13838 | }, |
| 13852 | .x86_fp80 => { | 13839 | .x86_fp80 => { |
| 13853 | const extra = self.constantExtraData(Constant.Fp80, data); | 13840 | const extra = self.constantExtraData(Constant.Fp80, data); |
| 13854 | try constants_block.writeAbbrev(Constants.Fp80{ | 13841 | try constants_block.writeAbbrev(ConstantsBlock.Fp80{ |
| 13855 | .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 | | 13842 | .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 | |
| 13856 | extra.lo_lo >> 16, | 13843 | extra.lo_lo >> 16, |
| 13857 | .lo = @truncate(extra.lo_lo), | 13844 | .lo = @truncate(extra.lo_lo), |
| ... | @@ -13861,7 +13848,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13861,7 +13848,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13861 | .ppc_fp128, | 13848 | .ppc_fp128, |
| 13862 | => { | 13849 | => { |
| 13863 | const extra = self.constantExtraData(Constant.Fp128, data); | 13850 | const extra = self.constantExtraData(Constant.Fp128, data); |
| 13864 | try constants_block.writeAbbrev(Constants.Fp128{ | 13851 | try constants_block.writeAbbrev(ConstantsBlock.Fp128{ |
| 13865 | .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo), | 13852 | .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo), |
| 13866 | .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo), | 13853 | .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo), |
| 13867 | }); | 13854 | }); |
| ... | @@ -13876,35 +13863,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13876,35 +13863,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13876 | const values = extra.trail.next(len, Constant, self); | 13863 | const values = extra.trail.next(len, Constant, self); |
| 13877 | | 13864 | |
| 13878 | try constants_block.writeAbbrevAdapted( | 13865 | try constants_block.writeAbbrevAdapted( |
| 13879 | Constants.Aggregate{ .values = values }, | 13866 | ConstantsBlock.Aggregate{ .values = values }, |
| 13880 | constant_adapter, | 13867 | constant_adapter, |
| 13881 | ); | 13868 | ); |
| 13882 | }, | 13869 | }, |
| 13883 | .splat => { | 13870 | .splat => { |
| 13884 | const ConstantsWriter = @TypeOf(constants_block); | 13871 | const ConstantsBlockWriter = @TypeOf(constants_block); |
| 13885 | const extra = self.constantExtraData(Constant.Splat, data); | 13872 | const extra = self.constantExtraData(Constant.Splat, data); |
| 13886 | const vector_len = extra.type.vectorLen(self); | 13873 | const vector_len = extra.type.vectorLen(self); |
| 13887 | const c = constant_adapter.getConstantIndex(extra.value); | 13874 | const c = constant_adapter.getConstantIndex(extra.value); |
| 13888 | | 13875 | |
| 13889 | try bitcode.writeBits( | 13876 | try bitcode.writeBits( |
| 13890 | ConstantsWriter.abbrevId(Constants.Aggregate), | 13877 | ConstantsBlockWriter.abbrevId(ConstantsBlock.Aggregate), |
| 13891 | ConstantsWriter.abbrev_len, | 13878 | ConstantsBlockWriter.abbrev_len, |
| 13892 | ); | 13879 | ); |
| 13893 | try bitcode.writeVBR(vector_len, 6); | 13880 | try bitcode.writeVbr(vector_len, 6); |
| 13894 | for (0..vector_len) |_| { | 13881 | for (0..vector_len) |_| { |
| 13895 | try bitcode.writeBits(c, Constants.Aggregate.ops[1].array_fixed); | 13882 | try bitcode.writeBits(c, ConstantsBlock.Aggregate.ops[1].array_fixed); |
| 13896 | } | 13883 | } |
| 13897 | }, | 13884 | }, |
| 13898 | .string => { | 13885 | .string => { |
| 13899 | const str: String = @enumFromInt(data); | 13886 | const str: String = @enumFromInt(data); |
| 13900 | if (str == .none) { | 13887 | if (str == .none) { |
| 13901 | try constants_block.writeAbbrev(Constants.Null{}); | 13888 | try constants_block.writeAbbrev(ConstantsBlock.Null{}); |
| 13902 | } else { | 13889 | } else { |
| 13903 | const slice = str.slice(self).?; | 13890 | const slice = str.slice(self).?; |
| 13904 | if (slice.len > 0 and slice[slice.len - 1] == 0) | 13891 | if (slice.len > 0 and slice[slice.len - 1] == 0) |
| 13905 | try constants_block.writeAbbrev(Constants.CString{ .string = slice[0 .. slice.len - 1] }) | 13892 | try constants_block.writeAbbrev(ConstantsBlock.CString{ .string = slice[0 .. slice.len - 1] }) |
| 13906 | else | 13893 | else |
| 13907 | try constants_block.writeAbbrev(Constants.String{ .string = slice }); | 13894 | try constants_block.writeAbbrev(ConstantsBlock.String{ .string = slice }); |
| 13908 | } | 13895 | } |
| 13909 | }, | 13896 | }, |
| 13910 | .bitcast, | 13897 | .bitcast, |
| ... | @@ -13914,7 +13901,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13914,7 +13901,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13914 | .trunc, | 13901 | .trunc, |
| 13915 | => |tag| { | 13902 | => |tag| { |
| 13916 | const extra = self.constantExtraData(Constant.Cast, data); | 13903 | const extra = self.constantExtraData(Constant.Cast, data); |
| 13917 | try constants_block.writeAbbrevAdapted(Constants.Cast{ | 13904 | try constants_block.writeAbbrevAdapted(ConstantsBlock.Cast{ |
| 13918 | .type_index = extra.type, | 13905 | .type_index = extra.type, |
| 13919 | .val = extra.val, | 13906 | .val = extra.val, |
| 13920 | .opcode = tag.toCastOpcode(), | 13907 | .opcode = tag.toCastOpcode(), |
| ... | @@ -13930,7 +13917,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -13930,7 +13917,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13930 | .xor, | 13917 | .xor, |
| 13931 | => |tag| { | 13918 | => |tag| { |
| 13932 | const extra = self.constantExtraData(Constant.Binary, data); | 13919 | const extra = self.constantExtraData(Constant.Binary, data); |
| 13933 | try constants_block.writeAbbrevAdapted(Constants.Binary{ | 13920 | try constants_block.writeAbbrevAdapted(ConstantsBlock.Binary{ |
| 13934 | .opcode = tag.toBinaryOpcode(), | 13921 | .opcode = tag.toBinaryOpcode(), |
| 13935 | .lhs = extra.lhs, | 13922 | .lhs = extra.lhs, |
| 13936 | .rhs = extra.rhs, | 13923 | .rhs = extra.rhs, |
| ... | @@ -14014,7 +14001,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14014,7 +14001,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14014 | }, | 14001 | }, |
| 14015 | .blockaddress => { | 14002 | .blockaddress => { |
| 14016 | const extra = self.constantExtraData(Constant.BlockAddress, data); | 14003 | const extra = self.constantExtraData(Constant.BlockAddress, data); |
| 14017 | try constants_block.writeAbbrev(Constants.BlockAddress{ | 14004 | try constants_block.writeAbbrev(ConstantsBlock.BlockAddress{ |
| 14018 | .type_id = extra.function.typeOf(self), | 14005 | .type_id = extra.function.typeOf(self), |
| 14019 | .function = constant_adapter.getConstantIndex(extra.function.toConst(self)), | 14006 | .function = constant_adapter.getConstantIndex(extra.function.toConst(self)), |
| 14020 | .block = @intFromEnum(extra.block), | 14007 | .block = @intFromEnum(extra.block), |
| ... | @@ -14024,10 +14011,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14024,10 +14011,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14024 | .no_cfi, | 14011 | .no_cfi, |
| 14025 | => |tag| { | 14012 | => |tag| { |
| 14026 | const function: Function.Index = @enumFromInt(data); | 14013 | const function: Function.Index = @enumFromInt(data); |
| 14027 | try constants_block.writeAbbrev(Constants.DsoLocalEquivalentOrNoCfi{ | 14014 | try constants_block.writeAbbrev(ConstantsBlock.DsoLocalEquivalentOrNoCfi{ |
| 14028 | .code = switch (tag) { | 14015 | .code = switch (tag) { |
| 14029 | .dso_local_equivalent => 27, | 14016 | .dso_local_equivalent => .DSO_LOCAL_EQUIVALENT, |
| 14030 | .no_cfi => 29, | 14017 | .no_cfi => .NO_CFI_VALUE, |
| 14031 | else => unreachable, | 14018 | else => unreachable, |
| 14032 | }, | 14019 | }, |
| 14033 | .type_id = function.typeOf(self), | 14020 | .type_id = function.typeOf(self), |
| ... | @@ -14042,7 +14029,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14042,7 +14029,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14042 | | 14029 | |
| 14043 | // METADATA_KIND_BLOCK | 14030 | // METADATA_KIND_BLOCK |
| 14044 | { | 14031 | { |
| 14045 | const MetadataKindBlock = ir.MetadataKindBlock; | 14032 | const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock; |
| 14046 | var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true); | 14033 | var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true); |
| 14047 | | 14034 | |
| 14048 | inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| { | 14035 | inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| { |
| ... | @@ -14059,95 +14046,85 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14059,95 +14046,85 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14059 | } | 14046 | } |
| 14060 | | 14047 | |
| 14061 | const MetadataAdapter = struct { | 14048 | const MetadataAdapter = struct { |
| 14062 | builder: *const Builder, | | |
| 14063 | constant_adapter: ConstantAdapter, | 14049 | constant_adapter: ConstantAdapter, |
| 14064 | | 14050 | |
| 14065 | pub fn init( | 14051 | pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { |
| 14066 | builder: *const Builder, | 14052 | Metadata, Metadata.Optional, Metadata.String, Metadata.String.Optional, Constant => u32, |
| 14067 | const_adapter: ConstantAdapter, | 14053 | else => |Result| Result, |
| 14068 | ) @This() { | 14054 | } { |
| 14069 | return .{ | 14055 | return switch (@TypeOf(param)) { |
| 14070 | .builder = builder, | 14056 | Metadata => adapter.getMetadataIndex(param), |
| 14071 | .constant_adapter = const_adapter, | 14057 | Metadata.Optional => adapter.getOptionalMetadataIndex(param), |
| 14072 | }; | 14058 | Metadata.String => adapter.getMetadataIndex(param.toMetadata()), |
| 14073 | } | 14059 | Metadata.String.Optional => adapter.getOptionalMetadataIndex(param.toMetadata()), |
| 14074 | | 14060 | Constant => adapter.constant_adapter.getConstantIndex(param), |
| 14075 | pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) { | 14061 | else => param, |
| 14076 | _ = field_name; | | |
| 14077 | const Ty = @TypeOf(value); | | |
| 14078 | return switch (Ty) { | | |
| 14079 | Metadata => @enumFromInt(adapter.getMetadataIndex(value)), | | |
| 14080 | MetadataString => @enumFromInt(adapter.getMetadataStringIndex(value)), | | |
| 14081 | Constant => @enumFromInt(adapter.constant_adapter.getConstantIndex(value)), | | |
| 14082 | else => value, | | |
| 14083 | }; | 14062 | }; |
| 14084 | } | 14063 | } |
| 14085 | | 14064 | |
| 14086 | pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 { | 14065 | pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 { |
| 14087 | if (metadata == .none) return 0; | 14066 | const builder = adapter.constant_adapter.builder; |
| 14088 | return @intCast(adapter.builder.metadata_string_map.count() + | 14067 | const unwrapped_metadata = metadata.unwrap(builder); |
| 14089 | @intFromEnum(metadata.unwrap(adapter.builder)) - 1); | 14068 | return switch (unwrapped_metadata.kind) { |
| | 14069 | .string => unwrapped_metadata.index, |
| | 14070 | .node => @intCast(builder.metadata_string_map.count() + unwrapped_metadata.index), |
| | 14071 | .forward, .local => unreachable, |
| | 14072 | }; |
| 14090 | } | 14073 | } |
| 14091 | | 14074 | |
| 14092 | pub fn getMetadataStringIndex(_: @This(), metadata_string: MetadataString) u32 { | 14075 | pub fn getOptionalMetadataIndex(adapter: @This(), metadata: Metadata.Optional) u32 { |
| 14093 | return @intFromEnum(metadata_string); | 14076 | return if (metadata.unwrap()) |m| 1 + adapter.getMetadataIndex(m) else 0; |
| 14094 | } | 14077 | } |
| 14095 | }; | 14078 | }; |
| 14096 | | 14079 | const metadata_adapter: MetadataAdapter = .{ .constant_adapter = constant_adapter }; |
| 14097 | const metadata_adapter = MetadataAdapter.init(self, constant_adapter); | | |
| 14098 | | 14080 | |
| 14099 | // METADATA_BLOCK | 14081 | // METADATA_BLOCK |
| 14100 | { | 14082 | { |
| 14101 | const MetadataBlock = ir.MetadataBlock; | 14083 | const MetadataBlock = ir.ModuleBlock.MetadataBlock; |
| 14102 | var metadata_block = try module_block.enterSubBlock(MetadataBlock, true); | 14084 | var metadata_block = try module_block.enterSubBlock(MetadataBlock, true); |
| 14103 | | 14085 | |
| 14104 | const MetadataBlockWriter = @TypeOf(metadata_block); | 14086 | const MetadataBlockWriter = @TypeOf(metadata_block); |
| 14105 | | 14087 | |
| 14106 | // Emit all MetadataStrings | 14088 | // Emit all Metadata.Strings |
| 14107 | if (self.metadata_string_map.count() > 1) { | 14089 | const strings_len: u32 = @intCast(self.metadata_string_map.count()); |
| 14108 | const strings_offset, const strings_size = blk: { | 14090 | if (strings_len > 0) { |
| 14109 | var strings_offset: u32 = 0; | 14091 | const string_bytes_offset = string_bytes_offset: { |
| 14110 | var strings_size: u32 = 0; | 14092 | var string_bytes_bit_offset: u32 = 0; |
| 14111 | for (1..self.metadata_string_map.count()) |metadata_string_index| { | 14093 | for ( |
| 14112 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); | 14094 | self.metadata_string_indices.items[0..strings_len], |
| 14113 | const slice = metadata_string.slice(self); | 14095 | self.metadata_string_indices.items[1..], |
| 14114 | strings_offset += bitcode.bitsVBR(@as(u32, @intCast(slice.len)), 6); | 14096 | ) |start, end| string_bytes_bit_offset += BitcodeWriter.bitsVbr(end - start, 6); |
| 14115 | strings_size += @intCast(slice.len * 8); | 14097 | break :string_bytes_offset @divExact( |
| 14116 | } | 14098 | std.mem.alignForward(u32, string_bytes_bit_offset, 32), |
| 14117 | break :blk .{ | 14099 | 8, |
| 14118 | std.mem.alignForward(u32, strings_offset, 32) / 8, | 14100 | ); |
| 14119 | std.mem.alignForward(u32, strings_size, 32) / 8, | | |
| 14120 | }; | | |
| 14121 | }; | 14101 | }; |
| | 14102 | const string_bytes_len = |
| | 14103 | std.mem.alignForward(u32, @intCast(self.metadata_string_bytes.items.len), 4); |
| 14122 | | 14104 | |
| 14123 | try bitcode.writeBits( | 14105 | try bitcode.writeBits( |
| 14124 | comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings), | 14106 | comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings), |
| 14125 | MetadataBlockWriter.abbrev_len, | 14107 | MetadataBlockWriter.abbrev_len, |
| 14126 | ); | 14108 | ); |
| 14127 | | 14109 | |
| 14128 | try bitcode.writeVBR(@as(u32, @intCast(self.metadata_string_map.count() - 1)), 6); | 14110 | try bitcode.writeVbr(strings_len, 6); |
| 14129 | try bitcode.writeVBR(strings_offset, 6); | 14111 | try bitcode.writeVbr(string_bytes_offset, 6); |
| 14130 | | 14112 | |
| 14131 | try bitcode.writeVBR(strings_size + strings_offset, 6); | 14113 | try bitcode.writeVbr(string_bytes_offset + string_bytes_len, 6); |
| 14132 | | 14114 | |
| 14133 | try bitcode.alignTo32(); | 14115 | try bitcode.alignTo32(); |
| 14134 | | 14116 | |
| 14135 | for (1..self.metadata_string_map.count()) |metadata_string_index| { | 14117 | for ( |
| 14136 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); | 14118 | self.metadata_string_indices.items[0..strings_len], |
| 14137 | const slice = metadata_string.slice(self); | 14119 | self.metadata_string_indices.items[1..], |
| 14138 | try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6); | 14120 | ) |start, end| try bitcode.writeVbr(end - start, 6); |
| 14139 | } | | |
| 14140 | | 14121 | |
| 14141 | try bitcode.writeBlob(self.metadata_string_bytes.items); | 14122 | try bitcode.writeBlob(self.metadata_string_bytes.items); |
| 14142 | } | 14123 | } |
| 14143 | | 14124 | |
| 14144 | for ( | 14125 | for (self.metadata_items.items(.tag), self.metadata_items.items(.data)) |tag, data| { |
| 14145 | self.metadata_items.items(.tag)[1..], | | |
| 14146 | self.metadata_items.items(.data)[1..], | | |
| 14147 | ) |tag, data| { | | |
| 14148 | record.clearRetainingCapacity(); | 14126 | record.clearRetainingCapacity(); |
| 14149 | switch (tag) { | 14127 | switch (tag) { |
| 14150 | .none => unreachable, | | |
| 14151 | .file => { | 14128 | .file => { |
| 14152 | const extra = self.metadataExtraData(Metadata.File, data); | 14129 | const extra = self.metadataExtraData(Metadata.File, data); |
| 14153 | | 14130 | |
| ... | @@ -14209,13 +14186,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14209,13 +14186,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14209 | }, | 14186 | }, |
| 14210 | .location => { | 14187 | .location => { |
| 14211 | const extra = self.metadataExtraData(Metadata.Location, data); | 14188 | const extra = self.metadataExtraData(Metadata.Location, data); |
| 14212 | assert(extra.scope != .none); | 14189 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Location{ |
| 14213 | try metadata_block.writeAbbrev(MetadataBlock.Location{ | | |
| 14214 | .line = extra.line, | 14190 | .line = extra.line, |
| 14215 | .column = extra.column, | 14191 | .column = extra.column, |
| 14216 | .scope = metadata_adapter.getMetadataIndex(extra.scope) - 1, | 14192 | .scope = extra.scope, |
| 14217 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)), | 14193 | .inlined_at = extra.inlined_at, |
| 14218 | }); | 14194 | }, metadata_adapter); |
| 14219 | }, | 14195 | }, |
| 14220 | .basic_bool_type, | 14196 | .basic_bool_type, |
| 14221 | .basic_unsigned_type, | 14197 | .basic_unsigned_type, |
| ... | @@ -14325,7 +14301,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14325,7 +14301,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14325 | @bitCast(flags), | 14301 | @bitCast(flags), |
| 14326 | )); | 14302 | )); |
| 14327 | record.appendAssumeCapacity(extra.bit_width); | 14303 | record.appendAssumeCapacity(extra.bit_width); |
| 14328 | record.appendAssumeCapacity(metadata_adapter.getMetadataStringIndex(extra.name)); | 14304 | record.appendAssumeCapacity(metadata_adapter.getOptionalMetadataIndex(extra.name.toMetadata())); |
| 14329 | const limbs = record.addManyAsSliceAssumeCapacity(limbs_len); | 14305 | const limbs = record.addManyAsSliceAssumeCapacity(limbs_len); |
| 14330 | bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little); | 14306 | bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little); |
| 14331 | for (limbs) |*limb| { | 14307 | for (limbs) |*limb| { |
| ... | @@ -14335,7 +14311,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14335,7 +14311,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14335 | else | 14311 | else |
| 14336 | -%val << 1 | 1); | 14312 | -%val << 1 | 1); |
| 14337 | } | 14313 | } |
| 14338 | try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Enumerator.id), record.items); | 14314 | try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Code.ENUMERATOR), record.items); |
| 14339 | continue; | 14315 | continue; |
| 14340 | }; | 14316 | }; |
| 14341 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{ | 14317 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{ |
| ... | @@ -14350,7 +14326,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14350,7 +14326,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14350 | }, | 14326 | }, |
| 14351 | .subrange => { | 14327 | .subrange => { |
| 14352 | const extra = self.metadataExtraData(Metadata.Subrange, data); | 14328 | const extra = self.metadataExtraData(Metadata.Subrange, data); |
| 14353 | | | |
| 14354 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{ | 14329 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{ |
| 14355 | .count = extra.count, | 14330 | .count = extra.count, |
| 14356 | .lower_bound = extra.lower_bound, | 14331 | .lower_bound = extra.lower_bound, |
| ... | @@ -14358,48 +14333,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14358,48 +14333,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14358 | }, | 14333 | }, |
| 14359 | .expression => { | 14334 | .expression => { |
| 14360 | var extra = self.metadataExtraDataTrail(Metadata.Expression, data); | 14335 | var extra = self.metadataExtraDataTrail(Metadata.Expression, data); |
| 14361 | | | |
| 14362 | const elements = extra.trail.next(extra.data.elements_len, u32, self); | 14336 | const elements = extra.trail.next(extra.data.elements_len, u32, self); |
| 14363 | | | |
| 14364 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{ | 14337 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{ |
| 14365 | .elements = elements, | 14338 | .elements = elements, |
| 14366 | }, metadata_adapter); | 14339 | }, metadata_adapter); |
| 14367 | }, | 14340 | }, |
| 14368 | .tuple => { | 14341 | .tuple => { |
| 14369 | var extra = self.metadataExtraDataTrail(Metadata.Tuple, data); | 14342 | var extra = self.metadataExtraDataTrail(Metadata.Tuple, data); |
| 14370 | | 14343 | const elements = |
| 14371 | const elements = extra.trail.next(extra.data.elements_len, Metadata, self); | 14344 | extra.trail.next(extra.data.elements_len, Metadata.Optional, self); |
| 14372 | | | |
| 14373 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{ | 14345 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{ |
| 14374 | .elements = elements, | 14346 | .elements = elements, |
| 14375 | }, metadata_adapter); | 14347 | }, metadata_adapter); |
| 14376 | }, | 14348 | }, |
| 14377 | .str_tuple => { | | |
| 14378 | var extra = self.metadataExtraDataTrail(Metadata.StrTuple, data); | | |
| 14379 | | | |
| 14380 | const elements = extra.trail.next(extra.data.elements_len, Metadata, self); | | |
| 14381 | | | |
| 14382 | const all_elems = try self.gpa.alloc(Metadata, elements.len + 1); | | |
| 14383 | defer self.gpa.free(all_elems); | | |
| 14384 | all_elems[0] = @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.data.str)); | | |
| 14385 | for (elements, all_elems[1..]) |elem, *out_elem| { | | |
| 14386 | out_elem.* = @enumFromInt(metadata_adapter.getMetadataIndex(elem)); | | |
| 14387 | } | | |
| 14388 | | | |
| 14389 | try metadata_block.writeAbbrev(MetadataBlock.Node{ | | |
| 14390 | .elements = all_elems, | | |
| 14391 | }); | | |
| 14392 | }, | | |
| 14393 | .module_flag => { | | |
| 14394 | const extra = self.metadataExtraData(Metadata.ModuleFlag, data); | | |
| 14395 | try metadata_block.writeAbbrev(MetadataBlock.Node{ | | |
| 14396 | .elements = &.{ | | |
| 14397 | @enumFromInt(metadata_adapter.getMetadataIndex(extra.behavior)), | | |
| 14398 | @enumFromInt(metadata_adapter.getMetadataStringIndex(extra.name)), | | |
| 14399 | @enumFromInt(metadata_adapter.getMetadataIndex(extra.constant)), | | |
| 14400 | }, | | |
| 14401 | }); | | |
| 14402 | }, | | |
| 14403 | .local_var => { | 14349 | .local_var => { |
| 14404 | const extra = self.metadataExtraData(Metadata.LocalVar, data); | 14350 | const extra = self.metadataExtraData(Metadata.LocalVar, data); |
| 14405 | try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{ | 14351 | try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{ |
| ... | @@ -14454,37 +14400,28 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14454,37 +14400,28 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14454 | | 14400 | |
| 14455 | // Write named metadata | 14401 | // Write named metadata |
| 14456 | for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| { | 14402 | for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| { |
| 14457 | const slice = name.slice(self); | 14403 | try metadata_block.writeAbbrev(MetadataBlock.Name{ .name = name.slice(self).? }); |
| 14458 | try metadata_block.writeAbbrev(MetadataBlock.Name{ | 14404 | try metadata_block.writeAbbrevAdapted(MetadataBlock.NamedNode{ |
| 14459 | .name = slice, | 14405 | .elements = @ptrCast(self.metadata_extra.items[operands.index..][0..operands.len]), |
| 14460 | }); | 14406 | }, metadata_adapter); |
| 14461 | | | |
| 14462 | const elements = self.metadata_extra.items[operands.index..][0..operands.len]; | | |
| 14463 | for (elements) |*e| { | | |
| 14464 | e.* = metadata_adapter.getMetadataIndex(@enumFromInt(e.*)) - 1; | | |
| 14465 | } | | |
| 14466 | | | |
| 14467 | try metadata_block.writeAbbrev(MetadataBlock.NamedNode{ | | |
| 14468 | .elements = @ptrCast(elements), | | |
| 14469 | }); | | |
| 14470 | } | 14407 | } |
| 14471 | | 14408 | |
| 14472 | // Write global attached metadata | 14409 | // Write global attached metadata |
| 14473 | { | 14410 | { |
| 14474 | for (globals.keys()) |global| { | 14411 | for (globals.keys()) |global_index| { |
| 14475 | const global_ptr = global.ptrConst(self); | 14412 | const global = global_index.ptrConst(self); |
| 14476 | if (global_ptr.dbg == .none) continue; | 14413 | if (global.dbg.unwrap()) |dbg| { |
| | 14414 | switch (global.kind) { |
| | 14415 | .function => |f| if (f.ptrConst(self).instructions.len != 0) continue, |
| | 14416 | else => {}, |
| | 14417 | } |
| 14477 | | 14418 | |
| 14478 | switch (global_ptr.kind) { | 14419 | try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalDeclAttachment{ |
| 14479 | .function => |f| if (f.ptrConst(self).instructions.len != 0) continue, | 14420 | .value = global_index.toConst(), |
| 14480 | else => {}, | 14421 | .kind = .dbg, |
| | 14422 | .metadata = dbg, |
| | 14423 | }, metadata_adapter); |
| 14481 | } | 14424 | } |
| 14482 | | | |
| 14483 | try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{ | | |
| 14484 | .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())), | | |
| 14485 | .kind = .dbg, | | |
| 14486 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1), | | |
| 14487 | }); | | |
| 14488 | } | 14425 | } |
| 14489 | } | 14426 | } |
| 14490 | | 14427 | |
| ... | @@ -14493,10 +14430,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14493,10 +14430,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14493 | | 14430 | |
| 14494 | // OPERAND_BUNDLE_TAGS_BLOCK | 14431 | // OPERAND_BUNDLE_TAGS_BLOCK |
| 14495 | { | 14432 | { |
| 14496 | const OperandBundleTags = ir.OperandBundleTags; | 14433 | const OperandBundleTagsBlock = ir.ModuleBlock.OperandBundleTagsBlock; |
| 14497 | var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTags, true); | 14434 | var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTagsBlock, true); |
| 14498 | | 14435 | |
| 14499 | try operand_bundle_tags_block.writeAbbrev(OperandBundleTags.OperandBundleTag{ | 14436 | try operand_bundle_tags_block.writeAbbrev(OperandBundleTagsBlock.OperandBundleTag{ |
| 14500 | .tag = "cold", | 14437 | .tag = "cold", |
| 14501 | }); | 14438 | }); |
| 14502 | | 14439 | |
| ... | @@ -14505,26 +14442,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14505,26 +14442,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14505 | | 14442 | |
| 14506 | // Block info | 14443 | // Block info |
| 14507 | { | 14444 | { |
| 14508 | const BlockInfo = ir.BlockInfo; | 14445 | const BlockInfoBlock = ir.BlockInfoBlock; |
| 14509 | var block_info_block = try module_block.enterSubBlock(BlockInfo, true); | 14446 | var block_info_block = try module_block.enterSubBlock(BlockInfoBlock, true); |
| 14510 | | 14447 | |
| 14511 | try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionBlock.id}); | 14448 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ |
| 14512 | inline for (ir.FunctionBlock.abbrevs) |abbrev| { | 14449 | @intFromEnum(ir.ModuleBlock.FunctionBlock.id), |
| | 14450 | }); |
| | 14451 | inline for (ir.ModuleBlock.FunctionBlock.abbrevs) |abbrev| { |
| 14513 | try block_info_block.defineAbbrev(&abbrev.ops); | 14452 | try block_info_block.defineAbbrev(&abbrev.ops); |
| 14514 | } | 14453 | } |
| 14515 | | 14454 | |
| 14516 | try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionValueSymbolTable.id}); | 14455 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ |
| 14517 | inline for (ir.FunctionValueSymbolTable.abbrevs) |abbrev| { | 14456 | @intFromEnum(ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.id), |
| | 14457 | }); |
| | 14458 | inline for (ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.abbrevs) |abbrev| { |
| 14518 | try block_info_block.defineAbbrev(&abbrev.ops); | 14459 | try block_info_block.defineAbbrev(&abbrev.ops); |
| 14519 | } | 14460 | } |
| 14520 | | 14461 | |
| 14521 | try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.FunctionMetadataBlock.id}); | 14462 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ |
| 14522 | inline for (ir.FunctionMetadataBlock.abbrevs) |abbrev| { | 14463 | @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataBlock.id), |
| | 14464 | }); |
| | 14465 | inline for (ir.ModuleBlock.FunctionBlock.MetadataBlock.abbrevs) |abbrev| { |
| 14523 | try block_info_block.defineAbbrev(&abbrev.ops); | 14466 | try block_info_block.defineAbbrev(&abbrev.ops); |
| 14524 | } | 14467 | } |
| 14525 | | 14468 | |
| 14526 | try block_info_block.writeUnabbrev(BlockInfo.set_block_id, &.{ir.MetadataAttachmentBlock.id}); | 14469 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ |
| 14527 | inline for (ir.MetadataAttachmentBlock.abbrevs) |abbrev| { | 14470 | @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.id), |
| | 14471 | }); |
| | 14472 | inline for (ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.abbrevs) |abbrev| { |
| 14528 | try block_info_block.defineAbbrev(&abbrev.ops); | 14473 | try block_info_block.defineAbbrev(&abbrev.ops); |
| 14529 | } | 14474 | } |
| 14530 | | 14475 | |
| ... | @@ -14534,38 +14479,40 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14534,38 +14479,40 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14534 | // FUNCTION_BLOCKS | 14479 | // FUNCTION_BLOCKS |
| 14535 | { | 14480 | { |
| 14536 | const FunctionAdapter = struct { | 14481 | const FunctionAdapter = struct { |
| 14537 | constant_adapter: ConstantAdapter, | | |
| 14538 | metadata_adapter: MetadataAdapter, | 14482 | metadata_adapter: MetadataAdapter, |
| 14539 | func: *const Function, | 14483 | func: *const Function, |
| 14540 | instruction_index: Function.Instruction.Index, | 14484 | instruction_index: Function.Instruction.Index, |
| 14541 | | 14485 | |
| 14542 | pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) { | 14486 | pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { |
| 14543 | _ = field_name; | 14487 | Value, Constant, FunctionAttributes => u32, |
| 14544 | const Ty = @TypeOf(value); | 14488 | else => |Result| Result, |
| 14545 | return switch (Ty) { | 14489 | } { |
| 14546 | Value => @enumFromInt(adapter.getOffsetValueIndex(value)), | 14490 | return switch (@TypeOf(param)) { |
| 14547 | Constant => @enumFromInt(adapter.getOffsetConstantIndex(value)), | 14491 | Value => adapter.getOffsetValueIndex(param), |
| 14548 | FunctionAttributes => @enumFromInt(switch (value) { | 14492 | Constant => adapter.getOffsetConstantIndex(param), |
| | 14493 | FunctionAttributes => switch (param) { |
| 14549 | .none => 0, | 14494 | .none => 0, |
| 14550 | else => 1 + adapter.constant_adapter.builder.function_attributes_set.getIndex(value).?, | 14495 | else => @intCast(1 + adapter.metadata_adapter.constant_adapter.builder |
| 14551 | }), | 14496 | .function_attributes_set.getIndex(param).?), |
| 14552 | else => value, | 14497 | }, |
| | 14498 | else => param, |
| 14553 | }; | 14499 | }; |
| 14554 | } | 14500 | } |
| 14555 | | 14501 | |
| 14556 | pub fn getValueIndex(adapter: @This(), value: Value) u32 { | 14502 | pub fn getValueIndex(adapter: @This(), value: Value) u32 { |
| 14557 | return @intCast(switch (value.unwrap()) { | 14503 | return @intCast(switch (value.unwrap()) { |
| 14558 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), | 14504 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), |
| 14559 | .constant => |constant| adapter.constant_adapter.getConstantIndex(constant), | 14505 | .constant => |constant| adapter.metadata_adapter.constant_adapter.getConstantIndex(constant), |
| 14560 | .metadata => |metadata| { | 14506 | .metadata => |metadata| { |
| 14561 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); | 14507 | const builder = adapter.metadata_adapter.constant_adapter.builder; |
| 14562 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) | 14508 | const unwrapped_metadata = metadata.unwrap(builder); |
| 14563 | return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; | 14509 | return switch (unwrapped_metadata.kind) { |
| 14564 | | 14510 | .string, .node => adapter.metadata_adapter.getMetadataIndex(unwrapped_metadata), |
| 14565 | return @intCast(@intFromEnum(metadata) - | 14511 | .forward => unreachable, |
| 14566 | Metadata.first_local_metadata + | 14512 | .local => @intCast(builder.metadata_string_map.count() + |
| 14567 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + | 14513 | builder.metadata_map.count() + |
| 14568 | adapter.metadata_adapter.builder.metadata_map.count() - 1); | 14514 | unwrapped_metadata.index), |
| | 14515 | }; |
| 14569 | }, | 14516 | }, |
| 14570 | }); | 14517 | }); |
| 14571 | } | 14518 | } |
| ... | @@ -14589,12 +14536,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14589,12 +14536,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14589 | } | 14536 | } |
| 14590 | | 14537 | |
| 14591 | fn firstInstr(adapter: @This()) u32 { | 14538 | fn firstInstr(adapter: @This()) u32 { |
| 14592 | return adapter.constant_adapter.numConstants(); | 14539 | return adapter.metadata_adapter.constant_adapter.numConstants(); |
| 14593 | } | 14540 | } |
| 14594 | }; | 14541 | }; |
| 14595 | | 14542 | |
| 14596 | for (self.functions.items, 0..) |func, func_index| { | 14543 | for (self.functions.items, 0..) |func, func_index| { |
| 14597 | const FunctionBlock = ir.FunctionBlock; | 14544 | const FunctionBlock = ir.ModuleBlock.FunctionBlock; |
| 14598 | if (func.global.getReplacement(self) != .none) continue; | 14545 | if (func.global.getReplacement(self) != .none) continue; |
| 14599 | | 14546 | |
| 14600 | if (func.instructions.len == 0) continue; | 14547 | if (func.instructions.len == 0) continue; |
| ... | @@ -14604,7 +14551,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14604,7 +14551,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14604 | try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len }); | 14551 | try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len }); |
| 14605 | | 14552 | |
| 14606 | var adapter: FunctionAdapter = .{ | 14553 | var adapter: FunctionAdapter = .{ |
| 14607 | .constant_adapter = constant_adapter, | | |
| 14608 | .metadata_adapter = metadata_adapter, | 14554 | .metadata_adapter = metadata_adapter, |
| 14609 | .func = &func, | 14555 | .func = &func, |
| 14610 | .instruction_index = @enumFromInt(0), | 14556 | .instruction_index = @enumFromInt(0), |
| ... | @@ -14612,7 +14558,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -14612,7 +14558,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14612 | | 14558 | |
| 14613 | // Emit function level metadata block | 14559 | // Emit function level metadata block |
| 14614 | if (!func.strip and func.debug_values.len > 0) { | 14560 | if (!func.strip and func.debug_values.len > 0) { |
| 14615 | const MetadataBlock = ir.FunctionMetadataBlock; | 14561 | const MetadataBlock = ir.ModuleBlock.FunctionBlock.MetadataBlock; |
| 14616 | var metadata_block = try function_block.enterSubBlock(MetadataBlock, false); | 14562 | var metadata_block = try function_block.enterSubBlock(MetadataBlock, false); |
| 14617 | | 14563 | |
| 14618 | for (func.debug_values) |value| { | 14564 | for (func.debug_values) |value| { |
| ... | @@ -15048,7 +14994,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -15048,7 +14994,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15048 | const vals = extra.trail.next(extra.data.cases_len, Constant, &func); | 14994 | const vals = extra.trail.next(extra.data.cases_len, Constant, &func); |
| 15049 | const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func); | 14995 | const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func); |
| 15050 | for (vals, blocks) |val, block| { | 14996 | for (vals, blocks) |val, block| { |
| 15051 | record.appendAssumeCapacity(adapter.constant_adapter.getConstantIndex(val)); | 14997 | record.appendAssumeCapacity(adapter.metadata_adapter.constant_adapter.getConstantIndex(val)); |
| 15052 | record.appendAssumeCapacity(@intFromEnum(block)); | 14998 | record.appendAssumeCapacity(@intFromEnum(block)); |
| 15053 | } | 14999 | } |
| 15054 | | 15000 | |
| ... | @@ -15135,12 +15081,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -15135,12 +15081,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15135 | switch (debug_location) { | 15081 | switch (debug_location) { |
| 15136 | .no_location => has_location = false, | 15082 | .no_location => has_location = false, |
| 15137 | .location => |location| { | 15083 | .location => |location| { |
| 15138 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ | 15084 | try function_block.writeAbbrevAdapted(FunctionBlock.DebugLoc{ |
| 15139 | .line = location.line, | 15085 | .line = location.line, |
| 15140 | .column = location.column, | 15086 | .column = location.column, |
| 15141 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)), | 15087 | .scope = location.scope, |
| 15142 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)), | 15088 | .inlined_at = location.inlined_at, |
| 15143 | }); | 15089 | }, metadata_adapter); |
| 15144 | has_location = true; | 15090 | has_location = true; |
| 15145 | }, | 15091 | }, |
| 15146 | } | 15092 | } |
| ... | @@ -15152,16 +15098,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -15152,16 +15098,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15152 | | 15098 | |
| 15153 | // VALUE_SYMTAB | 15099 | // VALUE_SYMTAB |
| 15154 | if (!func.strip) { | 15100 | if (!func.strip) { |
| 15155 | const ValueSymbolTable = ir.FunctionValueSymbolTable; | 15101 | const ValueSymtabBlock = ir.ModuleBlock.FunctionBlock.ValueSymtabBlock; |
| 15156 | | 15102 | |
| 15157 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable, false); | 15103 | var value_symtab_block = try function_block.enterSubBlock(ValueSymtabBlock, false); |
| 15158 | | 15104 | |
| 15159 | for (func.blocks, 0..) |block, block_index| { | 15105 | for (func.blocks, 0..) |block, block_index| { |
| 15160 | const name = block.instruction.name(&func); | 15106 | const name = block.instruction.name(&func); |
| 15161 | | 15107 | |
| 15162 | if (name == .none or name == .empty) continue; | 15108 | if (name == .none or name == .empty) continue; |
| 15163 | | 15109 | |
| 15164 | try value_symtab_block.writeAbbrev(ValueSymbolTable.BlockEntry{ | 15110 | try value_symtab_block.writeAbbrev(ValueSymtabBlock.BlockEntry{ |
| 15165 | .value_id = @intCast(block_index), | 15111 | .value_id = @intCast(block_index), |
| 15166 | .string = name.slice(self).?, | 15112 | .string = name.slice(self).?, |
| 15167 | }); | 15113 | }); |
| ... | @@ -15174,17 +15120,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -15174,17 +15120,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15174 | | 15120 | |
| 15175 | // METADATA_ATTACHMENT_BLOCK | 15121 | // METADATA_ATTACHMENT_BLOCK |
| 15176 | { | 15122 | { |
| 15177 | const MetadataAttachmentBlock = ir.MetadataAttachmentBlock; | 15123 | const MetadataAttachmentBlock = ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock; |
| 15178 | var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false); | 15124 | var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false); |
| 15179 | | 15125 | |
| 15180 | dbg: { | 15126 | if (func.global.ptrConst(self).dbg.unwrap()) |dbg| { |
| 15181 | if (func.strip) break :dbg; | 15127 | try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentGlobalSingle{ |
| 15182 | const dbg = func.global.ptrConst(self).dbg; | | |
| 15183 | if (dbg == .none) break :dbg; | | |
| 15184 | try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{ | | |
| 15185 | .kind = .dbg, | 15128 | .kind = .dbg, |
| 15186 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1), | 15129 | .metadata = dbg, |
| 15187 | }); | 15130 | }, metadata_adapter); |
| 15188 | } | 15131 | } |
| 15189 | | 15132 | |
| 15190 | var instr_index: u32 = 0; | 15133 | var instr_index: u32 = 0; |
| ... | @@ -15201,16 +15144,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -15201,16 +15144,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15201 | }; | 15144 | }; |
| 15202 | switch (weights) { | 15145 | switch (weights) { |
| 15203 | .none => {}, | 15146 | .none => {}, |
| 15204 | .unpredictable => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{ | 15147 | .unpredictable => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{ |
| 15205 | .inst = instr_index, | 15148 | .inst = instr_index, |
| 15206 | .kind = .unpredictable, | 15149 | .kind = .unpredictable, |
| 15207 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1), | 15150 | .metadata = .empty_tuple, |
| 15208 | }), | 15151 | }, metadata_adapter), |
| 15209 | _ => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{ | 15152 | _ => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{ |
| 15210 | .inst = instr_index, | 15153 | .inst = instr_index, |
| 15211 | .kind = .prof, | 15154 | .kind = .prof, |
| 15212 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(@enumFromInt(@intFromEnum(weights))) - 1), | 15155 | .metadata = weights.toMetadata(), |
| 15213 | }), | 15156 | }, metadata_adapter), |
| 15214 | } | 15157 | } |
| 15215 | instr_index += 1; | 15158 | instr_index += 1; |
| 15216 | }, | 15159 | }, |
| ... | @@ -15228,7 +15171,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco | ... | @@ -15228,7 +15171,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15228 | | 15171 | |
| 15229 | // STRTAB_BLOCK | 15172 | // STRTAB_BLOCK |
| 15230 | { | 15173 | { |
| 15231 | const Strtab = ir.Strtab; | 15174 | const Strtab = ir.StrtabBlock; |
| 15232 | var strtab_block = try bitcode.enterTopBlock(Strtab); | 15175 | var strtab_block = try bitcode.enterTopBlock(Strtab); |
| 15233 | | 15176 | |
| 15234 | try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items }); | 15177 | try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items }); |