| author | |
| committer | |
| log | d28006153e3f221a3755d78c74f9c7716ad660b5 |
| tree | a5cc1052c40360571f99ff677e3139c327ca2691 |
| parent | 2810e4b173507b6d94a7108462b5c9bdcc0b6e0b |
Closes #254864 files changed, 3090 insertions(+), 2728 deletions(-)
lib/std/zig/llvm/Builder.zig+830-887| ... | ... | @@ -56,8 +56,8 @@ metadata_map: std.AutoArrayHashMapUnmanaged(void, void), |
| 56 | 56 | metadata_items: std.MultiArrayList(Metadata.Item), |
| 57 | 57 | metadata_extra: std.ArrayListUnmanaged(u32), |
| 58 | 58 | metadata_limbs: std.ArrayListUnmanaged(std.math.big.Limb), |
| 59 | metadata_forward_references: std.ArrayListUnmanaged(Metadata), | |
| 60 | metadata_named: std.AutoArrayHashMapUnmanaged(MetadataString, struct { | |
| 59 | metadata_forward_references: std.ArrayListUnmanaged(Metadata.Optional), | |
| 60 | metadata_named: std.AutoArrayHashMapUnmanaged(String, struct { | |
| 61 | 61 | len: u32, |
| 62 | 62 | index: Metadata.Item.ExtraIndex, |
| 63 | 63 | }), |
| ... | ... | @@ -265,19 +265,20 @@ pub const Type = enum(u32) { |
| 265 | 265 | }; |
| 266 | 266 | |
| 267 | 267 | pub const Simple = enum(u5) { |
| 268 | void = 2, | |
| 269 | half = 10, | |
| 270 | bfloat = 23, | |
| 271 | float = 3, | |
| 272 | double = 4, | |
| 273 | fp128 = 14, | |
| 274 | x86_fp80 = 13, | |
| 275 | ppc_fp128 = 15, | |
| 276 | x86_amx = 24, | |
| 277 | x86_mmx = 17, | |
| 278 | label = 5, | |
| 279 | token = 22, | |
| 280 | metadata = 16, | |
| 268 | const Code = ir.ModuleBlock.TypeBlock.Code; | |
| 269 | void = @intFromEnum(Code.VOID), | |
| 270 | half = @intFromEnum(Code.HALF), | |
| 271 | bfloat = @intFromEnum(Code.BFLOAT), | |
| 272 | float = @intFromEnum(Code.FLOAT), | |
| 273 | double = @intFromEnum(Code.DOUBLE), | |
| 274 | fp128 = @intFromEnum(Code.FP128), | |
| 275 | x86_fp80 = @intFromEnum(Code.X86_FP80), | |
| 276 | ppc_fp128 = @intFromEnum(Code.PPC_FP128), | |
| 277 | x86_amx = @intFromEnum(Code.X86_AMX), | |
| 278 | x86_mmx = @intFromEnum(Code.X86_MMX), | |
| 279 | label = @intFromEnum(Code.LABEL), | |
| 280 | token = @intFromEnum(Code.TOKEN), | |
| 281 | metadata = @intFromEnum(Code.METADATA), | |
| 281 | 282 | }; |
| 282 | 283 | |
| 283 | 284 | pub const Function = struct { |
| ... | ... | @@ -1325,8 +1326,8 @@ pub const Attribute = union(Kind) { |
| 1325 | 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 | return .{ .data = .{ .attribute_index = self, .builder = builder, .mode = mode } }; | |
| 1329 | pub fn fmt(self: Index, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) { | |
| 1330 | return .{ .data = .{ .attribute_index = self, .builder = builder, .flags = flags } }; | |
| 1330 | 1331 | } |
| 1331 | 1332 | |
| 1332 | 1333 | fn toStorage(self: Index, builder: *const Builder) Storage { |
| ... | ... | @@ -2295,7 +2296,7 @@ pub const Global = struct { |
| 2295 | 2296 | externally_initialized: ExternallyInitialized = .default, |
| 2296 | 2297 | type: Type, |
| 2297 | 2298 | partition: String = .none, |
| 2298 | dbg: Metadata = .none, | |
| 2299 | dbg: Metadata.Optional = .none, | |
| 2299 | 2300 | kind: union(enum) { |
| 2300 | 2301 | alias: Alias.Index, |
| 2301 | 2302 | variable: Variable.Index, |
| ... | ... | @@ -2375,7 +2376,11 @@ pub const Global = struct { |
| 2375 | 2376 | } |
| 2376 | 2377 | |
| 2377 | 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 | 2386 | const FormatData = struct { |
| ... | ... | @@ -2606,6 +2611,10 @@ pub const Variable = struct { |
| 2606 | 2611 | pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void { |
| 2607 | 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 | 4116 | pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void { |
| 4108 | 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 | 4125 | pub const Block = struct { |
| ... | ... | @@ -4869,13 +4882,20 @@ pub const Function = struct { |
| 4869 | 4882 | then: Block.Index, |
| 4870 | 4883 | @"else": Block.Index, |
| 4871 | 4884 | weights: Weights, |
| 4885 | ||
| 4872 | 4886 | pub const Weights = enum(u32) { |
| 4873 | // We can do this as metadata indices 0 and 1 are reserved. | |
| 4874 | none = 0, | |
| 4875 | unpredictable = 1, | |
| 4876 | /// These values should be converted to `Metadata` to be used | |
| 4877 | /// in a `prof` annotation providing branch weights. | |
| 4887 | none = @bitCast(Metadata.Optional.none), | |
| 4888 | unpredictable, | |
| 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 | 5150 | pub const Location = struct { |
| 5131 | 5151 | line: u32, |
| 5132 | 5152 | column: u32, |
| 5133 | scope: Builder.Metadata, | |
| 5134 | inlined_at: Builder.Metadata, | |
| 5153 | scope: Builder.Metadata.Optional, | |
| 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 | 5158 | return switch (self) { |
| 5139 | 5159 | .no_location => .none, |
| 5140 | .location => |location| try builder.debugLocation( | |
| 5160 | .location => |location| (try builder.debugLocation( | |
| 5141 | 5161 | location.line, |
| 5142 | 5162 | location.column, |
| 5143 | location.scope, | |
| 5144 | location.inlined_at, | |
| 5145 | ), | |
| 5163 | location.scope.unwrap().?, | |
| 5164 | location.inlined_at.unwrap(), | |
| 5165 | )).toOptional(), | |
| 5146 | 5166 | }; |
| 5147 | 5167 | } |
| 5148 | 5168 | }; |
| ... | ... | @@ -5280,20 +5300,19 @@ pub const WipFunction = struct { |
| 5280 | 5300 | .cond = cond, |
| 5281 | 5301 | .then = then, |
| 5282 | 5302 | .@"else" = @"else", |
| 5283 | .weights = switch (weights) { | |
| 5303 | .weights = weights: switch (weights) { | |
| 5284 | 5304 | .none => .none, |
| 5285 | 5305 | .unpredictable => .unpredictable, |
| 5286 | .then_likely, .else_likely => w: { | |
| 5306 | .then_likely, .else_likely => { | |
| 5287 | 5307 | const branch_weights_str = try self.builder.metadataString("branch_weights"); |
| 5288 | 5308 | const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1)); |
| 5289 | 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 | 5311 | .none, .unpredictable => unreachable, |
| 5292 | .then_likely => .{ likely_const, unlikely_const }, | |
| 5293 | .else_likely => .{ unlikely_const, likely_const }, | |
| 5312 | .then_likely => .{ branch_weights_str.toMetadata(), likely_const, unlikely_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); | |
| 5296 | break :w @enumFromInt(@intFromEnum(tuple)); | |
| 5315 | break :weights .fromMetadata(try self.builder.metadataTuple(&weight_vals)); | |
| 5297 | 5316 | }, |
| 5298 | 5317 | }, |
| 5299 | 5318 | }), |
| ... | ... | @@ -6197,20 +6216,18 @@ pub const WipFunction = struct { |
| 6197 | 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 | 6220 | if (self.strip) return .none; |
| 6202 | return switch (value.unwrap()) { | |
| 6203 | .instruction => |instr_index| blk: { | |
| 6221 | const metadata: Metadata = metadata: switch (value.unwrap()) { | |
| 6222 | .instruction => |instr_index| { | |
| 6204 | 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 | 6224 | if (!gop.found_existing) gop.key_ptr.* = instr_index; |
| 6208 | ||
| 6209 | break :blk metadata; | |
| 6225 | break :metadata .{ .index = @intCast(gop.index), .kind = .local }; | |
| 6210 | 6226 | }, |
| 6211 | 6227 | .constant => |constant| try self.builder.metadataConstant(constant), |
| 6212 | 6228 | .metadata => |metadata| metadata, |
| 6213 | 6229 | }; |
| 6230 | return metadata.toOptional(); | |
| 6214 | 6231 | } |
| 6215 | 6232 | |
| 6216 | 6233 | pub fn finish(self: *WipFunction) Allocator.Error!void { |
| ... | ... | @@ -7820,7 +7837,7 @@ pub const Value = enum(u32) { |
| 7820 | 7837 | else if (@intFromEnum(self) < first_metadata) |
| 7821 | 7838 | .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) } |
| 7822 | 7839 | else |
| 7823 | .{ .metadata = @enumFromInt(@intFromEnum(self) - first_metadata) }; | |
| 7840 | .{ .metadata = @bitCast(@intFromEnum(self) - first_metadata) }; | |
| 7824 | 7841 | } |
| 7825 | 7842 | |
| 7826 | 7843 | pub fn typeOfWip(self: Value, wip: *const WipFunction) Type { |
| ... | ... | @@ -7873,50 +7890,110 @@ pub const Value = enum(u32) { |
| 7873 | 7890 | } |
| 7874 | 7891 | }; |
| 7875 | 7892 | |
| 7876 | pub const MetadataString = enum(u32) { | |
| 7877 | none = 0, | |
| 7878 | _, | |
| 7893 | pub const Metadata = packed struct(u32) { | |
| 7894 | index: u29, | |
| 7895 | kind: Kind, | |
| 7896 | unused: enum(u1) { unused = 0 } = .unused, | |
| 7879 | 7897 | |
| 7880 | pub fn slice(self: MetadataString, builder: *const Builder) []const u8 { | |
| 7881 | const index = @intFromEnum(self); | |
| 7882 | const start = builder.metadata_string_indices.items[index]; | |
| 7883 | const end = builder.metadata_string_indices.items[index + 1]; | |
| 7884 | return builder.metadata_string_bytes.items[start..end]; | |
| 7885 | } | |
| 7898 | pub const Kind = enum(u2) { | |
| 7899 | string, | |
| 7900 | node, | |
| 7901 | forward, | |
| 7902 | local, | |
| 7903 | }; | |
| 7886 | 7904 | |
| 7887 | const Adapter = struct { | |
| 7888 | builder: *const Builder, | |
| 7889 | pub fn hash(_: Adapter, key: []const u8) u32 { | |
| 7890 | return @truncate(std.hash.Wyhash.hash(0, key)); | |
| 7905 | pub const empty_tuple: Metadata = .{ .kind = .node, .index = 0 }; | |
| 7906 | ||
| 7907 | pub const Optional = packed struct(u32) { | |
| 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 { | |
| 7893 | const rhs_metadata_string: MetadataString = @enumFromInt(rhs_index); | |
| 7894 | return std.mem.eql(u8, lhs_key, rhs_metadata_string.slice(ctx.builder)); | |
| 7918 | pub fn unwrap(metadata: Metadata.Optional) ?Metadata { | |
| 7919 | return if (metadata.is_none) null else .{ .index = metadata.index, .kind = metadata.kind }; | |
| 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 | ||
| 7898 | const FormatData = struct { | |
| 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); | |
| 7928 | pub fn toOptional(metadata: Metadata) Metadata.Optional { | |
| 7929 | return .{ .index = metadata.index, .kind = metadata.kind, .is_none = false }; | |
| 7904 | 7930 | } |
| 7905 | fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Alt(FormatData, format) { | |
| 7906 | return .{ .data = .{ .metadata_string = self, .builder = builder } }; | |
| 7931 | pub fn toValue(metadata: Metadata) Value { | |
| 7932 | return @enumFromInt(Value.first_metadata + @as(u32, @bitCast(metadata))); | |
| 7907 | 7933 | } |
| 7908 | }; | |
| 7909 | 7934 | |
| 7910 | pub const Metadata = enum(u32) { | |
| 7911 | none = 0, | |
| 7912 | empty_tuple = 1, | |
| 7913 | _, | |
| 7935 | pub const String = enum(u32) { | |
| 7936 | _, | |
| 7937 | ||
| 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; | |
| 7916 | const first_local_metadata = 1 << 30; | |
| 7962 | pub fn slice(metadata: Metadata.String, builder: *const Builder) []const u8 { | |
| 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 | 7996 | pub const Tag = enum(u6) { |
| 7919 | none, | |
| 7920 | 7997 | file, |
| 7921 | 7998 | compile_unit, |
| 7922 | 7999 | @"compile_unit optimized", |
| ... | ... | @@ -7947,8 +8024,6 @@ pub const Metadata = enum(u32) { |
| 7947 | 8024 | enumerator_signed_negative, |
| 7948 | 8025 | subrange, |
| 7949 | 8026 | tuple, |
| 7950 | str_tuple, | |
| 7951 | module_flag, | |
| 7952 | 8027 | expression, |
| 7953 | 8028 | local_var, |
| 7954 | 8029 | parameter, |
| ... | ... | @@ -7957,9 +8032,8 @@ pub const Metadata = enum(u32) { |
| 7957 | 8032 | global_var_expression, |
| 7958 | 8033 | constant, |
| 7959 | 8034 | |
| 7960 | pub fn isInline(tag: Tag) bool { | |
| 7961 | return switch (tag) { | |
| 7962 | .none, | |
| 8035 | pub fn isInline(metadata_tag: Metadata.Tag) bool { | |
| 8036 | return switch (metadata_tag) { | |
| 7963 | 8037 | .expression, |
| 7964 | 8038 | .constant, |
| 7965 | 8039 | => true, |
| ... | ... | @@ -7993,8 +8067,6 @@ pub const Metadata = enum(u32) { |
| 7993 | 8067 | .enumerator_signed_negative, |
| 7994 | 8068 | .subrange, |
| 7995 | 8069 | .tuple, |
| 7996 | .str_tuple, | |
| 7997 | .module_flag, | |
| 7998 | 8070 | .local_var, |
| 7999 | 8071 | .parameter, |
| 8000 | 8072 | .global_var, |
| ... | ... | @@ -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 { | |
| 8009 | return builder.metadata_items.items(.tag)[@intFromEnum(self)].isInline(); | |
| 8080 | pub fn tag(metadata: Metadata, builder: *const Builder) Tag { | |
| 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 { | |
| 8013 | var metadata = self; | |
| 8014 | while (@intFromEnum(metadata) >= Metadata.first_forward_reference and | |
| 8015 | @intFromEnum(metadata) < Metadata.first_local_metadata) | |
| 8016 | { | |
| 8017 | const index = @intFromEnum(metadata) - Metadata.first_forward_reference; | |
| 8018 | metadata = builder.metadata_forward_references.items[index]; | |
| 8019 | assert(metadata != .none); | |
| 8085 | pub fn item(metadata: Metadata, builder: *const Builder) Item { | |
| 8086 | assert(metadata.kind == .node); | |
| 8087 | return builder.metadata_items.get(metadata.index); | |
| 8088 | } | |
| 8089 | ||
| 8090 | pub fn isInline(metadata: Metadata, builder: *const Builder) bool { | |
| 8091 | return metadata.tag(builder).isInline(); | |
| 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 | 8107 | pub const Item = struct { |
| ... | ... | @@ -8086,8 +8169,8 @@ pub const Metadata = enum(u32) { |
| 8086 | 8169 | }; |
| 8087 | 8170 | |
| 8088 | 8171 | pub const File = struct { |
| 8089 | filename: MetadataString, | |
| 8090 | directory: MetadataString, | |
| 8172 | filename: Metadata.String.Optional, | |
| 8173 | directory: Metadata.String.Optional, | |
| 8091 | 8174 | }; |
| 8092 | 8175 | |
| 8093 | 8176 | pub const CompileUnit = struct { |
| ... | ... | @@ -8095,10 +8178,10 @@ pub const Metadata = enum(u32) { |
| 8095 | 8178 | optimized: bool, |
| 8096 | 8179 | }; |
| 8097 | 8180 | |
| 8098 | file: Metadata, | |
| 8099 | producer: MetadataString, | |
| 8100 | enums: Metadata, | |
| 8101 | globals: Metadata, | |
| 8181 | file: Metadata.Optional, | |
| 8182 | producer: Metadata.String.Optional, | |
| 8183 | enums: Metadata.Optional, | |
| 8184 | globals: Metadata.Optional, | |
| 8102 | 8185 | }; |
| 8103 | 8186 | |
| 8104 | 8187 | pub const Subprogram = struct { |
| ... | ... | @@ -8142,19 +8225,34 @@ pub const Metadata = enum(u32) { |
| 8142 | 8225 | } |
| 8143 | 8226 | }; |
| 8144 | 8227 | |
| 8145 | file: Metadata, | |
| 8146 | name: MetadataString, | |
| 8147 | linkage_name: MetadataString, | |
| 8228 | file: Metadata.Optional, | |
| 8229 | name: Metadata.String.Optional, | |
| 8230 | linkage_name: Metadata.String.Optional, | |
| 8148 | 8231 | line: u32, |
| 8149 | 8232 | scope_line: u32, |
| 8150 | ty: Metadata, | |
| 8233 | ty: Metadata.Optional, | |
| 8151 | 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 | 8253 | pub const LexicalBlock = struct { |
| 8156 | scope: Metadata, | |
| 8157 | file: Metadata, | |
| 8254 | scope: Metadata.Optional, | |
| 8255 | file: Metadata.Optional, | |
| 8158 | 8256 | line: u32, |
| 8159 | 8257 | column: u32, |
| 8160 | 8258 | }; |
| ... | ... | @@ -8163,11 +8261,11 @@ pub const Metadata = enum(u32) { |
| 8163 | 8261 | line: u32, |
| 8164 | 8262 | column: u32, |
| 8165 | 8263 | scope: Metadata, |
| 8166 | inlined_at: Metadata, | |
| 8264 | inlined_at: Metadata.Optional, | |
| 8167 | 8265 | }; |
| 8168 | 8266 | |
| 8169 | 8267 | pub const BasicType = struct { |
| 8170 | name: MetadataString, | |
| 8268 | name: Metadata.String.Optional, | |
| 8171 | 8269 | size_in_bits_lo: u32, |
| 8172 | 8270 | size_in_bits_hi: u32, |
| 8173 | 8271 | |
| ... | ... | @@ -8177,16 +8275,16 @@ pub const Metadata = enum(u32) { |
| 8177 | 8275 | }; |
| 8178 | 8276 | |
| 8179 | 8277 | pub const CompositeType = struct { |
| 8180 | name: MetadataString, | |
| 8181 | file: Metadata, | |
| 8182 | scope: Metadata, | |
| 8278 | name: Metadata.String.Optional, | |
| 8279 | file: Metadata.Optional, | |
| 8280 | scope: Metadata.Optional, | |
| 8183 | 8281 | line: u32, |
| 8184 | underlying_type: Metadata, | |
| 8282 | underlying_type: Metadata.Optional, | |
| 8185 | 8283 | size_in_bits_lo: u32, |
| 8186 | 8284 | size_in_bits_hi: u32, |
| 8187 | 8285 | align_in_bits_lo: u32, |
| 8188 | 8286 | align_in_bits_hi: u32, |
| 8189 | fields_tuple: Metadata, | |
| 8287 | fields_tuple: Metadata.Optional, | |
| 8190 | 8288 | |
| 8191 | 8289 | pub fn bitSize(self: CompositeType) u64 { |
| 8192 | 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 | 8295 | }; |
| 8198 | 8296 | |
| 8199 | 8297 | pub const DerivedType = struct { |
| 8200 | name: MetadataString, | |
| 8201 | file: Metadata, | |
| 8202 | scope: Metadata, | |
| 8298 | name: Metadata.String.Optional, | |
| 8299 | file: Metadata.Optional, | |
| 8300 | scope: Metadata.Optional, | |
| 8203 | 8301 | line: u32, |
| 8204 | underlying_type: Metadata, | |
| 8302 | underlying_type: Metadata.Optional, | |
| 8205 | 8303 | size_in_bits_lo: u32, |
| 8206 | 8304 | size_in_bits_hi: u32, |
| 8207 | 8305 | align_in_bits_lo: u32, |
| ... | ... | @@ -8221,19 +8319,19 @@ pub const Metadata = enum(u32) { |
| 8221 | 8319 | }; |
| 8222 | 8320 | |
| 8223 | 8321 | pub const SubroutineType = struct { |
| 8224 | types_tuple: Metadata, | |
| 8322 | types_tuple: Metadata.Optional, | |
| 8225 | 8323 | }; |
| 8226 | 8324 | |
| 8227 | 8325 | pub const Enumerator = struct { |
| 8228 | name: MetadataString, | |
| 8326 | name: Metadata.String.Optional, | |
| 8229 | 8327 | bit_width: u32, |
| 8230 | 8328 | limbs_index: u32, |
| 8231 | 8329 | limbs_len: u32, |
| 8232 | 8330 | }; |
| 8233 | 8331 | |
| 8234 | 8332 | pub const Subrange = struct { |
| 8235 | lower_bound: Metadata, | |
| 8236 | count: Metadata, | |
| 8333 | lower_bound: Metadata.Optional, | |
| 8334 | count: Metadata.Optional, | |
| 8237 | 8335 | }; |
| 8238 | 8336 | |
| 8239 | 8337 | pub const Expression = struct { |
| ... | ... | @@ -8248,33 +8346,20 @@ pub const Metadata = enum(u32) { |
| 8248 | 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 | 8349 | pub const LocalVar = struct { |
| 8265 | name: MetadataString, | |
| 8266 | file: Metadata, | |
| 8267 | scope: Metadata, | |
| 8350 | name: Metadata.String.Optional, | |
| 8351 | file: Metadata.Optional, | |
| 8352 | scope: Metadata.Optional, | |
| 8268 | 8353 | line: u32, |
| 8269 | ty: Metadata, | |
| 8354 | ty: Metadata.Optional, | |
| 8270 | 8355 | }; |
| 8271 | 8356 | |
| 8272 | 8357 | pub const Parameter = struct { |
| 8273 | name: MetadataString, | |
| 8274 | file: Metadata, | |
| 8275 | scope: Metadata, | |
| 8358 | name: Metadata.String.Optional, | |
| 8359 | file: Metadata.Optional, | |
| 8360 | scope: Metadata.Optional, | |
| 8276 | 8361 | line: u32, |
| 8277 | ty: Metadata, | |
| 8362 | ty: Metadata.Optional, | |
| 8278 | 8363 | arg_no: u32, |
| 8279 | 8364 | }; |
| 8280 | 8365 | |
| ... | ... | @@ -8283,24 +8368,20 @@ pub const Metadata = enum(u32) { |
| 8283 | 8368 | local: bool, |
| 8284 | 8369 | }; |
| 8285 | 8370 | |
| 8286 | name: MetadataString, | |
| 8287 | linkage_name: MetadataString, | |
| 8288 | file: Metadata, | |
| 8289 | scope: Metadata, | |
| 8371 | name: Metadata.String.Optional, | |
| 8372 | linkage_name: Metadata.String.Optional, | |
| 8373 | file: Metadata.Optional, | |
| 8374 | scope: Metadata.Optional, | |
| 8290 | 8375 | line: u32, |
| 8291 | ty: Metadata, | |
| 8376 | ty: Metadata.Optional, | |
| 8292 | 8377 | variable: Variable.Index, |
| 8293 | 8378 | }; |
| 8294 | 8379 | |
| 8295 | 8380 | pub const GlobalVarExpression = struct { |
| 8296 | variable: Metadata, | |
| 8297 | expression: Metadata, | |
| 8381 | variable: Metadata.Optional, | |
| 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 | 8385 | const Formatter = struct { |
| 8305 | 8386 | builder: *Builder, |
| 8306 | 8387 | need_comma: bool, |
| ... | ... | @@ -8325,7 +8406,7 @@ pub const Metadata = enum(u32) { |
| 8325 | 8406 | local_inline: Metadata, |
| 8326 | 8407 | local_index: u32, |
| 8327 | 8408 | |
| 8328 | string: MetadataString, | |
| 8409 | string: Metadata.String, | |
| 8329 | 8410 | bool: bool, |
| 8330 | 8411 | u32: u32, |
| 8331 | 8412 | u64: u64, |
| ... | ... | @@ -8356,10 +8437,10 @@ pub const Metadata = enum(u32) { |
| 8356 | 8437 | defer data.formatter.need_comma = needed_comma; |
| 8357 | 8438 | data.formatter.need_comma = false; |
| 8358 | 8439 | |
| 8359 | const item = builder.metadata_items.get(@intFromEnum(node)); | |
| 8360 | switch (item.tag) { | |
| 8440 | const node_item = node.item(builder); | |
| 8441 | switch (node_item.tag) { | |
| 8361 | 8442 | .expression => { |
| 8362 | var extra = builder.metadataExtraDataTrail(Expression, item.data); | |
| 8443 | var extra = builder.metadataExtraDataTrail(Expression, node_item.data); | |
| 8363 | 8444 | const elements = extra.trail.next(extra.data.elements_len, u32, builder); |
| 8364 | 8445 | try w.writeAll("!DIExpression("); |
| 8365 | 8446 | for (elements) |element| try format(.{ |
| ... | ... | @@ -8370,7 +8451,7 @@ pub const Metadata = enum(u32) { |
| 8370 | 8451 | try w.writeByte(')'); |
| 8371 | 8452 | }, |
| 8372 | 8453 | .constant => try Constant.format(.{ |
| 8373 | .constant = @enumFromInt(item.data), | |
| 8454 | .constant = @enumFromInt(node_item.data), | |
| 8374 | 8455 | .builder = builder, |
| 8375 | 8456 | .flags = data.specialized orelse .{}, |
| 8376 | 8457 | }, w), |
| ... | ... | @@ -8378,17 +8459,17 @@ pub const Metadata = enum(u32) { |
| 8378 | 8459 | } |
| 8379 | 8460 | }, |
| 8380 | 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 | 8463 | .value = node.value, |
| 8383 | 8464 | .function = node.function, |
| 8384 | 8465 | .builder = builder, |
| 8385 | .flags = switch (tag) { | |
| 8466 | .flags = switch (node_tag) { | |
| 8386 | 8467 | .local_value => data.specialized orelse .{}, |
| 8387 | 8468 | .local_metadata => .{ .percent = true }, |
| 8388 | 8469 | else => unreachable, |
| 8389 | 8470 | }, |
| 8390 | 8471 | }, w), |
| 8391 | inline .local_inline, .local_index => |node, tag| { | |
| 8472 | inline .local_inline, .local_index => |node, node_tag| { | |
| 8392 | 8473 | if (data.specialized) |flags| { |
| 8393 | 8474 | if (flags.onlyPercent()) { |
| 8394 | 8475 | try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)}); |
| ... | ... | @@ -8396,39 +8477,43 @@ pub const Metadata = enum(u32) { |
| 8396 | 8477 | } |
| 8397 | 8478 | try format(.{ |
| 8398 | 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 | 8481 | .specialized = .{ .percent = true }, |
| 8401 | 8482 | }, w); |
| 8402 | 8483 | }, |
| 8403 | .string => |node| try w.print("{s}{f}", .{ | |
| 8404 | @as([]const u8, if (is_specialized) "!" else ""), node.fmt(builder), | |
| 8405 | }), | |
| 8484 | .string => |s| { | |
| 8485 | if (is_specialized) try w.writeByte('!'); | |
| 8486 | try w.print("{f}", .{s.fmt(builder)}); | |
| 8487 | }, | |
| 8406 | 8488 | inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}), |
| 8407 | 8489 | inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}), |
| 8408 | 8490 | .raw => |node| try w.writeAll(node), |
| 8409 | 8491 | } |
| 8410 | 8492 | } |
| 8411 | 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 | 8495 | else => error{}, |
| 8414 | 8496 | }!std.fmt.Alt(FormatData, format) { |
| 8415 | 8497 | const Node = @TypeOf(node); |
| 8416 | const MaybeNode = switch (@typeInfo(Node)) { | |
| 8417 | .optional => Node, | |
| 8418 | .null => ?noreturn, | |
| 8419 | else => ?Node, | |
| 8498 | const MaybeNode = switch (Node) { | |
| 8499 | Metadata.Optional => ?Metadata, | |
| 8500 | Metadata.String.Optional => ?Metadata.String, | |
| 8501 | else => switch (@typeInfo(Node)) { | |
| 8502 | .optional => Node, | |
| 8503 | .null => ?noreturn, | |
| 8504 | else => ?Node, | |
| 8505 | }, | |
| 8420 | 8506 | }; |
| 8421 | 8507 | const Some = @typeInfo(MaybeNode).optional.child; |
| 8422 | 8508 | return .{ .data = .{ |
| 8423 | 8509 | .formatter = formatter, |
| 8424 | 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 | 8515 | .@"enum" => |enum_info| switch (Some) { |
| 8427 | Metadata => switch (some) { | |
| 8428 | .none => .none, | |
| 8429 | else => try formatter.refUnwrapped(some.unwrap(formatter.builder)), | |
| 8430 | }, | |
| 8431 | MetadataString => .{ .string = some }, | |
| 8516 | Metadata.String => .{ .string = some }, | |
| 8432 | 8517 | else => if (enum_info.is_exhaustive) |
| 8433 | 8518 | .{ .raw = @tagName(some) } |
| 8434 | 8519 | else |
| ... | ... | @@ -8438,15 +8523,23 @@ pub const Metadata = enum(u32) { |
| 8438 | 8523 | .bool => .{ .bool = some }, |
| 8439 | 8524 | .@"struct" => switch (Some) { |
| 8440 | 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 | 8531 | Subprogram.DISPFlags => .{ .sp_flags = some }, |
| 8442 | 8532 | else => @compileError("unknown type to format: " ++ @typeName(Node)), |
| 8443 | 8533 | }, |
| 8444 | 8534 | .int, .comptime_int => .{ .u64 = some }, |
| 8445 | 8535 | .pointer => .{ .raw = some }, |
| 8446 | 8536 | else => @compileError("unknown type to format: " ++ @typeName(Node)), |
| 8447 | } else switch (@typeInfo(Node)) { | |
| 8448 | .optional, .null => .none, | |
| 8449 | else => unreachable, | |
| 8537 | } else switch (Node) { | |
| 8538 | Metadata.Optional, Metadata.String.Optional => .none, | |
| 8539 | else => switch (@typeInfo(Node)) { | |
| 8540 | .optional, .null => .none, | |
| 8541 | else => unreachable, | |
| 8542 | }, | |
| 8450 | 8543 | }, |
| 8451 | 8544 | .specialized = special, |
| 8452 | 8545 | } }; |
| ... | ... | @@ -8460,24 +8553,26 @@ pub const Metadata = enum(u32) { |
| 8460 | 8553 | return .{ .data = .{ |
| 8461 | 8554 | .formatter = formatter, |
| 8462 | 8555 | .prefix = prefix, |
| 8463 | .node = switch (value.unwrap()) { | |
| 8556 | .node = node: switch (value.unwrap()) { | |
| 8464 | 8557 | .instruction, .constant => .{ .local_value = .{ |
| 8465 | 8558 | .value = value, |
| 8466 | 8559 | .function = function, |
| 8467 | 8560 | } }, |
| 8468 | .metadata => |metadata| if (value == .none) .none else node: { | |
| 8561 | .metadata => |metadata| if (value == .none) .none else { | |
| 8469 | 8562 | const unwrapped = metadata.unwrap(formatter.builder); |
| 8470 | break :node if (@intFromEnum(unwrapped) >= first_local_metadata) | |
| 8471 | .{ .local_metadata = .{ | |
| 8563 | break :node switch (unwrapped.kind) { | |
| 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 | 8571 | .value = function.ptrConst(formatter.builder).debug_values[ |
| 8473 | @intFromEnum(unwrapped) - first_local_metadata | |
| 8572 | unwrapped.index | |
| 8474 | 8573 | ].toValue(), |
| 8475 | 8574 | .function = function, |
| 8476 | } } | |
| 8477 | else switch (try formatter.refUnwrapped(unwrapped)) { | |
| 8478 | .@"inline" => |node| .{ .local_inline = node }, | |
| 8479 | .index => |node| .{ .local_index = node }, | |
| 8480 | else => unreachable, | |
| 8575 | } }, | |
| 8481 | 8576 | }; |
| 8482 | 8577 | }, |
| 8483 | 8578 | }, |
| ... | ... | @@ -8485,16 +8580,12 @@ pub const Metadata = enum(u32) { |
| 8485 | 8580 | } }; |
| 8486 | 8581 | } |
| 8487 | 8582 | fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node { |
| 8488 | assert(node != .none); | |
| 8489 | assert(@intFromEnum(node) < first_forward_reference); | |
| 8490 | 8583 | const builder = formatter.builder; |
| 8491 | 8584 | const unwrapped_metadata = node.unwrap(builder); |
| 8492 | const tag = formatter.builder.metadata_items.items(.tag)[@intFromEnum(unwrapped_metadata)]; | |
| 8493 | switch (tag) { | |
| 8494 | .none => unreachable, | |
| 8585 | switch (unwrapped_metadata.tag(builder)) { | |
| 8495 | 8586 | .expression, .constant => return .{ .@"inline" = unwrapped_metadata }, |
| 8496 | else => { | |
| 8497 | assert(!tag.isInline()); | |
| 8587 | else => |metadata_tag| { | |
| 8588 | assert(!metadata_tag.isInline()); | |
| 8498 | 8589 | const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata }); |
| 8499 | 8590 | return .{ .index = @intCast(gop.index) }; |
| 8500 | 8591 | }, |
| ... | ... | @@ -8669,11 +8760,9 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8669 | 8760 | assert(try self.intConst(.i32, 1) == .@"1"); |
| 8670 | 8761 | assert(try self.noneConst(.token) == .none); |
| 8671 | 8762 | |
| 8672 | assert(try self.metadataNone() == .none); | |
| 8673 | assert(try self.metadataTuple(&.{}) == .empty_tuple); | |
| 8763 | assert(try self.metadataTuple(&.{}) == Metadata.empty_tuple); | |
| 8674 | 8764 | |
| 8675 | 8765 | try self.metadata_string_indices.append(self.gpa, 0); |
| 8676 | assert(try self.metadataString("") == .none); | |
| 8677 | 8766 | |
| 8678 | 8767 | return self; |
| 8679 | 8768 | } |
| ... | ... | @@ -9232,8 +9321,8 @@ pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant { |
| 9232 | 9321 | return self.halfConstAssumeCapacity(val); |
| 9233 | 9322 | } |
| 9234 | 9323 | |
| 9235 | pub fn halfValue(self: *Builder, ty: Type, value: f16) Allocator.Error!Value { | |
| 9236 | return (try self.halfConst(ty, value)).toValue(); | |
| 9324 | pub fn halfValue(self: *Builder, value: f16) Allocator.Error!Value { | |
| 9325 | return (try self.halfConst(value)).toValue(); | |
| 9237 | 9326 | } |
| 9238 | 9327 | |
| 9239 | 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 | 9330 | return self.bfloatConstAssumeCapacity(val); |
| 9242 | 9331 | } |
| 9243 | 9332 | |
| 9244 | pub fn bfloatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value { | |
| 9245 | return (try self.bfloatConst(ty, value)).toValue(); | |
| 9333 | pub fn bfloatValue(self: *Builder, value: f32) Allocator.Error!Value { | |
| 9334 | return (try self.bfloatConst(value)).toValue(); | |
| 9246 | 9335 | } |
| 9247 | 9336 | |
| 9248 | 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 | 9339 | return self.floatConstAssumeCapacity(val); |
| 9251 | 9340 | } |
| 9252 | 9341 | |
| 9253 | pub fn floatValue(self: *Builder, ty: Type, value: f32) Allocator.Error!Value { | |
| 9254 | return (try self.floatConst(ty, value)).toValue(); | |
| 9342 | pub fn floatValue(self: *Builder, value: f32) Allocator.Error!Value { | |
| 9343 | return (try self.floatConst(value)).toValue(); | |
| 9255 | 9344 | } |
| 9256 | 9345 | |
| 9257 | 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 | 9348 | return self.doubleConstAssumeCapacity(val); |
| 9260 | 9349 | } |
| 9261 | 9350 | |
| 9262 | pub fn doubleValue(self: *Builder, ty: Type, value: f64) Allocator.Error!Value { | |
| 9263 | return (try self.doubleConst(ty, value)).toValue(); | |
| 9351 | pub fn doubleValue(self: *Builder, value: f64) Allocator.Error!Value { | |
| 9352 | return (try self.doubleConst(value)).toValue(); | |
| 9264 | 9353 | } |
| 9265 | 9354 | |
| 9266 | 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 | 9357 | return self.fp128ConstAssumeCapacity(val); |
| 9269 | 9358 | } |
| 9270 | 9359 | |
| 9271 | pub fn fp128Value(self: *Builder, ty: Type, value: f128) Allocator.Error!Value { | |
| 9272 | return (try self.fp128Const(ty, value)).toValue(); | |
| 9360 | pub fn fp128Value(self: *Builder, value: f128) Allocator.Error!Value { | |
| 9361 | return (try self.fp128Const(value)).toValue(); | |
| 9273 | 9362 | } |
| 9274 | 9363 | |
| 9275 | 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 | 9366 | return self.x86_fp80ConstAssumeCapacity(val); |
| 9278 | 9367 | } |
| 9279 | 9368 | |
| 9280 | pub fn x86_fp80Value(self: *Builder, ty: Type, value: f80) Allocator.Error!Value { | |
| 9281 | return (try self.x86_fp80Const(ty, value)).toValue(); | |
| 9369 | pub fn x86_fp80Value(self: *Builder, value: f80) Allocator.Error!Value { | |
| 9370 | return (try self.x86_fp80Const(value)).toValue(); | |
| 9282 | 9371 | } |
| 9283 | 9372 | |
| 9284 | 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 | 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 { | |
| 9290 | return (try self.ppc_fp128Const(ty, value)).toValue(); | |
| 9378 | pub fn ppc_fp128Value(self: *Builder, value: [2]f64) Allocator.Error!Value { | |
| 9379 | return (try self.ppc_fp128Const(value)).toValue(); | |
| 9291 | 9380 | } |
| 9292 | 9381 | |
| 9293 | 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 | 9959 | .none => {}, |
| 9871 | 9960 | .unpredictable => try w.writeAll("!unpredictable !{}"), |
| 9872 | 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 | 10242 | .none => {}, |
| 10154 | 10243 | .unpredictable => try w.writeAll("!unpredictable !{}"), |
| 10155 | 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 | 10282 | const elements: []const Metadata = |
| 10194 | 10283 | @ptrCast(self.metadata_extra.items[data.index..][0..data.len]); |
| 10195 | 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 | 10286 | try w.writeAll(" = !{"); |
| 10198 | 10287 | metadata_formatter.need_comma = false; |
| 10199 | 10288 | defer metadata_formatter.need_comma = undefined; |
| ... | ... | @@ -10223,11 +10312,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10223 | 10312 | }, w); |
| 10224 | 10313 | continue; |
| 10225 | 10314 | }, |
| 10226 | .metadata => |metadata| self.metadata_items.get(@intFromEnum(metadata)), | |
| 10315 | .metadata => |metadata| metadata.item(self), | |
| 10227 | 10316 | }; |
| 10228 | 10317 | |
| 10229 | 10318 | switch (metadata_item.tag) { |
| 10230 | .none, .expression, .constant => unreachable, | |
| 10319 | .expression, .constant => unreachable, | |
| 10231 | 10320 | .file => { |
| 10232 | 10321 | const extra = self.metadataExtraData(Metadata.File, metadata_item.data); |
| 10233 | 10322 | try metadata_formatter.specialized(.@"!", .DIFile, .{ |
| ... | ... | @@ -10330,10 +10419,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10330 | 10419 | const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data); |
| 10331 | 10420 | try metadata_formatter.specialized(.@"!", .DIBasicType, .{ |
| 10332 | 10421 | .tag = null, |
| 10333 | .name = switch (extra.name) { | |
| 10334 | .none => null, | |
| 10335 | else => extra.name, | |
| 10336 | }, | |
| 10422 | .name = extra.name, | |
| 10337 | 10423 | .size = extra.bitSize(), |
| 10338 | 10424 | .@"align" = null, |
| 10339 | 10425 | .encoding = @as(enum { |
| ... | ... | @@ -10371,10 +10457,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10371 | 10457 | .composite_array_type, .composite_vector_type => .DW_TAG_array_type, |
| 10372 | 10458 | else => unreachable, |
| 10373 | 10459 | }), |
| 10374 | .name = switch (extra.name) { | |
| 10375 | .none => null, | |
| 10376 | else => extra.name, | |
| 10377 | }, | |
| 10460 | .name = extra.name, | |
| 10378 | 10461 | .scope = extra.scope, |
| 10379 | 10462 | .file = null, |
| 10380 | 10463 | .line = null, |
| ... | ... | @@ -10409,10 +10492,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10409 | 10492 | .derived_member_type => .DW_TAG_member, |
| 10410 | 10493 | else => unreachable, |
| 10411 | 10494 | }), |
| 10412 | .name = switch (extra.name) { | |
| 10413 | .none => null, | |
| 10414 | else => extra.name, | |
| 10415 | }, | |
| 10495 | .name = extra.name, | |
| 10416 | 10496 | .scope = extra.scope, |
| 10417 | 10497 | .file = null, |
| 10418 | 10498 | .line = null, |
| ... | ... | @@ -10505,25 +10585,6 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10505 | 10585 | }); |
| 10506 | 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 | 10588 | .local_var => { |
| 10528 | 10589 | const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data); |
| 10529 | 10590 | try metadata_formatter.specialized(.@"!", .DILocalVariable, .{ |
| ... | ... | @@ -11914,8 +11975,8 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item. |
| 11914 | 11975 | const value = @field(extra, field.name); |
| 11915 | 11976 | self.metadata_extra.appendAssumeCapacity(switch (field.type) { |
| 11916 | 11977 | u32 => value, |
| 11917 | MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value), | |
| 11918 | Metadata.DIFlags => @bitCast(value), | |
| 11978 | Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value), | |
| 11979 | Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value), | |
| 11919 | 11980 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 11920 | 11981 | }); |
| 11921 | 11982 | } |
| ... | ... | @@ -11953,8 +12014,8 @@ fn metadataExtraDataTrail( |
| 11953 | 12014 | inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value| |
| 11954 | 12015 | @field(result, field.name) = switch (field.type) { |
| 11955 | 12016 | u32 => value, |
| 11956 | MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value), | |
| 11957 | Metadata.DIFlags => @bitCast(value), | |
| 12017 | Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value), | |
| 12018 | Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value), | |
| 11958 | 12019 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 11959 | 12020 | }; |
| 11960 | 12021 | return .{ |
| ... | ... | @@ -11967,48 +12028,65 @@ fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Ite |
| 11967 | 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 | 12033 | try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len); |
| 11972 | 12034 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 11973 | 12035 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 11974 | 12036 | |
| 11975 | 12037 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted( |
| 11976 | 12038 | bytes, |
| 11977 | MetadataString.Adapter{ .builder = self }, | |
| 12039 | Metadata.String.Adapter{ .builder = self }, | |
| 11978 | 12040 | ); |
| 11979 | 12041 | if (!gop.found_existing) { |
| 11980 | 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 | 12047 | return @enumFromInt(gop.index); |
| 11984 | 12048 | } |
| 11985 | 12049 | |
| 11986 | pub fn metadataStringFromStrtabString(self: *Builder, str: StrtabString) Allocator.Error!MetadataString { | |
| 11987 | if (str == .none or str == .empty) return MetadataString.none; | |
| 12050 | pub fn metadataStringFromStrtabString( | |
| 12051 | self: *Builder, | |
| 12052 | str: StrtabString, | |
| 12053 | ) Allocator.Error!Metadata.String { | |
| 11988 | 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 | 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 | 12067 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 11995 | 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 | 12076 | self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args); |
| 12000 | 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 | 12081 | try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 12005 | 12082 | try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 12006 | 12083 | return self.trailingMetadataStringAssumeCapacity(); |
| 12007 | 12084 | } |
| 12008 | 12085 | |
| 12009 | pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString { | |
| 12086 | pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String { | |
| 12010 | 12087 | const start = self.metadata_string_indices.getLast(); |
| 12011 | 12088 | const bytes: []const u8 = self.metadata_string_bytes.items[start..]; |
| 12089 | assert(bytes.len > 0); | |
| 12012 | 12090 | const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self }); |
| 12013 | 12091 | if (gop.found_existing) { |
| 12014 | 12092 | self.metadata_string_bytes.shrinkRetainingCapacity(start); |
| ... | ... | @@ -12018,21 +12096,16 @@ pub fn trailingMetadataStringAssumeCapacity(self: *Builder) MetadataString { |
| 12018 | 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 | 12100 | try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len); |
| 12023 | 12101 | try self.metadata_named.ensureUnusedCapacity(self.gpa, 1); |
| 12024 | self.metadataNamedAssumeCapacity(name, operands); | |
| 12025 | } | |
| 12026 | ||
| 12027 | fn metadataNone(self: *Builder) Allocator.Error!Metadata { | |
| 12028 | try self.ensureUnusedMetadataCapacity(1, NoExtra, 0); | |
| 12029 | return self.metadataNoneAssumeCapacity(); | |
| 12102 | self.addNamedMetadataAssumeCapacity(name, operands); | |
| 12030 | 12103 | } |
| 12031 | 12104 | |
| 12032 | 12105 | pub fn debugFile( |
| 12033 | 12106 | self: *Builder, |
| 12034 | filename: MetadataString, | |
| 12035 | directory: MetadataString, | |
| 12107 | filename: ?Metadata.String, | |
| 12108 | directory: ?Metadata.String, | |
| 12036 | 12109 | ) Allocator.Error!Metadata { |
| 12037 | 12110 | try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0); |
| 12038 | 12111 | return self.debugFileAssumeCapacity(filename, directory); |
| ... | ... | @@ -12040,10 +12113,10 @@ pub fn debugFile( |
| 12040 | 12113 | |
| 12041 | 12114 | pub fn debugCompileUnit( |
| 12042 | 12115 | self: *Builder, |
| 12043 | file: Metadata, | |
| 12044 | producer: MetadataString, | |
| 12045 | enums: Metadata, | |
| 12046 | globals: Metadata, | |
| 12116 | file: ?Metadata, | |
| 12117 | producer: ?Metadata.String, | |
| 12118 | enums: ?Metadata, | |
| 12119 | globals: ?Metadata, | |
| 12047 | 12120 | options: Metadata.CompileUnit.Options, |
| 12048 | 12121 | ) Allocator.Error!Metadata { |
| 12049 | 12122 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0); |
| ... | ... | @@ -12052,14 +12125,14 @@ pub fn debugCompileUnit( |
| 12052 | 12125 | |
| 12053 | 12126 | pub fn debugSubprogram( |
| 12054 | 12127 | self: *Builder, |
| 12055 | file: Metadata, | |
| 12056 | name: MetadataString, | |
| 12057 | linkage_name: MetadataString, | |
| 12128 | file: ?Metadata, | |
| 12129 | name: ?Metadata.String, | |
| 12130 | linkage_name: ?Metadata.String, | |
| 12058 | 12131 | line: u32, |
| 12059 | 12132 | scope_line: u32, |
| 12060 | ty: Metadata, | |
| 12133 | ty: ?Metadata, | |
| 12061 | 12134 | options: Metadata.Subprogram.Options, |
| 12062 | compile_unit: Metadata, | |
| 12135 | compile_unit: ?Metadata, | |
| 12063 | 12136 | ) Allocator.Error!Metadata { |
| 12064 | 12137 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0); |
| 12065 | 12138 | return self.debugSubprogramAssumeCapacity( |
| ... | ... | @@ -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 | 12157 | try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0); |
| 12079 | 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 | 12168 | try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0); |
| 12084 | 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 | 12177 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12089 | 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 | 12186 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12094 | 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 | 12195 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12099 | 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 | 12204 | try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0); |
| 12104 | 12205 | return self.debugFloatTypeAssumeCapacity(name, size_in_bits); |
| 12105 | 12206 | } |
| ... | ... | @@ -12111,14 +12212,14 @@ pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata { |
| 12111 | 12212 | |
| 12112 | 12213 | pub fn debugStructType( |
| 12113 | 12214 | self: *Builder, |
| 12114 | name: MetadataString, | |
| 12115 | file: Metadata, | |
| 12116 | scope: Metadata, | |
| 12215 | name: ?Metadata.String, | |
| 12216 | file: ?Metadata, | |
| 12217 | scope: ?Metadata, | |
| 12117 | 12218 | line: u32, |
| 12118 | underlying_type: Metadata, | |
| 12219 | underlying_type: ?Metadata, | |
| 12119 | 12220 | size_in_bits: u64, |
| 12120 | 12221 | align_in_bits: u64, |
| 12121 | fields_tuple: Metadata, | |
| 12222 | fields_tuple: ?Metadata, | |
| 12122 | 12223 | ) Allocator.Error!Metadata { |
| 12123 | 12224 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12124 | 12225 | return self.debugStructTypeAssumeCapacity( |
| ... | ... | @@ -12135,14 +12236,14 @@ pub fn debugStructType( |
| 12135 | 12236 | |
| 12136 | 12237 | pub fn debugUnionType( |
| 12137 | 12238 | self: *Builder, |
| 12138 | name: MetadataString, | |
| 12139 | file: Metadata, | |
| 12140 | scope: Metadata, | |
| 12239 | name: ?Metadata.String, | |
| 12240 | file: ?Metadata, | |
| 12241 | scope: ?Metadata, | |
| 12141 | 12242 | line: u32, |
| 12142 | underlying_type: Metadata, | |
| 12243 | underlying_type: ?Metadata, | |
| 12143 | 12244 | size_in_bits: u64, |
| 12144 | 12245 | align_in_bits: u64, |
| 12145 | fields_tuple: Metadata, | |
| 12246 | fields_tuple: ?Metadata, | |
| 12146 | 12247 | ) Allocator.Error!Metadata { |
| 12147 | 12248 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12148 | 12249 | return self.debugUnionTypeAssumeCapacity( |
| ... | ... | @@ -12159,14 +12260,14 @@ pub fn debugUnionType( |
| 12159 | 12260 | |
| 12160 | 12261 | pub fn debugEnumerationType( |
| 12161 | 12262 | self: *Builder, |
| 12162 | name: MetadataString, | |
| 12163 | file: Metadata, | |
| 12164 | scope: Metadata, | |
| 12263 | name: ?Metadata.String, | |
| 12264 | file: ?Metadata, | |
| 12265 | scope: ?Metadata, | |
| 12165 | 12266 | line: u32, |
| 12166 | underlying_type: Metadata, | |
| 12267 | underlying_type: ?Metadata, | |
| 12167 | 12268 | size_in_bits: u64, |
| 12168 | 12269 | align_in_bits: u64, |
| 12169 | fields_tuple: Metadata, | |
| 12270 | fields_tuple: ?Metadata, | |
| 12170 | 12271 | ) Allocator.Error!Metadata { |
| 12171 | 12272 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12172 | 12273 | return self.debugEnumerationTypeAssumeCapacity( |
| ... | ... | @@ -12183,14 +12284,14 @@ pub fn debugEnumerationType( |
| 12183 | 12284 | |
| 12184 | 12285 | pub fn debugArrayType( |
| 12185 | 12286 | self: *Builder, |
| 12186 | name: MetadataString, | |
| 12187 | file: Metadata, | |
| 12188 | scope: Metadata, | |
| 12287 | name: ?Metadata.String, | |
| 12288 | file: ?Metadata, | |
| 12289 | scope: ?Metadata, | |
| 12189 | 12290 | line: u32, |
| 12190 | underlying_type: Metadata, | |
| 12291 | underlying_type: ?Metadata, | |
| 12191 | 12292 | size_in_bits: u64, |
| 12192 | 12293 | align_in_bits: u64, |
| 12193 | fields_tuple: Metadata, | |
| 12294 | fields_tuple: ?Metadata, | |
| 12194 | 12295 | ) Allocator.Error!Metadata { |
| 12195 | 12296 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12196 | 12297 | return self.debugArrayTypeAssumeCapacity( |
| ... | ... | @@ -12207,14 +12308,14 @@ pub fn debugArrayType( |
| 12207 | 12308 | |
| 12208 | 12309 | pub fn debugVectorType( |
| 12209 | 12310 | self: *Builder, |
| 12210 | name: MetadataString, | |
| 12211 | file: Metadata, | |
| 12212 | scope: Metadata, | |
| 12311 | name: ?Metadata.String, | |
| 12312 | file: ?Metadata, | |
| 12313 | scope: ?Metadata, | |
| 12213 | 12314 | line: u32, |
| 12214 | underlying_type: Metadata, | |
| 12315 | underlying_type: ?Metadata, | |
| 12215 | 12316 | size_in_bits: u64, |
| 12216 | 12317 | align_in_bits: u64, |
| 12217 | fields_tuple: Metadata, | |
| 12318 | fields_tuple: ?Metadata, | |
| 12218 | 12319 | ) Allocator.Error!Metadata { |
| 12219 | 12320 | try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0); |
| 12220 | 12321 | return self.debugVectorTypeAssumeCapacity( |
| ... | ... | @@ -12231,11 +12332,11 @@ pub fn debugVectorType( |
| 12231 | 12332 | |
| 12232 | 12333 | pub fn debugPointerType( |
| 12233 | 12334 | self: *Builder, |
| 12234 | name: MetadataString, | |
| 12235 | file: Metadata, | |
| 12236 | scope: Metadata, | |
| 12335 | name: ?Metadata.String, | |
| 12336 | file: ?Metadata, | |
| 12337 | scope: ?Metadata, | |
| 12237 | 12338 | line: u32, |
| 12238 | underlying_type: Metadata, | |
| 12339 | underlying_type: ?Metadata, | |
| 12239 | 12340 | size_in_bits: u64, |
| 12240 | 12341 | align_in_bits: u64, |
| 12241 | 12342 | offset_in_bits: u64, |
| ... | ... | @@ -12255,11 +12356,11 @@ pub fn debugPointerType( |
| 12255 | 12356 | |
| 12256 | 12357 | pub fn debugMemberType( |
| 12257 | 12358 | self: *Builder, |
| 12258 | name: MetadataString, | |
| 12259 | file: Metadata, | |
| 12260 | scope: Metadata, | |
| 12359 | name: ?Metadata.String, | |
| 12360 | file: ?Metadata, | |
| 12361 | scope: ?Metadata, | |
| 12261 | 12362 | line: u32, |
| 12262 | underlying_type: Metadata, | |
| 12363 | underlying_type: ?Metadata, | |
| 12263 | 12364 | size_in_bits: u64, |
| 12264 | 12365 | align_in_bits: u64, |
| 12265 | 12366 | offset_in_bits: u64, |
| ... | ... | @@ -12277,17 +12378,14 @@ pub fn debugMemberType( |
| 12277 | 12378 | ); |
| 12278 | 12379 | } |
| 12279 | 12380 | |
| 12280 | pub fn debugSubroutineType( | |
| 12281 | self: *Builder, | |
| 12282 | types_tuple: Metadata, | |
| 12283 | ) Allocator.Error!Metadata { | |
| 12381 | pub fn debugSubroutineType(self: *Builder, types_tuple: ?Metadata) Allocator.Error!Metadata { | |
| 12284 | 12382 | try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0); |
| 12285 | 12383 | return self.debugSubroutineTypeAssumeCapacity(types_tuple); |
| 12286 | 12384 | } |
| 12287 | 12385 | |
| 12288 | 12386 | pub fn debugEnumerator( |
| 12289 | 12387 | self: *Builder, |
| 12290 | name: MetadataString, | |
| 12388 | name: ?Metadata.String, | |
| 12291 | 12389 | unsigned: bool, |
| 12292 | 12390 | bit_width: u32, |
| 12293 | 12391 | value: std.math.big.int.Const, |
| ... | ... | @@ -12300,55 +12398,37 @@ pub fn debugEnumerator( |
| 12300 | 12398 | |
| 12301 | 12399 | pub fn debugSubrange( |
| 12302 | 12400 | self: *Builder, |
| 12303 | lower_bound: Metadata, | |
| 12304 | count: Metadata, | |
| 12401 | lower_bound: ?Metadata, | |
| 12402 | count: ?Metadata, | |
| 12305 | 12403 | ) Allocator.Error!Metadata { |
| 12306 | 12404 | try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0); |
| 12307 | 12405 | return self.debugSubrangeAssumeCapacity(lower_bound, count); |
| 12308 | 12406 | } |
| 12309 | 12407 | |
| 12310 | pub fn debugExpression( | |
| 12311 | self: *Builder, | |
| 12312 | elements: []const u32, | |
| 12313 | ) Allocator.Error!Metadata { | |
| 12408 | pub fn debugExpression(self: *Builder, elements: []const u32) Allocator.Error!Metadata { | |
| 12314 | 12409 | try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len); |
| 12315 | 12410 | return self.debugExpressionAssumeCapacity(elements); |
| 12316 | 12411 | } |
| 12317 | 12412 | |
| 12318 | pub fn metadataTuple( | |
| 12319 | self: *Builder, | |
| 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); | |
| 12413 | pub fn metadataTuple(self: *Builder, elements: []const Metadata) Allocator.Error!Metadata { | |
| 12414 | return self.metadataTupleOptionals(@ptrCast(elements)); | |
| 12333 | 12415 | } |
| 12334 | 12416 | |
| 12335 | pub fn metadataModuleFlag( | |
| 12417 | pub fn metadataTupleOptionals( | |
| 12336 | 12418 | self: *Builder, |
| 12337 | behavior: Metadata, | |
| 12338 | name: MetadataString, | |
| 12339 | constant: Metadata, | |
| 12419 | elements: []const Metadata.Optional, | |
| 12340 | 12420 | ) Allocator.Error!Metadata { |
| 12341 | try self.ensureUnusedMetadataCapacity(1, Metadata.ModuleFlag, 0); | |
| 12342 | return self.metadataModuleFlagAssumeCapacity(behavior, name, constant); | |
| 12421 | try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len); | |
| 12422 | return self.metadataTupleOptionalsAssumeCapacity(elements); | |
| 12343 | 12423 | } |
| 12344 | 12424 | |
| 12345 | 12425 | pub fn debugLocalVar( |
| 12346 | 12426 | self: *Builder, |
| 12347 | name: MetadataString, | |
| 12348 | file: Metadata, | |
| 12349 | scope: Metadata, | |
| 12427 | name: ?Metadata.String, | |
| 12428 | file: ?Metadata, | |
| 12429 | scope: ?Metadata, | |
| 12350 | 12430 | line: u32, |
| 12351 | ty: Metadata, | |
| 12431 | ty: ?Metadata, | |
| 12352 | 12432 | ) Allocator.Error!Metadata { |
| 12353 | 12433 | try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0); |
| 12354 | 12434 | return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty); |
| ... | ... | @@ -12356,11 +12436,11 @@ pub fn debugLocalVar( |
| 12356 | 12436 | |
| 12357 | 12437 | pub fn debugParameter( |
| 12358 | 12438 | self: *Builder, |
| 12359 | name: MetadataString, | |
| 12360 | file: Metadata, | |
| 12361 | scope: Metadata, | |
| 12439 | name: ?Metadata.String, | |
| 12440 | file: ?Metadata, | |
| 12441 | scope: ?Metadata, | |
| 12362 | 12442 | line: u32, |
| 12363 | ty: Metadata, | |
| 12443 | ty: ?Metadata, | |
| 12364 | 12444 | arg_no: u32, |
| 12365 | 12445 | ) Allocator.Error!Metadata { |
| 12366 | 12446 | try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0); |
| ... | ... | @@ -12369,12 +12449,12 @@ pub fn debugParameter( |
| 12369 | 12449 | |
| 12370 | 12450 | pub fn debugGlobalVar( |
| 12371 | 12451 | self: *Builder, |
| 12372 | name: MetadataString, | |
| 12373 | linkage_name: MetadataString, | |
| 12374 | file: Metadata, | |
| 12375 | scope: Metadata, | |
| 12452 | name: ?Metadata.String, | |
| 12453 | linkage_name: ?Metadata.String, | |
| 12454 | file: ?Metadata, | |
| 12455 | scope: ?Metadata, | |
| 12376 | 12456 | line: u32, |
| 12377 | ty: Metadata, | |
| 12457 | ty: ?Metadata, | |
| 12378 | 12458 | variable: Variable.Index, |
| 12379 | 12459 | options: Metadata.GlobalVar.Options, |
| 12380 | 12460 | ) Allocator.Error!Metadata { |
| ... | ... | @@ -12393,8 +12473,8 @@ pub fn debugGlobalVar( |
| 12393 | 12473 | |
| 12394 | 12474 | pub fn debugGlobalVarExpression( |
| 12395 | 12475 | self: *Builder, |
| 12396 | variable: Metadata, | |
| 12397 | expression: Metadata, | |
| 12476 | variable: ?Metadata, | |
| 12477 | expression: ?Metadata, | |
| 12398 | 12478 | ) Allocator.Error!Metadata { |
| 12399 | 12479 | try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0); |
| 12400 | 12480 | return self.debugGlobalVarExpressionAssumeCapacity(variable, expression); |
| ... | ... | @@ -12405,13 +12485,11 @@ pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadat |
| 12405 | 12485 | return self.metadataConstantAssumeCapacity(value); |
| 12406 | 12486 | } |
| 12407 | 12487 | |
| 12408 | pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void { | |
| 12409 | assert( | |
| 12410 | @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and | |
| 12411 | @intFromEnum(fwd_ref) <= Metadata.first_local_metadata, | |
| 12412 | ); | |
| 12413 | const index = @intFromEnum(fwd_ref) - Metadata.first_forward_reference; | |
| 12414 | self.metadata_forward_references.items[index] = ty; | |
| 12488 | pub fn resolveDebugForwardReference(self: *Builder, fwd_ref: Metadata, value: Metadata) void { | |
| 12489 | assert(fwd_ref.kind == .forward); | |
| 12490 | const resolved = &self.metadata_forward_references.items[fwd_ref.index]; | |
| 12491 | assert(resolved.is_none); | |
| 12492 | resolved.* = value.toOptional(); | |
| 12415 | 12493 | } |
| 12416 | 12494 | |
| 12417 | 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 | 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 | 12534 | fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata { |
| 12457 | const Key = struct { tag: Metadata.Tag, index: Metadata }; | |
| 12458 | const Adapter = struct { | |
| 12459 | pub fn hash(_: @This(), key: Key) u32 { | |
| 12460 | return @truncate(std.hash.Wyhash.hash( | |
| 12461 | std.hash.int(@intFromEnum(key.tag)), | |
| 12462 | std.mem.asBytes(&key.index), | |
| 12463 | )); | |
| 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); | |
| 12535 | const index = self.metadata_items.len; | |
| 12536 | _ = self.metadata_map.entries.addOneAssumeCapacity(); | |
| 12537 | self.metadata_items.appendAssumeCapacity(.{ | |
| 12538 | .tag = tag, | |
| 12539 | .data = self.addMetadataExtraAssumeCapacity(value), | |
| 12540 | }); | |
| 12541 | return .{ .index = @intCast(index), .kind = .node }; | |
| 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 | 12545 | assert(name != .none); |
| 12489 | 12546 | const extra_index: u32 = @intCast(self.metadata_extra.items.len); |
| 12490 | 12547 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(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 | 12556 | fn debugFileAssumeCapacity( |
| 12504 | 12557 | self: *Builder, |
| 12505 | filename: MetadataString, | |
| 12506 | directory: MetadataString, | |
| 12558 | filename: ?Metadata.String, | |
| 12559 | directory: ?Metadata.String, | |
| 12507 | 12560 | ) Metadata { |
| 12508 | 12561 | assert(!self.strip); |
| 12509 | 12562 | return self.metadataSimpleAssumeCapacity(.file, Metadata.File{ |
| 12510 | .filename = filename, | |
| 12511 | .directory = directory, | |
| 12563 | .filename = .wrap(filename), | |
| 12564 | .directory = .wrap(directory), | |
| 12512 | 12565 | }); |
| 12513 | 12566 | } |
| 12514 | 12567 | |
| 12515 | 12568 | pub fn debugCompileUnitAssumeCapacity( |
| 12516 | 12569 | self: *Builder, |
| 12517 | file: Metadata, | |
| 12518 | producer: MetadataString, | |
| 12519 | enums: Metadata, | |
| 12520 | globals: Metadata, | |
| 12570 | file: ?Metadata, | |
| 12571 | producer: ?Metadata.String, | |
| 12572 | enums: ?Metadata, | |
| 12573 | globals: ?Metadata, | |
| 12521 | 12574 | options: Metadata.CompileUnit.Options, |
| 12522 | 12575 | ) Metadata { |
| 12523 | 12576 | assert(!self.strip); |
| 12524 | 12577 | return self.metadataDistinctAssumeCapacity( |
| 12525 | 12578 | if (options.optimized) .@"compile_unit optimized" else .compile_unit, |
| 12526 | 12579 | Metadata.CompileUnit{ |
| 12527 | .file = file, | |
| 12528 | .producer = producer, | |
| 12529 | .enums = enums, | |
| 12530 | .globals = globals, | |
| 12580 | .file = .wrap(file), | |
| 12581 | .producer = .wrap(producer), | |
| 12582 | .enums = .wrap(enums), | |
| 12583 | .globals = .wrap(globals), | |
| 12531 | 12584 | }, |
| 12532 | 12585 | ); |
| 12533 | 12586 | } |
| 12534 | 12587 | |
| 12535 | 12588 | fn debugSubprogramAssumeCapacity( |
| 12536 | 12589 | self: *Builder, |
| 12537 | file: Metadata, | |
| 12538 | name: MetadataString, | |
| 12539 | linkage_name: MetadataString, | |
| 12590 | file: ?Metadata, | |
| 12591 | name: ?Metadata.String, | |
| 12592 | linkage_name: ?Metadata.String, | |
| 12540 | 12593 | line: u32, |
| 12541 | 12594 | scope_line: u32, |
| 12542 | ty: Metadata, | |
| 12595 | ty: ?Metadata, | |
| 12543 | 12596 | options: Metadata.Subprogram.Options, |
| 12544 | compile_unit: Metadata, | |
| 12597 | compile_unit: ?Metadata, | |
| 12545 | 12598 | ) Metadata { |
| 12546 | 12599 | assert(!self.strip); |
| 12547 | 12600 | const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) + |
| 12548 | 12601 | @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2))); |
| 12549 | 12602 | return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{ |
| 12550 | .file = file, | |
| 12551 | .name = name, | |
| 12552 | .linkage_name = linkage_name, | |
| 12603 | .file = .wrap(file), | |
| 12604 | .name = .wrap(name), | |
| 12605 | .linkage_name = .wrap(linkage_name), | |
| 12553 | 12606 | .line = line, |
| 12554 | 12607 | .scope_line = scope_line, |
| 12555 | .ty = ty, | |
| 12608 | .ty = .wrap(ty), | |
| 12556 | 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 | 12621 | assert(!self.strip); |
| 12563 | 12622 | return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{ |
| 12564 | .scope = scope, | |
| 12565 | .file = file, | |
| 12623 | .scope = .wrap(scope), | |
| 12624 | .file = .wrap(file), | |
| 12566 | 12625 | .line = line, |
| 12567 | 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 | 12637 | assert(!self.strip); |
| 12573 | 12638 | return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{ |
| 12574 | 12639 | .line = line, |
| 12575 | 12640 | .column = column, |
| 12576 | 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 | 12647 | assert(!self.strip); |
| 12583 | 12648 | return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{ |
| 12584 | .name = name, | |
| 12649 | .name = .wrap(name), | |
| 12585 | 12650 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12586 | 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 | 12656 | assert(!self.strip); |
| 12592 | 12657 | return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{ |
| 12593 | .name = name, | |
| 12658 | .name = .wrap(name), | |
| 12594 | 12659 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12595 | 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 | 12665 | assert(!self.strip); |
| 12601 | 12666 | return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{ |
| 12602 | .name = name, | |
| 12667 | .name = .wrap(name), | |
| 12603 | 12668 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12604 | 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 | 12674 | assert(!self.strip); |
| 12610 | 12675 | return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{ |
| 12611 | .name = name, | |
| 12676 | .name = .wrap(name), | |
| 12612 | 12677 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12613 | 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 | 12681 | |
| 12617 | 12682 | fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata { |
| 12618 | 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 | 12685 | self.metadata_forward_references.appendAssumeCapacity(.none); |
| 12621 | return @enumFromInt(index); | |
| 12686 | return .{ .index = @intCast(index), .kind = .forward }; | |
| 12622 | 12687 | } |
| 12623 | 12688 | |
| 12624 | 12689 | fn debugStructTypeAssumeCapacity( |
| 12625 | 12690 | self: *Builder, |
| 12626 | name: MetadataString, | |
| 12627 | file: Metadata, | |
| 12628 | scope: Metadata, | |
| 12691 | name: ?Metadata.String, | |
| 12692 | file: ?Metadata, | |
| 12693 | scope: ?Metadata, | |
| 12629 | 12694 | line: u32, |
| 12630 | underlying_type: Metadata, | |
| 12695 | underlying_type: ?Metadata, | |
| 12631 | 12696 | size_in_bits: u64, |
| 12632 | 12697 | align_in_bits: u64, |
| 12633 | fields_tuple: Metadata, | |
| 12698 | fields_tuple: ?Metadata, | |
| 12634 | 12699 | ) Metadata { |
| 12635 | 12700 | assert(!self.strip); |
| 12636 | 12701 | return self.debugCompositeTypeAssumeCapacity( |
| ... | ... | @@ -12648,14 +12713,14 @@ fn debugStructTypeAssumeCapacity( |
| 12648 | 12713 | |
| 12649 | 12714 | fn debugUnionTypeAssumeCapacity( |
| 12650 | 12715 | self: *Builder, |
| 12651 | name: MetadataString, | |
| 12652 | file: Metadata, | |
| 12653 | scope: Metadata, | |
| 12716 | name: ?Metadata.String, | |
| 12717 | file: ?Metadata, | |
| 12718 | scope: ?Metadata, | |
| 12654 | 12719 | line: u32, |
| 12655 | underlying_type: Metadata, | |
| 12720 | underlying_type: ?Metadata, | |
| 12656 | 12721 | size_in_bits: u64, |
| 12657 | 12722 | align_in_bits: u64, |
| 12658 | fields_tuple: Metadata, | |
| 12723 | fields_tuple: ?Metadata, | |
| 12659 | 12724 | ) Metadata { |
| 12660 | 12725 | assert(!self.strip); |
| 12661 | 12726 | return self.debugCompositeTypeAssumeCapacity( |
| ... | ... | @@ -12673,14 +12738,14 @@ fn debugUnionTypeAssumeCapacity( |
| 12673 | 12738 | |
| 12674 | 12739 | fn debugEnumerationTypeAssumeCapacity( |
| 12675 | 12740 | self: *Builder, |
| 12676 | name: MetadataString, | |
| 12677 | file: Metadata, | |
| 12678 | scope: Metadata, | |
| 12741 | name: ?Metadata.String, | |
| 12742 | file: ?Metadata, | |
| 12743 | scope: ?Metadata, | |
| 12679 | 12744 | line: u32, |
| 12680 | underlying_type: Metadata, | |
| 12745 | underlying_type: ?Metadata, | |
| 12681 | 12746 | size_in_bits: u64, |
| 12682 | 12747 | align_in_bits: u64, |
| 12683 | fields_tuple: Metadata, | |
| 12748 | fields_tuple: ?Metadata, | |
| 12684 | 12749 | ) Metadata { |
| 12685 | 12750 | assert(!self.strip); |
| 12686 | 12751 | return self.debugCompositeTypeAssumeCapacity( |
| ... | ... | @@ -12698,14 +12763,14 @@ fn debugEnumerationTypeAssumeCapacity( |
| 12698 | 12763 | |
| 12699 | 12764 | fn debugArrayTypeAssumeCapacity( |
| 12700 | 12765 | self: *Builder, |
| 12701 | name: MetadataString, | |
| 12702 | file: Metadata, | |
| 12703 | scope: Metadata, | |
| 12766 | name: ?Metadata.String, | |
| 12767 | file: ?Metadata, | |
| 12768 | scope: ?Metadata, | |
| 12704 | 12769 | line: u32, |
| 12705 | underlying_type: Metadata, | |
| 12770 | underlying_type: ?Metadata, | |
| 12706 | 12771 | size_in_bits: u64, |
| 12707 | 12772 | align_in_bits: u64, |
| 12708 | fields_tuple: Metadata, | |
| 12773 | fields_tuple: ?Metadata, | |
| 12709 | 12774 | ) Metadata { |
| 12710 | 12775 | assert(!self.strip); |
| 12711 | 12776 | return self.debugCompositeTypeAssumeCapacity( |
| ... | ... | @@ -12723,14 +12788,14 @@ fn debugArrayTypeAssumeCapacity( |
| 12723 | 12788 | |
| 12724 | 12789 | fn debugVectorTypeAssumeCapacity( |
| 12725 | 12790 | self: *Builder, |
| 12726 | name: MetadataString, | |
| 12727 | file: Metadata, | |
| 12728 | scope: Metadata, | |
| 12791 | name: ?Metadata.String, | |
| 12792 | file: ?Metadata, | |
| 12793 | scope: ?Metadata, | |
| 12729 | 12794 | line: u32, |
| 12730 | underlying_type: Metadata, | |
| 12795 | underlying_type: ?Metadata, | |
| 12731 | 12796 | size_in_bits: u64, |
| 12732 | 12797 | align_in_bits: u64, |
| 12733 | fields_tuple: Metadata, | |
| 12798 | fields_tuple: ?Metadata, | |
| 12734 | 12799 | ) Metadata { |
| 12735 | 12800 | assert(!self.strip); |
| 12736 | 12801 | return self.debugCompositeTypeAssumeCapacity( |
| ... | ... | @@ -12749,48 +12814,48 @@ fn debugVectorTypeAssumeCapacity( |
| 12749 | 12814 | fn debugCompositeTypeAssumeCapacity( |
| 12750 | 12815 | self: *Builder, |
| 12751 | 12816 | tag: Metadata.Tag, |
| 12752 | name: MetadataString, | |
| 12753 | file: Metadata, | |
| 12754 | scope: Metadata, | |
| 12817 | name: ?Metadata.String, | |
| 12818 | file: ?Metadata, | |
| 12819 | scope: ?Metadata, | |
| 12755 | 12820 | line: u32, |
| 12756 | underlying_type: Metadata, | |
| 12821 | underlying_type: ?Metadata, | |
| 12757 | 12822 | size_in_bits: u64, |
| 12758 | 12823 | align_in_bits: u64, |
| 12759 | fields_tuple: Metadata, | |
| 12824 | fields_tuple: ?Metadata, | |
| 12760 | 12825 | ) Metadata { |
| 12761 | 12826 | assert(!self.strip); |
| 12762 | 12827 | return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{ |
| 12763 | .name = name, | |
| 12764 | .file = file, | |
| 12765 | .scope = scope, | |
| 12828 | .name = .wrap(name), | |
| 12829 | .file = .wrap(file), | |
| 12830 | .scope = .wrap(scope), | |
| 12766 | 12831 | .line = line, |
| 12767 | .underlying_type = underlying_type, | |
| 12832 | .underlying_type = .wrap(underlying_type), | |
| 12768 | 12833 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12769 | 12834 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12770 | 12835 | .align_in_bits_lo = @truncate(align_in_bits), |
| 12771 | 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 | 12841 | fn debugPointerTypeAssumeCapacity( |
| 12777 | 12842 | self: *Builder, |
| 12778 | name: MetadataString, | |
| 12779 | file: Metadata, | |
| 12780 | scope: Metadata, | |
| 12843 | name: ?Metadata.String, | |
| 12844 | file: ?Metadata, | |
| 12845 | scope: ?Metadata, | |
| 12781 | 12846 | line: u32, |
| 12782 | underlying_type: Metadata, | |
| 12847 | underlying_type: ?Metadata, | |
| 12783 | 12848 | size_in_bits: u64, |
| 12784 | 12849 | align_in_bits: u64, |
| 12785 | 12850 | offset_in_bits: u64, |
| 12786 | 12851 | ) Metadata { |
| 12787 | 12852 | assert(!self.strip); |
| 12788 | 12853 | return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{ |
| 12789 | .name = name, | |
| 12790 | .file = file, | |
| 12791 | .scope = scope, | |
| 12854 | .name = .wrap(name), | |
| 12855 | .file = .wrap(file), | |
| 12856 | .scope = .wrap(scope), | |
| 12792 | 12857 | .line = line, |
| 12793 | .underlying_type = underlying_type, | |
| 12858 | .underlying_type = .wrap(underlying_type), | |
| 12794 | 12859 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12795 | 12860 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12796 | 12861 | .align_in_bits_lo = @truncate(align_in_bits), |
| ... | ... | @@ -12802,22 +12867,22 @@ fn debugPointerTypeAssumeCapacity( |
| 12802 | 12867 | |
| 12803 | 12868 | fn debugMemberTypeAssumeCapacity( |
| 12804 | 12869 | self: *Builder, |
| 12805 | name: MetadataString, | |
| 12806 | file: Metadata, | |
| 12807 | scope: Metadata, | |
| 12870 | name: ?Metadata.String, | |
| 12871 | file: ?Metadata, | |
| 12872 | scope: ?Metadata, | |
| 12808 | 12873 | line: u32, |
| 12809 | underlying_type: Metadata, | |
| 12874 | underlying_type: ?Metadata, | |
| 12810 | 12875 | size_in_bits: u64, |
| 12811 | 12876 | align_in_bits: u64, |
| 12812 | 12877 | offset_in_bits: u64, |
| 12813 | 12878 | ) Metadata { |
| 12814 | 12879 | assert(!self.strip); |
| 12815 | 12880 | return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{ |
| 12816 | .name = name, | |
| 12817 | .file = file, | |
| 12818 | .scope = scope, | |
| 12881 | .name = .wrap(name), | |
| 12882 | .file = .wrap(file), | |
| 12883 | .scope = .wrap(scope), | |
| 12819 | 12884 | .line = line, |
| 12820 | .underlying_type = underlying_type, | |
| 12885 | .underlying_type = .wrap(underlying_type), | |
| 12821 | 12886 | .size_in_bits_lo = @truncate(size_in_bits), |
| 12822 | 12887 | .size_in_bits_hi = @truncate(size_in_bits >> 32), |
| 12823 | 12888 | .align_in_bits_lo = @truncate(align_in_bits), |
| ... | ... | @@ -12827,19 +12892,16 @@ fn debugMemberTypeAssumeCapacity( |
| 12827 | 12892 | }); |
| 12828 | 12893 | } |
| 12829 | 12894 | |
| 12830 | fn debugSubroutineTypeAssumeCapacity( | |
| 12831 | self: *Builder, | |
| 12832 | types_tuple: Metadata, | |
| 12833 | ) Metadata { | |
| 12895 | fn debugSubroutineTypeAssumeCapacity(self: *Builder, types_tuple: ?Metadata) Metadata { | |
| 12834 | 12896 | assert(!self.strip); |
| 12835 | 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 | 12902 | fn debugEnumeratorAssumeCapacity( |
| 12841 | 12903 | self: *Builder, |
| 12842 | name: MetadataString, | |
| 12904 | name: ?Metadata.String, | |
| 12843 | 12905 | unsigned: bool, |
| 12844 | 12906 | bit_width: u32, |
| 12845 | 12907 | value: std.math.big.int.Const, |
| ... | ... | @@ -12847,7 +12909,7 @@ fn debugEnumeratorAssumeCapacity( |
| 12847 | 12909 | assert(!self.strip); |
| 12848 | 12910 | const Key = struct { |
| 12849 | 12911 | tag: Metadata.Tag, |
| 12850 | name: MetadataString, | |
| 12912 | name: Metadata.String.Optional, | |
| 12851 | 12913 | bit_width: u32, |
| 12852 | 12914 | value: std.math.big.int.Const, |
| 12853 | 12915 | }; |
| ... | ... | @@ -12886,15 +12948,12 @@ fn debugEnumeratorAssumeCapacity( |
| 12886 | 12948 | |
| 12887 | 12949 | assert(!(tag == .enumerator_unsigned and !value.positive)); |
| 12888 | 12950 | |
| 12889 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted( | |
| 12890 | Key{ | |
| 12891 | .tag = tag, | |
| 12892 | .name = name, | |
| 12893 | .bit_width = bit_width, | |
| 12894 | .value = value, | |
| 12895 | }, | |
| 12896 | Adapter{ .builder = self }, | |
| 12897 | ); | |
| 12951 | const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(Key{ | |
| 12952 | .tag = tag, | |
| 12953 | .name = .wrap(name), | |
| 12954 | .bit_width = bit_width, | |
| 12955 | .value = value, | |
| 12956 | }, Adapter{ .builder = self }); | |
| 12898 | 12957 | |
| 12899 | 12958 | if (!gop.found_existing) { |
| 12900 | 12959 | gop.key_ptr.* = {}; |
| ... | ... | @@ -12902,7 +12961,7 @@ fn debugEnumeratorAssumeCapacity( |
| 12902 | 12961 | self.metadata_items.appendAssumeCapacity(.{ |
| 12903 | 12962 | .tag = tag, |
| 12904 | 12963 | .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{ |
| 12905 | .name = name, | |
| 12964 | .name = .wrap(name), | |
| 12906 | 12965 | .bit_width = bit_width, |
| 12907 | 12966 | .limbs_index = @intCast(self.metadata_limbs.items.len), |
| 12908 | 12967 | .limbs_len = @intCast(value.limbs.len), |
| ... | ... | @@ -12910,25 +12969,18 @@ fn debugEnumeratorAssumeCapacity( |
| 12910 | 12969 | }); |
| 12911 | 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( | |
| 12917 | self: *Builder, | |
| 12918 | lower_bound: Metadata, | |
| 12919 | count: Metadata, | |
| 12920 | ) Metadata { | |
| 12975 | fn debugSubrangeAssumeCapacity(self: *Builder, lower_bound: ?Metadata, count: ?Metadata) Metadata { | |
| 12921 | 12976 | assert(!self.strip); |
| 12922 | 12977 | return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{ |
| 12923 | .lower_bound = lower_bound, | |
| 12924 | .count = count, | |
| 12978 | .lower_bound = .wrap(lower_bound), | |
| 12979 | .count = .wrap(count), | |
| 12925 | 12980 | }); |
| 12926 | 12981 | } |
| 12927 | 12982 | |
| 12928 | fn debugExpressionAssumeCapacity( | |
| 12929 | self: *Builder, | |
| 12930 | elements: []const u32, | |
| 12931 | ) Metadata { | |
| 12983 | fn debugExpressionAssumeCapacity(self: *Builder, elements: []const u32) Metadata { | |
| 12932 | 12984 | assert(!self.strip); |
| 12933 | 12985 | const Key = struct { |
| 12934 | 12986 | elements: []const u32, |
| ... | ... | @@ -12936,13 +12988,15 @@ fn debugExpressionAssumeCapacity( |
| 12936 | 12988 | const Adapter = struct { |
| 12937 | 12989 | builder: *const Builder, |
| 12938 | 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 | 12993 | hasher.update(std.mem.sliceAsBytes(key.elements)); |
| 12941 | 12994 | return @truncate(hasher.final()); |
| 12942 | 12995 | } |
| 12943 | 12996 | |
| 12944 | 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 | 13000 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 12947 | 13001 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data); |
| 12948 | 13002 | return std.mem.eql( |
| ... | ... | @@ -12969,15 +13023,12 @@ fn debugExpressionAssumeCapacity( |
| 12969 | 13023 | }); |
| 12970 | 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( | |
| 12976 | self: *Builder, | |
| 12977 | elements: []const Metadata, | |
| 12978 | ) Metadata { | |
| 13029 | fn metadataTupleOptionalsAssumeCapacity(self: *Builder, elements: []const Metadata.Optional) Metadata { | |
| 12979 | 13030 | const Key = struct { |
| 12980 | elements: []const Metadata, | |
| 13031 | elements: []const Metadata.Optional, | |
| 12981 | 13032 | }; |
| 12982 | 13033 | const Adapter = struct { |
| 12983 | 13034 | builder: *const Builder, |
| ... | ... | @@ -12992,9 +13043,9 @@ fn metadataTupleAssumeCapacity( |
| 12992 | 13043 | const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index]; |
| 12993 | 13044 | var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data); |
| 12994 | 13045 | return std.mem.eql( |
| 12995 | Metadata, | |
| 13046 | Metadata.Optional, | |
| 12996 | 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 | 13066 | }); |
| 13016 | 13067 | self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements)); |
| 13017 | 13068 | } |
| 13018 | return @enumFromInt(gop.index); | |
| 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 | }); | |
| 13069 | return .{ .index = @intCast(gop.index), .kind = .node }; | |
| 13081 | 13070 | } |
| 13082 | 13071 | |
| 13083 | 13072 | fn debugLocalVarAssumeCapacity( |
| 13084 | 13073 | self: *Builder, |
| 13085 | name: MetadataString, | |
| 13086 | file: Metadata, | |
| 13087 | scope: Metadata, | |
| 13074 | name: ?Metadata.String, | |
| 13075 | file: ?Metadata, | |
| 13076 | scope: ?Metadata, | |
| 13088 | 13077 | line: u32, |
| 13089 | ty: Metadata, | |
| 13078 | ty: ?Metadata, | |
| 13090 | 13079 | ) Metadata { |
| 13091 | 13080 | assert(!self.strip); |
| 13092 | 13081 | return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{ |
| 13093 | .name = name, | |
| 13094 | .file = file, | |
| 13095 | .scope = scope, | |
| 13082 | .name = .wrap(name), | |
| 13083 | .file = .wrap(file), | |
| 13084 | .scope = .wrap(scope), | |
| 13096 | 13085 | .line = line, |
| 13097 | .ty = ty, | |
| 13086 | .ty = .wrap(ty), | |
| 13098 | 13087 | }); |
| 13099 | 13088 | } |
| 13100 | 13089 | |
| 13101 | 13090 | fn debugParameterAssumeCapacity( |
| 13102 | 13091 | self: *Builder, |
| 13103 | name: MetadataString, | |
| 13104 | file: Metadata, | |
| 13105 | scope: Metadata, | |
| 13092 | name: ?Metadata.String, | |
| 13093 | file: ?Metadata, | |
| 13094 | scope: ?Metadata, | |
| 13106 | 13095 | line: u32, |
| 13107 | ty: Metadata, | |
| 13096 | ty: ?Metadata, | |
| 13108 | 13097 | arg_no: u32, |
| 13109 | 13098 | ) Metadata { |
| 13110 | 13099 | assert(!self.strip); |
| 13111 | 13100 | return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{ |
| 13112 | .name = name, | |
| 13113 | .file = file, | |
| 13114 | .scope = scope, | |
| 13101 | .name = .wrap(name), | |
| 13102 | .file = .wrap(file), | |
| 13103 | .scope = .wrap(scope), | |
| 13115 | 13104 | .line = line, |
| 13116 | .ty = ty, | |
| 13105 | .ty = .wrap(ty), | |
| 13117 | 13106 | .arg_no = arg_no, |
| 13118 | 13107 | }); |
| 13119 | 13108 | } |
| 13120 | 13109 | |
| 13121 | 13110 | fn debugGlobalVarAssumeCapacity( |
| 13122 | 13111 | self: *Builder, |
| 13123 | name: MetadataString, | |
| 13124 | linkage_name: MetadataString, | |
| 13125 | file: Metadata, | |
| 13126 | scope: Metadata, | |
| 13112 | name: ?Metadata.String, | |
| 13113 | linkage_name: ?Metadata.String, | |
| 13114 | file: ?Metadata, | |
| 13115 | scope: ?Metadata, | |
| 13127 | 13116 | line: u32, |
| 13128 | ty: Metadata, | |
| 13117 | ty: ?Metadata, | |
| 13129 | 13118 | variable: Variable.Index, |
| 13130 | 13119 | options: Metadata.GlobalVar.Options, |
| 13131 | 13120 | ) Metadata { |
| ... | ... | @@ -13133,12 +13122,12 @@ fn debugGlobalVarAssumeCapacity( |
| 13133 | 13122 | return self.metadataDistinctAssumeCapacity( |
| 13134 | 13123 | if (options.local) .@"global_var local" else .global_var, |
| 13135 | 13124 | Metadata.GlobalVar{ |
| 13136 | .name = name, | |
| 13137 | .linkage_name = linkage_name, | |
| 13138 | .file = file, | |
| 13139 | .scope = scope, | |
| 13125 | .name = .wrap(name), | |
| 13126 | .linkage_name = .wrap(linkage_name), | |
| 13127 | .file = .wrap(file), | |
| 13128 | .scope = .wrap(scope), | |
| 13140 | 13129 | .line = line, |
| 13141 | .ty = ty, | |
| 13130 | .ty = .wrap(ty), | |
| 13142 | 13131 | .variable = variable, |
| 13143 | 13132 | }, |
| 13144 | 13133 | ); |
| ... | ... | @@ -13146,13 +13135,13 @@ fn debugGlobalVarAssumeCapacity( |
| 13146 | 13135 | |
| 13147 | 13136 | fn debugGlobalVarExpressionAssumeCapacity( |
| 13148 | 13137 | self: *Builder, |
| 13149 | variable: Metadata, | |
| 13150 | expression: Metadata, | |
| 13138 | variable: ?Metadata, | |
| 13139 | expression: ?Metadata, | |
| 13151 | 13140 | ) Metadata { |
| 13152 | 13141 | assert(!self.strip); |
| 13153 | 13142 | return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{ |
| 13154 | .variable = variable, | |
| 13155 | .expression = expression, | |
| 13143 | .variable = .wrap(variable), | |
| 13144 | .expression = .wrap(expression), | |
| 13156 | 13145 | }); |
| 13157 | 13146 | } |
| 13158 | 13147 | |
| ... | ... | @@ -13185,7 +13174,7 @@ fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata { |
| 13185 | 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 | 13180 | pub const Producer = struct { |
| ... | ... | @@ -13209,8 +13198,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13209 | 13198 | |
| 13210 | 13199 | // IDENTIFICATION_BLOCK |
| 13211 | 13200 | { |
| 13212 | const Identification = ir.Identification; | |
| 13213 | var identification_block = try bitcode.enterTopBlock(Identification); | |
| 13201 | const IdentificationBlock = ir.IdentificationBlock; | |
| 13202 | var identification_block = try bitcode.enterTopBlock(IdentificationBlock); | |
| 13214 | 13203 | |
| 13215 | 13204 | const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{ |
| 13216 | 13205 | producer.name, |
| ... | ... | @@ -13220,42 +13209,42 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13220 | 13209 | }); |
| 13221 | 13210 | defer self.gpa.free(producer_str); |
| 13222 | 13211 | |
| 13223 | try identification_block.writeAbbrev(Identification.Version{ .string = producer_str }); | |
| 13224 | try identification_block.writeAbbrev(Identification.Epoch{ .epoch = 0 }); | |
| 13212 | try identification_block.writeAbbrev(IdentificationBlock.Version{ .string = producer_str }); | |
| 13213 | try identification_block.writeAbbrev(IdentificationBlock.Epoch{ .epoch = 0 }); | |
| 13225 | 13214 | |
| 13226 | 13215 | try identification_block.end(); |
| 13227 | 13216 | } |
| 13228 | 13217 | |
| 13229 | 13218 | // MODULE_BLOCK |
| 13230 | 13219 | { |
| 13231 | const Module = ir.Module; | |
| 13232 | var module_block = try bitcode.enterTopBlock(Module); | |
| 13220 | const ModuleBlock = ir.ModuleBlock; | |
| 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 | 13225 | if (self.target_triple.slice(self)) |triple| { |
| 13237 | try module_block.writeAbbrev(Module.String{ | |
| 13226 | try module_block.writeAbbrev(ModuleBlock.String{ | |
| 13238 | 13227 | .code = 2, |
| 13239 | 13228 | .string = triple, |
| 13240 | 13229 | }); |
| 13241 | 13230 | } |
| 13242 | 13231 | |
| 13243 | 13232 | if (self.data_layout.slice(self)) |data_layout| { |
| 13244 | try module_block.writeAbbrev(Module.String{ | |
| 13233 | try module_block.writeAbbrev(ModuleBlock.String{ | |
| 13245 | 13234 | .code = 3, |
| 13246 | 13235 | .string = data_layout, |
| 13247 | 13236 | }); |
| 13248 | 13237 | } |
| 13249 | 13238 | |
| 13250 | 13239 | if (self.source_filename.slice(self)) |source_filename| { |
| 13251 | try module_block.writeAbbrev(Module.String{ | |
| 13240 | try module_block.writeAbbrev(ModuleBlock.String{ | |
| 13252 | 13241 | .code = 16, |
| 13253 | 13242 | .string = source_filename, |
| 13254 | 13243 | }); |
| 13255 | 13244 | } |
| 13256 | 13245 | |
| 13257 | 13246 | if (self.module_asm.items.len != 0) { |
| 13258 | try module_block.writeAbbrev(Module.String{ | |
| 13247 | try module_block.writeAbbrev(ModuleBlock.String{ | |
| 13259 | 13248 | .code = 4, |
| 13260 | 13249 | .string = self.module_asm.items, |
| 13261 | 13250 | }); |
| ... | ... | @@ -13263,16 +13252,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13263 | 13252 | |
| 13264 | 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 | 13260 | for (self.type_items.items, 0..) |item, i| { |
| 13271 | 13261 | const ty: Type = @enumFromInt(i); |
| 13272 | 13262 | |
| 13273 | 13263 | switch (item.tag) { |
| 13274 | .simple => try type_block.writeAbbrev(ir.Type.Simple{ .code = @truncate(item.data) }), | |
| 13275 | .integer => try type_block.writeAbbrev(ir.Type.Integer{ .width = item.data }), | |
| 13264 | .simple => try type_block.writeAbbrev(TypeBlock.Simple{ .code = @enumFromInt(item.data) }), | |
| 13265 | .integer => try type_block.writeAbbrev(TypeBlock.Integer{ .width = item.data }), | |
| 13276 | 13266 | .structure, |
| 13277 | 13267 | .packed_structure, |
| 13278 | 13268 | => |kind| { |
| ... | ... | @@ -13282,19 +13272,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13282 | 13272 | else => unreachable, |
| 13283 | 13273 | }; |
| 13284 | 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 | 13276 | .is_packed = is_packed, |
| 13287 | 13277 | .types = extra.trail.next(extra.data.fields_len, Type, self), |
| 13288 | 13278 | }); |
| 13289 | 13279 | }, |
| 13290 | 13280 | .named_structure => { |
| 13291 | 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 | 13283 | .string = extra.id.slice(self).?, |
| 13294 | 13284 | }); |
| 13295 | 13285 | |
| 13296 | 13286 | switch (extra.body) { |
| 13297 | .none => try type_block.writeAbbrev(ir.Type.Opaque{}), | |
| 13287 | .none => try type_block.writeAbbrev(TypeBlock.Opaque{}), | |
| 13298 | 13288 | else => { |
| 13299 | 13289 | const real_struct = self.type_items.items[@intFromEnum(extra.body)]; |
| 13300 | 13290 | const is_packed: bool = switch (real_struct.tag) { |
| ... | ... | @@ -13304,7 +13294,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13304 | 13294 | }; |
| 13305 | 13295 | |
| 13306 | 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 | 13298 | .is_packed = is_packed, |
| 13309 | 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 | 13303 | }, |
| 13314 | 13304 | .array, |
| 13315 | 13305 | .small_array, |
| 13316 | => try type_block.writeAbbrev(ir.Type.Array{ | |
| 13306 | => try type_block.writeAbbrev(TypeBlock.Array{ | |
| 13317 | 13307 | .len = ty.aggregateLen(self), |
| 13318 | 13308 | .child = ty.childType(self), |
| 13319 | 13309 | }), |
| 13320 | 13310 | .vector, |
| 13321 | 13311 | .scalable_vector, |
| 13322 | => try type_block.writeAbbrev(ir.Type.Vector{ | |
| 13312 | => try type_block.writeAbbrev(TypeBlock.Vector{ | |
| 13323 | 13313 | .len = ty.aggregateLen(self), |
| 13324 | 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 | 13317 | .addr_space = ty.pointerAddrSpace(self), |
| 13328 | 13318 | }), |
| 13329 | 13319 | .target => { |
| 13330 | 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 | 13322 | .string = extra.data.name.slice(self).?, |
| 13333 | 13323 | }); |
| 13334 | 13324 | |
| 13335 | 13325 | const types = extra.trail.next(extra.data.types_len, Type, self); |
| 13336 | 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 | 13329 | .num_types = extra.data.types_len, |
| 13340 | 13330 | .types = types, |
| 13341 | 13331 | .ints = ints, |
| ... | ... | @@ -13348,7 +13338,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13348 | 13338 | else => unreachable, |
| 13349 | 13339 | }; |
| 13350 | 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 | 13342 | .is_vararg = is_vararg, |
| 13353 | 13343 | .return_type = extra.data.ret, |
| 13354 | 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 | 13358 | |
| 13369 | 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 | 13365 | for (self.function_attributes_set.keys()) |func_attributes| { |
| 13376 | 13366 | for (func_attributes.slice(self), 0..) |attributes, i| { |
| ... | ... | @@ -13572,8 +13562,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13572 | 13562 | |
| 13573 | 13563 | // PARAMATTR_BLOCK |
| 13574 | 13564 | { |
| 13575 | const Paramattr = ir.Paramattr; | |
| 13576 | var paramattr_block = try module_block.enterSubBlock(Paramattr, true); | |
| 13565 | const ParamattrBlock = ir.ModuleBlock.ParamattrBlock; | |
| 13566 | var paramattr_block = try module_block.enterSubBlock(ParamattrBlock, true); | |
| 13577 | 13567 | |
| 13578 | 13568 | for (self.function_attributes_set.keys()) |func_attributes| { |
| 13579 | 13569 | const func_attributes_slice = func_attributes.slice(self); |
| ... | ... | @@ -13590,7 +13580,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13590 | 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 | 13586 | try paramattr_block.end(); |
| ... | ... | @@ -13624,38 +13614,35 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13624 | 13614 | } |
| 13625 | 13615 | |
| 13626 | 13616 | const ConstantAdapter = struct { |
| 13627 | const ConstantAdapter = @This(); | |
| 13628 | 13617 | builder: *const Builder, |
| 13629 | 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) { | |
| 13632 | _ = field_name; | |
| 13620 | pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { | |
| 13621 | Constant => u32, | |
| 13622 | else => |Param| Param, | |
| 13623 | } { | |
| 13633 | 13624 | return switch (@TypeOf(param)) { |
| 13634 | Constant => @enumFromInt(adapter.getConstantIndex(param)), | |
| 13625 | Constant => adapter.getConstantIndex(param), | |
| 13635 | 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 | 13631 | return switch (constant.unwrap()) { |
| 13641 | 13632 | .constant => |c| c + adapter.numGlobals(), |
| 13642 | 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 | 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 | 13642 | return @intCast(adapter.globals.count()); |
| 13652 | 13643 | } |
| 13653 | 13644 | }; |
| 13654 | ||
| 13655 | const constant_adapter = ConstantAdapter{ | |
| 13656 | .builder = self, | |
| 13657 | .globals = &globals, | |
| 13658 | }; | |
| 13645 | const constant_adapter: ConstantAdapter = .{ .builder = self, .globals = &globals }; | |
| 13659 | 13646 | |
| 13660 | 13647 | // Globals |
| 13661 | 13648 | { |
| ... | ... | @@ -13670,7 +13657,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13670 | 13657 | if (variable.section == .none) break :blk 0; |
| 13671 | 13658 | const gop = section_map.getOrPutAssumeCapacity(variable.section); |
| 13672 | 13659 | if (!gop.found_existing) { |
| 13673 | try module_block.writeAbbrev(Module.String{ | |
| 13660 | try module_block.writeAbbrev(ModuleBlock.String{ | |
| 13674 | 13661 | .code = 5, |
| 13675 | 13662 | .string = variable.section.slice(self).?, |
| 13676 | 13663 | }); |
| ... | ... | @@ -13686,7 +13673,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13686 | 13673 | const strtab = variable.global.strtab(self); |
| 13687 | 13674 | |
| 13688 | 13675 | const global = variable.global.ptrConst(self); |
| 13689 | try module_block.writeAbbrev(Module.Variable{ | |
| 13676 | try module_block.writeAbbrev(ModuleBlock.Variable{ | |
| 13690 | 13677 | .strtab_offset = strtab.offset, |
| 13691 | 13678 | .strtab_size = strtab.size, |
| 13692 | 13679 | .type_index = global.type, |
| ... | ... | @@ -13717,7 +13704,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13717 | 13704 | if (func.section == .none) break :blk 0; |
| 13718 | 13705 | const gop = section_map.getOrPutAssumeCapacity(func.section); |
| 13719 | 13706 | if (!gop.found_existing) { |
| 13720 | try module_block.writeAbbrev(Module.String{ | |
| 13707 | try module_block.writeAbbrev(ModuleBlock.String{ | |
| 13721 | 13708 | .code = 5, |
| 13722 | 13709 | .string = func.section.slice(self).?, |
| 13723 | 13710 | }); |
| ... | ... | @@ -13733,7 +13720,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13733 | 13720 | const strtab = func.global.strtab(self); |
| 13734 | 13721 | |
| 13735 | 13722 | const global = func.global.ptrConst(self); |
| 13736 | try module_block.writeAbbrev(Module.Function{ | |
| 13723 | try module_block.writeAbbrev(ModuleBlock.Function{ | |
| 13737 | 13724 | .strtab_offset = strtab.offset, |
| 13738 | 13725 | .strtab_size = strtab.size, |
| 13739 | 13726 | .type_index = global.type, |
| ... | ... | @@ -13757,7 +13744,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13757 | 13744 | const strtab = alias.global.strtab(self); |
| 13758 | 13745 | |
| 13759 | 13746 | const global = alias.global.ptrConst(self); |
| 13760 | try module_block.writeAbbrev(Module.Alias{ | |
| 13747 | try module_block.writeAbbrev(ModuleBlock.Alias{ | |
| 13761 | 13748 | .strtab_offset = strtab.offset, |
| 13762 | 13749 | .strtab_size = strtab.size, |
| 13763 | 13750 | .type_index = global.type, |
| ... | ... | @@ -13775,8 +13762,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13775 | 13762 | |
| 13776 | 13763 | // CONSTANTS_BLOCK |
| 13777 | 13764 | { |
| 13778 | const Constants = ir.Constants; | |
| 13779 | var constants_block = try module_block.enterSubBlock(Constants, true); | |
| 13765 | const ConstantsBlock = ir.ModuleBlock.ConstantsBlock; | |
| 13766 | var constants_block = try module_block.enterSubBlock(ConstantsBlock, true); | |
| 13780 | 13767 | |
| 13781 | 13768 | var current_type: Type = .none; |
| 13782 | 13769 | const tags = self.constant_items.items(.tag); |
| ... | ... | @@ -13786,7 +13773,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13786 | 13773 | const constant: Constant = @enumFromInt(index); |
| 13787 | 13774 | const constant_type = constant.typeOf(self); |
| 13788 | 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 | 13777 | current_type = constant_type; |
| 13791 | 13778 | } |
| 13792 | 13779 | const data = datas[index]; |
| ... | ... | @@ -13794,9 +13781,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13794 | 13781 | .null, |
| 13795 | 13782 | .zeroinitializer, |
| 13796 | 13783 | .none, |
| 13797 | => try constants_block.writeAbbrev(Constants.Null{}), | |
| 13798 | .undef => try constants_block.writeAbbrev(Constants.Undef{}), | |
| 13799 | .poison => try constants_block.writeAbbrev(Constants.Poison{}), | |
| 13784 | => try constants_block.writeAbbrev(ConstantsBlock.Null{}), | |
| 13785 | .undef => try constants_block.writeAbbrev(ConstantsBlock.Undef{}), | |
| 13786 | .poison => try constants_block.writeAbbrev(ConstantsBlock.Poison{}), | |
| 13800 | 13787 | .positive_integer, |
| 13801 | 13788 | .negative_integer, |
| 13802 | 13789 | => |tag| { |
| ... | ... | @@ -13832,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13832 | 13819 | try constants_block.writeUnabbrev(5, record.items); |
| 13833 | 13820 | continue; |
| 13834 | 13821 | }; |
| 13835 | try constants_block.writeAbbrev(Constants.Integer{ | |
| 13822 | try constants_block.writeAbbrev(ConstantsBlock.Integer{ | |
| 13836 | 13823 | .value = @bitCast(if (val >= 0) |
| 13837 | 13824 | val << 1 | 0 |
| 13838 | 13825 | else |
| ... | ... | @@ -13841,17 +13828,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13841 | 13828 | }, |
| 13842 | 13829 | .half, |
| 13843 | 13830 | .bfloat, |
| 13844 | => try constants_block.writeAbbrev(Constants.Half{ .value = @truncate(data) }), | |
| 13845 | .float => try constants_block.writeAbbrev(Constants.Float{ .value = data }), | |
| 13831 | => try constants_block.writeAbbrev(ConstantsBlock.Half{ .value = @truncate(data) }), | |
| 13832 | .float => try constants_block.writeAbbrev(ConstantsBlock.Float{ .value = data }), | |
| 13846 | 13833 | .double => { |
| 13847 | 13834 | const extra = self.constantExtraData(Constant.Double, data); |
| 13848 | try constants_block.writeAbbrev(Constants.Double{ | |
| 13835 | try constants_block.writeAbbrev(ConstantsBlock.Double{ | |
| 13849 | 13836 | .value = (@as(u64, extra.hi) << 32) | extra.lo, |
| 13850 | 13837 | }); |
| 13851 | 13838 | }, |
| 13852 | 13839 | .x86_fp80 => { |
| 13853 | 13840 | const extra = self.constantExtraData(Constant.Fp80, data); |
| 13854 | try constants_block.writeAbbrev(Constants.Fp80{ | |
| 13841 | try constants_block.writeAbbrev(ConstantsBlock.Fp80{ | |
| 13855 | 13842 | .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 | |
| 13856 | 13843 | extra.lo_lo >> 16, |
| 13857 | 13844 | .lo = @truncate(extra.lo_lo), |
| ... | ... | @@ -13861,7 +13848,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13861 | 13848 | .ppc_fp128, |
| 13862 | 13849 | => { |
| 13863 | 13850 | const extra = self.constantExtraData(Constant.Fp128, data); |
| 13864 | try constants_block.writeAbbrev(Constants.Fp128{ | |
| 13851 | try constants_block.writeAbbrev(ConstantsBlock.Fp128{ | |
| 13865 | 13852 | .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo), |
| 13866 | 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 | 13863 | const values = extra.trail.next(len, Constant, self); |
| 13877 | 13864 | |
| 13878 | 13865 | try constants_block.writeAbbrevAdapted( |
| 13879 | Constants.Aggregate{ .values = values }, | |
| 13866 | ConstantsBlock.Aggregate{ .values = values }, | |
| 13880 | 13867 | constant_adapter, |
| 13881 | 13868 | ); |
| 13882 | 13869 | }, |
| 13883 | 13870 | .splat => { |
| 13884 | const ConstantsWriter = @TypeOf(constants_block); | |
| 13871 | const ConstantsBlockWriter = @TypeOf(constants_block); | |
| 13885 | 13872 | const extra = self.constantExtraData(Constant.Splat, data); |
| 13886 | 13873 | const vector_len = extra.type.vectorLen(self); |
| 13887 | 13874 | const c = constant_adapter.getConstantIndex(extra.value); |
| 13888 | 13875 | |
| 13889 | 13876 | try bitcode.writeBits( |
| 13890 | ConstantsWriter.abbrevId(Constants.Aggregate), | |
| 13891 | ConstantsWriter.abbrev_len, | |
| 13877 | ConstantsBlockWriter.abbrevId(ConstantsBlock.Aggregate), | |
| 13878 | ConstantsBlockWriter.abbrev_len, | |
| 13892 | 13879 | ); |
| 13893 | try bitcode.writeVBR(vector_len, 6); | |
| 13880 | try bitcode.writeVbr(vector_len, 6); | |
| 13894 | 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 | 13885 | .string => { |
| 13899 | 13886 | const str: String = @enumFromInt(data); |
| 13900 | 13887 | if (str == .none) { |
| 13901 | try constants_block.writeAbbrev(Constants.Null{}); | |
| 13888 | try constants_block.writeAbbrev(ConstantsBlock.Null{}); | |
| 13902 | 13889 | } else { |
| 13903 | 13890 | const slice = str.slice(self).?; |
| 13904 | 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 | 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 | 13897 | .bitcast, |
| ... | ... | @@ -13914,7 +13901,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13914 | 13901 | .trunc, |
| 13915 | 13902 | => |tag| { |
| 13916 | 13903 | const extra = self.constantExtraData(Constant.Cast, data); |
| 13917 | try constants_block.writeAbbrevAdapted(Constants.Cast{ | |
| 13904 | try constants_block.writeAbbrevAdapted(ConstantsBlock.Cast{ | |
| 13918 | 13905 | .type_index = extra.type, |
| 13919 | 13906 | .val = extra.val, |
| 13920 | 13907 | .opcode = tag.toCastOpcode(), |
| ... | ... | @@ -13930,7 +13917,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13930 | 13917 | .xor, |
| 13931 | 13918 | => |tag| { |
| 13932 | 13919 | const extra = self.constantExtraData(Constant.Binary, data); |
| 13933 | try constants_block.writeAbbrevAdapted(Constants.Binary{ | |
| 13920 | try constants_block.writeAbbrevAdapted(ConstantsBlock.Binary{ | |
| 13934 | 13921 | .opcode = tag.toBinaryOpcode(), |
| 13935 | 13922 | .lhs = extra.lhs, |
| 13936 | 13923 | .rhs = extra.rhs, |
| ... | ... | @@ -14014,7 +14001,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14014 | 14001 | }, |
| 14015 | 14002 | .blockaddress => { |
| 14016 | 14003 | const extra = self.constantExtraData(Constant.BlockAddress, data); |
| 14017 | try constants_block.writeAbbrev(Constants.BlockAddress{ | |
| 14004 | try constants_block.writeAbbrev(ConstantsBlock.BlockAddress{ | |
| 14018 | 14005 | .type_id = extra.function.typeOf(self), |
| 14019 | 14006 | .function = constant_adapter.getConstantIndex(extra.function.toConst(self)), |
| 14020 | 14007 | .block = @intFromEnum(extra.block), |
| ... | ... | @@ -14024,10 +14011,10 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14024 | 14011 | .no_cfi, |
| 14025 | 14012 | => |tag| { |
| 14026 | 14013 | const function: Function.Index = @enumFromInt(data); |
| 14027 | try constants_block.writeAbbrev(Constants.DsoLocalEquivalentOrNoCfi{ | |
| 14014 | try constants_block.writeAbbrev(ConstantsBlock.DsoLocalEquivalentOrNoCfi{ | |
| 14028 | 14015 | .code = switch (tag) { |
| 14029 | .dso_local_equivalent => 27, | |
| 14030 | .no_cfi => 29, | |
| 14016 | .dso_local_equivalent => .DSO_LOCAL_EQUIVALENT, | |
| 14017 | .no_cfi => .NO_CFI_VALUE, | |
| 14031 | 14018 | else => unreachable, |
| 14032 | 14019 | }, |
| 14033 | 14020 | .type_id = function.typeOf(self), |
| ... | ... | @@ -14042,7 +14029,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14042 | 14029 | |
| 14043 | 14030 | // METADATA_KIND_BLOCK |
| 14044 | 14031 | { |
| 14045 | const MetadataKindBlock = ir.MetadataKindBlock; | |
| 14032 | const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock; | |
| 14046 | 14033 | var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true); |
| 14047 | 14034 | |
| 14048 | 14035 | inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| { |
| ... | ... | @@ -14059,95 +14046,85 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14059 | 14046 | } |
| 14060 | 14047 | |
| 14061 | 14048 | const MetadataAdapter = struct { |
| 14062 | builder: *const Builder, | |
| 14063 | 14049 | constant_adapter: ConstantAdapter, |
| 14064 | 14050 | |
| 14065 | pub fn init( | |
| 14066 | builder: *const Builder, | |
| 14067 | const_adapter: ConstantAdapter, | |
| 14068 | ) @This() { | |
| 14069 | return .{ | |
| 14070 | .builder = builder, | |
| 14071 | .constant_adapter = const_adapter, | |
| 14072 | }; | |
| 14073 | } | |
| 14074 | ||
| 14075 | pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) { | |
| 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, | |
| 14051 | pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { | |
| 14052 | Metadata, Metadata.Optional, Metadata.String, Metadata.String.Optional, Constant => u32, | |
| 14053 | else => |Result| Result, | |
| 14054 | } { | |
| 14055 | return switch (@TypeOf(param)) { | |
| 14056 | Metadata => adapter.getMetadataIndex(param), | |
| 14057 | Metadata.Optional => adapter.getOptionalMetadataIndex(param), | |
| 14058 | Metadata.String => adapter.getMetadataIndex(param.toMetadata()), | |
| 14059 | Metadata.String.Optional => adapter.getOptionalMetadataIndex(param.toMetadata()), | |
| 14060 | Constant => adapter.constant_adapter.getConstantIndex(param), | |
| 14061 | else => param, | |
| 14083 | 14062 | }; |
| 14084 | 14063 | } |
| 14085 | 14064 | |
| 14086 | 14065 | pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 { |
| 14087 | if (metadata == .none) return 0; | |
| 14088 | return @intCast(adapter.builder.metadata_string_map.count() + | |
| 14089 | @intFromEnum(metadata.unwrap(adapter.builder)) - 1); | |
| 14066 | const builder = adapter.constant_adapter.builder; | |
| 14067 | const unwrapped_metadata = metadata.unwrap(builder); | |
| 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 { | |
| 14093 | return @intFromEnum(metadata_string); | |
| 14075 | pub fn getOptionalMetadataIndex(adapter: @This(), metadata: Metadata.Optional) u32 { | |
| 14076 | return if (metadata.unwrap()) |m| 1 + adapter.getMetadataIndex(m) else 0; | |
| 14094 | 14077 | } |
| 14095 | 14078 | }; |
| 14096 | ||
| 14097 | const metadata_adapter = MetadataAdapter.init(self, constant_adapter); | |
| 14079 | const metadata_adapter: MetadataAdapter = .{ .constant_adapter = constant_adapter }; | |
| 14098 | 14080 | |
| 14099 | 14081 | // METADATA_BLOCK |
| 14100 | 14082 | { |
| 14101 | const MetadataBlock = ir.MetadataBlock; | |
| 14083 | const MetadataBlock = ir.ModuleBlock.MetadataBlock; | |
| 14102 | 14084 | var metadata_block = try module_block.enterSubBlock(MetadataBlock, true); |
| 14103 | 14085 | |
| 14104 | 14086 | const MetadataBlockWriter = @TypeOf(metadata_block); |
| 14105 | 14087 | |
| 14106 | // Emit all MetadataStrings | |
| 14107 | if (self.metadata_string_map.count() > 1) { | |
| 14108 | const strings_offset, const strings_size = blk: { | |
| 14109 | var strings_offset: u32 = 0; | |
| 14110 | var strings_size: u32 = 0; | |
| 14111 | for (1..self.metadata_string_map.count()) |metadata_string_index| { | |
| 14112 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); | |
| 14113 | const slice = metadata_string.slice(self); | |
| 14114 | strings_offset += bitcode.bitsVBR(@as(u32, @intCast(slice.len)), 6); | |
| 14115 | strings_size += @intCast(slice.len * 8); | |
| 14116 | } | |
| 14117 | break :blk .{ | |
| 14118 | std.mem.alignForward(u32, strings_offset, 32) / 8, | |
| 14119 | std.mem.alignForward(u32, strings_size, 32) / 8, | |
| 14120 | }; | |
| 14088 | // Emit all Metadata.Strings | |
| 14089 | const strings_len: u32 = @intCast(self.metadata_string_map.count()); | |
| 14090 | if (strings_len > 0) { | |
| 14091 | const string_bytes_offset = string_bytes_offset: { | |
| 14092 | var string_bytes_bit_offset: u32 = 0; | |
| 14093 | for ( | |
| 14094 | self.metadata_string_indices.items[0..strings_len], | |
| 14095 | self.metadata_string_indices.items[1..], | |
| 14096 | ) |start, end| string_bytes_bit_offset += BitcodeWriter.bitsVbr(end - start, 6); | |
| 14097 | break :string_bytes_offset @divExact( | |
| 14098 | std.mem.alignForward(u32, string_bytes_bit_offset, 32), | |
| 14099 | 8, | |
| 14100 | ); | |
| 14121 | 14101 | }; |
| 14102 | const string_bytes_len = | |
| 14103 | std.mem.alignForward(u32, @intCast(self.metadata_string_bytes.items.len), 4); | |
| 14122 | 14104 | |
| 14123 | 14105 | try bitcode.writeBits( |
| 14124 | 14106 | comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings), |
| 14125 | 14107 | MetadataBlockWriter.abbrev_len, |
| 14126 | 14108 | ); |
| 14127 | 14109 | |
| 14128 | try bitcode.writeVBR(@as(u32, @intCast(self.metadata_string_map.count() - 1)), 6); | |
| 14129 | try bitcode.writeVBR(strings_offset, 6); | |
| 14110 | try bitcode.writeVbr(strings_len, 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 | 14115 | try bitcode.alignTo32(); |
| 14134 | 14116 | |
| 14135 | for (1..self.metadata_string_map.count()) |metadata_string_index| { | |
| 14136 | const metadata_string: MetadataString = @enumFromInt(metadata_string_index); | |
| 14137 | const slice = metadata_string.slice(self); | |
| 14138 | try bitcode.writeVBR(@as(u32, @intCast(slice.len)), 6); | |
| 14139 | } | |
| 14117 | for ( | |
| 14118 | self.metadata_string_indices.items[0..strings_len], | |
| 14119 | self.metadata_string_indices.items[1..], | |
| 14120 | ) |start, end| try bitcode.writeVbr(end - start, 6); | |
| 14140 | 14121 | |
| 14141 | 14122 | try bitcode.writeBlob(self.metadata_string_bytes.items); |
| 14142 | 14123 | } |
| 14143 | 14124 | |
| 14144 | for ( | |
| 14145 | self.metadata_items.items(.tag)[1..], | |
| 14146 | self.metadata_items.items(.data)[1..], | |
| 14147 | ) |tag, data| { | |
| 14125 | for (self.metadata_items.items(.tag), self.metadata_items.items(.data)) |tag, data| { | |
| 14148 | 14126 | record.clearRetainingCapacity(); |
| 14149 | 14127 | switch (tag) { |
| 14150 | .none => unreachable, | |
| 14151 | 14128 | .file => { |
| 14152 | 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 | 14186 | }, |
| 14210 | 14187 | .location => { |
| 14211 | 14188 | const extra = self.metadataExtraData(Metadata.Location, data); |
| 14212 | assert(extra.scope != .none); | |
| 14213 | try metadata_block.writeAbbrev(MetadataBlock.Location{ | |
| 14189 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Location{ | |
| 14214 | 14190 | .line = extra.line, |
| 14215 | 14191 | .column = extra.column, |
| 14216 | .scope = metadata_adapter.getMetadataIndex(extra.scope) - 1, | |
| 14217 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(extra.inlined_at)), | |
| 14218 | }); | |
| 14192 | .scope = extra.scope, | |
| 14193 | .inlined_at = extra.inlined_at, | |
| 14194 | }, metadata_adapter); | |
| 14219 | 14195 | }, |
| 14220 | 14196 | .basic_bool_type, |
| 14221 | 14197 | .basic_unsigned_type, |
| ... | ... | @@ -14325,7 +14301,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14325 | 14301 | @bitCast(flags), |
| 14326 | 14302 | )); |
| 14327 | 14303 | record.appendAssumeCapacity(extra.bit_width); |
| 14328 | record.appendAssumeCapacity(metadata_adapter.getMetadataStringIndex(extra.name)); | |
| 14304 | record.appendAssumeCapacity(metadata_adapter.getOptionalMetadataIndex(extra.name.toMetadata())); | |
| 14329 | 14305 | const limbs = record.addManyAsSliceAssumeCapacity(limbs_len); |
| 14330 | 14306 | bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little); |
| 14331 | 14307 | for (limbs) |*limb| { |
| ... | ... | @@ -14335,7 +14311,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14335 | 14311 | else |
| 14336 | 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 | 14315 | continue; |
| 14340 | 14316 | }; |
| 14341 | 14317 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{ |
| ... | ... | @@ -14350,7 +14326,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14350 | 14326 | }, |
| 14351 | 14327 | .subrange => { |
| 14352 | 14328 | const extra = self.metadataExtraData(Metadata.Subrange, data); |
| 14353 | ||
| 14354 | 14329 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{ |
| 14355 | 14330 | .count = extra.count, |
| 14356 | 14331 | .lower_bound = extra.lower_bound, |
| ... | ... | @@ -14358,48 +14333,19 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14358 | 14333 | }, |
| 14359 | 14334 | .expression => { |
| 14360 | 14335 | var extra = self.metadataExtraDataTrail(Metadata.Expression, data); |
| 14361 | ||
| 14362 | 14336 | const elements = extra.trail.next(extra.data.elements_len, u32, self); |
| 14363 | ||
| 14364 | 14337 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{ |
| 14365 | 14338 | .elements = elements, |
| 14366 | 14339 | }, metadata_adapter); |
| 14367 | 14340 | }, |
| 14368 | 14341 | .tuple => { |
| 14369 | 14342 | var extra = self.metadataExtraDataTrail(Metadata.Tuple, data); |
| 14370 | ||
| 14371 | const elements = extra.trail.next(extra.data.elements_len, Metadata, self); | |
| 14372 | ||
| 14343 | const elements = | |
| 14344 | extra.trail.next(extra.data.elements_len, Metadata.Optional, self); | |
| 14373 | 14345 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{ |
| 14374 | 14346 | .elements = elements, |
| 14375 | 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 | 14349 | .local_var => { |
| 14404 | 14350 | const extra = self.metadataExtraData(Metadata.LocalVar, data); |
| 14405 | 14351 | try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{ |
| ... | ... | @@ -14454,37 +14400,28 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14454 | 14400 | |
| 14455 | 14401 | // Write named metadata |
| 14456 | 14402 | for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| { |
| 14457 | const slice = name.slice(self); | |
| 14458 | try metadata_block.writeAbbrev(MetadataBlock.Name{ | |
| 14459 | .name = slice, | |
| 14460 | }); | |
| 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 | }); | |
| 14403 | try metadata_block.writeAbbrev(MetadataBlock.Name{ .name = name.slice(self).? }); | |
| 14404 | try metadata_block.writeAbbrevAdapted(MetadataBlock.NamedNode{ | |
| 14405 | .elements = @ptrCast(self.metadata_extra.items[operands.index..][0..operands.len]), | |
| 14406 | }, metadata_adapter); | |
| 14470 | 14407 | } |
| 14471 | 14408 | |
| 14472 | 14409 | // Write global attached metadata |
| 14473 | 14410 | { |
| 14474 | for (globals.keys()) |global| { | |
| 14475 | const global_ptr = global.ptrConst(self); | |
| 14476 | if (global_ptr.dbg == .none) continue; | |
| 14411 | for (globals.keys()) |global_index| { | |
| 14412 | const global = global_index.ptrConst(self); | |
| 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) { | |
| 14479 | .function => |f| if (f.ptrConst(self).instructions.len != 0) continue, | |
| 14480 | else => {}, | |
| 14419 | try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalDeclAttachment{ | |
| 14420 | .value = global_index.toConst(), | |
| 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 | 14430 | |
| 14494 | 14431 | // OPERAND_BUNDLE_TAGS_BLOCK |
| 14495 | 14432 | { |
| 14496 | const OperandBundleTags = ir.OperandBundleTags; | |
| 14497 | var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTags, true); | |
| 14433 | const OperandBundleTagsBlock = ir.ModuleBlock.OperandBundleTagsBlock; | |
| 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 | 14437 | .tag = "cold", |
| 14501 | 14438 | }); |
| 14502 | 14439 | |
| ... | ... | @@ -14505,26 +14442,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14505 | 14442 | |
| 14506 | 14443 | // Block info |
| 14507 | 14444 | { |
| 14508 | const BlockInfo = ir.BlockInfo; | |
| 14509 | var block_info_block = try module_block.enterSubBlock(BlockInfo, true); | |
| 14445 | const BlockInfoBlock = ir.BlockInfoBlock; | |
| 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}); | |
| 14512 | inline for (ir.FunctionBlock.abbrevs) |abbrev| { | |
| 14448 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ | |
| 14449 | @intFromEnum(ir.ModuleBlock.FunctionBlock.id), | |
| 14450 | }); | |
| 14451 | inline for (ir.ModuleBlock.FunctionBlock.abbrevs) |abbrev| { | |
| 14513 | 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}); | |
| 14517 | inline for (ir.FunctionValueSymbolTable.abbrevs) |abbrev| { | |
| 14455 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ | |
| 14456 | @intFromEnum(ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.id), | |
| 14457 | }); | |
| 14458 | inline for (ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.abbrevs) |abbrev| { | |
| 14518 | 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}); | |
| 14522 | inline for (ir.FunctionMetadataBlock.abbrevs) |abbrev| { | |
| 14462 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ | |
| 14463 | @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataBlock.id), | |
| 14464 | }); | |
| 14465 | inline for (ir.ModuleBlock.FunctionBlock.MetadataBlock.abbrevs) |abbrev| { | |
| 14523 | 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}); | |
| 14527 | inline for (ir.MetadataAttachmentBlock.abbrevs) |abbrev| { | |
| 14469 | try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{ | |
| 14470 | @intFromEnum(ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.id), | |
| 14471 | }); | |
| 14472 | inline for (ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.abbrevs) |abbrev| { | |
| 14528 | 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 | 14479 | // FUNCTION_BLOCKS |
| 14535 | 14480 | { |
| 14536 | 14481 | const FunctionAdapter = struct { |
| 14537 | constant_adapter: ConstantAdapter, | |
| 14538 | 14482 | metadata_adapter: MetadataAdapter, |
| 14539 | 14483 | func: *const Function, |
| 14540 | 14484 | instruction_index: Function.Instruction.Index, |
| 14541 | 14485 | |
| 14542 | pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) { | |
| 14543 | _ = field_name; | |
| 14544 | const Ty = @TypeOf(value); | |
| 14545 | return switch (Ty) { | |
| 14546 | Value => @enumFromInt(adapter.getOffsetValueIndex(value)), | |
| 14547 | Constant => @enumFromInt(adapter.getOffsetConstantIndex(value)), | |
| 14548 | FunctionAttributes => @enumFromInt(switch (value) { | |
| 14486 | pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { | |
| 14487 | Value, Constant, FunctionAttributes => u32, | |
| 14488 | else => |Result| Result, | |
| 14489 | } { | |
| 14490 | return switch (@TypeOf(param)) { | |
| 14491 | Value => adapter.getOffsetValueIndex(param), | |
| 14492 | Constant => adapter.getOffsetConstantIndex(param), | |
| 14493 | FunctionAttributes => switch (param) { | |
| 14549 | 14494 | .none => 0, |
| 14550 | else => 1 + adapter.constant_adapter.builder.function_attributes_set.getIndex(value).?, | |
| 14551 | }), | |
| 14552 | else => value, | |
| 14495 | else => @intCast(1 + adapter.metadata_adapter.constant_adapter.builder | |
| 14496 | .function_attributes_set.getIndex(param).?), | |
| 14497 | }, | |
| 14498 | else => param, | |
| 14553 | 14499 | }; |
| 14554 | 14500 | } |
| 14555 | 14501 | |
| 14556 | 14502 | pub fn getValueIndex(adapter: @This(), value: Value) u32 { |
| 14557 | 14503 | return @intCast(switch (value.unwrap()) { |
| 14558 | 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 | 14506 | .metadata => |metadata| { |
| 14561 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); | |
| 14562 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) | |
| 14563 | return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; | |
| 14564 | ||
| 14565 | return @intCast(@intFromEnum(metadata) - | |
| 14566 | Metadata.first_local_metadata + | |
| 14567 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + | |
| 14568 | adapter.metadata_adapter.builder.metadata_map.count() - 1); | |
| 14507 | const builder = adapter.metadata_adapter.constant_adapter.builder; | |
| 14508 | const unwrapped_metadata = metadata.unwrap(builder); | |
| 14509 | return switch (unwrapped_metadata.kind) { | |
| 14510 | .string, .node => adapter.metadata_adapter.getMetadataIndex(unwrapped_metadata), | |
| 14511 | .forward => unreachable, | |
| 14512 | .local => @intCast(builder.metadata_string_map.count() + | |
| 14513 | builder.metadata_map.count() + | |
| 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 | 14536 | } |
| 14590 | 14537 | |
| 14591 | 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 | 14543 | for (self.functions.items, 0..) |func, func_index| { |
| 14597 | const FunctionBlock = ir.FunctionBlock; | |
| 14544 | const FunctionBlock = ir.ModuleBlock.FunctionBlock; | |
| 14598 | 14545 | if (func.global.getReplacement(self) != .none) continue; |
| 14599 | 14546 | |
| 14600 | 14547 | if (func.instructions.len == 0) continue; |
| ... | ... | @@ -14604,7 +14551,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14604 | 14551 | try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len }); |
| 14605 | 14552 | |
| 14606 | 14553 | var adapter: FunctionAdapter = .{ |
| 14607 | .constant_adapter = constant_adapter, | |
| 14608 | 14554 | .metadata_adapter = metadata_adapter, |
| 14609 | 14555 | .func = &func, |
| 14610 | 14556 | .instruction_index = @enumFromInt(0), |
| ... | ... | @@ -14612,7 +14558,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14612 | 14558 | |
| 14613 | 14559 | // Emit function level metadata block |
| 14614 | 14560 | if (!func.strip and func.debug_values.len > 0) { |
| 14615 | const MetadataBlock = ir.FunctionMetadataBlock; | |
| 14561 | const MetadataBlock = ir.ModuleBlock.FunctionBlock.MetadataBlock; | |
| 14616 | 14562 | var metadata_block = try function_block.enterSubBlock(MetadataBlock, false); |
| 14617 | 14563 | |
| 14618 | 14564 | for (func.debug_values) |value| { |
| ... | ... | @@ -15048,7 +14994,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15048 | 14994 | const vals = extra.trail.next(extra.data.cases_len, Constant, &func); |
| 15049 | 14995 | const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func); |
| 15050 | 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 | 14998 | record.appendAssumeCapacity(@intFromEnum(block)); |
| 15053 | 14999 | } |
| 15054 | 15000 | |
| ... | ... | @@ -15135,12 +15081,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15135 | 15081 | switch (debug_location) { |
| 15136 | 15082 | .no_location => has_location = false, |
| 15137 | 15083 | .location => |location| { |
| 15138 | try function_block.writeAbbrev(FunctionBlock.DebugLoc{ | |
| 15084 | try function_block.writeAbbrevAdapted(FunctionBlock.DebugLoc{ | |
| 15139 | 15085 | .line = location.line, |
| 15140 | 15086 | .column = location.column, |
| 15141 | .scope = @enumFromInt(metadata_adapter.getMetadataIndex(location.scope)), | |
| 15142 | .inlined_at = @enumFromInt(metadata_adapter.getMetadataIndex(location.inlined_at)), | |
| 15143 | }); | |
| 15087 | .scope = location.scope, | |
| 15088 | .inlined_at = location.inlined_at, | |
| 15089 | }, metadata_adapter); | |
| 15144 | 15090 | has_location = true; |
| 15145 | 15091 | }, |
| 15146 | 15092 | } |
| ... | ... | @@ -15152,16 +15098,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15152 | 15098 | |
| 15153 | 15099 | // VALUE_SYMTAB |
| 15154 | 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 | 15105 | for (func.blocks, 0..) |block, block_index| { |
| 15160 | 15106 | const name = block.instruction.name(&func); |
| 15161 | 15107 | |
| 15162 | 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 | 15111 | .value_id = @intCast(block_index), |
| 15166 | 15112 | .string = name.slice(self).?, |
| 15167 | 15113 | }); |
| ... | ... | @@ -15174,17 +15120,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15174 | 15120 | |
| 15175 | 15121 | // METADATA_ATTACHMENT_BLOCK |
| 15176 | 15122 | { |
| 15177 | const MetadataAttachmentBlock = ir.MetadataAttachmentBlock; | |
| 15123 | const MetadataAttachmentBlock = ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock; | |
| 15178 | 15124 | var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false); |
| 15179 | 15125 | |
| 15180 | dbg: { | |
| 15181 | if (func.strip) break :dbg; | |
| 15182 | const dbg = func.global.ptrConst(self).dbg; | |
| 15183 | if (dbg == .none) break :dbg; | |
| 15184 | try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{ | |
| 15126 | if (func.global.ptrConst(self).dbg.unwrap()) |dbg| { | |
| 15127 | try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentGlobalSingle{ | |
| 15185 | 15128 | .kind = .dbg, |
| 15186 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1), | |
| 15187 | }); | |
| 15129 | .metadata = dbg, | |
| 15130 | }, metadata_adapter); | |
| 15188 | 15131 | } |
| 15189 | 15132 | |
| 15190 | 15133 | var instr_index: u32 = 0; |
| ... | ... | @@ -15201,16 +15144,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15201 | 15144 | }; |
| 15202 | 15145 | switch (weights) { |
| 15203 | 15146 | .none => {}, |
| 15204 | .unpredictable => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{ | |
| 15147 | .unpredictable => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{ | |
| 15205 | 15148 | .inst = instr_index, |
| 15206 | 15149 | .kind = .unpredictable, |
| 15207 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1), | |
| 15208 | }), | |
| 15209 | _ => try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{ | |
| 15150 | .metadata = .empty_tuple, | |
| 15151 | }, metadata_adapter), | |
| 15152 | _ => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{ | |
| 15210 | 15153 | .inst = instr_index, |
| 15211 | 15154 | .kind = .prof, |
| 15212 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(@enumFromInt(@intFromEnum(weights))) - 1), | |
| 15213 | }), | |
| 15155 | .metadata = weights.toMetadata(), | |
| 15156 | }, metadata_adapter), | |
| 15214 | 15157 | } |
| 15215 | 15158 | instr_index += 1; |
| 15216 | 15159 | }, |
| ... | ... | @@ -15228,7 +15171,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 15228 | 15171 | |
| 15229 | 15172 | // STRTAB_BLOCK |
| 15230 | 15173 | { |
| 15231 | const Strtab = ir.Strtab; | |
| 15174 | const Strtab = ir.StrtabBlock; | |
| 15232 | 15175 | var strtab_block = try bitcode.enterTopBlock(Strtab); |
| 15233 | 15176 | |
| 15234 | 15177 | try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items }); |
lib/std/zig/llvm/bitcode_writer.zig+30-32| ... | ... | @@ -88,7 +88,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | pub fn writeVBR(self: *BcWriter, value: anytype, comptime vbr_bits: usize) Error!void { | |
| 91 | pub fn writeVbr(self: *BcWriter, value: anytype, comptime vbr_bits: usize) Error!void { | |
| 92 | 92 | comptime { |
| 93 | 93 | std.debug.assert(vbr_bits > 1); |
| 94 | 94 | if (@bitSizeOf(@TypeOf(value)) > 64) @compileError("Unsupported VBR block type: " ++ @typeName(@TypeOf(value))); |
| ... | ... | @@ -110,7 +110,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 110 | 110 | try self.writeBits(in_buffer, vbr_bits); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | pub fn bitsVBR(_: *const BcWriter, value: anytype, comptime vbr_bits: usize) u16 { | |
| 113 | pub fn bitsVbr(value: anytype, comptime vbr_bits: usize) u16 { | |
| 114 | 114 | comptime { |
| 115 | 115 | std.debug.assert(vbr_bits > 1); |
| 116 | 116 | if (@bitSizeOf(@TypeOf(value)) > 64) @compileError("Unsupported VBR block type: " ++ @typeName(@TypeOf(value))); |
| ... | ... | @@ -177,8 +177,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 177 | 177 | |
| 178 | 178 | pub fn init(bitcode: *BcWriter, comptime parent_abbrev_len: u6, comptime define_abbrevs: bool) Error!Self { |
| 179 | 179 | try bitcode.writeBits(1, parent_abbrev_len); |
| 180 | try bitcode.writeVBR(Block.id, 8); | |
| 181 | try bitcode.writeVBR(abbrev_len, 4); | |
| 180 | try bitcode.writeVbr(Block.id, 8); | |
| 181 | try bitcode.writeVbr(abbrev_len, 4); | |
| 182 | 182 | try bitcode.alignTo32(); |
| 183 | 183 | |
| 184 | 184 | // We store the index of the block size and store a dummy value as the number of words in the block |
| ... | ... | @@ -214,16 +214,16 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 214 | 214 | |
| 215 | 215 | pub fn writeUnabbrev(self: *Self, code: u32, values: []const u64) Error!void { |
| 216 | 216 | try self.bitcode.writeBits(3, abbrev_len); |
| 217 | try self.bitcode.writeVBR(code, 6); | |
| 218 | try self.bitcode.writeVBR(values.len, 6); | |
| 217 | try self.bitcode.writeVbr(code, 6); | |
| 218 | try self.bitcode.writeVbr(values.len, 6); | |
| 219 | 219 | for (values) |val| { |
| 220 | try self.bitcode.writeVBR(val, 6); | |
| 220 | try self.bitcode.writeVbr(val, 6); | |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | pub fn writeAbbrev(self: *Self, params: anytype) Error!void { |
| 225 | 225 | return self.writeAbbrevAdapted(params, struct { |
| 226 | pub fn get(_: @This(), param: anytype, comptime _: []const u8) @TypeOf(param) { | |
| 226 | pub fn get(_: @This(), param: anytype) @TypeOf(param) { | |
| 227 | 227 | return param; |
| 228 | 228 | } |
| 229 | 229 | }{}); |
| ... | ... | @@ -253,47 +253,45 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 253 | 253 | |
| 254 | 254 | comptime var field_index: usize = 0; |
| 255 | 255 | inline for (Abbrev.ops) |ty| { |
| 256 | const field_name = fields[field_index].name; | |
| 257 | const param = @field(params, field_name); | |
| 258 | ||
| 256 | const param = @field(params, fields[field_index].name); | |
| 259 | 257 | switch (ty) { |
| 260 | 258 | .literal => continue, |
| 261 | .fixed => |len| try self.bitcode.writeBits(adapter.get(param, field_name), len), | |
| 259 | .fixed => |len| try self.bitcode.writeBits(adapter.get(param), len), | |
| 262 | 260 | .fixed_runtime => |width_ty| try self.bitcode.writeBits( |
| 263 | adapter.get(param, field_name), | |
| 261 | adapter.get(param), | |
| 264 | 262 | self.bitcode.getTypeWidth(width_ty), |
| 265 | 263 | ), |
| 266 | .vbr => |len| try self.bitcode.writeVBR(adapter.get(param, field_name), len), | |
| 267 | .char6 => try self.bitcode.write6BitChar(adapter.get(param, field_name)), | |
| 264 | .vbr => |len| try self.bitcode.writeVbr(adapter.get(param), len), | |
| 265 | .char6 => try self.bitcode.write6BitChar(adapter.get(param)), | |
| 268 | 266 | .blob => { |
| 269 | try self.bitcode.writeVBR(param.len, 6); | |
| 267 | try self.bitcode.writeVbr(param.len, 6); | |
| 270 | 268 | try self.bitcode.writeBlob(param); |
| 271 | 269 | }, |
| 272 | 270 | .array_fixed => |len| { |
| 273 | try self.bitcode.writeVBR(param.len, 6); | |
| 271 | try self.bitcode.writeVbr(param.len, 6); | |
| 274 | 272 | for (param) |x| { |
| 275 | try self.bitcode.writeBits(adapter.get(x, field_name), len); | |
| 273 | try self.bitcode.writeBits(adapter.get(x), len); | |
| 276 | 274 | } |
| 277 | 275 | }, |
| 278 | 276 | .array_fixed_runtime => |width_ty| { |
| 279 | try self.bitcode.writeVBR(param.len, 6); | |
| 277 | try self.bitcode.writeVbr(param.len, 6); | |
| 280 | 278 | for (param) |x| { |
| 281 | 279 | try self.bitcode.writeBits( |
| 282 | adapter.get(x, field_name), | |
| 280 | adapter.get(x), | |
| 283 | 281 | self.bitcode.getTypeWidth(width_ty), |
| 284 | 282 | ); |
| 285 | 283 | } |
| 286 | 284 | }, |
| 287 | 285 | .array_vbr => |len| { |
| 288 | try self.bitcode.writeVBR(param.len, 6); | |
| 286 | try self.bitcode.writeVbr(param.len, 6); | |
| 289 | 287 | for (param) |x| { |
| 290 | try self.bitcode.writeVBR(adapter.get(x, field_name), len); | |
| 288 | try self.bitcode.writeVbr(adapter.get(x), len); | |
| 291 | 289 | } |
| 292 | 290 | }, |
| 293 | 291 | .array_char6 => { |
| 294 | try self.bitcode.writeVBR(param.len, 6); | |
| 292 | try self.bitcode.writeVbr(param.len, 6); | |
| 295 | 293 | for (param) |x| { |
| 296 | try self.bitcode.write6BitChar(adapter.get(x, field_name)); | |
| 294 | try self.bitcode.write6BitChar(adapter.get(x)); | |
| 297 | 295 | } |
| 298 | 296 | }, |
| 299 | 297 | } |
| ... | ... | @@ -307,7 +305,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 307 | 305 | try bitcode.writeBits(2, abbrev_len); |
| 308 | 306 | |
| 309 | 307 | // ops.len is not accurate because arrays are actually two ops |
| 310 | try bitcode.writeVBR(blk: { | |
| 308 | try bitcode.writeVbr(blk: { | |
| 311 | 309 | var count: usize = 0; |
| 312 | 310 | inline for (ops) |op| { |
| 313 | 311 | count += switch (op) { |
| ... | ... | @@ -322,22 +320,22 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 322 | 320 | switch (op) { |
| 323 | 321 | .literal => |value| { |
| 324 | 322 | try bitcode.writeBits(1, 1); |
| 325 | try bitcode.writeVBR(value, 8); | |
| 323 | try bitcode.writeVbr(value, 8); | |
| 326 | 324 | }, |
| 327 | 325 | .fixed => |width| { |
| 328 | 326 | try bitcode.writeBits(0, 1); |
| 329 | 327 | try bitcode.writeBits(1, 3); |
| 330 | try bitcode.writeVBR(width, 5); | |
| 328 | try bitcode.writeVbr(width, 5); | |
| 331 | 329 | }, |
| 332 | 330 | .fixed_runtime => |width_ty| { |
| 333 | 331 | try bitcode.writeBits(0, 1); |
| 334 | 332 | try bitcode.writeBits(1, 3); |
| 335 | try bitcode.writeVBR(bitcode.getTypeWidth(width_ty), 5); | |
| 333 | try bitcode.writeVbr(bitcode.getTypeWidth(width_ty), 5); | |
| 336 | 334 | }, |
| 337 | 335 | .vbr => |width| { |
| 338 | 336 | try bitcode.writeBits(0, 1); |
| 339 | 337 | try bitcode.writeBits(2, 3); |
| 340 | try bitcode.writeVBR(width, 5); | |
| 338 | try bitcode.writeVbr(width, 5); | |
| 341 | 339 | }, |
| 342 | 340 | .char6 => { |
| 343 | 341 | try bitcode.writeBits(0, 1); |
| ... | ... | @@ -355,7 +353,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 355 | 353 | // Fixed or VBR op |
| 356 | 354 | try bitcode.writeBits(0, 1); |
| 357 | 355 | try bitcode.writeBits(1, 3); |
| 358 | try bitcode.writeVBR(width, 5); | |
| 356 | try bitcode.writeVbr(width, 5); | |
| 359 | 357 | }, |
| 360 | 358 | .array_fixed_runtime => |width_ty| { |
| 361 | 359 | // Array op |
| ... | ... | @@ -365,7 +363,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 365 | 363 | // Fixed or VBR op |
| 366 | 364 | try bitcode.writeBits(0, 1); |
| 367 | 365 | try bitcode.writeBits(1, 3); |
| 368 | try bitcode.writeVBR(bitcode.getTypeWidth(width_ty), 5); | |
| 366 | try bitcode.writeVbr(bitcode.getTypeWidth(width_ty), 5); | |
| 369 | 367 | }, |
| 370 | 368 | .array_vbr => |width| { |
| 371 | 369 | // Array op |
| ... | ... | @@ -375,7 +373,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 375 | 373 | // Fixed or VBR op |
| 376 | 374 | try bitcode.writeBits(0, 1); |
| 377 | 375 | try bitcode.writeBits(2, 3); |
| 378 | try bitcode.writeVBR(width, 5); | |
| 376 | try bitcode.writeVbr(width, 5); | |
| 379 | 377 | }, |
| 380 | 378 | .array_char6 => { |
| 381 | 379 | // Array op |
lib/std/zig/llvm/ir.zig+2048-1612| ... | ... | @@ -21,9 +21,60 @@ const ColumnAbbrev = AbbrevOp{ .vbr = 8 }; |
| 21 | 21 | const BlockAbbrev = AbbrevOp{ .vbr = 6 }; |
| 22 | 22 | const BlockArrayAbbrev = AbbrevOp{ .array_vbr = 6 }; |
| 23 | 23 | |
| 24 | /// All bitcode files can optionally include a BLOCKINFO block, which contains | |
| 25 | /// metadata about other blocks in the file. | |
| 26 | /// The only top-level block types are MODULE, IDENTIFICATION, STRTAB and SYMTAB. | |
| 27 | pub const BlockId = enum(u5) { | |
| 28 | /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example, | |
| 29 | /// standard abbrevs that should be available to all blocks of a specified | |
| 30 | /// ID. | |
| 31 | BLOCKINFO = 0, | |
| 32 | ||
| 33 | /// Blocks | |
| 34 | MODULE = FIRST_APPLICATION, | |
| 35 | ||
| 36 | /// Module sub-block id's. | |
| 37 | PARAMATTR, | |
| 38 | PARAMATTR_GROUP, | |
| 39 | ||
| 40 | CONSTANTS, | |
| 41 | FUNCTION, | |
| 42 | ||
| 43 | /// Block intended to contains information on the bitcode versioning. | |
| 44 | /// Can be used to provide better error messages when we fail to parse a | |
| 45 | /// bitcode file. | |
| 46 | IDENTIFICATION, | |
| 47 | ||
| 48 | VALUE_SYMTAB, | |
| 49 | METADATA, | |
| 50 | METADATA_ATTACHMENT, | |
| 51 | ||
| 52 | TYPE, | |
| 53 | ||
| 54 | USELIST, | |
| 55 | ||
| 56 | MODULE_STRTAB, | |
| 57 | GLOBALVAL_SUMMARY, | |
| 58 | ||
| 59 | OPERAND_BUNDLE_TAGS, | |
| 60 | ||
| 61 | METADATA_KIND, | |
| 62 | ||
| 63 | STRTAB, | |
| 64 | ||
| 65 | FULL_LTO_GLOBALVAL_SUMMARY, | |
| 66 | ||
| 67 | SYMTAB, | |
| 68 | ||
| 69 | SYNC_SCOPE_NAMES, | |
| 70 | ||
| 71 | /// Block IDs 1-7 are reserved for future expansion. | |
| 72 | pub const FIRST_APPLICATION = 8; | |
| 73 | }; | |
| 74 | ||
| 24 | 75 | /// Unused tags are commented out so that they are omitted in the generated |
| 25 | 76 | /// bitcode, which scans over this enum using reflection. |
| 26 | pub const FixedMetadataKind = enum(u8) { | |
| 77 | pub const FixedMetadataKind = enum(u6) { | |
| 27 | 78 | dbg = 0, |
| 28 | 79 | //tbaa = 1, |
| 29 | 80 | prof = 2, |
| ... | ... | @@ -66,138 +117,79 @@ pub const FixedMetadataKind = enum(u8) { |
| 66 | 117 | //@"coro.outside.frame" = 39, |
| 67 | 118 | }; |
| 68 | 119 | |
| 69 | pub const MetadataCode = enum(u8) { | |
| 70 | /// MDSTRING: [values] | |
| 71 | STRING_OLD = 1, | |
| 72 | /// VALUE: [type num, value num] | |
| 73 | VALUE = 2, | |
| 74 | /// NODE: [n x md num] | |
| 75 | NODE = 3, | |
| 76 | /// STRING: [values] | |
| 77 | NAME = 4, | |
| 78 | /// DISTINCT_NODE: [n x md num] | |
| 79 | DISTINCT_NODE = 5, | |
| 80 | /// [n x [id, name]] | |
| 81 | KIND = 6, | |
| 82 | /// [distinct, line, col, scope, inlined-at?] | |
| 83 | LOCATION = 7, | |
| 84 | /// OLD_NODE: [n x (type num, value num)] | |
| 85 | OLD_NODE = 8, | |
| 86 | /// OLD_FN_NODE: [n x (type num, value num)] | |
| 87 | OLD_FN_NODE = 9, | |
| 88 | /// NAMED_NODE: [n x mdnodes] | |
| 89 | NAMED_NODE = 10, | |
| 90 | /// [m x [value, [n x [id, mdnode]]] | |
| 91 | ATTACHMENT = 11, | |
| 92 | /// [distinct, tag, vers, header, n x md num] | |
| 93 | GENERIC_DEBUG = 12, | |
| 94 | /// [distinct, count, lo] | |
| 95 | SUBRANGE = 13, | |
| 96 | /// [isUnsigned|distinct, value, name] | |
| 97 | ENUMERATOR = 14, | |
| 98 | /// [distinct, tag, name, size, align, enc] | |
| 99 | BASIC_TYPE = 15, | |
| 100 | /// [distinct, filename, directory, checksumkind, checksum] | |
| 101 | FILE = 16, | |
| 102 | /// [distinct, ...] | |
| 103 | DERIVED_TYPE = 17, | |
| 104 | /// [distinct, ...] | |
| 105 | COMPOSITE_TYPE = 18, | |
| 106 | /// [distinct, flags, types, cc] | |
| 107 | SUBROUTINE_TYPE = 19, | |
| 108 | /// [distinct, ...] | |
| 109 | COMPILE_UNIT = 20, | |
| 110 | /// [distinct, ...] | |
| 111 | SUBPROGRAM = 21, | |
| 112 | /// [distinct, scope, file, line, column] | |
| 113 | LEXICAL_BLOCK = 22, | |
| 114 | ///[distinct, scope, file, discriminator] | |
| 115 | LEXICAL_BLOCK_FILE = 23, | |
| 116 | /// [distinct, scope, file, name, line, exportSymbols] | |
| 117 | NAMESPACE = 24, | |
| 118 | /// [distinct, scope, name, type, ...] | |
| 119 | TEMPLATE_TYPE = 25, | |
| 120 | /// [distinct, scope, name, type, value, ...] | |
| 121 | TEMPLATE_VALUE = 26, | |
| 122 | /// [distinct, ...] | |
| 123 | GLOBAL_VAR = 27, | |
| 124 | /// [distinct, ...] | |
| 125 | LOCAL_VAR = 28, | |
| 126 | /// [distinct, n x element] | |
| 127 | EXPRESSION = 29, | |
| 128 | /// [distinct, name, file, line, ...] | |
| 129 | OBJC_PROPERTY = 30, | |
| 130 | /// [distinct, tag, scope, entity, line, name] | |
| 131 | IMPORTED_ENTITY = 31, | |
| 132 | /// [distinct, scope, name, ...] | |
| 133 | MODULE = 32, | |
| 134 | /// [distinct, macinfo, line, name, value] | |
| 135 | MACRO = 33, | |
| 136 | /// [distinct, macinfo, line, file, ...] | |
| 137 | MACRO_FILE = 34, | |
| 138 | /// [count, offset] blob([lengths][chars]) | |
| 139 | STRINGS = 35, | |
| 140 | /// [valueid, n x [id, mdnode]] | |
| 141 | GLOBAL_DECL_ATTACHMENT = 36, | |
| 142 | /// [distinct, var, expr] | |
| 143 | GLOBAL_VAR_EXPR = 37, | |
| 144 | /// [offset] | |
| 145 | INDEX_OFFSET = 38, | |
| 146 | /// [bitpos] | |
| 147 | INDEX = 39, | |
| 148 | /// [distinct, scope, name, file, line] | |
| 149 | LABEL = 40, | |
| 150 | /// [distinct, name, size, align,...] | |
| 151 | STRING_TYPE = 41, | |
| 152 | /// [distinct, scope, name, variable,...] | |
| 153 | COMMON_BLOCK = 44, | |
| 154 | /// [distinct, count, lo, up, stride] | |
| 155 | GENERIC_SUBRANGE = 45, | |
| 156 | /// [n x [type num, value num]] | |
| 157 | ARG_LIST = 46, | |
| 158 | /// [distinct, ...] | |
| 159 | ASSIGN_ID = 47, | |
| 120 | pub const BlockInfoBlock = struct { | |
| 121 | pub const id: BlockId = .BLOCKINFO; | |
| 122 | ||
| 123 | pub const set_block_id = 1; | |
| 124 | ||
| 125 | pub const abbrevs = [_]type{}; | |
| 160 | 126 | }; |
| 161 | 127 | |
| 162 | pub const Identification = struct { | |
| 163 | pub const id = 13; | |
| 128 | /// MODULE blocks have a number of optional fields and subblocks. | |
| 129 | pub const ModuleBlock = struct { | |
| 130 | pub const id: BlockId = .MODULE; | |
| 164 | 131 | |
| 165 | 132 | pub const abbrevs = [_]type{ |
| 166 | Version, | |
| 167 | Epoch, | |
| 133 | ModuleBlock.Version, | |
| 134 | ModuleBlock.String, | |
| 135 | ModuleBlock.Variable, | |
| 136 | ModuleBlock.Function, | |
| 137 | ModuleBlock.Alias, | |
| 168 | 138 | }; |
| 169 | 139 | |
| 170 | pub const Version = struct { | |
| 171 | pub const ops = [_]AbbrevOp{ | |
| 172 | .{ .literal = 1 }, | |
| 173 | .{ .array_fixed = 8 }, | |
| 174 | }; | |
| 175 | string: []const u8, | |
| 176 | }; | |
| 140 | pub const Code = enum(u5) { | |
| 141 | /// VERSION: [version#] | |
| 142 | VERSION = 1, | |
| 143 | /// TRIPLE: [strchr x N] | |
| 144 | TRIPLE = 2, | |
| 145 | /// DATALAYOUT: [strchr x N] | |
| 146 | DATALAYOUT = 3, | |
| 147 | /// ASM: [strchr x N] | |
| 148 | ASM = 4, | |
| 149 | /// SECTIONNAME: [strchr x N] | |
| 150 | SECTIONNAME = 5, | |
| 177 | 151 | |
| 178 | pub const Epoch = struct { | |
| 179 | pub const ops = [_]AbbrevOp{ | |
| 180 | .{ .literal = 2 }, | |
| 181 | .{ .vbr = 6 }, | |
| 182 | }; | |
| 183 | epoch: u32, | |
| 184 | }; | |
| 185 | }; | |
| 152 | /// Deprecated, but still needed to read old bitcode files. | |
| 153 | /// DEPLIB: [strchr x N] | |
| 154 | DEPLIB = 6, | |
| 186 | 155 | |
| 187 | pub const Module = struct { | |
| 188 | pub const id = 8; | |
| 156 | /// GLOBALVAR: [pointer type, isconst, initid, | |
| 157 | /// linkage, alignment, section, visibility, threadlocal] | |
| 158 | GLOBALVAR = 7, | |
| 189 | 159 | |
| 190 | pub const abbrevs = [_]type{ | |
| 191 | Version, | |
| 192 | String, | |
| 193 | Variable, | |
| 194 | Function, | |
| 195 | Alias, | |
| 160 | /// FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment, | |
| 161 | /// section, visibility, gc, unnamed_addr] | |
| 162 | FUNCTION = 8, | |
| 163 | ||
| 164 | /// ALIAS: [alias type, aliasee val#, linkage, visibility] | |
| 165 | ALIAS_OLD = 9, | |
| 166 | ||
| 167 | /// GCNAME: [strchr x N] | |
| 168 | GCNAME = 11, | |
| 169 | /// COMDAT: [selection_kind, name] | |
| 170 | COMDAT = 12, | |
| 171 | ||
| 172 | /// VSTOFFSET: [offset] | |
| 173 | VSTOFFSET = 13, | |
| 174 | ||
| 175 | /// ALIAS: [alias value type, addrspace, aliasee val#, linkage, visibility] | |
| 176 | ALIAS = 14, | |
| 177 | ||
| 178 | METADATA_VALUES_UNUSED = 15, | |
| 179 | ||
| 180 | /// SOURCE_FILENAME: [namechar x N] | |
| 181 | SOURCE_FILENAME = 16, | |
| 182 | ||
| 183 | /// HASH: [5*i32] | |
| 184 | HASH = 17, | |
| 185 | ||
| 186 | /// IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility] | |
| 187 | IFUNC = 18, | |
| 196 | 188 | }; |
| 197 | 189 | |
| 198 | 190 | pub const Version = struct { |
| 199 | 191 | pub const ops = [_]AbbrevOp{ |
| 200 | .{ .literal = 1 }, | |
| 192 | .{ .literal = @intFromEnum(ModuleBlock.Code.VERSION) }, | |
| 201 | 193 | .{ .literal = 2 }, |
| 202 | 194 | }; |
| 203 | 195 | }; |
| ... | ... | @@ -219,7 +211,7 @@ pub const Module = struct { |
| 219 | 211 | }; |
| 220 | 212 | |
| 221 | 213 | pub const ops = [_]AbbrevOp{ |
| 222 | .{ .literal = 7 }, // Code | |
| 214 | .{ .literal = @intFromEnum(ModuleBlock.Code.GLOBALVAR) }, // Code | |
| 223 | 215 | .{ .vbr = 16 }, // strtab_offset |
| 224 | 216 | .{ .vbr = 16 }, // strtab_size |
| 225 | 217 | .{ .fixed_runtime = Builder.Type }, |
| ... | ... | @@ -255,7 +247,7 @@ pub const Module = struct { |
| 255 | 247 | |
| 256 | 248 | pub const Function = struct { |
| 257 | 249 | pub const ops = [_]AbbrevOp{ |
| 258 | .{ .literal = 8 }, // Code | |
| 250 | .{ .literal = @intFromEnum(ModuleBlock.Code.FUNCTION) }, // Code | |
| 259 | 251 | .{ .vbr = 16 }, // strtab_offset |
| 260 | 252 | .{ .vbr = 16 }, // strtab_size |
| 261 | 253 | .{ .fixed_runtime = Builder.Type }, |
| ... | ... | @@ -294,7 +286,7 @@ pub const Module = struct { |
| 294 | 286 | |
| 295 | 287 | pub const Alias = struct { |
| 296 | 288 | pub const ops = [_]AbbrevOp{ |
| 297 | .{ .literal = 14 }, // Code | |
| 289 | .{ .literal = @intFromEnum(ModuleBlock.Code.ALIAS) }, // Code | |
| 298 | 290 | .{ .vbr = 16 }, // strtab_offset |
| 299 | 291 | .{ .vbr = 16 }, // strtab_size |
| 300 | 292 | .{ .fixed_runtime = Builder.Type }, |
| ... | ... | @@ -319,1542 +311,1986 @@ pub const Module = struct { |
| 319 | 311 | unnamed_addr: Builder.UnnamedAddr, |
| 320 | 312 | preemption: Builder.Preemption, |
| 321 | 313 | }; |
| 322 | }; | |
| 323 | ||
| 324 | pub const BlockInfo = struct { | |
| 325 | pub const id = 0; | |
| 326 | ||
| 327 | pub const set_block_id = 1; | |
| 328 | ||
| 329 | pub const abbrevs = [_]type{}; | |
| 330 | }; | |
| 331 | ||
| 332 | pub const Type = struct { | |
| 333 | pub const id = 17; | |
| 334 | ||
| 335 | pub const abbrevs = [_]type{ | |
| 336 | NumEntry, | |
| 337 | Simple, | |
| 338 | Opaque, | |
| 339 | Integer, | |
| 340 | StructAnon, | |
| 341 | StructNamed, | |
| 342 | StructName, | |
| 343 | Array, | |
| 344 | Vector, | |
| 345 | Pointer, | |
| 346 | Target, | |
| 347 | Function, | |
| 348 | }; | |
| 349 | ||
| 350 | pub const NumEntry = struct { | |
| 351 | pub const ops = [_]AbbrevOp{ | |
| 352 | .{ .literal = 1 }, | |
| 353 | .{ .fixed = 32 }, | |
| 354 | }; | |
| 355 | num: u32, | |
| 356 | }; | |
| 357 | ||
| 358 | pub const Simple = struct { | |
| 359 | pub const ops = [_]AbbrevOp{ | |
| 360 | .{ .vbr = 4 }, | |
| 361 | }; | |
| 362 | code: u5, | |
| 363 | }; | |
| 364 | 314 | |
| 365 | pub const Opaque = struct { | |
| 366 | pub const ops = [_]AbbrevOp{ | |
| 367 | .{ .literal = 6 }, | |
| 368 | .{ .literal = 0 }, | |
| 369 | }; | |
| 370 | }; | |
| 371 | ||
| 372 | pub const Integer = struct { | |
| 373 | pub const ops = [_]AbbrevOp{ | |
| 374 | .{ .literal = 7 }, | |
| 375 | .{ .fixed = 28 }, | |
| 315 | /// PARAMATTR blocks have code for defining a parameter attribute set. | |
| 316 | pub const ParamattrBlock = struct { | |
| 317 | pub const id: BlockId = .PARAMATTR; | |
| 318 | ||
| 319 | pub const abbrevs = [_]type{ | |
| 320 | ModuleBlock.ParamattrBlock.Entry, | |
| 321 | }; | |
| 322 | ||
| 323 | pub const Code = enum(u2) { | |
| 324 | /// Deprecated, but still needed to read old bitcode files. | |
| 325 | /// ENTRY: [paramidx0, attr0, paramidx1, attr1...] | |
| 326 | ENTRY_OLD = 1, | |
| 327 | /// ENTRY: [attrgrp0, attrgrp1, ...] | |
| 328 | ENTRY = 2, | |
| 329 | }; | |
| 330 | ||
| 331 | pub const Entry = struct { | |
| 332 | pub const ops = [_]AbbrevOp{ | |
| 333 | .{ .literal = @intFromEnum(ModuleBlock.ParamattrBlock.Code.ENTRY) }, | |
| 334 | .{ .array_vbr = 8 }, | |
| 335 | }; | |
| 336 | group_indices: []const u64, | |
| 337 | }; | |
| 338 | }; | |
| 339 | ||
| 340 | pub const ParamattrGroupBlock = struct { | |
| 341 | pub const id: BlockId = .PARAMATTR_GROUP; | |
| 342 | ||
| 343 | pub const abbrevs = [_]type{}; | |
| 344 | ||
| 345 | pub const Code = enum(u2) { | |
| 346 | /// ENTRY: [grpid, idx, attr0, attr1, ...] | |
| 347 | CODE_ENTRY = 3, | |
| 348 | }; | |
| 349 | }; | |
| 350 | ||
| 351 | /// The constants block (CONSTANTS_BLOCK_ID) describes emission for each | |
| 352 | /// constant and maintains an implicit current type value. | |
| 353 | pub const ConstantsBlock = struct { | |
| 354 | pub const id: BlockId = .CONSTANTS; | |
| 355 | ||
| 356 | pub const abbrevs = [_]type{ | |
| 357 | ModuleBlock.ConstantsBlock.SetType, | |
| 358 | ModuleBlock.ConstantsBlock.Null, | |
| 359 | ModuleBlock.ConstantsBlock.Undef, | |
| 360 | ModuleBlock.ConstantsBlock.Poison, | |
| 361 | ModuleBlock.ConstantsBlock.Integer, | |
| 362 | ModuleBlock.ConstantsBlock.Half, | |
| 363 | ModuleBlock.ConstantsBlock.Float, | |
| 364 | ModuleBlock.ConstantsBlock.Double, | |
| 365 | ModuleBlock.ConstantsBlock.Fp80, | |
| 366 | ModuleBlock.ConstantsBlock.Fp128, | |
| 367 | ModuleBlock.ConstantsBlock.Aggregate, | |
| 368 | ModuleBlock.ConstantsBlock.String, | |
| 369 | ModuleBlock.ConstantsBlock.CString, | |
| 370 | ModuleBlock.ConstantsBlock.Cast, | |
| 371 | ModuleBlock.ConstantsBlock.Binary, | |
| 372 | ModuleBlock.ConstantsBlock.Cmp, | |
| 373 | ModuleBlock.ConstantsBlock.ExtractElement, | |
| 374 | ModuleBlock.ConstantsBlock.InsertElement, | |
| 375 | ModuleBlock.ConstantsBlock.ShuffleVector, | |
| 376 | ModuleBlock.ConstantsBlock.ShuffleVectorEx, | |
| 377 | ModuleBlock.ConstantsBlock.BlockAddress, | |
| 378 | ModuleBlock.ConstantsBlock.DsoLocalEquivalentOrNoCfi, | |
| 379 | }; | |
| 380 | ||
| 381 | pub const Code = enum(u6) { | |
| 382 | /// SETTYPE: [typeid] | |
| 383 | SETTYPE = 1, | |
| 384 | /// NULL | |
| 385 | NULL = 2, | |
| 386 | /// UNDEF | |
| 387 | UNDEF = 3, | |
| 388 | /// INTEGER: [intval] | |
| 389 | INTEGER = 4, | |
| 390 | /// WIDE_INTEGER: [n x intval] | |
| 391 | WIDE_INTEGER = 5, | |
| 392 | /// FLOAT: [fpval] | |
| 393 | FLOAT = 6, | |
| 394 | /// AGGREGATE: [n x value number] | |
| 395 | AGGREGATE = 7, | |
| 396 | /// STRING: [values] | |
| 397 | STRING = 8, | |
| 398 | /// CSTRING: [values] | |
| 399 | CSTRING = 9, | |
| 400 | /// CE_BINOP: [opcode, opval, opval] | |
| 401 | CE_BINOP = 10, | |
| 402 | /// CE_CAST: [opcode, opty, opval] | |
| 403 | CE_CAST = 11, | |
| 404 | /// CE_GEP: [n x operands] | |
| 405 | CE_GEP_OLD = 12, | |
| 406 | /// CE_SELECT: [opval, opval, opval] | |
| 407 | CE_SELECT = 13, | |
| 408 | /// CE_EXTRACTELT: [opty, opval, opval] | |
| 409 | CE_EXTRACTELT = 14, | |
| 410 | /// CE_INSERTELT: [opval, opval, opval] | |
| 411 | CE_INSERTELT = 15, | |
| 412 | /// CE_SHUFFLEVEC: [opval, opval, opval] | |
| 413 | CE_SHUFFLEVEC = 16, | |
| 414 | /// CE_CMP: [opty, opval, opval, pred] | |
| 415 | CE_CMP = 17, | |
| 416 | /// INLINEASM: [sideeffect|alignstack,asmstr,conststr] | |
| 417 | INLINEASM_OLD = 18, | |
| 418 | /// SHUFVEC_EX: [opty, opval, opval, opval] | |
| 419 | CE_SHUFVEC_EX = 19, | |
| 420 | /// INBOUNDS_GEP: [n x operands] | |
| 421 | CE_INBOUNDS_GEP = 20, | |
| 422 | /// BLOCKADDRESS: [fnty, fnval, bb#] | |
| 423 | BLOCKADDRESS = 21, | |
| 424 | /// DATA: [n x elements] | |
| 425 | DATA = 22, | |
| 426 | /// INLINEASM: [sideeffect|alignstack|asmdialect,asmstr,conststr] | |
| 427 | INLINEASM_OLD2 = 23, | |
| 428 | /// [opty, flags, n x operands] | |
| 429 | CE_GEP_WITH_INRANGE_INDEX_OLD = 24, | |
| 430 | /// CE_UNOP: [opcode, opval] | |
| 431 | CE_UNOP = 25, | |
| 432 | /// POISON | |
| 433 | POISON = 26, | |
| 434 | /// DSO_LOCAL_EQUIVALENT [gvty, gv] | |
| 435 | DSO_LOCAL_EQUIVALENT = 27, | |
| 436 | /// INLINEASM: [sideeffect|alignstack|asmdialect|unwind,asmstr, | |
| 437 | /// conststr] | |
| 438 | INLINEASM_OLD3 = 28, | |
| 439 | /// NO_CFI [ fty, f ] | |
| 440 | NO_CFI_VALUE = 29, | |
| 441 | /// INLINEASM: [fnty,sideeffect|alignstack|asmdialect|unwind, | |
| 442 | /// asmstr,conststr] | |
| 443 | INLINEASM = 30, | |
| 444 | /// [opty, flags, range, n x operands] | |
| 445 | CE_GEP_WITH_INRANGE = 31, | |
| 446 | /// [opty, flags, n x operands] | |
| 447 | CE_GEP = 32, | |
| 448 | /// [ptr, key, disc, addrdisc] | |
| 449 | PTRAUTH = 33, | |
| 450 | }; | |
| 451 | ||
| 452 | pub const SetType = struct { | |
| 453 | pub const ops = [_]AbbrevOp{ | |
| 454 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.SETTYPE) }, | |
| 455 | .{ .fixed_runtime = Builder.Type }, | |
| 456 | }; | |
| 457 | type_id: Builder.Type, | |
| 458 | }; | |
| 459 | ||
| 460 | pub const Null = struct { | |
| 461 | pub const ops = [_]AbbrevOp{ | |
| 462 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.NULL) }, | |
| 463 | }; | |
| 464 | }; | |
| 465 | ||
| 466 | pub const Undef = struct { | |
| 467 | pub const ops = [_]AbbrevOp{ | |
| 468 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.UNDEF) }, | |
| 469 | }; | |
| 470 | }; | |
| 471 | ||
| 472 | pub const Poison = struct { | |
| 473 | pub const ops = [_]AbbrevOp{ | |
| 474 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.POISON) }, | |
| 475 | }; | |
| 476 | }; | |
| 477 | ||
| 478 | pub const Integer = struct { | |
| 479 | pub const ops = [_]AbbrevOp{ | |
| 480 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.INTEGER) }, | |
| 481 | .{ .vbr = 16 }, | |
| 482 | }; | |
| 483 | value: u64, | |
| 484 | }; | |
| 485 | ||
| 486 | pub const Half = struct { | |
| 487 | pub const ops = [_]AbbrevOp{ | |
| 488 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) }, | |
| 489 | .{ .fixed = 16 }, | |
| 490 | }; | |
| 491 | value: u16, | |
| 492 | }; | |
| 493 | ||
| 494 | pub const Float = struct { | |
| 495 | pub const ops = [_]AbbrevOp{ | |
| 496 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) }, | |
| 497 | .{ .fixed = 32 }, | |
| 498 | }; | |
| 499 | value: u32, | |
| 500 | }; | |
| 501 | ||
| 502 | pub const Double = struct { | |
| 503 | pub const ops = [_]AbbrevOp{ | |
| 504 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) }, | |
| 505 | .{ .vbr = 6 }, | |
| 506 | }; | |
| 507 | value: u64, | |
| 508 | }; | |
| 509 | ||
| 510 | pub const Fp80 = struct { | |
| 511 | pub const ops = [_]AbbrevOp{ | |
| 512 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) }, | |
| 513 | .{ .vbr = 6 }, | |
| 514 | .{ .vbr = 6 }, | |
| 515 | }; | |
| 516 | hi: u64, | |
| 517 | lo: u16, | |
| 518 | }; | |
| 519 | ||
| 520 | pub const Fp128 = struct { | |
| 521 | pub const ops = [_]AbbrevOp{ | |
| 522 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.FLOAT) }, | |
| 523 | .{ .vbr = 6 }, | |
| 524 | .{ .vbr = 6 }, | |
| 525 | }; | |
| 526 | lo: u64, | |
| 527 | hi: u64, | |
| 528 | }; | |
| 529 | ||
| 530 | pub const Aggregate = struct { | |
| 531 | pub const ops = [_]AbbrevOp{ | |
| 532 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.AGGREGATE) }, | |
| 533 | .{ .array_fixed = 32 }, | |
| 534 | }; | |
| 535 | values: []const Builder.Constant, | |
| 536 | }; | |
| 537 | ||
| 538 | pub const String = struct { | |
| 539 | pub const ops = [_]AbbrevOp{ | |
| 540 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.STRING) }, | |
| 541 | .{ .array_fixed = 8 }, | |
| 542 | }; | |
| 543 | string: []const u8, | |
| 544 | }; | |
| 545 | ||
| 546 | pub const CString = struct { | |
| 547 | pub const ops = [_]AbbrevOp{ | |
| 548 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CSTRING) }, | |
| 549 | .{ .array_fixed = 8 }, | |
| 550 | }; | |
| 551 | string: []const u8, | |
| 552 | }; | |
| 553 | ||
| 554 | pub const Cast = struct { | |
| 555 | const CastOpcode = Builder.CastOpcode; | |
| 556 | pub const ops = [_]AbbrevOp{ | |
| 557 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_CAST) }, | |
| 558 | .{ .fixed = @bitSizeOf(CastOpcode) }, | |
| 559 | .{ .fixed_runtime = Builder.Type }, | |
| 560 | ConstantAbbrev, | |
| 561 | }; | |
| 562 | ||
| 563 | opcode: CastOpcode, | |
| 564 | type_index: Builder.Type, | |
| 565 | val: Builder.Constant, | |
| 566 | }; | |
| 567 | ||
| 568 | pub const Binary = struct { | |
| 569 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 570 | pub const ops = [_]AbbrevOp{ | |
| 571 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_BINOP) }, | |
| 572 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 573 | ConstantAbbrev, | |
| 574 | ConstantAbbrev, | |
| 575 | }; | |
| 576 | ||
| 577 | opcode: BinaryOpcode, | |
| 578 | lhs: Builder.Constant, | |
| 579 | rhs: Builder.Constant, | |
| 580 | }; | |
| 581 | ||
| 582 | pub const Cmp = struct { | |
| 583 | pub const ops = [_]AbbrevOp{ | |
| 584 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_CMP) }, | |
| 585 | .{ .fixed_runtime = Builder.Type }, | |
| 586 | ConstantAbbrev, | |
| 587 | ConstantAbbrev, | |
| 588 | .{ .vbr = 6 }, | |
| 589 | }; | |
| 590 | ||
| 591 | ty: Builder.Type, | |
| 592 | lhs: Builder.Constant, | |
| 593 | rhs: Builder.Constant, | |
| 594 | pred: u32, | |
| 595 | }; | |
| 596 | ||
| 597 | pub const ExtractElement = struct { | |
| 598 | pub const ops = [_]AbbrevOp{ | |
| 599 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_EXTRACTELT) }, | |
| 600 | .{ .fixed_runtime = Builder.Type }, | |
| 601 | ConstantAbbrev, | |
| 602 | .{ .fixed_runtime = Builder.Type }, | |
| 603 | ConstantAbbrev, | |
| 604 | }; | |
| 605 | ||
| 606 | val_type: Builder.Type, | |
| 607 | val: Builder.Constant, | |
| 608 | index_type: Builder.Type, | |
| 609 | index: Builder.Constant, | |
| 610 | }; | |
| 611 | ||
| 612 | pub const InsertElement = struct { | |
| 613 | pub const ops = [_]AbbrevOp{ | |
| 614 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_INSERTELT) }, | |
| 615 | ConstantAbbrev, | |
| 616 | ConstantAbbrev, | |
| 617 | .{ .fixed_runtime = Builder.Type }, | |
| 618 | ConstantAbbrev, | |
| 619 | }; | |
| 620 | ||
| 621 | val: Builder.Constant, | |
| 622 | elem: Builder.Constant, | |
| 623 | index_type: Builder.Type, | |
| 624 | index: Builder.Constant, | |
| 625 | }; | |
| 626 | ||
| 627 | pub const ShuffleVector = struct { | |
| 628 | pub const ops = [_]AbbrevOp{ | |
| 629 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_SHUFFLEVEC) }, | |
| 630 | ValueAbbrev, | |
| 631 | ValueAbbrev, | |
| 632 | ValueAbbrev, | |
| 633 | }; | |
| 634 | ||
| 635 | lhs: Builder.Constant, | |
| 636 | rhs: Builder.Constant, | |
| 637 | mask: Builder.Constant, | |
| 638 | }; | |
| 639 | ||
| 640 | pub const ShuffleVectorEx = struct { | |
| 641 | pub const ops = [_]AbbrevOp{ | |
| 642 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.CE_SHUFVEC_EX) }, | |
| 643 | .{ .fixed_runtime = Builder.Type }, | |
| 644 | ValueAbbrev, | |
| 645 | ValueAbbrev, | |
| 646 | ValueAbbrev, | |
| 647 | }; | |
| 648 | ||
| 649 | ty: Builder.Type, | |
| 650 | lhs: Builder.Constant, | |
| 651 | rhs: Builder.Constant, | |
| 652 | mask: Builder.Constant, | |
| 653 | }; | |
| 654 | ||
| 655 | pub const BlockAddress = struct { | |
| 656 | pub const ops = [_]AbbrevOp{ | |
| 657 | .{ .literal = @intFromEnum(ModuleBlock.ConstantsBlock.Code.BLOCKADDRESS) }, | |
| 658 | .{ .fixed_runtime = Builder.Type }, | |
| 659 | ConstantAbbrev, | |
| 660 | BlockAbbrev, | |
| 661 | }; | |
| 662 | type_id: Builder.Type, | |
| 663 | function: u32, | |
| 664 | block: u32, | |
| 665 | }; | |
| 666 | ||
| 667 | pub const DsoLocalEquivalentOrNoCfi = struct { | |
| 668 | pub const ops = [_]AbbrevOp{ | |
| 669 | .{ .fixed = 5 }, | |
| 670 | .{ .fixed_runtime = Builder.Type }, | |
| 671 | ConstantAbbrev, | |
| 672 | }; | |
| 673 | code: ModuleBlock.ConstantsBlock.Code, | |
| 674 | type_id: Builder.Type, | |
| 675 | function: u32, | |
| 676 | }; | |
| 677 | }; | |
| 678 | ||
| 679 | /// The function body block (FUNCTION_BLOCK_ID) describes function bodies. It | |
| 680 | /// can contain a constant block (CONSTANTS_BLOCK_ID). | |
| 681 | pub const FunctionBlock = struct { | |
| 682 | pub const id: BlockId = .FUNCTION; | |
| 683 | ||
| 684 | pub const abbrevs = [_]type{ | |
| 685 | ModuleBlock.FunctionBlock.DeclareBlocks, | |
| 686 | ModuleBlock.FunctionBlock.Call, | |
| 687 | ModuleBlock.FunctionBlock.CallFast, | |
| 688 | ModuleBlock.FunctionBlock.FNeg, | |
| 689 | ModuleBlock.FunctionBlock.FNegFast, | |
| 690 | ModuleBlock.FunctionBlock.Binary, | |
| 691 | ModuleBlock.FunctionBlock.BinaryNoWrap, | |
| 692 | ModuleBlock.FunctionBlock.BinaryExact, | |
| 693 | ModuleBlock.FunctionBlock.BinaryFast, | |
| 694 | ModuleBlock.FunctionBlock.Cmp, | |
| 695 | ModuleBlock.FunctionBlock.CmpFast, | |
| 696 | ModuleBlock.FunctionBlock.Select, | |
| 697 | ModuleBlock.FunctionBlock.SelectFast, | |
| 698 | ModuleBlock.FunctionBlock.Cast, | |
| 699 | ModuleBlock.FunctionBlock.Alloca, | |
| 700 | ModuleBlock.FunctionBlock.GetElementPtr, | |
| 701 | ModuleBlock.FunctionBlock.ExtractValue, | |
| 702 | ModuleBlock.FunctionBlock.InsertValue, | |
| 703 | ModuleBlock.FunctionBlock.ExtractElement, | |
| 704 | ModuleBlock.FunctionBlock.InsertElement, | |
| 705 | ModuleBlock.FunctionBlock.ShuffleVector, | |
| 706 | ModuleBlock.FunctionBlock.RetVoid, | |
| 707 | ModuleBlock.FunctionBlock.Ret, | |
| 708 | ModuleBlock.FunctionBlock.Unreachable, | |
| 709 | ModuleBlock.FunctionBlock.Load, | |
| 710 | ModuleBlock.FunctionBlock.LoadAtomic, | |
| 711 | ModuleBlock.FunctionBlock.Store, | |
| 712 | ModuleBlock.FunctionBlock.StoreAtomic, | |
| 713 | ModuleBlock.FunctionBlock.BrUnconditional, | |
| 714 | ModuleBlock.FunctionBlock.BrConditional, | |
| 715 | ModuleBlock.FunctionBlock.VaArg, | |
| 716 | ModuleBlock.FunctionBlock.AtomicRmw, | |
| 717 | ModuleBlock.FunctionBlock.CmpXchg, | |
| 718 | ModuleBlock.FunctionBlock.Fence, | |
| 719 | ModuleBlock.FunctionBlock.DebugLoc, | |
| 720 | ModuleBlock.FunctionBlock.DebugLocAgain, | |
| 721 | ModuleBlock.FunctionBlock.ColdOperandBundle, | |
| 722 | ModuleBlock.FunctionBlock.IndirectBr, | |
| 723 | }; | |
| 724 | ||
| 725 | pub const Code = enum(u7) { | |
| 726 | /// DECLAREBLOCKS: [n] | |
| 727 | DECLAREBLOCKS = 1, | |
| 728 | ||
| 729 | /// BINOP: [opcode, ty, opval, opval] | |
| 730 | INST_BINOP = 2, | |
| 731 | /// CAST: [opcode, ty, opty, opval] | |
| 732 | INST_CAST = 3, | |
| 733 | /// GEP: [n x operands] | |
| 734 | INST_GEP_OLD = 4, | |
| 735 | /// SELECT: [ty, opval, opval, opval] | |
| 736 | INST_SELECT = 5, | |
| 737 | /// EXTRACTELT: [opty, opval, opval] | |
| 738 | INST_EXTRACTELT = 6, | |
| 739 | /// INSERTELT: [ty, opval, opval, opval] | |
| 740 | INST_INSERTELT = 7, | |
| 741 | /// SHUFFLEVEC: [ty, opval, opval, opval] | |
| 742 | INST_SHUFFLEVEC = 8, | |
| 743 | /// CMP: [opty, opval, opval, pred] | |
| 744 | INST_CMP = 9, | |
| 745 | ||
| 746 | /// RET: [opty,opval<both optional>] | |
| 747 | INST_RET = 10, | |
| 748 | /// BR: [bb#, bb#, cond] or [bb#] | |
| 749 | INST_BR = 11, | |
| 750 | /// SWITCH: [opty, op0, op1, ...] | |
| 751 | INST_SWITCH = 12, | |
| 752 | /// INVOKE: [attr, fnty, op0,op1, ...] | |
| 753 | INST_INVOKE = 13, | |
| 754 | /// UNREACHABLE | |
| 755 | INST_UNREACHABLE = 15, | |
| 756 | ||
| 757 | /// PHI: [ty, val0,bb0, ...] | |
| 758 | INST_PHI = 16, | |
| 759 | /// ALLOCA: [instty, opty, op, align] | |
| 760 | INST_ALLOCA = 19, | |
| 761 | /// LOAD: [opty, op, align, vol] | |
| 762 | INST_LOAD = 20, | |
| 763 | /// VAARG: [valistty, valist, instty] | |
| 764 | /// This store code encodes the pointer type, rather than the value type | |
| 765 | /// this is so information only available in the pointer type (e.g. address | |
| 766 | /// spaces) is retained. | |
| 767 | INST_VAARG = 23, | |
| 768 | /// STORE: [ptrty,ptr,val, align, vol] | |
| 769 | INST_STORE_OLD = 24, | |
| 770 | ||
| 771 | /// EXTRACTVAL: [n x operands] | |
| 772 | INST_EXTRACTVAL = 26, | |
| 773 | /// INSERTVAL: [n x operands] | |
| 774 | INST_INSERTVAL = 27, | |
| 775 | /// fcmp/icmp returning Int1TY or vector of Int1Ty. Same as CMP, exists to | |
| 776 | /// support legacy vicmp/vfcmp instructions. | |
| 777 | /// CMP2: [opty, opval, opval, pred] | |
| 778 | INST_CMP2 = 28, | |
| 779 | /// new select on i1 or [N x i1] | |
| 780 | /// VSELECT: [ty,opval,opval,predty,pred] | |
| 781 | INST_VSELECT = 29, | |
| 782 | /// INBOUNDS_GEP: [n x operands] | |
| 783 | INST_INBOUNDS_GEP_OLD = 30, | |
| 784 | /// INDIRECTBR: [opty, op0, op1, ...] | |
| 785 | INST_INDIRECTBR = 31, | |
| 786 | ||
| 787 | /// DEBUG_LOC_AGAIN | |
| 788 | DEBUG_LOC_AGAIN = 33, | |
| 789 | ||
| 790 | /// CALL: [attr, cc, fnty, fnid, args...] | |
| 791 | INST_CALL = 34, | |
| 792 | ||
| 793 | /// DEBUG_LOC: [Line,Col,ScopeVal, IAVal] | |
| 794 | DEBUG_LOC = 35, | |
| 795 | /// FENCE: [ordering, synchscope] | |
| 796 | INST_FENCE = 36, | |
| 797 | /// CMPXCHG: [ptrty, ptr, cmp, val, vol, | |
| 798 | /// ordering, synchscope, | |
| 799 | /// failure_ordering?, weak?] | |
| 800 | INST_CMPXCHG_OLD = 37, | |
| 801 | /// ATOMICRMW: [ptrty,ptr,val, operation, | |
| 802 | /// align, vol, | |
| 803 | /// ordering, synchscope] | |
| 804 | INST_ATOMICRMW_OLD = 38, | |
| 805 | /// RESUME: [opval] | |
| 806 | INST_RESUME = 39, | |
| 807 | /// LANDINGPAD: [ty,val,val,num,id0,val0...] | |
| 808 | INST_LANDINGPAD_OLD = 40, | |
| 809 | /// LOAD: [opty, op, align, vol, | |
| 810 | /// ordering, synchscope] | |
| 811 | INST_LOADATOMIC = 41, | |
| 812 | /// STORE: [ptrty,ptr,val, align, vol | |
| 813 | /// ordering, synchscope] | |
| 814 | INST_STOREATOMIC_OLD = 42, | |
| 815 | ||
| 816 | /// GEP: [inbounds, n x operands] | |
| 817 | INST_GEP = 43, | |
| 818 | /// STORE: [ptrty,ptr,valty,val, align, vol] | |
| 819 | INST_STORE = 44, | |
| 820 | /// STORE: [ptrty,ptr,val, align, vol | |
| 821 | INST_STOREATOMIC = 45, | |
| 822 | /// CMPXCHG: [ptrty, ptr, cmp, val, vol, | |
| 823 | /// success_ordering, synchscope, | |
| 824 | /// failure_ordering, weak] | |
| 825 | INST_CMPXCHG = 46, | |
| 826 | /// LANDINGPAD: [ty,val,num,id0,val0...] | |
| 827 | INST_LANDINGPAD = 47, | |
| 828 | /// CLEANUPRET: [val] or [val,bb#] | |
| 829 | INST_CLEANUPRET = 48, | |
| 830 | /// CATCHRET: [val,bb#] | |
| 831 | INST_CATCHRET = 49, | |
| 832 | /// CATCHPAD: [bb#,bb#,num,args...] | |
| 833 | INST_CATCHPAD = 50, | |
| 834 | /// CLEANUPPAD: [num,args...] | |
| 835 | INST_CLEANUPPAD = 51, | |
| 836 | /// CATCHSWITCH: [num,args...] or [num,args...,bb] | |
| 837 | INST_CATCHSWITCH = 52, | |
| 838 | /// OPERAND_BUNDLE: [tag#, value...] | |
| 839 | OPERAND_BUNDLE = 55, | |
| 840 | /// UNOP: [opcode, ty, opval] | |
| 841 | INST_UNOP = 56, | |
| 842 | /// CALLBR: [attr, cc, norm, transfs, | |
| 843 | /// fnty, fnid, args...] | |
| 844 | INST_CALLBR = 57, | |
| 845 | /// FREEZE: [opty, opval] | |
| 846 | INST_FREEZE = 58, | |
| 847 | /// ATOMICRMW: [ptrty, ptr, valty, val, | |
| 848 | /// operation, align, vol, | |
| 849 | /// ordering, synchscope] | |
| 850 | INST_ATOMICRMW = 59, | |
| 851 | /// BLOCKADDR_USERS: [value...] | |
| 852 | BLOCKADDR_USERS = 60, | |
| 853 | ||
| 854 | /// [DILocation, DILocalVariable, DIExpression, ValueAsMetadata] | |
| 855 | DEBUG_RECORD_VALUE = 61, | |
| 856 | /// [DILocation, DILocalVariable, DIExpression, ValueAsMetadata] | |
| 857 | DEBUG_RECORD_DECLARE = 62, | |
| 858 | /// [DILocation, DILocalVariable, DIExpression, ValueAsMetadata, | |
| 859 | /// DIAssignID, DIExpression (addr), ValueAsMetadata (addr)] | |
| 860 | DEBUG_RECORD_ASSIGN = 63, | |
| 861 | /// [DILocation, DILocalVariable, DIExpression, Value] | |
| 862 | DEBUG_RECORD_VALUE_SIMPLE = 64, | |
| 863 | /// [DILocation, DILabel] | |
| 864 | DEBUG_RECORD_LABEL = 65, | |
| 865 | }; | |
| 866 | ||
| 867 | pub const DeclareBlocks = struct { | |
| 868 | pub const ops = [_]AbbrevOp{ | |
| 869 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.DECLAREBLOCKS) }, | |
| 870 | .{ .vbr = 8 }, | |
| 871 | }; | |
| 872 | num_blocks: usize, | |
| 873 | }; | |
| 874 | ||
| 875 | pub const Call = struct { | |
| 876 | pub const CallType = packed struct(u17) { | |
| 877 | tail: bool = false, | |
| 878 | call_conv: Builder.CallConv, | |
| 879 | reserved: u3 = 0, | |
| 880 | must_tail: bool = false, | |
| 881 | // We always use the explicit type version as that is what LLVM does | |
| 882 | explicit_type: bool = true, | |
| 883 | no_tail: bool = false, | |
| 884 | }; | |
| 885 | pub const ops = [_]AbbrevOp{ | |
| 886 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CALL) }, | |
| 887 | .{ .fixed_runtime = Builder.FunctionAttributes }, | |
| 888 | .{ .fixed = @bitSizeOf(CallType) }, | |
| 889 | .{ .fixed_runtime = Builder.Type }, | |
| 890 | ValueAbbrev, // Callee | |
| 891 | ValueArrayAbbrev, // Args | |
| 892 | }; | |
| 893 | ||
| 894 | attributes: Builder.FunctionAttributes, | |
| 895 | call_type: CallType, | |
| 896 | type_id: Builder.Type, | |
| 897 | callee: Builder.Value, | |
| 898 | args: []const Builder.Value, | |
| 899 | }; | |
| 900 | ||
| 901 | pub const CallFast = struct { | |
| 902 | const CallType = packed struct(u18) { | |
| 903 | tail: bool = false, | |
| 904 | call_conv: Builder.CallConv, | |
| 905 | reserved: u3 = 0, | |
| 906 | must_tail: bool = false, | |
| 907 | // We always use the explicit type version as that is what LLVM does | |
| 908 | explicit_type: bool = true, | |
| 909 | no_tail: bool = false, | |
| 910 | fast: bool = true, | |
| 911 | }; | |
| 912 | ||
| 913 | pub const ops = [_]AbbrevOp{ | |
| 914 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CALL) }, | |
| 915 | .{ .fixed_runtime = Builder.FunctionAttributes }, | |
| 916 | .{ .fixed = @bitSizeOf(CallType) }, | |
| 917 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 918 | .{ .fixed_runtime = Builder.Type }, | |
| 919 | ValueAbbrev, // Callee | |
| 920 | ValueArrayAbbrev, // Args | |
| 921 | }; | |
| 922 | ||
| 923 | attributes: Builder.FunctionAttributes, | |
| 924 | call_type: CallType, | |
| 925 | fast_math: Builder.FastMath, | |
| 926 | type_id: Builder.Type, | |
| 927 | callee: Builder.Value, | |
| 928 | args: []const Builder.Value, | |
| 929 | }; | |
| 930 | ||
| 931 | pub const FNeg = struct { | |
| 932 | pub const ops = [_]AbbrevOp{ | |
| 933 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_UNOP) }, | |
| 934 | ValueAbbrev, | |
| 935 | .{ .literal = 0 }, | |
| 936 | }; | |
| 937 | ||
| 938 | val: u32, | |
| 939 | }; | |
| 940 | ||
| 941 | pub const FNegFast = struct { | |
| 942 | pub const ops = [_]AbbrevOp{ | |
| 943 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_UNOP) }, | |
| 944 | ValueAbbrev, | |
| 945 | .{ .literal = 0 }, | |
| 946 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 947 | }; | |
| 948 | ||
| 949 | val: u32, | |
| 950 | fast_math: Builder.FastMath, | |
| 951 | }; | |
| 952 | ||
| 953 | pub const Binary = struct { | |
| 954 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 955 | pub const ops = [_]AbbrevOp{ | |
| 956 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) }, | |
| 957 | ValueAbbrev, | |
| 958 | ValueAbbrev, | |
| 959 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 960 | }; | |
| 961 | ||
| 962 | lhs: u32, | |
| 963 | rhs: u32, | |
| 964 | opcode: BinaryOpcode, | |
| 965 | }; | |
| 966 | ||
| 967 | pub const BinaryNoWrap = struct { | |
| 968 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 969 | pub const ops = [_]AbbrevOp{ | |
| 970 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) }, | |
| 971 | ValueAbbrev, | |
| 972 | ValueAbbrev, | |
| 973 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 974 | .{ .fixed = 2 }, | |
| 975 | }; | |
| 976 | ||
| 977 | lhs: u32, | |
| 978 | rhs: u32, | |
| 979 | opcode: BinaryOpcode, | |
| 980 | flags: packed struct(u2) { | |
| 981 | no_unsigned_wrap: bool, | |
| 982 | no_signed_wrap: bool, | |
| 983 | }, | |
| 984 | }; | |
| 985 | ||
| 986 | pub const BinaryExact = struct { | |
| 987 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 988 | pub const ops = [_]AbbrevOp{ | |
| 989 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) }, | |
| 990 | ValueAbbrev, | |
| 991 | ValueAbbrev, | |
| 992 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 993 | .{ .literal = 1 }, | |
| 994 | }; | |
| 995 | ||
| 996 | lhs: u32, | |
| 997 | rhs: u32, | |
| 998 | opcode: BinaryOpcode, | |
| 999 | }; | |
| 1000 | ||
| 1001 | pub const BinaryFast = struct { | |
| 1002 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 1003 | pub const ops = [_]AbbrevOp{ | |
| 1004 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BINOP) }, | |
| 1005 | ValueAbbrev, | |
| 1006 | ValueAbbrev, | |
| 1007 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 1008 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1009 | }; | |
| 1010 | ||
| 1011 | lhs: u32, | |
| 1012 | rhs: u32, | |
| 1013 | opcode: BinaryOpcode, | |
| 1014 | fast_math: Builder.FastMath, | |
| 1015 | }; | |
| 1016 | ||
| 1017 | pub const Cmp = struct { | |
| 1018 | const CmpPredicate = Builder.CmpPredicate; | |
| 1019 | pub const ops = [_]AbbrevOp{ | |
| 1020 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CMP2) }, | |
| 1021 | ValueAbbrev, | |
| 1022 | ValueAbbrev, | |
| 1023 | .{ .fixed = @bitSizeOf(CmpPredicate) }, | |
| 1024 | }; | |
| 1025 | ||
| 1026 | lhs: u32, | |
| 1027 | rhs: u32, | |
| 1028 | pred: CmpPredicate, | |
| 1029 | }; | |
| 1030 | ||
| 1031 | pub const CmpFast = struct { | |
| 1032 | const CmpPredicate = Builder.CmpPredicate; | |
| 1033 | pub const ops = [_]AbbrevOp{ | |
| 1034 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CMP2) }, | |
| 1035 | ValueAbbrev, | |
| 1036 | ValueAbbrev, | |
| 1037 | .{ .fixed = @bitSizeOf(CmpPredicate) }, | |
| 1038 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1039 | }; | |
| 1040 | ||
| 1041 | lhs: u32, | |
| 1042 | rhs: u32, | |
| 1043 | pred: CmpPredicate, | |
| 1044 | fast_math: Builder.FastMath, | |
| 1045 | }; | |
| 1046 | ||
| 1047 | pub const Select = struct { | |
| 1048 | pub const ops = [_]AbbrevOp{ | |
| 1049 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_VSELECT) }, | |
| 1050 | ValueAbbrev, | |
| 1051 | ValueAbbrev, | |
| 1052 | ValueAbbrev, | |
| 1053 | }; | |
| 1054 | ||
| 1055 | lhs: u32, | |
| 1056 | rhs: u32, | |
| 1057 | cond: u32, | |
| 1058 | }; | |
| 1059 | ||
| 1060 | pub const SelectFast = struct { | |
| 1061 | pub const ops = [_]AbbrevOp{ | |
| 1062 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_VSELECT) }, | |
| 1063 | ValueAbbrev, | |
| 1064 | ValueAbbrev, | |
| 1065 | ValueAbbrev, | |
| 1066 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1067 | }; | |
| 1068 | ||
| 1069 | lhs: u32, | |
| 1070 | rhs: u32, | |
| 1071 | cond: u32, | |
| 1072 | fast_math: Builder.FastMath, | |
| 1073 | }; | |
| 1074 | ||
| 1075 | pub const Cast = struct { | |
| 1076 | const CastOpcode = Builder.CastOpcode; | |
| 1077 | pub const ops = [_]AbbrevOp{ | |
| 1078 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CAST) }, | |
| 1079 | ValueAbbrev, | |
| 1080 | .{ .fixed_runtime = Builder.Type }, | |
| 1081 | .{ .fixed = @bitSizeOf(CastOpcode) }, | |
| 1082 | }; | |
| 1083 | ||
| 1084 | val: u32, | |
| 1085 | type_index: Builder.Type, | |
| 1086 | opcode: CastOpcode, | |
| 1087 | }; | |
| 1088 | ||
| 1089 | pub const Alloca = struct { | |
| 1090 | pub const Flags = packed struct(u11) { | |
| 1091 | align_lower: u5, | |
| 1092 | inalloca: bool, | |
| 1093 | explicit_type: bool, | |
| 1094 | swift_error: bool, | |
| 1095 | align_upper: u3, | |
| 1096 | }; | |
| 1097 | pub const ops = [_]AbbrevOp{ | |
| 1098 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_ALLOCA) }, | |
| 1099 | .{ .fixed_runtime = Builder.Type }, | |
| 1100 | .{ .fixed_runtime = Builder.Type }, | |
| 1101 | ValueAbbrev, | |
| 1102 | .{ .fixed = @bitSizeOf(Flags) }, | |
| 1103 | }; | |
| 1104 | ||
| 1105 | inst_type: Builder.Type, | |
| 1106 | len_type: Builder.Type, | |
| 1107 | len_value: u32, | |
| 1108 | flags: Flags, | |
| 1109 | }; | |
| 1110 | ||
| 1111 | pub const RetVoid = struct { | |
| 1112 | pub const ops = [_]AbbrevOp{ | |
| 1113 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_RET) }, | |
| 1114 | }; | |
| 1115 | }; | |
| 1116 | ||
| 1117 | pub const Ret = struct { | |
| 1118 | pub const ops = [_]AbbrevOp{ | |
| 1119 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_RET) }, | |
| 1120 | ValueAbbrev, | |
| 1121 | }; | |
| 1122 | val: u32, | |
| 1123 | }; | |
| 1124 | ||
| 1125 | pub const GetElementPtr = struct { | |
| 1126 | pub const ops = [_]AbbrevOp{ | |
| 1127 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_GEP) }, | |
| 1128 | .{ .fixed = 1 }, | |
| 1129 | .{ .fixed_runtime = Builder.Type }, | |
| 1130 | ValueAbbrev, | |
| 1131 | ValueArrayAbbrev, | |
| 1132 | }; | |
| 1133 | ||
| 1134 | is_inbounds: bool, | |
| 1135 | type_index: Builder.Type, | |
| 1136 | base: Builder.Value, | |
| 1137 | indices: []const Builder.Value, | |
| 1138 | }; | |
| 1139 | ||
| 1140 | pub const ExtractValue = struct { | |
| 1141 | pub const ops = [_]AbbrevOp{ | |
| 1142 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_EXTRACTVAL) }, | |
| 1143 | ValueAbbrev, | |
| 1144 | ValueArrayAbbrev, | |
| 1145 | }; | |
| 1146 | ||
| 1147 | val: u32, | |
| 1148 | indices: []const u32, | |
| 1149 | }; | |
| 1150 | ||
| 1151 | pub const InsertValue = struct { | |
| 1152 | pub const ops = [_]AbbrevOp{ | |
| 1153 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_INSERTVAL) }, | |
| 1154 | ValueAbbrev, | |
| 1155 | ValueAbbrev, | |
| 1156 | ValueArrayAbbrev, | |
| 1157 | }; | |
| 1158 | ||
| 1159 | val: u32, | |
| 1160 | elem: u32, | |
| 1161 | indices: []const u32, | |
| 1162 | }; | |
| 1163 | ||
| 1164 | pub const ExtractElement = struct { | |
| 1165 | pub const ops = [_]AbbrevOp{ | |
| 1166 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_EXTRACTELT) }, | |
| 1167 | ValueAbbrev, | |
| 1168 | ValueAbbrev, | |
| 1169 | }; | |
| 1170 | ||
| 1171 | val: u32, | |
| 1172 | index: u32, | |
| 1173 | }; | |
| 1174 | ||
| 1175 | pub const InsertElement = struct { | |
| 1176 | pub const ops = [_]AbbrevOp{ | |
| 1177 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_INSERTELT) }, | |
| 1178 | ValueAbbrev, | |
| 1179 | ValueAbbrev, | |
| 1180 | ValueAbbrev, | |
| 1181 | }; | |
| 1182 | ||
| 1183 | val: u32, | |
| 1184 | elem: u32, | |
| 1185 | index: u32, | |
| 1186 | }; | |
| 1187 | ||
| 1188 | pub const ShuffleVector = struct { | |
| 1189 | pub const ops = [_]AbbrevOp{ | |
| 1190 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_SHUFFLEVEC) }, | |
| 1191 | ValueAbbrev, | |
| 1192 | ValueAbbrev, | |
| 1193 | ValueAbbrev, | |
| 1194 | }; | |
| 1195 | ||
| 1196 | lhs: u32, | |
| 1197 | rhs: u32, | |
| 1198 | mask: u32, | |
| 1199 | }; | |
| 1200 | ||
| 1201 | pub const Unreachable = struct { | |
| 1202 | pub const ops = [_]AbbrevOp{ | |
| 1203 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_UNREACHABLE) }, | |
| 1204 | }; | |
| 1205 | }; | |
| 1206 | ||
| 1207 | pub const Load = struct { | |
| 1208 | pub const ops = [_]AbbrevOp{ | |
| 1209 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_LOAD) }, | |
| 1210 | ValueAbbrev, | |
| 1211 | .{ .fixed_runtime = Builder.Type }, | |
| 1212 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1213 | .{ .fixed = 1 }, | |
| 1214 | }; | |
| 1215 | ptr: u32, | |
| 1216 | ty: Builder.Type, | |
| 1217 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1218 | is_volatile: bool, | |
| 1219 | }; | |
| 1220 | ||
| 1221 | pub const LoadAtomic = struct { | |
| 1222 | pub const ops = [_]AbbrevOp{ | |
| 1223 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_LOADATOMIC) }, | |
| 1224 | ValueAbbrev, | |
| 1225 | .{ .fixed_runtime = Builder.Type }, | |
| 1226 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1227 | .{ .fixed = 1 }, | |
| 1228 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1229 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1230 | }; | |
| 1231 | ptr: u32, | |
| 1232 | ty: Builder.Type, | |
| 1233 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1234 | is_volatile: bool, | |
| 1235 | success_ordering: Builder.AtomicOrdering, | |
| 1236 | sync_scope: Builder.SyncScope, | |
| 1237 | }; | |
| 1238 | ||
| 1239 | pub const Store = struct { | |
| 1240 | pub const ops = [_]AbbrevOp{ | |
| 1241 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_STORE) }, | |
| 1242 | ValueAbbrev, | |
| 1243 | ValueAbbrev, | |
| 1244 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1245 | .{ .fixed = 1 }, | |
| 1246 | }; | |
| 1247 | ptr: u32, | |
| 1248 | val: u32, | |
| 1249 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1250 | is_volatile: bool, | |
| 1251 | }; | |
| 1252 | ||
| 1253 | pub const StoreAtomic = struct { | |
| 1254 | pub const ops = [_]AbbrevOp{ | |
| 1255 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_STOREATOMIC) }, | |
| 1256 | ValueAbbrev, | |
| 1257 | ValueAbbrev, | |
| 1258 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1259 | .{ .fixed = 1 }, | |
| 1260 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1261 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1262 | }; | |
| 1263 | ptr: u32, | |
| 1264 | val: u32, | |
| 1265 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1266 | is_volatile: bool, | |
| 1267 | success_ordering: Builder.AtomicOrdering, | |
| 1268 | sync_scope: Builder.SyncScope, | |
| 1269 | }; | |
| 1270 | ||
| 1271 | pub const BrUnconditional = struct { | |
| 1272 | pub const ops = [_]AbbrevOp{ | |
| 1273 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BR) }, | |
| 1274 | BlockAbbrev, | |
| 1275 | }; | |
| 1276 | block: u32, | |
| 1277 | }; | |
| 1278 | ||
| 1279 | pub const BrConditional = struct { | |
| 1280 | pub const ops = [_]AbbrevOp{ | |
| 1281 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_BR) }, | |
| 1282 | BlockAbbrev, | |
| 1283 | BlockAbbrev, | |
| 1284 | BlockAbbrev, | |
| 1285 | }; | |
| 1286 | then_block: u32, | |
| 1287 | else_block: u32, | |
| 1288 | condition: u32, | |
| 1289 | }; | |
| 1290 | ||
| 1291 | pub const VaArg = struct { | |
| 1292 | pub const ops = [_]AbbrevOp{ | |
| 1293 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_VAARG) }, | |
| 1294 | .{ .fixed_runtime = Builder.Type }, | |
| 1295 | ValueAbbrev, | |
| 1296 | .{ .fixed_runtime = Builder.Type }, | |
| 1297 | }; | |
| 1298 | list_type: Builder.Type, | |
| 1299 | list: u32, | |
| 1300 | type: Builder.Type, | |
| 1301 | }; | |
| 1302 | ||
| 1303 | pub const AtomicRmw = struct { | |
| 1304 | pub const ops = [_]AbbrevOp{ | |
| 1305 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_ATOMICRMW) }, | |
| 1306 | ValueAbbrev, | |
| 1307 | ValueAbbrev, | |
| 1308 | .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) }, | |
| 1309 | .{ .fixed = 1 }, | |
| 1310 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1311 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1312 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1313 | }; | |
| 1314 | ptr: u32, | |
| 1315 | val: u32, | |
| 1316 | operation: Builder.Function.Instruction.AtomicRmw.Operation, | |
| 1317 | is_volatile: bool, | |
| 1318 | success_ordering: Builder.AtomicOrdering, | |
| 1319 | sync_scope: Builder.SyncScope, | |
| 1320 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1321 | }; | |
| 1322 | ||
| 1323 | pub const CmpXchg = struct { | |
| 1324 | pub const ops = [_]AbbrevOp{ | |
| 1325 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_CMPXCHG) }, | |
| 1326 | ValueAbbrev, | |
| 1327 | ValueAbbrev, | |
| 1328 | ValueAbbrev, | |
| 1329 | .{ .fixed = 1 }, | |
| 1330 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1331 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1332 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1333 | .{ .fixed = 1 }, | |
| 1334 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1335 | }; | |
| 1336 | ptr: u32, | |
| 1337 | cmp: u32, | |
| 1338 | new: u32, | |
| 1339 | is_volatile: bool, | |
| 1340 | success_ordering: Builder.AtomicOrdering, | |
| 1341 | sync_scope: Builder.SyncScope, | |
| 1342 | failure_ordering: Builder.AtomicOrdering, | |
| 1343 | is_weak: bool, | |
| 1344 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1345 | }; | |
| 1346 | ||
| 1347 | pub const Fence = struct { | |
| 1348 | pub const ops = [_]AbbrevOp{ | |
| 1349 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_FENCE) }, | |
| 1350 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1351 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1352 | }; | |
| 1353 | ordering: Builder.AtomicOrdering, | |
| 1354 | sync_scope: Builder.SyncScope, | |
| 1355 | }; | |
| 1356 | ||
| 1357 | pub const DebugLoc = struct { | |
| 1358 | pub const ops = [_]AbbrevOp{ | |
| 1359 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.DEBUG_LOC) }, | |
| 1360 | LineAbbrev, | |
| 1361 | ColumnAbbrev, | |
| 1362 | MetadataAbbrev, | |
| 1363 | MetadataAbbrev, | |
| 1364 | .{ .literal = 0 }, | |
| 1365 | }; | |
| 1366 | line: u32, | |
| 1367 | column: u32, | |
| 1368 | scope: Builder.Metadata.Optional, | |
| 1369 | inlined_at: Builder.Metadata.Optional, | |
| 1370 | }; | |
| 1371 | ||
| 1372 | pub const DebugLocAgain = struct { | |
| 1373 | pub const ops = [_]AbbrevOp{ | |
| 1374 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.DEBUG_LOC_AGAIN) }, | |
| 1375 | }; | |
| 1376 | }; | |
| 1377 | ||
| 1378 | pub const ColdOperandBundle = struct { | |
| 1379 | pub const ops = [_]AbbrevOp{ | |
| 1380 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.OPERAND_BUNDLE) }, | |
| 1381 | .{ .literal = 0 }, | |
| 1382 | }; | |
| 1383 | }; | |
| 1384 | ||
| 1385 | pub const IndirectBr = struct { | |
| 1386 | pub const ops = [_]AbbrevOp{ | |
| 1387 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.Code.INST_INDIRECTBR) }, | |
| 1388 | .{ .fixed_runtime = Builder.Type }, | |
| 1389 | ValueAbbrev, | |
| 1390 | BlockArrayAbbrev, | |
| 1391 | }; | |
| 1392 | ty: Builder.Type, | |
| 1393 | addr: Builder.Value, | |
| 1394 | targets: []const Builder.Function.Block.Index, | |
| 1395 | }; | |
| 1396 | ||
| 1397 | pub const ValueSymtabBlock = struct { | |
| 1398 | pub const id: BlockId = .VALUE_SYMTAB; | |
| 1399 | ||
| 1400 | pub const abbrevs = [_]type{ | |
| 1401 | ModuleBlock.FunctionBlock.ValueSymtabBlock.BlockEntry, | |
| 1402 | }; | |
| 1403 | ||
| 1404 | /// Value symbol table codes. | |
| 1405 | pub const Code = enum(u3) { | |
| 1406 | /// VST_ENTRY: [valueid, namechar x N] | |
| 1407 | ENTRY = 1, | |
| 1408 | /// VST_BBENTRY: [bbid, namechar x N] | |
| 1409 | BBENTRY = 2, | |
| 1410 | /// VST_FNENTRY: [valueid, offset, namechar x N] | |
| 1411 | FNENTRY = 3, | |
| 1412 | /// VST_COMBINED_ENTRY: [valueid, refguid] | |
| 1413 | COMBINED_ENTRY = 5, | |
| 1414 | }; | |
| 1415 | ||
| 1416 | pub const BlockEntry = struct { | |
| 1417 | pub const ops = [_]AbbrevOp{ | |
| 1418 | .{ .literal = @intFromEnum(ModuleBlock.FunctionBlock.ValueSymtabBlock.Code.BBENTRY) }, | |
| 1419 | ValueAbbrev, | |
| 1420 | .{ .array_fixed = 8 }, | |
| 1421 | }; | |
| 1422 | value_id: u32, | |
| 1423 | string: []const u8, | |
| 1424 | }; | |
| 1425 | }; | |
| 1426 | ||
| 1427 | pub const MetadataBlock = struct { | |
| 1428 | pub const id: BlockId = .METADATA; | |
| 1429 | ||
| 1430 | pub const abbrevs = [_]type{ | |
| 1431 | ModuleBlock.FunctionBlock.MetadataBlock.Value, | |
| 1432 | }; | |
| 1433 | ||
| 1434 | pub const Value = struct { | |
| 1435 | pub const ops = [_]AbbrevOp{ | |
| 1436 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.VALUE) }, | |
| 1437 | .{ .fixed = 32 }, // variable | |
| 1438 | .{ .fixed = 32 }, // expression | |
| 1439 | }; | |
| 1440 | ||
| 1441 | ty: Builder.Type, | |
| 1442 | value: Builder.Value, | |
| 1443 | }; | |
| 1444 | }; | |
| 1445 | ||
| 1446 | pub const MetadataAttachmentBlock = struct { | |
| 1447 | pub const id: BlockId = .METADATA_ATTACHMENT; | |
| 1448 | ||
| 1449 | pub const abbrevs = [_]type{ | |
| 1450 | ModuleBlock.FunctionBlock.MetadataAttachmentBlock.AttachmentGlobalSingle, | |
| 1451 | ModuleBlock.FunctionBlock.MetadataAttachmentBlock.AttachmentInstructionSingle, | |
| 1452 | }; | |
| 1453 | ||
| 1454 | pub const AttachmentGlobalSingle = struct { | |
| 1455 | pub const ops = [_]AbbrevOp{ | |
| 1456 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.ATTACHMENT) }, | |
| 1457 | .{ .fixed = 1 }, | |
| 1458 | MetadataAbbrev, | |
| 1459 | }; | |
| 1460 | kind: FixedMetadataKind, | |
| 1461 | metadata: Builder.Metadata, | |
| 1462 | }; | |
| 1463 | ||
| 1464 | pub const AttachmentInstructionSingle = struct { | |
| 1465 | pub const ops = [_]AbbrevOp{ | |
| 1466 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.ATTACHMENT) }, | |
| 1467 | ValueAbbrev, | |
| 1468 | .{ .fixed = 5 }, | |
| 1469 | MetadataAbbrev, | |
| 1470 | }; | |
| 1471 | inst: u32, | |
| 1472 | kind: FixedMetadataKind, | |
| 1473 | metadata: Builder.Metadata, | |
| 1474 | }; | |
| 1475 | }; | |
| 1476 | }; | |
| 1477 | ||
| 1478 | pub const MetadataBlock = struct { | |
| 1479 | pub const id: BlockId = .METADATA; | |
| 1480 | ||
| 1481 | pub const abbrevs = [_]type{ | |
| 1482 | ModuleBlock.MetadataBlock.Strings, | |
| 1483 | ModuleBlock.MetadataBlock.File, | |
| 1484 | ModuleBlock.MetadataBlock.CompileUnit, | |
| 1485 | ModuleBlock.MetadataBlock.Subprogram, | |
| 1486 | ModuleBlock.MetadataBlock.LexicalBlock, | |
| 1487 | ModuleBlock.MetadataBlock.Location, | |
| 1488 | ModuleBlock.MetadataBlock.BasicType, | |
| 1489 | ModuleBlock.MetadataBlock.CompositeType, | |
| 1490 | ModuleBlock.MetadataBlock.DerivedType, | |
| 1491 | ModuleBlock.MetadataBlock.SubroutineType, | |
| 1492 | ModuleBlock.MetadataBlock.Enumerator, | |
| 1493 | ModuleBlock.MetadataBlock.Subrange, | |
| 1494 | ModuleBlock.MetadataBlock.Expression, | |
| 1495 | ModuleBlock.MetadataBlock.Node, | |
| 1496 | ModuleBlock.MetadataBlock.LocalVar, | |
| 1497 | ModuleBlock.MetadataBlock.Parameter, | |
| 1498 | ModuleBlock.MetadataBlock.GlobalVar, | |
| 1499 | ModuleBlock.MetadataBlock.GlobalVarExpression, | |
| 1500 | ModuleBlock.MetadataBlock.Constant, | |
| 1501 | ModuleBlock.MetadataBlock.Name, | |
| 1502 | ModuleBlock.MetadataBlock.NamedNode, | |
| 1503 | ModuleBlock.MetadataBlock.GlobalDeclAttachment, | |
| 1504 | }; | |
| 1505 | ||
| 1506 | pub const Code = enum(u6) { | |
| 1507 | /// MDSTRING: [values] | |
| 1508 | STRING_OLD = 1, | |
| 1509 | /// VALUE: [type num, value num] | |
| 1510 | VALUE = 2, | |
| 1511 | /// NODE: [n x md num] | |
| 1512 | NODE = 3, | |
| 1513 | /// STRING: [values] | |
| 1514 | NAME = 4, | |
| 1515 | /// DISTINCT_NODE: [n x md num] | |
| 1516 | DISTINCT_NODE = 5, | |
| 1517 | /// [n x [id, name]] | |
| 1518 | KIND = 6, | |
| 1519 | /// [distinct, line, col, scope, inlined-at?] | |
| 1520 | LOCATION = 7, | |
| 1521 | /// OLD_NODE: [n x (type num, value num)] | |
| 1522 | OLD_NODE = 8, | |
| 1523 | /// OLD_FN_NODE: [n x (type num, value num)] | |
| 1524 | OLD_FN_NODE = 9, | |
| 1525 | /// NAMED_NODE: [n x mdnodes] | |
| 1526 | NAMED_NODE = 10, | |
| 1527 | /// [m x [value, [n x [id, mdnode]]] | |
| 1528 | ATTACHMENT = 11, | |
| 1529 | /// [distinct, tag, vers, header, n x md num] | |
| 1530 | GENERIC_DEBUG = 12, | |
| 1531 | /// [distinct, count, lo] | |
| 1532 | SUBRANGE = 13, | |
| 1533 | /// [isUnsigned|distinct, value, name] | |
| 1534 | ENUMERATOR = 14, | |
| 1535 | /// [distinct, tag, name, size, align, enc] | |
| 1536 | BASIC_TYPE = 15, | |
| 1537 | /// [distinct, filename, directory, checksumkind, checksum] | |
| 1538 | FILE = 16, | |
| 1539 | /// [distinct, ...] | |
| 1540 | DERIVED_TYPE = 17, | |
| 1541 | /// [distinct, ...] | |
| 1542 | COMPOSITE_TYPE = 18, | |
| 1543 | /// [distinct, flags, types, cc] | |
| 1544 | SUBROUTINE_TYPE = 19, | |
| 1545 | /// [distinct, ...] | |
| 1546 | COMPILE_UNIT = 20, | |
| 1547 | /// [distinct, ...] | |
| 1548 | SUBPROGRAM = 21, | |
| 1549 | /// [distinct, scope, file, line, column] | |
| 1550 | LEXICAL_BLOCK = 22, | |
| 1551 | ///[distinct, scope, file, discriminator] | |
| 1552 | LEXICAL_BLOCK_FILE = 23, | |
| 1553 | /// [distinct, scope, file, name, line, exportSymbols] | |
| 1554 | NAMESPACE = 24, | |
| 1555 | /// [distinct, scope, name, type, ...] | |
| 1556 | TEMPLATE_TYPE = 25, | |
| 1557 | /// [distinct, scope, name, type, value, ...] | |
| 1558 | TEMPLATE_VALUE = 26, | |
| 1559 | /// [distinct, ...] | |
| 1560 | GLOBAL_VAR = 27, | |
| 1561 | /// [distinct, ...] | |
| 1562 | LOCAL_VAR = 28, | |
| 1563 | /// [distinct, n x element] | |
| 1564 | EXPRESSION = 29, | |
| 1565 | /// [distinct, name, file, line, ...] | |
| 1566 | OBJC_PROPERTY = 30, | |
| 1567 | /// [distinct, tag, scope, entity, line, name] | |
| 1568 | IMPORTED_ENTITY = 31, | |
| 1569 | /// [distinct, scope, name, ...] | |
| 1570 | MODULE = 32, | |
| 1571 | /// [distinct, macinfo, line, name, value] | |
| 1572 | MACRO = 33, | |
| 1573 | /// [distinct, macinfo, line, file, ...] | |
| 1574 | MACRO_FILE = 34, | |
| 1575 | /// [count, offset] blob([lengths][chars]) | |
| 1576 | STRINGS = 35, | |
| 1577 | /// [valueid, n x [id, mdnode]] | |
| 1578 | GLOBAL_DECL_ATTACHMENT = 36, | |
| 1579 | /// [distinct, var, expr] | |
| 1580 | GLOBAL_VAR_EXPR = 37, | |
| 1581 | /// [offset] | |
| 1582 | INDEX_OFFSET = 38, | |
| 1583 | /// [bitpos] | |
| 1584 | INDEX = 39, | |
| 1585 | /// [distinct, scope, name, file, line] | |
| 1586 | LABEL = 40, | |
| 1587 | /// [distinct, name, size, align,...] | |
| 1588 | STRING_TYPE = 41, | |
| 1589 | /// [distinct, scope, name, variable,...] | |
| 1590 | COMMON_BLOCK = 44, | |
| 1591 | /// [distinct, count, lo, up, stride] | |
| 1592 | GENERIC_SUBRANGE = 45, | |
| 1593 | /// [n x [type num, value num]] | |
| 1594 | ARG_LIST = 46, | |
| 1595 | /// [distinct, ...] | |
| 1596 | ASSIGN_ID = 47, | |
| 1597 | }; | |
| 1598 | ||
| 1599 | pub const Strings = struct { | |
| 1600 | pub const ops = [_]AbbrevOp{ | |
| 1601 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.STRINGS) }, | |
| 1602 | .{ .vbr = 6 }, | |
| 1603 | .{ .vbr = 6 }, | |
| 1604 | .blob, | |
| 1605 | }; | |
| 1606 | num_strings: u32, | |
| 1607 | strings_offset: u32, | |
| 1608 | blob: []const u8, | |
| 1609 | }; | |
| 1610 | ||
| 1611 | pub const File = struct { | |
| 1612 | pub const ops = [_]AbbrevOp{ | |
| 1613 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.FILE) }, | |
| 1614 | .{ .literal = 0 }, // is distinct | |
| 1615 | MetadataAbbrev, // filename | |
| 1616 | MetadataAbbrev, // directory | |
| 1617 | .{ .literal = 0 }, // checksum | |
| 1618 | .{ .literal = 0 }, // checksum | |
| 1619 | }; | |
| 1620 | ||
| 1621 | filename: Builder.Metadata.String.Optional, | |
| 1622 | directory: Builder.Metadata.String.Optional, | |
| 1623 | }; | |
| 1624 | ||
| 1625 | pub const CompileUnit = struct { | |
| 1626 | pub const ops = [_]AbbrevOp{ | |
| 1627 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.COMPILE_UNIT) }, | |
| 1628 | .{ .literal = 1 }, // is distinct | |
| 1629 | .{ .literal = std.dwarf.LANG.C99 }, // source language | |
| 1630 | MetadataAbbrev, // file | |
| 1631 | MetadataAbbrev, // producer | |
| 1632 | .{ .fixed = 1 }, // isOptimized | |
| 1633 | .{ .literal = 0 }, // raw flags | |
| 1634 | .{ .literal = 0 }, // runtime version | |
| 1635 | .{ .literal = 0 }, // split debug file name | |
| 1636 | .{ .literal = 1 }, // emission kind | |
| 1637 | MetadataAbbrev, // enums | |
| 1638 | .{ .literal = 0 }, // retained types | |
| 1639 | .{ .literal = 0 }, // subprograms | |
| 1640 | MetadataAbbrev, // globals | |
| 1641 | .{ .literal = 0 }, // imported entities | |
| 1642 | .{ .literal = 0 }, // DWO ID | |
| 1643 | .{ .literal = 0 }, // macros | |
| 1644 | .{ .literal = 0 }, // split debug inlining | |
| 1645 | .{ .literal = 0 }, // debug info profiling | |
| 1646 | .{ .literal = 0 }, // name table kind | |
| 1647 | .{ .literal = 0 }, // ranges base address | |
| 1648 | .{ .literal = 0 }, // raw sysroot | |
| 1649 | .{ .literal = 0 }, // raw SDK | |
| 1650 | }; | |
| 1651 | ||
| 1652 | file: Builder.Metadata.Optional, | |
| 1653 | producer: Builder.Metadata.String.Optional, | |
| 1654 | is_optimized: bool, | |
| 1655 | enums: Builder.Metadata.Optional, | |
| 1656 | globals: Builder.Metadata.Optional, | |
| 1657 | }; | |
| 1658 | ||
| 1659 | pub const Subprogram = struct { | |
| 1660 | pub const ops = [_]AbbrevOp{ | |
| 1661 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.SUBPROGRAM) }, | |
| 1662 | .{ .literal = 0b111 }, // is distinct | has sp flags | has flags | |
| 1663 | MetadataAbbrev, // scope | |
| 1664 | MetadataAbbrev, // name | |
| 1665 | MetadataAbbrev, // linkage name | |
| 1666 | MetadataAbbrev, // file | |
| 1667 | LineAbbrev, // line | |
| 1668 | MetadataAbbrev, // type | |
| 1669 | LineAbbrev, // scope line | |
| 1670 | .{ .literal = 0 }, // containing type | |
| 1671 | .{ .fixed = 32 }, // sp flags | |
| 1672 | .{ .literal = 0 }, // virtual index | |
| 1673 | .{ .fixed = 32 }, // flags | |
| 1674 | MetadataAbbrev, // compile unit | |
| 1675 | .{ .literal = 0 }, // template params | |
| 1676 | .{ .literal = 0 }, // declaration | |
| 1677 | .{ .literal = 0 }, // retained nodes | |
| 1678 | .{ .literal = 0 }, // this adjustment | |
| 1679 | .{ .literal = 0 }, // thrown types | |
| 1680 | .{ .literal = 0 }, // annotations | |
| 1681 | .{ .literal = 0 }, // target function name | |
| 1682 | }; | |
| 1683 | ||
| 1684 | scope: Builder.Metadata.Optional, | |
| 1685 | name: Builder.Metadata.String.Optional, | |
| 1686 | linkage_name: Builder.Metadata.String.Optional, | |
| 1687 | file: Builder.Metadata.Optional, | |
| 1688 | line: u32, | |
| 1689 | ty: Builder.Metadata.Optional, | |
| 1690 | scope_line: u32, | |
| 1691 | sp_flags: Builder.Metadata.Subprogram.DISPFlags, | |
| 1692 | flags: Builder.Metadata.DIFlags, | |
| 1693 | compile_unit: Builder.Metadata.Optional, | |
| 1694 | }; | |
| 1695 | ||
| 1696 | pub const LexicalBlock = struct { | |
| 1697 | pub const ops = [_]AbbrevOp{ | |
| 1698 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LEXICAL_BLOCK) }, | |
| 1699 | .{ .literal = 0 }, // is distinct | |
| 1700 | MetadataAbbrev, // scope | |
| 1701 | MetadataAbbrev, // file | |
| 1702 | LineAbbrev, // line | |
| 1703 | ColumnAbbrev, // column | |
| 1704 | }; | |
| 1705 | ||
| 1706 | scope: Builder.Metadata.Optional, | |
| 1707 | file: Builder.Metadata.Optional, | |
| 1708 | line: u32, | |
| 1709 | column: u32, | |
| 1710 | }; | |
| 1711 | ||
| 1712 | pub const Location = struct { | |
| 1713 | pub const ops = [_]AbbrevOp{ | |
| 1714 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LOCATION) }, | |
| 1715 | .{ .literal = 0 }, // is distinct | |
| 1716 | LineAbbrev, // line | |
| 1717 | ColumnAbbrev, // column | |
| 1718 | MetadataAbbrev, // scope | |
| 1719 | MetadataAbbrev, // inlined at | |
| 1720 | .{ .literal = 0 }, // is implicit code | |
| 1721 | }; | |
| 1722 | ||
| 1723 | line: u32, | |
| 1724 | column: u32, | |
| 1725 | scope: Builder.Metadata, | |
| 1726 | inlined_at: Builder.Metadata.Optional, | |
| 1727 | }; | |
| 1728 | ||
| 1729 | pub const BasicType = struct { | |
| 1730 | pub const ops = [_]AbbrevOp{ | |
| 1731 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.BASIC_TYPE) }, | |
| 1732 | .{ .literal = 0 }, // is distinct | |
| 1733 | .{ .literal = std.dwarf.TAG.base_type }, // tag | |
| 1734 | MetadataAbbrev, // name | |
| 1735 | .{ .vbr = 6 }, // size in bits | |
| 1736 | .{ .literal = 0 }, // align in bits | |
| 1737 | .{ .vbr = 8 }, // encoding | |
| 1738 | .{ .literal = 0 }, // flags | |
| 1739 | }; | |
| 1740 | ||
| 1741 | name: Builder.Metadata.String.Optional, | |
| 1742 | size_in_bits: u64, | |
| 1743 | encoding: u32, | |
| 1744 | }; | |
| 1745 | ||
| 1746 | pub const CompositeType = struct { | |
| 1747 | pub const ops = [_]AbbrevOp{ | |
| 1748 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.COMPOSITE_TYPE) }, | |
| 1749 | .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref | |
| 1750 | .{ .fixed = 32 }, // tag | |
| 1751 | MetadataAbbrev, // name | |
| 1752 | MetadataAbbrev, // file | |
| 1753 | LineAbbrev, // line | |
| 1754 | MetadataAbbrev, // scope | |
| 1755 | MetadataAbbrev, // underlying type | |
| 1756 | .{ .vbr = 6 }, // size in bits | |
| 1757 | .{ .vbr = 6 }, // align in bits | |
| 1758 | .{ .literal = 0 }, // offset in bits | |
| 1759 | .{ .fixed = 32 }, // flags | |
| 1760 | MetadataAbbrev, // elements | |
| 1761 | .{ .literal = 0 }, // runtime lang | |
| 1762 | .{ .literal = 0 }, // vtable holder | |
| 1763 | .{ .literal = 0 }, // template params | |
| 1764 | .{ .literal = 0 }, // raw id | |
| 1765 | .{ .literal = 0 }, // discriminator | |
| 1766 | .{ .literal = 0 }, // data location | |
| 1767 | .{ .literal = 0 }, // associated | |
| 1768 | .{ .literal = 0 }, // allocated | |
| 1769 | .{ .literal = 0 }, // rank | |
| 1770 | .{ .literal = 0 }, // annotations | |
| 1771 | }; | |
| 1772 | ||
| 1773 | tag: u32, | |
| 1774 | name: Builder.Metadata.String.Optional, | |
| 1775 | file: Builder.Metadata.Optional, | |
| 1776 | line: u32, | |
| 1777 | scope: Builder.Metadata.Optional, | |
| 1778 | underlying_type: Builder.Metadata.Optional, | |
| 1779 | size_in_bits: u64, | |
| 1780 | align_in_bits: u64, | |
| 1781 | flags: Builder.Metadata.DIFlags, | |
| 1782 | elements: Builder.Metadata.Optional, | |
| 1783 | }; | |
| 1784 | ||
| 1785 | pub const DerivedType = struct { | |
| 1786 | pub const ops = [_]AbbrevOp{ | |
| 1787 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.DERIVED_TYPE) }, | |
| 1788 | .{ .literal = 0 }, // is distinct | |
| 1789 | .{ .fixed = 32 }, // tag | |
| 1790 | MetadataAbbrev, // name | |
| 1791 | MetadataAbbrev, // file | |
| 1792 | LineAbbrev, // line | |
| 1793 | MetadataAbbrev, // scope | |
| 1794 | MetadataAbbrev, // underlying type | |
| 1795 | .{ .vbr = 6 }, // size in bits | |
| 1796 | .{ .vbr = 6 }, // align in bits | |
| 1797 | .{ .vbr = 6 }, // offset in bits | |
| 1798 | .{ .literal = 0 }, // flags | |
| 1799 | .{ .literal = 0 }, // extra data | |
| 1800 | }; | |
| 1801 | ||
| 1802 | tag: u32, | |
| 1803 | name: Builder.Metadata.String.Optional, | |
| 1804 | file: Builder.Metadata.Optional, | |
| 1805 | line: u32, | |
| 1806 | scope: Builder.Metadata.Optional, | |
| 1807 | underlying_type: Builder.Metadata.Optional, | |
| 1808 | size_in_bits: u64, | |
| 1809 | align_in_bits: u64, | |
| 1810 | offset_in_bits: u64, | |
| 1811 | }; | |
| 1812 | ||
| 1813 | pub const SubroutineType = struct { | |
| 1814 | pub const ops = [_]AbbrevOp{ | |
| 1815 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.SUBROUTINE_TYPE) }, | |
| 1816 | .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs | |
| 1817 | .{ .literal = 0 }, // flags | |
| 1818 | MetadataAbbrev, // types | |
| 1819 | .{ .literal = 0 }, // cc | |
| 1820 | }; | |
| 1821 | ||
| 1822 | types: Builder.Metadata.Optional, | |
| 1823 | }; | |
| 1824 | ||
| 1825 | pub const Enumerator = struct { | |
| 1826 | pub const Flags = packed struct(u3) { | |
| 1827 | distinct: bool = false, | |
| 1828 | unsigned: bool, | |
| 1829 | bigint: bool = true, | |
| 1830 | }; | |
| 1831 | ||
| 1832 | pub const ops = [_]AbbrevOp{ | |
| 1833 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.ENUMERATOR) }, | |
| 1834 | .{ .fixed = @bitSizeOf(Flags) }, // flags | |
| 1835 | .{ .vbr = 6 }, // bit width | |
| 1836 | MetadataAbbrev, // name | |
| 1837 | .{ .vbr = 16 }, // integer value | |
| 1838 | }; | |
| 1839 | ||
| 1840 | flags: Flags, | |
| 1841 | bit_width: u32, | |
| 1842 | name: Builder.Metadata.String.Optional, | |
| 1843 | value: u64, | |
| 1844 | }; | |
| 1845 | ||
| 1846 | pub const Subrange = struct { | |
| 1847 | pub const ops = [_]AbbrevOp{ | |
| 1848 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.SUBRANGE) }, | |
| 1849 | .{ .literal = 0 | (2 << 1) }, // is distinct | version | |
| 1850 | MetadataAbbrev, // count | |
| 1851 | MetadataAbbrev, // lower bound | |
| 1852 | .{ .literal = 0 }, // upper bound | |
| 1853 | .{ .literal = 0 }, // stride | |
| 1854 | }; | |
| 1855 | ||
| 1856 | count: Builder.Metadata.Optional, | |
| 1857 | lower_bound: Builder.Metadata.Optional, | |
| 1858 | }; | |
| 1859 | ||
| 1860 | pub const Expression = struct { | |
| 1861 | pub const ops = [_]AbbrevOp{ | |
| 1862 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.EXPRESSION) }, | |
| 1863 | .{ .literal = 0 | (3 << 1) }, // is distinct | version | |
| 1864 | MetadataArrayAbbrev, // elements | |
| 1865 | }; | |
| 1866 | ||
| 1867 | elements: []const u32, | |
| 1868 | }; | |
| 1869 | ||
| 1870 | pub const Node = struct { | |
| 1871 | pub const ops = [_]AbbrevOp{ | |
| 1872 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.NODE) }, | |
| 1873 | MetadataArrayAbbrev, // elements | |
| 1874 | }; | |
| 1875 | ||
| 1876 | elements: []const Builder.Metadata.Optional, | |
| 1877 | }; | |
| 1878 | ||
| 1879 | pub const LocalVar = struct { | |
| 1880 | pub const ops = [_]AbbrevOp{ | |
| 1881 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LOCAL_VAR) }, | |
| 1882 | .{ .literal = 0b10 }, // is distinct | has alignment | |
| 1883 | MetadataAbbrev, // scope | |
| 1884 | MetadataAbbrev, // name | |
| 1885 | MetadataAbbrev, // file | |
| 1886 | LineAbbrev, // line | |
| 1887 | MetadataAbbrev, // type | |
| 1888 | .{ .literal = 0 }, // arg | |
| 1889 | .{ .literal = 0 }, // flags | |
| 1890 | .{ .literal = 0 }, // align bits | |
| 1891 | .{ .literal = 0 }, // annotations | |
| 1892 | }; | |
| 1893 | ||
| 1894 | scope: Builder.Metadata.Optional, | |
| 1895 | name: Builder.Metadata.String.Optional, | |
| 1896 | file: Builder.Metadata.Optional, | |
| 1897 | line: u32, | |
| 1898 | ty: Builder.Metadata.Optional, | |
| 1899 | }; | |
| 1900 | ||
| 1901 | pub const Parameter = struct { | |
| 1902 | pub const ops = [_]AbbrevOp{ | |
| 1903 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.LOCAL_VAR) }, | |
| 1904 | .{ .literal = 0b10 }, // is distinct | has alignment | |
| 1905 | MetadataAbbrev, // scope | |
| 1906 | MetadataAbbrev, // name | |
| 1907 | MetadataAbbrev, // file | |
| 1908 | LineAbbrev, // line | |
| 1909 | MetadataAbbrev, // type | |
| 1910 | .{ .vbr = 4 }, // arg | |
| 1911 | .{ .literal = 0 }, // flags | |
| 1912 | .{ .literal = 0 }, // align bits | |
| 1913 | .{ .literal = 0 }, // annotations | |
| 1914 | }; | |
| 1915 | ||
| 1916 | scope: Builder.Metadata.Optional, | |
| 1917 | name: Builder.Metadata.String.Optional, | |
| 1918 | file: Builder.Metadata.Optional, | |
| 1919 | line: u32, | |
| 1920 | ty: Builder.Metadata.Optional, | |
| 1921 | arg: u32, | |
| 1922 | }; | |
| 1923 | ||
| 1924 | pub const GlobalVar = struct { | |
| 1925 | pub const ops = [_]AbbrevOp{ | |
| 1926 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.GLOBAL_VAR) }, | |
| 1927 | .{ .literal = 0b101 }, // is distinct | version | |
| 1928 | MetadataAbbrev, // scope | |
| 1929 | MetadataAbbrev, // name | |
| 1930 | MetadataAbbrev, // linkage name | |
| 1931 | MetadataAbbrev, // file | |
| 1932 | LineAbbrev, // line | |
| 1933 | MetadataAbbrev, // type | |
| 1934 | .{ .fixed = 1 }, // local | |
| 1935 | .{ .literal = 1 }, // defined | |
| 1936 | .{ .literal = 0 }, // static data members declaration | |
| 1937 | .{ .literal = 0 }, // template params | |
| 1938 | .{ .literal = 0 }, // align in bits | |
| 1939 | .{ .literal = 0 }, // annotations | |
| 1940 | }; | |
| 1941 | ||
| 1942 | scope: Builder.Metadata.Optional, | |
| 1943 | name: Builder.Metadata.String.Optional, | |
| 1944 | linkage_name: Builder.Metadata.String.Optional, | |
| 1945 | file: Builder.Metadata.Optional, | |
| 1946 | line: u32, | |
| 1947 | ty: Builder.Metadata.Optional, | |
| 1948 | local: bool, | |
| 1949 | }; | |
| 1950 | ||
| 1951 | pub const GlobalVarExpression = struct { | |
| 1952 | pub const ops = [_]AbbrevOp{ | |
| 1953 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.GLOBAL_VAR_EXPR) }, | |
| 1954 | .{ .literal = 0 }, // is distinct | |
| 1955 | MetadataAbbrev, // variable | |
| 1956 | MetadataAbbrev, // expression | |
| 1957 | }; | |
| 1958 | ||
| 1959 | variable: Builder.Metadata.Optional, | |
| 1960 | expression: Builder.Metadata.Optional, | |
| 1961 | }; | |
| 1962 | ||
| 1963 | pub const Constant = struct { | |
| 1964 | pub const ops = [_]AbbrevOp{ | |
| 1965 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.VALUE) }, | |
| 1966 | MetadataAbbrev, // type | |
| 1967 | MetadataAbbrev, // value | |
| 1968 | }; | |
| 1969 | ||
| 1970 | ty: Builder.Type, | |
| 1971 | constant: Builder.Constant, | |
| 1972 | }; | |
| 1973 | ||
| 1974 | pub const Name = struct { | |
| 1975 | pub const ops = [_]AbbrevOp{ | |
| 1976 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.NAME) }, | |
| 1977 | .{ .array_fixed = 8 }, // name | |
| 1978 | }; | |
| 1979 | ||
| 1980 | name: []const u8, | |
| 1981 | }; | |
| 1982 | ||
| 1983 | pub const NamedNode = struct { | |
| 1984 | pub const ops = [_]AbbrevOp{ | |
| 1985 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.NAMED_NODE) }, | |
| 1986 | MetadataArrayAbbrev, // elements | |
| 1987 | }; | |
| 1988 | ||
| 1989 | elements: []const Builder.Metadata, | |
| 1990 | }; | |
| 1991 | ||
| 1992 | pub const GlobalDeclAttachment = struct { | |
| 1993 | pub const ops = [_]AbbrevOp{ | |
| 1994 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.GLOBAL_DECL_ATTACHMENT) }, | |
| 1995 | ValueAbbrev, // value id | |
| 1996 | .{ .fixed = 1 }, // kind | |
| 1997 | MetadataAbbrev, // elements | |
| 1998 | }; | |
| 1999 | ||
| 2000 | value: Builder.Constant, | |
| 2001 | kind: FixedMetadataKind, | |
| 2002 | metadata: Builder.Metadata, | |
| 2003 | }; | |
| 2004 | }; | |
| 2005 | ||
| 2006 | /// TYPE blocks have codes for each type primitive they use. | |
| 2007 | pub const TypeBlock = struct { | |
| 2008 | pub const id: BlockId = .TYPE; | |
| 2009 | ||
| 2010 | pub const abbrevs = [_]type{ | |
| 2011 | ModuleBlock.TypeBlock.NumEntry, | |
| 2012 | ModuleBlock.TypeBlock.Simple, | |
| 2013 | ModuleBlock.TypeBlock.Opaque, | |
| 2014 | ModuleBlock.TypeBlock.Integer, | |
| 2015 | ModuleBlock.TypeBlock.StructAnon, | |
| 2016 | ModuleBlock.TypeBlock.StructNamed, | |
| 2017 | ModuleBlock.TypeBlock.StructName, | |
| 2018 | ModuleBlock.TypeBlock.Array, | |
| 2019 | ModuleBlock.TypeBlock.Vector, | |
| 2020 | ModuleBlock.TypeBlock.Pointer, | |
| 2021 | ModuleBlock.TypeBlock.Target, | |
| 2022 | ModuleBlock.TypeBlock.Function, | |
| 2023 | }; | |
| 2024 | ||
| 2025 | pub const Code = enum(u5) { | |
| 2026 | /// NUMENTRY: [numentries] | |
| 2027 | NUMENTRY = 1, | |
| 2028 | ||
| 2029 | // Type Codes | |
| 2030 | /// VOID | |
| 2031 | VOID = 2, | |
| 2032 | /// FLOAT | |
| 2033 | FLOAT = 3, | |
| 2034 | /// DOUBLE | |
| 2035 | DOUBLE = 4, | |
| 2036 | /// LABEL | |
| 2037 | LABEL = 5, | |
| 2038 | /// OPAQUE | |
| 2039 | OPAQUE = 6, | |
| 2040 | /// INTEGER: [width] | |
| 2041 | INTEGER = 7, | |
| 2042 | /// POINTER: [pointee type] | |
| 2043 | POINTER = 8, | |
| 2044 | ||
| 2045 | /// FUNCTION: [vararg, attrid, retty, paramty x N] | |
| 2046 | FUNCTION_OLD = 9, | |
| 2047 | ||
| 2048 | /// HALF | |
| 2049 | HALF = 10, | |
| 2050 | ||
| 2051 | /// ARRAY: [numelts, eltty] | |
| 2052 | ARRAY = 11, | |
| 2053 | /// VECTOR: [numelts, eltty] | |
| 2054 | VECTOR = 12, | |
| 2055 | ||
| 2056 | // These are not with the other floating point types because they're | |
| 2057 | // a late addition, and putting them in the right place breaks | |
| 2058 | // binary compatibility. | |
| 2059 | /// X86 LONG DOUBLE | |
| 2060 | X86_FP80 = 13, | |
| 2061 | /// LONG DOUBLE (112 bit mantissa) | |
| 2062 | FP128 = 14, | |
| 2063 | /// PPC LONG DOUBLE (2 doubles) | |
| 2064 | PPC_FP128 = 15, | |
| 2065 | ||
| 2066 | /// METADATA | |
| 2067 | METADATA = 16, | |
| 2068 | ||
| 2069 | /// X86 MMX | |
| 2070 | X86_MMX = 17, | |
| 2071 | ||
| 2072 | /// STRUCT_ANON: [ispacked, eltty x N] | |
| 2073 | STRUCT_ANON = 18, | |
| 2074 | /// STRUCT_NAME: [strchr x N] | |
| 2075 | STRUCT_NAME = 19, | |
| 2076 | /// STRUCT_NAMED: [ispacked, eltty x N] | |
| 2077 | STRUCT_NAMED = 20, | |
| 2078 | ||
| 2079 | /// FUNCTION: [vararg, retty, paramty x N] | |
| 2080 | FUNCTION = 21, | |
| 2081 | ||
| 2082 | /// TOKEN | |
| 2083 | TOKEN = 22, | |
| 2084 | ||
| 2085 | /// BRAIN FLOATING POINT | |
| 2086 | BFLOAT = 23, | |
| 2087 | /// X86 AMX | |
| 2088 | X86_AMX = 24, | |
| 2089 | ||
| 2090 | /// OPAQUE_POINTER: [addrspace] | |
| 2091 | OPAQUE_POINTER = 25, | |
| 2092 | ||
| 2093 | /// TARGET_TYPE | |
| 2094 | TARGET_TYPE = 26, | |
| 2095 | }; | |
| 2096 | ||
| 2097 | pub const NumEntry = struct { | |
| 2098 | pub const ops = [_]AbbrevOp{ | |
| 2099 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.NUMENTRY) }, | |
| 2100 | .{ .fixed = 32 }, | |
| 2101 | }; | |
| 2102 | num: u32, | |
| 2103 | }; | |
| 2104 | ||
| 2105 | pub const Simple = struct { | |
| 2106 | pub const ops = [_]AbbrevOp{ | |
| 2107 | .{ .vbr = 4 }, | |
| 2108 | }; | |
| 2109 | code: ModuleBlock.TypeBlock.Code, | |
| 2110 | }; | |
| 2111 | ||
| 2112 | pub const Opaque = struct { | |
| 2113 | pub const ops = [_]AbbrevOp{ | |
| 2114 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.OPAQUE) }, | |
| 2115 | .{ .literal = 0 }, | |
| 2116 | }; | |
| 2117 | }; | |
| 2118 | ||
| 2119 | pub const Integer = struct { | |
| 2120 | pub const ops = [_]AbbrevOp{ | |
| 2121 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.INTEGER) }, | |
| 2122 | .{ .fixed = 28 }, | |
| 2123 | }; | |
| 2124 | width: u28, | |
| 2125 | }; | |
| 2126 | ||
| 2127 | pub const StructAnon = struct { | |
| 2128 | pub const ops = [_]AbbrevOp{ | |
| 2129 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.STRUCT_ANON) }, | |
| 2130 | .{ .fixed = 1 }, | |
| 2131 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2132 | }; | |
| 2133 | is_packed: bool, | |
| 2134 | types: []const Builder.Type, | |
| 2135 | }; | |
| 2136 | ||
| 2137 | pub const StructNamed = struct { | |
| 2138 | pub const ops = [_]AbbrevOp{ | |
| 2139 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.STRUCT_NAMED) }, | |
| 2140 | .{ .fixed = 1 }, | |
| 2141 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2142 | }; | |
| 2143 | is_packed: bool, | |
| 2144 | types: []const Builder.Type, | |
| 2145 | }; | |
| 2146 | ||
| 2147 | pub const StructName = struct { | |
| 2148 | pub const ops = [_]AbbrevOp{ | |
| 2149 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.STRUCT_NAME) }, | |
| 2150 | .{ .array_fixed = 8 }, | |
| 2151 | }; | |
| 2152 | string: []const u8, | |
| 2153 | }; | |
| 2154 | ||
| 2155 | pub const Array = struct { | |
| 2156 | pub const ops = [_]AbbrevOp{ | |
| 2157 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.ARRAY) }, | |
| 2158 | .{ .vbr = 16 }, | |
| 2159 | .{ .fixed_runtime = Builder.Type }, | |
| 2160 | }; | |
| 2161 | len: u64, | |
| 2162 | child: Builder.Type, | |
| 2163 | }; | |
| 2164 | ||
| 2165 | pub const Vector = struct { | |
| 2166 | pub const ops = [_]AbbrevOp{ | |
| 2167 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.VECTOR) }, | |
| 2168 | .{ .vbr = 16 }, | |
| 2169 | .{ .fixed_runtime = Builder.Type }, | |
| 2170 | }; | |
| 2171 | len: u64, | |
| 2172 | child: Builder.Type, | |
| 2173 | }; | |
| 2174 | ||
| 2175 | pub const Pointer = struct { | |
| 2176 | pub const ops = [_]AbbrevOp{ | |
| 2177 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.OPAQUE_POINTER) }, | |
| 2178 | .{ .vbr = 4 }, | |
| 2179 | }; | |
| 2180 | addr_space: Builder.AddrSpace, | |
| 376 | 2181 | }; |
| 377 | width: u28, | |
| 378 | }; | |
| 379 | 2182 | |
| 380 | pub const StructAnon = struct { | |
| 381 | pub const ops = [_]AbbrevOp{ | |
| 382 | .{ .literal = 18 }, | |
| 383 | .{ .fixed = 1 }, | |
| 384 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2183 | pub const Target = struct { | |
| 2184 | pub const ops = [_]AbbrevOp{ | |
| 2185 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.TARGET_TYPE) }, | |
| 2186 | .{ .vbr = 4 }, | |
| 2187 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2188 | .{ .array_fixed = 32 }, | |
| 2189 | }; | |
| 2190 | num_types: u32, | |
| 2191 | types: []const Builder.Type, | |
| 2192 | ints: []const u32, | |
| 385 | 2193 | }; |
| 386 | is_packed: bool, | |
| 387 | types: []const Builder.Type, | |
| 388 | }; | |
| 389 | 2194 | |
| 390 | pub const StructNamed = struct { | |
| 391 | pub const ops = [_]AbbrevOp{ | |
| 392 | .{ .literal = 20 }, | |
| 393 | .{ .fixed = 1 }, | |
| 394 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2195 | pub const Function = struct { | |
| 2196 | pub const ops = [_]AbbrevOp{ | |
| 2197 | .{ .literal = @intFromEnum(ModuleBlock.TypeBlock.Code.FUNCTION) }, | |
| 2198 | .{ .fixed = 1 }, | |
| 2199 | .{ .fixed_runtime = Builder.Type }, | |
| 2200 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2201 | }; | |
| 2202 | is_vararg: bool, | |
| 2203 | return_type: Builder.Type, | |
| 2204 | param_types: []const Builder.Type, | |
| 395 | 2205 | }; |
| 396 | is_packed: bool, | |
| 397 | types: []const Builder.Type, | |
| 398 | 2206 | }; |
| 399 | 2207 | |
| 400 | pub const StructName = struct { | |
| 401 | pub const ops = [_]AbbrevOp{ | |
| 402 | .{ .literal = 19 }, | |
| 403 | .{ .array_fixed = 8 }, | |
| 404 | }; | |
| 405 | string: []const u8, | |
| 406 | }; | |
| 2208 | pub const OperandBundleTagsBlock = struct { | |
| 2209 | pub const id: BlockId = .OPERAND_BUNDLE_TAGS; | |
| 407 | 2210 | |
| 408 | pub const Array = struct { | |
| 409 | pub const ops = [_]AbbrevOp{ | |
| 410 | .{ .literal = 11 }, | |
| 411 | .{ .vbr = 16 }, | |
| 412 | .{ .fixed_runtime = Builder.Type }, | |
| 2211 | pub const abbrevs = [_]type{ | |
| 2212 | ModuleBlock.OperandBundleTagsBlock.OperandBundleTag, | |
| 413 | 2213 | }; |
| 414 | len: u64, | |
| 415 | child: Builder.Type, | |
| 416 | }; | |
| 417 | 2214 | |
| 418 | pub const Vector = struct { | |
| 419 | pub const ops = [_]AbbrevOp{ | |
| 420 | .{ .literal = 12 }, | |
| 421 | .{ .vbr = 16 }, | |
| 422 | .{ .fixed_runtime = Builder.Type }, | |
| 2215 | pub const Code = enum(u1) { | |
| 2216 | /// TAG: [strchr x N] | |
| 2217 | OPERAND_BUNDLE_TAG = 1, | |
| 423 | 2218 | }; |
| 424 | len: u64, | |
| 425 | child: Builder.Type, | |
| 426 | }; | |
| 427 | 2219 | |
| 428 | pub const Pointer = struct { | |
| 429 | pub const ops = [_]AbbrevOp{ | |
| 430 | .{ .literal = 25 }, | |
| 431 | .{ .vbr = 4 }, | |
| 2220 | pub const OperandBundleTag = struct { | |
| 2221 | pub const ops = [_]AbbrevOp{ | |
| 2222 | .{ .literal = @intFromEnum(ModuleBlock.OperandBundleTagsBlock.Code.OPERAND_BUNDLE_TAG) }, | |
| 2223 | .array_char6, | |
| 2224 | }; | |
| 2225 | tag: []const u8, | |
| 432 | 2226 | }; |
| 433 | addr_space: Builder.AddrSpace, | |
| 434 | 2227 | }; |
| 435 | 2228 | |
| 436 | pub const Target = struct { | |
| 437 | pub const ops = [_]AbbrevOp{ | |
| 438 | .{ .literal = 26 }, | |
| 439 | .{ .vbr = 4 }, | |
| 440 | .{ .array_fixed_runtime = Builder.Type }, | |
| 441 | .{ .array_fixed = 32 }, | |
| 442 | }; | |
| 443 | num_types: u32, | |
| 444 | types: []const Builder.Type, | |
| 445 | ints: []const u32, | |
| 446 | }; | |
| 2229 | pub const MetadataKindBlock = struct { | |
| 2230 | pub const id: BlockId = .METADATA_KIND; | |
| 447 | 2231 | |
| 448 | pub const Function = struct { | |
| 449 | pub const ops = [_]AbbrevOp{ | |
| 450 | .{ .literal = 21 }, | |
| 451 | .{ .fixed = 1 }, | |
| 452 | .{ .fixed_runtime = Builder.Type }, | |
| 453 | .{ .array_fixed_runtime = Builder.Type }, | |
| 2232 | pub const abbrevs = [_]type{ | |
| 2233 | ModuleBlock.MetadataKindBlock.Kind, | |
| 454 | 2234 | }; |
| 455 | is_vararg: bool, | |
| 456 | return_type: Builder.Type, | |
| 457 | param_types: []const Builder.Type, | |
| 458 | }; | |
| 459 | }; | |
| 460 | ||
| 461 | pub const Paramattr = struct { | |
| 462 | pub const id = 9; | |
| 463 | ||
| 464 | pub const abbrevs = [_]type{ | |
| 465 | Entry, | |
| 466 | }; | |
| 467 | 2235 | |
| 468 | pub const Entry = struct { | |
| 469 | pub const ops = [_]AbbrevOp{ | |
| 470 | .{ .literal = 2 }, | |
| 471 | .{ .array_vbr = 8 }, | |
| 2236 | pub const Kind = struct { | |
| 2237 | pub const ops = [_]AbbrevOp{ | |
| 2238 | .{ .literal = @intFromEnum(ModuleBlock.MetadataBlock.Code.KIND) }, | |
| 2239 | .{ .vbr = 4 }, | |
| 2240 | .{ .array_fixed = 8 }, | |
| 2241 | }; | |
| 2242 | id: u32, | |
| 2243 | name: []const u8, | |
| 472 | 2244 | }; |
| 473 | group_indices: []const u64, | |
| 474 | 2245 | }; |
| 475 | 2246 | }; |
| 476 | 2247 | |
| 477 | pub const ParamattrGroup = struct { | |
| 478 | pub const id = 10; | |
| 479 | ||
| 480 | pub const abbrevs = [_]type{}; | |
| 481 | }; | |
| 482 | ||
| 483 | pub const Constants = struct { | |
| 484 | pub const id = 11; | |
| 2248 | /// Identification block contains a string that describes the producer details, | |
| 2249 | /// and an epoch that defines the auto-upgrade capability. | |
| 2250 | pub const IdentificationBlock = struct { | |
| 2251 | pub const id: BlockId = .IDENTIFICATION; | |
| 485 | 2252 | |
| 486 | 2253 | pub const abbrevs = [_]type{ |
| 487 | SetType, | |
| 488 | Null, | |
| 489 | Undef, | |
| 490 | Poison, | |
| 491 | Integer, | |
| 492 | Half, | |
| 493 | Float, | |
| 494 | Double, | |
| 495 | Fp80, | |
| 496 | Fp128, | |
| 497 | Aggregate, | |
| 498 | String, | |
| 499 | CString, | |
| 500 | Cast, | |
| 501 | Binary, | |
| 502 | Cmp, | |
| 503 | ExtractElement, | |
| 504 | InsertElement, | |
| 505 | ShuffleVector, | |
| 506 | ShuffleVectorEx, | |
| 507 | BlockAddress, | |
| 508 | DsoLocalEquivalentOrNoCfi, | |
| 509 | }; | |
| 510 | ||
| 511 | pub const SetType = struct { | |
| 512 | pub const ops = [_]AbbrevOp{ | |
| 513 | .{ .literal = 1 }, | |
| 514 | .{ .fixed_runtime = Builder.Type }, | |
| 515 | }; | |
| 516 | type_id: Builder.Type, | |
| 517 | }; | |
| 518 | ||
| 519 | pub const Null = struct { | |
| 520 | pub const ops = [_]AbbrevOp{ | |
| 521 | .{ .literal = 2 }, | |
| 522 | }; | |
| 523 | }; | |
| 524 | ||
| 525 | pub const Undef = struct { | |
| 526 | pub const ops = [_]AbbrevOp{ | |
| 527 | .{ .literal = 3 }, | |
| 528 | }; | |
| 529 | }; | |
| 530 | ||
| 531 | pub const Poison = struct { | |
| 532 | pub const ops = [_]AbbrevOp{ | |
| 533 | .{ .literal = 26 }, | |
| 534 | }; | |
| 535 | }; | |
| 536 | ||
| 537 | pub const Integer = struct { | |
| 538 | pub const ops = [_]AbbrevOp{ | |
| 539 | .{ .literal = 4 }, | |
| 540 | .{ .vbr = 16 }, | |
| 541 | }; | |
| 542 | value: u64, | |
| 543 | }; | |
| 544 | ||
| 545 | pub const Half = struct { | |
| 546 | pub const ops = [_]AbbrevOp{ | |
| 547 | .{ .literal = 6 }, | |
| 548 | .{ .fixed = 16 }, | |
| 549 | }; | |
| 550 | value: u16, | |
| 551 | }; | |
| 552 | ||
| 553 | pub const Float = struct { | |
| 554 | pub const ops = [_]AbbrevOp{ | |
| 555 | .{ .literal = 6 }, | |
| 556 | .{ .fixed = 32 }, | |
| 557 | }; | |
| 558 | value: u32, | |
| 559 | }; | |
| 560 | ||
| 561 | pub const Double = struct { | |
| 562 | pub const ops = [_]AbbrevOp{ | |
| 563 | .{ .literal = 6 }, | |
| 564 | .{ .vbr = 6 }, | |
| 565 | }; | |
| 566 | value: u64, | |
| 567 | }; | |
| 568 | ||
| 569 | pub const Fp80 = struct { | |
| 570 | pub const ops = [_]AbbrevOp{ | |
| 571 | .{ .literal = 6 }, | |
| 572 | .{ .vbr = 6 }, | |
| 573 | .{ .vbr = 6 }, | |
| 574 | }; | |
| 575 | hi: u64, | |
| 576 | lo: u16, | |
| 577 | }; | |
| 578 | ||
| 579 | pub const Fp128 = struct { | |
| 580 | pub const ops = [_]AbbrevOp{ | |
| 581 | .{ .literal = 6 }, | |
| 582 | .{ .vbr = 6 }, | |
| 583 | .{ .vbr = 6 }, | |
| 584 | }; | |
| 585 | lo: u64, | |
| 586 | hi: u64, | |
| 587 | }; | |
| 588 | ||
| 589 | pub const Aggregate = struct { | |
| 590 | pub const ops = [_]AbbrevOp{ | |
| 591 | .{ .literal = 7 }, | |
| 592 | .{ .array_fixed = 32 }, | |
| 593 | }; | |
| 594 | values: []const Builder.Constant, | |
| 2254 | IdentificationBlock.Version, | |
| 2255 | IdentificationBlock.Epoch, | |
| 595 | 2256 | }; |
| 596 | 2257 | |
| 597 | pub const String = struct { | |
| 598 | pub const ops = [_]AbbrevOp{ | |
| 599 | .{ .literal = 8 }, | |
| 600 | .{ .array_fixed = 8 }, | |
| 601 | }; | |
| 602 | string: []const u8, | |
| 2258 | pub const Code = enum(u2) { | |
| 2259 | /// IDENTIFICATION: [strchr x N] | |
| 2260 | STRING = 1, | |
| 2261 | /// EPOCH: [epoch#] | |
| 2262 | EPOCH = 2, | |
| 603 | 2263 | }; |
| 604 | 2264 | |
| 605 | pub const CString = struct { | |
| 2265 | pub const Version = struct { | |
| 606 | 2266 | pub const ops = [_]AbbrevOp{ |
| 607 | .{ .literal = 9 }, | |
| 2267 | .{ .literal = @intFromEnum(IdentificationBlock.Code.STRING) }, | |
| 608 | 2268 | .{ .array_fixed = 8 }, |
| 609 | 2269 | }; |
| 610 | 2270 | string: []const u8, |
| 611 | 2271 | }; |
| 612 | 2272 | |
| 613 | pub const Cast = struct { | |
| 614 | const CastOpcode = Builder.CastOpcode; | |
| 615 | pub const ops = [_]AbbrevOp{ | |
| 616 | .{ .literal = 11 }, | |
| 617 | .{ .fixed = @bitSizeOf(CastOpcode) }, | |
| 618 | .{ .fixed_runtime = Builder.Type }, | |
| 619 | ConstantAbbrev, | |
| 620 | }; | |
| 621 | ||
| 622 | opcode: CastOpcode, | |
| 623 | type_index: Builder.Type, | |
| 624 | val: Builder.Constant, | |
| 625 | }; | |
| 626 | ||
| 627 | pub const Binary = struct { | |
| 628 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 629 | pub const ops = [_]AbbrevOp{ | |
| 630 | .{ .literal = 10 }, | |
| 631 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 632 | ConstantAbbrev, | |
| 633 | ConstantAbbrev, | |
| 634 | }; | |
| 635 | ||
| 636 | opcode: BinaryOpcode, | |
| 637 | lhs: Builder.Constant, | |
| 638 | rhs: Builder.Constant, | |
| 639 | }; | |
| 640 | ||
| 641 | pub const Cmp = struct { | |
| 2273 | pub const Epoch = struct { | |
| 642 | 2274 | pub const ops = [_]AbbrevOp{ |
| 643 | .{ .literal = 17 }, | |
| 644 | .{ .fixed_runtime = Builder.Type }, | |
| 645 | ConstantAbbrev, | |
| 646 | ConstantAbbrev, | |
| 2275 | .{ .literal = @intFromEnum(IdentificationBlock.Code.EPOCH) }, | |
| 647 | 2276 | .{ .vbr = 6 }, |
| 648 | 2277 | }; |
| 649 | ||
| 650 | ty: Builder.Type, | |
| 651 | lhs: Builder.Constant, | |
| 652 | rhs: Builder.Constant, | |
| 653 | pred: u32, | |
| 654 | }; | |
| 655 | ||
| 656 | pub const ExtractElement = struct { | |
| 657 | pub const ops = [_]AbbrevOp{ | |
| 658 | .{ .literal = 14 }, | |
| 659 | .{ .fixed_runtime = Builder.Type }, | |
| 660 | ConstantAbbrev, | |
| 661 | .{ .fixed_runtime = Builder.Type }, | |
| 662 | ConstantAbbrev, | |
| 663 | }; | |
| 664 | ||
| 665 | val_type: Builder.Type, | |
| 666 | val: Builder.Constant, | |
| 667 | index_type: Builder.Type, | |
| 668 | index: Builder.Constant, | |
| 669 | }; | |
| 670 | ||
| 671 | pub const InsertElement = struct { | |
| 672 | pub const ops = [_]AbbrevOp{ | |
| 673 | .{ .literal = 15 }, | |
| 674 | ConstantAbbrev, | |
| 675 | ConstantAbbrev, | |
| 676 | .{ .fixed_runtime = Builder.Type }, | |
| 677 | ConstantAbbrev, | |
| 678 | }; | |
| 679 | ||
| 680 | val: Builder.Constant, | |
| 681 | elem: Builder.Constant, | |
| 682 | index_type: Builder.Type, | |
| 683 | index: Builder.Constant, | |
| 684 | }; | |
| 685 | ||
| 686 | pub const ShuffleVector = struct { | |
| 687 | pub const ops = [_]AbbrevOp{ | |
| 688 | .{ .literal = 16 }, | |
| 689 | ValueAbbrev, | |
| 690 | ValueAbbrev, | |
| 691 | ValueAbbrev, | |
| 692 | }; | |
| 693 | ||
| 694 | lhs: Builder.Constant, | |
| 695 | rhs: Builder.Constant, | |
| 696 | mask: Builder.Constant, | |
| 697 | }; | |
| 698 | ||
| 699 | pub const ShuffleVectorEx = struct { | |
| 700 | pub const ops = [_]AbbrevOp{ | |
| 701 | .{ .literal = 19 }, | |
| 702 | .{ .fixed_runtime = Builder.Type }, | |
| 703 | ValueAbbrev, | |
| 704 | ValueAbbrev, | |
| 705 | ValueAbbrev, | |
| 706 | }; | |
| 707 | ||
| 708 | ty: Builder.Type, | |
| 709 | lhs: Builder.Constant, | |
| 710 | rhs: Builder.Constant, | |
| 711 | mask: Builder.Constant, | |
| 712 | }; | |
| 713 | ||
| 714 | pub const BlockAddress = struct { | |
| 715 | pub const ops = [_]AbbrevOp{ | |
| 716 | .{ .literal = 21 }, | |
| 717 | .{ .fixed_runtime = Builder.Type }, | |
| 718 | ConstantAbbrev, | |
| 719 | BlockAbbrev, | |
| 720 | }; | |
| 721 | type_id: Builder.Type, | |
| 722 | function: u32, | |
| 723 | block: u32, | |
| 724 | }; | |
| 725 | ||
| 726 | pub const DsoLocalEquivalentOrNoCfi = struct { | |
| 727 | pub const ops = [_]AbbrevOp{ | |
| 728 | .{ .fixed = 5 }, | |
| 729 | .{ .fixed_runtime = Builder.Type }, | |
| 730 | ConstantAbbrev, | |
| 731 | }; | |
| 732 | code: u5, | |
| 733 | type_id: Builder.Type, | |
| 734 | function: u32, | |
| 735 | }; | |
| 736 | }; | |
| 737 | ||
| 738 | pub const MetadataKindBlock = struct { | |
| 739 | pub const id = 22; | |
| 740 | ||
| 741 | pub const abbrevs = [_]type{ | |
| 742 | Kind, | |
| 743 | }; | |
| 744 | ||
| 745 | pub const Kind = struct { | |
| 746 | pub const ops = [_]AbbrevOp{ | |
| 747 | .{ .literal = 6 }, | |
| 748 | .{ .vbr = 4 }, | |
| 749 | .{ .array_fixed = 8 }, | |
| 750 | }; | |
| 751 | id: u32, | |
| 752 | name: []const u8, | |
| 753 | }; | |
| 754 | }; | |
| 755 | ||
| 756 | pub const MetadataAttachmentBlock = struct { | |
| 757 | pub const id = 16; | |
| 758 | ||
| 759 | pub const abbrevs = [_]type{ | |
| 760 | AttachmentGlobalSingle, | |
| 761 | AttachmentInstructionSingle, | |
| 762 | }; | |
| 763 | ||
| 764 | pub const AttachmentGlobalSingle = struct { | |
| 765 | pub const ops = [_]AbbrevOp{ | |
| 766 | .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) }, | |
| 767 | .{ .fixed = 1 }, | |
| 768 | MetadataAbbrev, | |
| 769 | }; | |
| 770 | kind: FixedMetadataKind, | |
| 771 | metadata: Builder.Metadata, | |
| 772 | }; | |
| 773 | ||
| 774 | pub const AttachmentInstructionSingle = struct { | |
| 775 | pub const ops = [_]AbbrevOp{ | |
| 776 | .{ .literal = @intFromEnum(MetadataCode.ATTACHMENT) }, | |
| 777 | ValueAbbrev, | |
| 778 | .{ .fixed = 5 }, | |
| 779 | MetadataAbbrev, | |
| 780 | }; | |
| 781 | inst: u32, | |
| 782 | kind: FixedMetadataKind, | |
| 783 | metadata: Builder.Metadata, | |
| 2278 | epoch: u32, | |
| 784 | 2279 | }; |
| 785 | 2280 | }; |
| 786 | 2281 | |
| 787 | pub const MetadataBlock = struct { | |
| 788 | pub const id = 15; | |
| 789 | ||
| 790 | pub const abbrevs = [_]type{ | |
| 791 | Strings, | |
| 792 | File, | |
| 793 | CompileUnit, | |
| 794 | Subprogram, | |
| 795 | LexicalBlock, | |
| 796 | Location, | |
| 797 | BasicType, | |
| 798 | CompositeType, | |
| 799 | DerivedType, | |
| 800 | SubroutineType, | |
| 801 | Enumerator, | |
| 802 | Subrange, | |
| 803 | Expression, | |
| 804 | Node, | |
| 805 | LocalVar, | |
| 806 | Parameter, | |
| 807 | GlobalVar, | |
| 808 | GlobalVarExpression, | |
| 809 | Constant, | |
| 810 | Name, | |
| 811 | NamedNode, | |
| 812 | GlobalDeclAttachment, | |
| 813 | }; | |
| 814 | ||
| 815 | pub const Strings = struct { | |
| 816 | pub const ops = [_]AbbrevOp{ | |
| 817 | .{ .literal = @intFromEnum(MetadataCode.STRINGS) }, | |
| 818 | .{ .vbr = 6 }, | |
| 819 | .{ .vbr = 6 }, | |
| 820 | .blob, | |
| 821 | }; | |
| 822 | num_strings: u32, | |
| 823 | strings_offset: u32, | |
| 824 | blob: []const u8, | |
| 825 | }; | |
| 826 | ||
| 827 | pub const File = struct { | |
| 828 | pub const ops = [_]AbbrevOp{ | |
| 829 | .{ .literal = @intFromEnum(MetadataCode.FILE) }, | |
| 830 | .{ .literal = 0 }, // is distinct | |
| 831 | MetadataAbbrev, // filename | |
| 832 | MetadataAbbrev, // directory | |
| 833 | .{ .literal = 0 }, // checksum | |
| 834 | .{ .literal = 0 }, // checksum | |
| 835 | }; | |
| 2282 | pub const StrtabBlock = struct { | |
| 2283 | pub const id: BlockId = .STRTAB; | |
| 836 | 2284 | |
| 837 | filename: Builder.MetadataString, | |
| 838 | directory: Builder.MetadataString, | |
| 839 | }; | |
| 2285 | pub const abbrevs = [_]type{Blob}; | |
| 840 | 2286 | |
| 841 | pub const CompileUnit = struct { | |
| 842 | pub const ops = [_]AbbrevOp{ | |
| 843 | .{ .literal = @intFromEnum(MetadataCode.COMPILE_UNIT) }, | |
| 844 | .{ .literal = 1 }, // is distinct | |
| 845 | .{ .literal = std.dwarf.LANG.C99 }, // source language | |
| 846 | MetadataAbbrev, // file | |
| 847 | MetadataAbbrev, // producer | |
| 848 | .{ .fixed = 1 }, // isOptimized | |
| 849 | .{ .literal = 0 }, // raw flags | |
| 850 | .{ .literal = 0 }, // runtime version | |
| 851 | .{ .literal = 0 }, // split debug file name | |
| 852 | .{ .literal = 1 }, // emission kind | |
| 853 | MetadataAbbrev, // enums | |
| 854 | .{ .literal = 0 }, // retained types | |
| 855 | .{ .literal = 0 }, // subprograms | |
| 856 | MetadataAbbrev, // globals | |
| 857 | .{ .literal = 0 }, // imported entities | |
| 858 | .{ .literal = 0 }, // DWO ID | |
| 859 | .{ .literal = 0 }, // macros | |
| 860 | .{ .literal = 0 }, // split debug inlining | |
| 861 | .{ .literal = 0 }, // debug info profiling | |
| 862 | .{ .literal = 0 }, // name table kind | |
| 863 | .{ .literal = 0 }, // ranges base address | |
| 864 | .{ .literal = 0 }, // raw sysroot | |
| 865 | .{ .literal = 0 }, // raw SDK | |
| 866 | }; | |
| 867 | ||
| 868 | file: Builder.Metadata, | |
| 869 | producer: Builder.MetadataString, | |
| 870 | is_optimized: bool, | |
| 871 | enums: Builder.Metadata, | |
| 872 | globals: Builder.Metadata, | |
| 2287 | pub const Code = enum(u1) { | |
| 2288 | BLOB = 1, | |
| 873 | 2289 | }; |
| 874 | 2290 | |
| 875 | pub const Subprogram = struct { | |
| 876 | pub const ops = [_]AbbrevOp{ | |
| 877 | .{ .literal = @intFromEnum(MetadataCode.SUBPROGRAM) }, | |
| 878 | .{ .literal = 0b111 }, // is distinct | has sp flags | has flags | |
| 879 | MetadataAbbrev, // scope | |
| 880 | MetadataAbbrev, // name | |
| 881 | MetadataAbbrev, // linkage name | |
| 882 | MetadataAbbrev, // file | |
| 883 | LineAbbrev, // line | |
| 884 | MetadataAbbrev, // type | |
| 885 | LineAbbrev, // scope line | |
| 886 | .{ .literal = 0 }, // containing type | |
| 887 | .{ .fixed = 32 }, // sp flags | |
| 888 | .{ .literal = 0 }, // virtual index | |
| 889 | .{ .fixed = 32 }, // flags | |
| 890 | MetadataAbbrev, // compile unit | |
| 891 | .{ .literal = 0 }, // template params | |
| 892 | .{ .literal = 0 }, // declaration | |
| 893 | .{ .literal = 0 }, // retained nodes | |
| 894 | .{ .literal = 0 }, // this adjustment | |
| 895 | .{ .literal = 0 }, // thrown types | |
| 896 | .{ .literal = 0 }, // annotations | |
| 897 | .{ .literal = 0 }, // target function name | |
| 898 | }; | |
| 899 | ||
| 900 | scope: Builder.Metadata, | |
| 901 | name: Builder.MetadataString, | |
| 902 | linkage_name: Builder.MetadataString, | |
| 903 | file: Builder.Metadata, | |
| 904 | line: u32, | |
| 905 | ty: Builder.Metadata, | |
| 906 | scope_line: u32, | |
| 907 | sp_flags: Builder.Metadata.Subprogram.DISPFlags, | |
| 908 | flags: Builder.Metadata.DIFlags, | |
| 909 | compile_unit: Builder.Metadata, | |
| 910 | }; | |
| 911 | ||
| 912 | pub const LexicalBlock = struct { | |
| 913 | pub const ops = [_]AbbrevOp{ | |
| 914 | .{ .literal = @intFromEnum(MetadataCode.LEXICAL_BLOCK) }, | |
| 915 | .{ .literal = 0 }, // is distinct | |
| 916 | MetadataAbbrev, // scope | |
| 917 | MetadataAbbrev, // file | |
| 918 | LineAbbrev, // line | |
| 919 | ColumnAbbrev, // column | |
| 920 | }; | |
| 921 | ||
| 922 | scope: Builder.Metadata, | |
| 923 | file: Builder.Metadata, | |
| 924 | line: u32, | |
| 925 | column: u32, | |
| 926 | }; | |
| 927 | ||
| 928 | pub const Location = struct { | |
| 929 | pub const ops = [_]AbbrevOp{ | |
| 930 | .{ .literal = @intFromEnum(MetadataCode.LOCATION) }, | |
| 931 | .{ .literal = 0 }, // is distinct | |
| 932 | LineAbbrev, // line | |
| 933 | ColumnAbbrev, // column | |
| 934 | MetadataAbbrev, // scope | |
| 935 | MetadataAbbrev, // inlined at | |
| 936 | .{ .literal = 0 }, // is implicit code | |
| 937 | }; | |
| 938 | ||
| 939 | line: u32, | |
| 940 | column: u32, | |
| 941 | scope: u32, | |
| 942 | inlined_at: Builder.Metadata, | |
| 943 | }; | |
| 944 | ||
| 945 | pub const BasicType = struct { | |
| 946 | pub const ops = [_]AbbrevOp{ | |
| 947 | .{ .literal = @intFromEnum(MetadataCode.BASIC_TYPE) }, | |
| 948 | .{ .literal = 0 }, // is distinct | |
| 949 | .{ .literal = std.dwarf.TAG.base_type }, // tag | |
| 950 | MetadataAbbrev, // name | |
| 951 | .{ .vbr = 6 }, // size in bits | |
| 952 | .{ .literal = 0 }, // align in bits | |
| 953 | .{ .vbr = 8 }, // encoding | |
| 954 | .{ .literal = 0 }, // flags | |
| 955 | }; | |
| 956 | ||
| 957 | name: Builder.MetadataString, | |
| 958 | size_in_bits: u64, | |
| 959 | encoding: u32, | |
| 960 | }; | |
| 961 | ||
| 962 | pub const CompositeType = struct { | |
| 963 | pub const ops = [_]AbbrevOp{ | |
| 964 | .{ .literal = @intFromEnum(MetadataCode.COMPOSITE_TYPE) }, | |
| 965 | .{ .literal = 0 | 0x2 }, // is distinct | is not used in old type ref | |
| 966 | .{ .fixed = 32 }, // tag | |
| 967 | MetadataAbbrev, // name | |
| 968 | MetadataAbbrev, // file | |
| 969 | LineAbbrev, // line | |
| 970 | MetadataAbbrev, // scope | |
| 971 | MetadataAbbrev, // underlying type | |
| 972 | .{ .vbr = 6 }, // size in bits | |
| 973 | .{ .vbr = 6 }, // align in bits | |
| 974 | .{ .literal = 0 }, // offset in bits | |
| 975 | .{ .fixed = 32 }, // flags | |
| 976 | MetadataAbbrev, // elements | |
| 977 | .{ .literal = 0 }, // runtime lang | |
| 978 | .{ .literal = 0 }, // vtable holder | |
| 979 | .{ .literal = 0 }, // template params | |
| 980 | .{ .literal = 0 }, // raw id | |
| 981 | .{ .literal = 0 }, // discriminator | |
| 982 | .{ .literal = 0 }, // data location | |
| 983 | .{ .literal = 0 }, // associated | |
| 984 | .{ .literal = 0 }, // allocated | |
| 985 | .{ .literal = 0 }, // rank | |
| 986 | .{ .literal = 0 }, // annotations | |
| 987 | }; | |
| 988 | ||
| 989 | tag: u32, | |
| 990 | name: Builder.MetadataString, | |
| 991 | file: Builder.Metadata, | |
| 992 | line: u32, | |
| 993 | scope: Builder.Metadata, | |
| 994 | underlying_type: Builder.Metadata, | |
| 995 | size_in_bits: u64, | |
| 996 | align_in_bits: u64, | |
| 997 | flags: Builder.Metadata.DIFlags, | |
| 998 | elements: Builder.Metadata, | |
| 999 | }; | |
| 1000 | ||
| 1001 | pub const DerivedType = struct { | |
| 1002 | pub const ops = [_]AbbrevOp{ | |
| 1003 | .{ .literal = @intFromEnum(MetadataCode.DERIVED_TYPE) }, | |
| 1004 | .{ .literal = 0 }, // is distinct | |
| 1005 | .{ .fixed = 32 }, // tag | |
| 1006 | MetadataAbbrev, // name | |
| 1007 | MetadataAbbrev, // file | |
| 1008 | LineAbbrev, // line | |
| 1009 | MetadataAbbrev, // scope | |
| 1010 | MetadataAbbrev, // underlying type | |
| 1011 | .{ .vbr = 6 }, // size in bits | |
| 1012 | .{ .vbr = 6 }, // align in bits | |
| 1013 | .{ .vbr = 6 }, // offset in bits | |
| 1014 | .{ .literal = 0 }, // flags | |
| 1015 | .{ .literal = 0 }, // extra data | |
| 1016 | }; | |
| 1017 | ||
| 1018 | tag: u32, | |
| 1019 | name: Builder.MetadataString, | |
| 1020 | file: Builder.Metadata, | |
| 1021 | line: u32, | |
| 1022 | scope: Builder.Metadata, | |
| 1023 | underlying_type: Builder.Metadata, | |
| 1024 | size_in_bits: u64, | |
| 1025 | align_in_bits: u64, | |
| 1026 | offset_in_bits: u64, | |
| 1027 | }; | |
| 1028 | ||
| 1029 | pub const SubroutineType = struct { | |
| 1030 | pub const ops = [_]AbbrevOp{ | |
| 1031 | .{ .literal = @intFromEnum(MetadataCode.SUBROUTINE_TYPE) }, | |
| 1032 | .{ .literal = 0 | 0x2 }, // is distinct | has no old type refs | |
| 1033 | .{ .literal = 0 }, // flags | |
| 1034 | MetadataAbbrev, // types | |
| 1035 | .{ .literal = 0 }, // cc | |
| 1036 | }; | |
| 1037 | ||
| 1038 | types: Builder.Metadata, | |
| 1039 | }; | |
| 1040 | ||
| 1041 | pub const Enumerator = struct { | |
| 1042 | pub const id: MetadataCode = .ENUMERATOR; | |
| 1043 | ||
| 1044 | pub const Flags = packed struct(u3) { | |
| 1045 | distinct: bool = false, | |
| 1046 | unsigned: bool, | |
| 1047 | bigint: bool = true, | |
| 1048 | }; | |
| 1049 | ||
| 1050 | pub const ops = [_]AbbrevOp{ | |
| 1051 | .{ .literal = @intFromEnum(Enumerator.id) }, | |
| 1052 | .{ .fixed = @bitSizeOf(Flags) }, // flags | |
| 1053 | .{ .vbr = 6 }, // bit width | |
| 1054 | MetadataAbbrev, // name | |
| 1055 | .{ .vbr = 16 }, // integer value | |
| 1056 | }; | |
| 1057 | ||
| 1058 | flags: Flags, | |
| 1059 | bit_width: u32, | |
| 1060 | name: Builder.MetadataString, | |
| 1061 | value: u64, | |
| 1062 | }; | |
| 1063 | ||
| 1064 | pub const Subrange = struct { | |
| 1065 | pub const ops = [_]AbbrevOp{ | |
| 1066 | .{ .literal = @intFromEnum(MetadataCode.SUBRANGE) }, | |
| 1067 | .{ .literal = 0 | (2 << 1) }, // is distinct | version | |
| 1068 | MetadataAbbrev, // count | |
| 1069 | MetadataAbbrev, // lower bound | |
| 1070 | .{ .literal = 0 }, // upper bound | |
| 1071 | .{ .literal = 0 }, // stride | |
| 1072 | }; | |
| 1073 | ||
| 1074 | count: Builder.Metadata, | |
| 1075 | lower_bound: Builder.Metadata, | |
| 1076 | }; | |
| 1077 | ||
| 1078 | pub const Expression = struct { | |
| 1079 | pub const ops = [_]AbbrevOp{ | |
| 1080 | .{ .literal = @intFromEnum(MetadataCode.EXPRESSION) }, | |
| 1081 | .{ .literal = 0 | (3 << 1) }, // is distinct | version | |
| 1082 | MetadataArrayAbbrev, // elements | |
| 1083 | }; | |
| 1084 | ||
| 1085 | elements: []const u32, | |
| 1086 | }; | |
| 1087 | ||
| 1088 | pub const Node = struct { | |
| 1089 | pub const ops = [_]AbbrevOp{ | |
| 1090 | .{ .literal = @intFromEnum(MetadataCode.NODE) }, | |
| 1091 | MetadataArrayAbbrev, // elements | |
| 1092 | }; | |
| 1093 | ||
| 1094 | elements: []const Builder.Metadata, | |
| 1095 | }; | |
| 1096 | ||
| 1097 | pub const LocalVar = struct { | |
| 1098 | pub const ops = [_]AbbrevOp{ | |
| 1099 | .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) }, | |
| 1100 | .{ .literal = 0b10 }, // is distinct | has alignment | |
| 1101 | MetadataAbbrev, // scope | |
| 1102 | MetadataAbbrev, // name | |
| 1103 | MetadataAbbrev, // file | |
| 1104 | LineAbbrev, // line | |
| 1105 | MetadataAbbrev, // type | |
| 1106 | .{ .literal = 0 }, // arg | |
| 1107 | .{ .literal = 0 }, // flags | |
| 1108 | .{ .literal = 0 }, // align bits | |
| 1109 | .{ .literal = 0 }, // annotations | |
| 1110 | }; | |
| 1111 | ||
| 1112 | scope: Builder.Metadata, | |
| 1113 | name: Builder.MetadataString, | |
| 1114 | file: Builder.Metadata, | |
| 1115 | line: u32, | |
| 1116 | ty: Builder.Metadata, | |
| 1117 | }; | |
| 1118 | ||
| 1119 | pub const Parameter = struct { | |
| 1120 | pub const ops = [_]AbbrevOp{ | |
| 1121 | .{ .literal = @intFromEnum(MetadataCode.LOCAL_VAR) }, | |
| 1122 | .{ .literal = 0b10 }, // is distinct | has alignment | |
| 1123 | MetadataAbbrev, // scope | |
| 1124 | MetadataAbbrev, // name | |
| 1125 | MetadataAbbrev, // file | |
| 1126 | LineAbbrev, // line | |
| 1127 | MetadataAbbrev, // type | |
| 1128 | .{ .vbr = 4 }, // arg | |
| 1129 | .{ .literal = 0 }, // flags | |
| 1130 | .{ .literal = 0 }, // align bits | |
| 1131 | .{ .literal = 0 }, // annotations | |
| 1132 | }; | |
| 1133 | ||
| 1134 | scope: Builder.Metadata, | |
| 1135 | name: Builder.MetadataString, | |
| 1136 | file: Builder.Metadata, | |
| 1137 | line: u32, | |
| 1138 | ty: Builder.Metadata, | |
| 1139 | arg: u32, | |
| 1140 | }; | |
| 1141 | ||
| 1142 | pub const GlobalVar = struct { | |
| 1143 | pub const ops = [_]AbbrevOp{ | |
| 1144 | .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR) }, | |
| 1145 | .{ .literal = 0b101 }, // is distinct | version | |
| 1146 | MetadataAbbrev, // scope | |
| 1147 | MetadataAbbrev, // name | |
| 1148 | MetadataAbbrev, // linkage name | |
| 1149 | MetadataAbbrev, // file | |
| 1150 | LineAbbrev, // line | |
| 1151 | MetadataAbbrev, // type | |
| 1152 | .{ .fixed = 1 }, // local | |
| 1153 | .{ .literal = 1 }, // defined | |
| 1154 | .{ .literal = 0 }, // static data members declaration | |
| 1155 | .{ .literal = 0 }, // template params | |
| 1156 | .{ .literal = 0 }, // align in bits | |
| 1157 | .{ .literal = 0 }, // annotations | |
| 1158 | }; | |
| 1159 | ||
| 1160 | scope: Builder.Metadata, | |
| 1161 | name: Builder.MetadataString, | |
| 1162 | linkage_name: Builder.MetadataString, | |
| 1163 | file: Builder.Metadata, | |
| 1164 | line: u32, | |
| 1165 | ty: Builder.Metadata, | |
| 1166 | local: bool, | |
| 1167 | }; | |
| 1168 | ||
| 1169 | pub const GlobalVarExpression = struct { | |
| 1170 | pub const ops = [_]AbbrevOp{ | |
| 1171 | .{ .literal = @intFromEnum(MetadataCode.GLOBAL_VAR_EXPR) }, | |
| 1172 | .{ .literal = 0 }, // is distinct | |
| 1173 | MetadataAbbrev, // variable | |
| 1174 | MetadataAbbrev, // expression | |
| 1175 | }; | |
| 1176 | ||
| 1177 | variable: Builder.Metadata, | |
| 1178 | expression: Builder.Metadata, | |
| 1179 | }; | |
| 1180 | ||
| 1181 | pub const Constant = struct { | |
| 1182 | pub const ops = [_]AbbrevOp{ | |
| 1183 | .{ .literal = @intFromEnum(MetadataCode.VALUE) }, | |
| 1184 | MetadataAbbrev, // type | |
| 1185 | MetadataAbbrev, // value | |
| 1186 | }; | |
| 1187 | ||
| 1188 | ty: Builder.Type, | |
| 1189 | constant: Builder.Constant, | |
| 1190 | }; | |
| 1191 | ||
| 1192 | pub const Name = struct { | |
| 1193 | pub const ops = [_]AbbrevOp{ | |
| 1194 | .{ .literal = @intFromEnum(MetadataCode.NAME) }, | |
| 1195 | .{ .array_fixed = 8 }, // name | |
| 1196 | }; | |
| 1197 | ||
| 1198 | name: []const u8, | |
| 1199 | }; | |
| 1200 | ||
| 1201 | pub const NamedNode = struct { | |
| 1202 | pub const ops = [_]AbbrevOp{ | |
| 1203 | .{ .literal = @intFromEnum(MetadataCode.NAMED_NODE) }, | |
| 1204 | MetadataArrayAbbrev, // elements | |
| 1205 | }; | |
| 1206 | ||
| 1207 | elements: []const Builder.Metadata, | |
| 1208 | }; | |
| 1209 | ||
| 1210 | pub const GlobalDeclAttachment = struct { | |
| 1211 | pub const ops = [_]AbbrevOp{ | |
| 1212 | .{ .literal = @intFromEnum(MetadataCode.GLOBAL_DECL_ATTACHMENT) }, | |
| 1213 | ValueAbbrev, // value id | |
| 1214 | .{ .fixed = 1 }, // kind | |
| 1215 | MetadataAbbrev, // elements | |
| 1216 | }; | |
| 1217 | ||
| 1218 | value: Builder.Constant, | |
| 1219 | kind: FixedMetadataKind, | |
| 1220 | metadata: Builder.Metadata, | |
| 1221 | }; | |
| 1222 | }; | |
| 1223 | ||
| 1224 | pub const OperandBundleTags = struct { | |
| 1225 | pub const id = 21; | |
| 1226 | ||
| 1227 | pub const abbrevs = [_]type{OperandBundleTag}; | |
| 1228 | ||
| 1229 | pub const OperandBundleTag = struct { | |
| 1230 | pub const ops = [_]AbbrevOp{ | |
| 1231 | .{ .literal = 1 }, | |
| 1232 | .array_char6, | |
| 1233 | }; | |
| 1234 | tag: []const u8, | |
| 1235 | }; | |
| 1236 | }; | |
| 1237 | ||
| 1238 | pub const FunctionMetadataBlock = struct { | |
| 1239 | pub const id = 15; | |
| 1240 | ||
| 1241 | pub const abbrevs = [_]type{ | |
| 1242 | Value, | |
| 1243 | }; | |
| 1244 | ||
| 1245 | pub const Value = struct { | |
| 1246 | pub const ops = [_]AbbrevOp{ | |
| 1247 | .{ .literal = 2 }, | |
| 1248 | .{ .fixed = 32 }, // variable | |
| 1249 | .{ .fixed = 32 }, // expression | |
| 1250 | }; | |
| 1251 | ||
| 1252 | ty: Builder.Type, | |
| 1253 | value: Builder.Value, | |
| 1254 | }; | |
| 1255 | }; | |
| 1256 | ||
| 1257 | pub const FunctionBlock = struct { | |
| 1258 | pub const id = 12; | |
| 1259 | ||
| 1260 | pub const abbrevs = [_]type{ | |
| 1261 | DeclareBlocks, | |
| 1262 | Call, | |
| 1263 | CallFast, | |
| 1264 | FNeg, | |
| 1265 | FNegFast, | |
| 1266 | Binary, | |
| 1267 | BinaryNoWrap, | |
| 1268 | BinaryExact, | |
| 1269 | BinaryFast, | |
| 1270 | Cmp, | |
| 1271 | CmpFast, | |
| 1272 | Select, | |
| 1273 | SelectFast, | |
| 1274 | Cast, | |
| 1275 | Alloca, | |
| 1276 | GetElementPtr, | |
| 1277 | ExtractValue, | |
| 1278 | InsertValue, | |
| 1279 | ExtractElement, | |
| 1280 | InsertElement, | |
| 1281 | ShuffleVector, | |
| 1282 | RetVoid, | |
| 1283 | Ret, | |
| 1284 | Unreachable, | |
| 1285 | Load, | |
| 1286 | LoadAtomic, | |
| 1287 | Store, | |
| 1288 | StoreAtomic, | |
| 1289 | BrUnconditional, | |
| 1290 | BrConditional, | |
| 1291 | VaArg, | |
| 1292 | AtomicRmw, | |
| 1293 | CmpXchg, | |
| 1294 | Fence, | |
| 1295 | DebugLoc, | |
| 1296 | DebugLocAgain, | |
| 1297 | ColdOperandBundle, | |
| 1298 | IndirectBr, | |
| 1299 | }; | |
| 1300 | ||
| 1301 | pub const DeclareBlocks = struct { | |
| 1302 | pub const ops = [_]AbbrevOp{ | |
| 1303 | .{ .literal = 1 }, | |
| 1304 | .{ .vbr = 8 }, | |
| 1305 | }; | |
| 1306 | num_blocks: usize, | |
| 1307 | }; | |
| 1308 | ||
| 1309 | pub const Call = struct { | |
| 1310 | pub const CallType = packed struct(u17) { | |
| 1311 | tail: bool = false, | |
| 1312 | call_conv: Builder.CallConv, | |
| 1313 | reserved: u3 = 0, | |
| 1314 | must_tail: bool = false, | |
| 1315 | // We always use the explicit type version as that is what LLVM does | |
| 1316 | explicit_type: bool = true, | |
| 1317 | no_tail: bool = false, | |
| 1318 | }; | |
| 1319 | pub const ops = [_]AbbrevOp{ | |
| 1320 | .{ .literal = 34 }, | |
| 1321 | .{ .fixed_runtime = Builder.FunctionAttributes }, | |
| 1322 | .{ .fixed = @bitSizeOf(CallType) }, | |
| 1323 | .{ .fixed_runtime = Builder.Type }, | |
| 1324 | ValueAbbrev, // Callee | |
| 1325 | ValueArrayAbbrev, // Args | |
| 1326 | }; | |
| 1327 | ||
| 1328 | attributes: Builder.FunctionAttributes, | |
| 1329 | call_type: CallType, | |
| 1330 | type_id: Builder.Type, | |
| 1331 | callee: Builder.Value, | |
| 1332 | args: []const Builder.Value, | |
| 1333 | }; | |
| 1334 | ||
| 1335 | pub const CallFast = struct { | |
| 1336 | const CallType = packed struct(u18) { | |
| 1337 | tail: bool = false, | |
| 1338 | call_conv: Builder.CallConv, | |
| 1339 | reserved: u3 = 0, | |
| 1340 | must_tail: bool = false, | |
| 1341 | // We always use the explicit type version as that is what LLVM does | |
| 1342 | explicit_type: bool = true, | |
| 1343 | no_tail: bool = false, | |
| 1344 | fast: bool = true, | |
| 1345 | }; | |
| 1346 | ||
| 1347 | pub const ops = [_]AbbrevOp{ | |
| 1348 | .{ .literal = 34 }, | |
| 1349 | .{ .fixed_runtime = Builder.FunctionAttributes }, | |
| 1350 | .{ .fixed = @bitSizeOf(CallType) }, | |
| 1351 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1352 | .{ .fixed_runtime = Builder.Type }, | |
| 1353 | ValueAbbrev, // Callee | |
| 1354 | ValueArrayAbbrev, // Args | |
| 1355 | }; | |
| 1356 | ||
| 1357 | attributes: Builder.FunctionAttributes, | |
| 1358 | call_type: CallType, | |
| 1359 | fast_math: Builder.FastMath, | |
| 1360 | type_id: Builder.Type, | |
| 1361 | callee: Builder.Value, | |
| 1362 | args: []const Builder.Value, | |
| 1363 | }; | |
| 1364 | ||
| 1365 | pub const FNeg = struct { | |
| 1366 | pub const ops = [_]AbbrevOp{ | |
| 1367 | .{ .literal = 56 }, | |
| 1368 | ValueAbbrev, | |
| 1369 | .{ .literal = 0 }, | |
| 1370 | }; | |
| 1371 | ||
| 1372 | val: u32, | |
| 1373 | }; | |
| 1374 | ||
| 1375 | pub const FNegFast = struct { | |
| 1376 | pub const ops = [_]AbbrevOp{ | |
| 1377 | .{ .literal = 56 }, | |
| 1378 | ValueAbbrev, | |
| 1379 | .{ .literal = 0 }, | |
| 1380 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1381 | }; | |
| 1382 | ||
| 1383 | val: u32, | |
| 1384 | fast_math: Builder.FastMath, | |
| 1385 | }; | |
| 1386 | ||
| 1387 | pub const Binary = struct { | |
| 1388 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 1389 | pub const ops = [_]AbbrevOp{ | |
| 1390 | .{ .literal = 2 }, | |
| 1391 | ValueAbbrev, | |
| 1392 | ValueAbbrev, | |
| 1393 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 1394 | }; | |
| 1395 | ||
| 1396 | lhs: u32, | |
| 1397 | rhs: u32, | |
| 1398 | opcode: BinaryOpcode, | |
| 1399 | }; | |
| 1400 | ||
| 1401 | pub const BinaryNoWrap = struct { | |
| 1402 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 1403 | pub const ops = [_]AbbrevOp{ | |
| 1404 | .{ .literal = 2 }, | |
| 1405 | ValueAbbrev, | |
| 1406 | ValueAbbrev, | |
| 1407 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 1408 | .{ .fixed = 2 }, | |
| 1409 | }; | |
| 1410 | ||
| 1411 | lhs: u32, | |
| 1412 | rhs: u32, | |
| 1413 | opcode: BinaryOpcode, | |
| 1414 | flags: packed struct(u2) { | |
| 1415 | no_unsigned_wrap: bool, | |
| 1416 | no_signed_wrap: bool, | |
| 1417 | }, | |
| 1418 | }; | |
| 1419 | ||
| 1420 | pub const BinaryExact = struct { | |
| 1421 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 1422 | pub const ops = [_]AbbrevOp{ | |
| 1423 | .{ .literal = 2 }, | |
| 1424 | ValueAbbrev, | |
| 1425 | ValueAbbrev, | |
| 1426 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 1427 | .{ .literal = 1 }, | |
| 1428 | }; | |
| 1429 | ||
| 1430 | lhs: u32, | |
| 1431 | rhs: u32, | |
| 1432 | opcode: BinaryOpcode, | |
| 1433 | }; | |
| 1434 | ||
| 1435 | pub const BinaryFast = struct { | |
| 1436 | const BinaryOpcode = Builder.BinaryOpcode; | |
| 1437 | pub const ops = [_]AbbrevOp{ | |
| 1438 | .{ .literal = 2 }, | |
| 1439 | ValueAbbrev, | |
| 1440 | ValueAbbrev, | |
| 1441 | .{ .fixed = @bitSizeOf(BinaryOpcode) }, | |
| 1442 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1443 | }; | |
| 1444 | ||
| 1445 | lhs: u32, | |
| 1446 | rhs: u32, | |
| 1447 | opcode: BinaryOpcode, | |
| 1448 | fast_math: Builder.FastMath, | |
| 1449 | }; | |
| 1450 | ||
| 1451 | pub const Cmp = struct { | |
| 1452 | const CmpPredicate = Builder.CmpPredicate; | |
| 1453 | pub const ops = [_]AbbrevOp{ | |
| 1454 | .{ .literal = 28 }, | |
| 1455 | ValueAbbrev, | |
| 1456 | ValueAbbrev, | |
| 1457 | .{ .fixed = @bitSizeOf(CmpPredicate) }, | |
| 1458 | }; | |
| 1459 | ||
| 1460 | lhs: u32, | |
| 1461 | rhs: u32, | |
| 1462 | pred: CmpPredicate, | |
| 1463 | }; | |
| 1464 | ||
| 1465 | pub const CmpFast = struct { | |
| 1466 | const CmpPredicate = Builder.CmpPredicate; | |
| 1467 | pub const ops = [_]AbbrevOp{ | |
| 1468 | .{ .literal = 28 }, | |
| 1469 | ValueAbbrev, | |
| 1470 | ValueAbbrev, | |
| 1471 | .{ .fixed = @bitSizeOf(CmpPredicate) }, | |
| 1472 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1473 | }; | |
| 1474 | ||
| 1475 | lhs: u32, | |
| 1476 | rhs: u32, | |
| 1477 | pred: CmpPredicate, | |
| 1478 | fast_math: Builder.FastMath, | |
| 1479 | }; | |
| 1480 | ||
| 1481 | pub const Select = struct { | |
| 1482 | pub const ops = [_]AbbrevOp{ | |
| 1483 | .{ .literal = 29 }, | |
| 1484 | ValueAbbrev, | |
| 1485 | ValueAbbrev, | |
| 1486 | ValueAbbrev, | |
| 1487 | }; | |
| 1488 | ||
| 1489 | lhs: u32, | |
| 1490 | rhs: u32, | |
| 1491 | cond: u32, | |
| 1492 | }; | |
| 1493 | ||
| 1494 | pub const SelectFast = struct { | |
| 1495 | pub const ops = [_]AbbrevOp{ | |
| 1496 | .{ .literal = 29 }, | |
| 1497 | ValueAbbrev, | |
| 1498 | ValueAbbrev, | |
| 1499 | ValueAbbrev, | |
| 1500 | .{ .fixed = @bitSizeOf(Builder.FastMath) }, | |
| 1501 | }; | |
| 1502 | ||
| 1503 | lhs: u32, | |
| 1504 | rhs: u32, | |
| 1505 | cond: u32, | |
| 1506 | fast_math: Builder.FastMath, | |
| 1507 | }; | |
| 1508 | ||
| 1509 | pub const Cast = struct { | |
| 1510 | const CastOpcode = Builder.CastOpcode; | |
| 1511 | pub const ops = [_]AbbrevOp{ | |
| 1512 | .{ .literal = 3 }, | |
| 1513 | ValueAbbrev, | |
| 1514 | .{ .fixed_runtime = Builder.Type }, | |
| 1515 | .{ .fixed = @bitSizeOf(CastOpcode) }, | |
| 1516 | }; | |
| 1517 | ||
| 1518 | val: u32, | |
| 1519 | type_index: Builder.Type, | |
| 1520 | opcode: CastOpcode, | |
| 1521 | }; | |
| 1522 | ||
| 1523 | pub const Alloca = struct { | |
| 1524 | pub const Flags = packed struct(u11) { | |
| 1525 | align_lower: u5, | |
| 1526 | inalloca: bool, | |
| 1527 | explicit_type: bool, | |
| 1528 | swift_error: bool, | |
| 1529 | align_upper: u3, | |
| 1530 | }; | |
| 1531 | pub const ops = [_]AbbrevOp{ | |
| 1532 | .{ .literal = 19 }, | |
| 1533 | .{ .fixed_runtime = Builder.Type }, | |
| 1534 | .{ .fixed_runtime = Builder.Type }, | |
| 1535 | ValueAbbrev, | |
| 1536 | .{ .fixed = @bitSizeOf(Flags) }, | |
| 1537 | }; | |
| 1538 | ||
| 1539 | inst_type: Builder.Type, | |
| 1540 | len_type: Builder.Type, | |
| 1541 | len_value: u32, | |
| 1542 | flags: Flags, | |
| 1543 | }; | |
| 1544 | ||
| 1545 | pub const RetVoid = struct { | |
| 1546 | pub const ops = [_]AbbrevOp{ | |
| 1547 | .{ .literal = 10 }, | |
| 1548 | }; | |
| 1549 | }; | |
| 1550 | ||
| 1551 | pub const Ret = struct { | |
| 1552 | pub const ops = [_]AbbrevOp{ | |
| 1553 | .{ .literal = 10 }, | |
| 1554 | ValueAbbrev, | |
| 1555 | }; | |
| 1556 | val: u32, | |
| 1557 | }; | |
| 1558 | ||
| 1559 | pub const GetElementPtr = struct { | |
| 1560 | pub const ops = [_]AbbrevOp{ | |
| 1561 | .{ .literal = 43 }, | |
| 1562 | .{ .fixed = 1 }, | |
| 1563 | .{ .fixed_runtime = Builder.Type }, | |
| 1564 | ValueAbbrev, | |
| 1565 | ValueArrayAbbrev, | |
| 1566 | }; | |
| 1567 | ||
| 1568 | is_inbounds: bool, | |
| 1569 | type_index: Builder.Type, | |
| 1570 | base: Builder.Value, | |
| 1571 | indices: []const Builder.Value, | |
| 1572 | }; | |
| 1573 | ||
| 1574 | pub const ExtractValue = struct { | |
| 1575 | pub const ops = [_]AbbrevOp{ | |
| 1576 | .{ .literal = 26 }, | |
| 1577 | ValueAbbrev, | |
| 1578 | ValueArrayAbbrev, | |
| 1579 | }; | |
| 1580 | ||
| 1581 | val: u32, | |
| 1582 | indices: []const u32, | |
| 1583 | }; | |
| 1584 | ||
| 1585 | pub const InsertValue = struct { | |
| 1586 | pub const ops = [_]AbbrevOp{ | |
| 1587 | .{ .literal = 27 }, | |
| 1588 | ValueAbbrev, | |
| 1589 | ValueAbbrev, | |
| 1590 | ValueArrayAbbrev, | |
| 1591 | }; | |
| 1592 | ||
| 1593 | val: u32, | |
| 1594 | elem: u32, | |
| 1595 | indices: []const u32, | |
| 1596 | }; | |
| 1597 | ||
| 1598 | pub const ExtractElement = struct { | |
| 1599 | pub const ops = [_]AbbrevOp{ | |
| 1600 | .{ .literal = 6 }, | |
| 1601 | ValueAbbrev, | |
| 1602 | ValueAbbrev, | |
| 1603 | }; | |
| 1604 | ||
| 1605 | val: u32, | |
| 1606 | index: u32, | |
| 1607 | }; | |
| 1608 | ||
| 1609 | pub const InsertElement = struct { | |
| 1610 | pub const ops = [_]AbbrevOp{ | |
| 1611 | .{ .literal = 7 }, | |
| 1612 | ValueAbbrev, | |
| 1613 | ValueAbbrev, | |
| 1614 | ValueAbbrev, | |
| 1615 | }; | |
| 1616 | ||
| 1617 | val: u32, | |
| 1618 | elem: u32, | |
| 1619 | index: u32, | |
| 1620 | }; | |
| 1621 | ||
| 1622 | pub const ShuffleVector = struct { | |
| 1623 | pub const ops = [_]AbbrevOp{ | |
| 1624 | .{ .literal = 8 }, | |
| 1625 | ValueAbbrev, | |
| 1626 | ValueAbbrev, | |
| 1627 | ValueAbbrev, | |
| 1628 | }; | |
| 1629 | ||
| 1630 | lhs: u32, | |
| 1631 | rhs: u32, | |
| 1632 | mask: u32, | |
| 1633 | }; | |
| 1634 | ||
| 1635 | pub const Unreachable = struct { | |
| 1636 | pub const ops = [_]AbbrevOp{ | |
| 1637 | .{ .literal = 15 }, | |
| 1638 | }; | |
| 1639 | }; | |
| 1640 | ||
| 1641 | pub const Load = struct { | |
| 1642 | pub const ops = [_]AbbrevOp{ | |
| 1643 | .{ .literal = 20 }, | |
| 1644 | ValueAbbrev, | |
| 1645 | .{ .fixed_runtime = Builder.Type }, | |
| 1646 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1647 | .{ .fixed = 1 }, | |
| 1648 | }; | |
| 1649 | ptr: u32, | |
| 1650 | ty: Builder.Type, | |
| 1651 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1652 | is_volatile: bool, | |
| 1653 | }; | |
| 1654 | ||
| 1655 | pub const LoadAtomic = struct { | |
| 1656 | pub const ops = [_]AbbrevOp{ | |
| 1657 | .{ .literal = 41 }, | |
| 1658 | ValueAbbrev, | |
| 1659 | .{ .fixed_runtime = Builder.Type }, | |
| 1660 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1661 | .{ .fixed = 1 }, | |
| 1662 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1663 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1664 | }; | |
| 1665 | ptr: u32, | |
| 1666 | ty: Builder.Type, | |
| 1667 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1668 | is_volatile: bool, | |
| 1669 | success_ordering: Builder.AtomicOrdering, | |
| 1670 | sync_scope: Builder.SyncScope, | |
| 1671 | }; | |
| 1672 | ||
| 1673 | pub const Store = struct { | |
| 1674 | pub const ops = [_]AbbrevOp{ | |
| 1675 | .{ .literal = 44 }, | |
| 1676 | ValueAbbrev, | |
| 1677 | ValueAbbrev, | |
| 1678 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1679 | .{ .fixed = 1 }, | |
| 1680 | }; | |
| 1681 | ptr: u32, | |
| 1682 | val: u32, | |
| 1683 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1684 | is_volatile: bool, | |
| 1685 | }; | |
| 1686 | ||
| 1687 | pub const StoreAtomic = struct { | |
| 1688 | pub const ops = [_]AbbrevOp{ | |
| 1689 | .{ .literal = 45 }, | |
| 1690 | ValueAbbrev, | |
| 1691 | ValueAbbrev, | |
| 1692 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1693 | .{ .fixed = 1 }, | |
| 1694 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1695 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1696 | }; | |
| 1697 | ptr: u32, | |
| 1698 | val: u32, | |
| 1699 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1700 | is_volatile: bool, | |
| 1701 | success_ordering: Builder.AtomicOrdering, | |
| 1702 | sync_scope: Builder.SyncScope, | |
| 1703 | }; | |
| 1704 | ||
| 1705 | pub const BrUnconditional = struct { | |
| 1706 | pub const ops = [_]AbbrevOp{ | |
| 1707 | .{ .literal = 11 }, | |
| 1708 | BlockAbbrev, | |
| 1709 | }; | |
| 1710 | block: u32, | |
| 1711 | }; | |
| 1712 | ||
| 1713 | pub const BrConditional = struct { | |
| 1714 | pub const ops = [_]AbbrevOp{ | |
| 1715 | .{ .literal = 11 }, | |
| 1716 | BlockAbbrev, | |
| 1717 | BlockAbbrev, | |
| 1718 | BlockAbbrev, | |
| 1719 | }; | |
| 1720 | then_block: u32, | |
| 1721 | else_block: u32, | |
| 1722 | condition: u32, | |
| 1723 | }; | |
| 1724 | ||
| 1725 | pub const VaArg = struct { | |
| 1726 | pub const ops = [_]AbbrevOp{ | |
| 1727 | .{ .literal = 23 }, | |
| 1728 | .{ .fixed_runtime = Builder.Type }, | |
| 1729 | ValueAbbrev, | |
| 1730 | .{ .fixed_runtime = Builder.Type }, | |
| 1731 | }; | |
| 1732 | list_type: Builder.Type, | |
| 1733 | list: u32, | |
| 1734 | type: Builder.Type, | |
| 1735 | }; | |
| 1736 | ||
| 1737 | pub const AtomicRmw = struct { | |
| 1738 | pub const ops = [_]AbbrevOp{ | |
| 1739 | .{ .literal = 59 }, | |
| 1740 | ValueAbbrev, | |
| 1741 | ValueAbbrev, | |
| 1742 | .{ .fixed = @bitSizeOf(Builder.Function.Instruction.AtomicRmw.Operation) }, | |
| 1743 | .{ .fixed = 1 }, | |
| 1744 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1745 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1746 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1747 | }; | |
| 1748 | ptr: u32, | |
| 1749 | val: u32, | |
| 1750 | operation: Builder.Function.Instruction.AtomicRmw.Operation, | |
| 1751 | is_volatile: bool, | |
| 1752 | success_ordering: Builder.AtomicOrdering, | |
| 1753 | sync_scope: Builder.SyncScope, | |
| 1754 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1755 | }; | |
| 1756 | ||
| 1757 | pub const CmpXchg = struct { | |
| 1758 | pub const ops = [_]AbbrevOp{ | |
| 1759 | .{ .literal = 46 }, | |
| 1760 | ValueAbbrev, | |
| 1761 | ValueAbbrev, | |
| 1762 | ValueAbbrev, | |
| 1763 | .{ .fixed = 1 }, | |
| 1764 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1765 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1766 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1767 | .{ .fixed = 1 }, | |
| 1768 | .{ .fixed = @bitSizeOf(Builder.Alignment) }, | |
| 1769 | }; | |
| 1770 | ptr: u32, | |
| 1771 | cmp: u32, | |
| 1772 | new: u32, | |
| 1773 | is_volatile: bool, | |
| 1774 | success_ordering: Builder.AtomicOrdering, | |
| 1775 | sync_scope: Builder.SyncScope, | |
| 1776 | failure_ordering: Builder.AtomicOrdering, | |
| 1777 | is_weak: bool, | |
| 1778 | alignment: std.meta.Int(.unsigned, @bitSizeOf(Builder.Alignment)), | |
| 1779 | }; | |
| 1780 | ||
| 1781 | pub const Fence = struct { | |
| 1782 | pub const ops = [_]AbbrevOp{ | |
| 1783 | .{ .literal = 36 }, | |
| 1784 | .{ .fixed = @bitSizeOf(Builder.AtomicOrdering) }, | |
| 1785 | .{ .fixed = @bitSizeOf(Builder.SyncScope) }, | |
| 1786 | }; | |
| 1787 | ordering: Builder.AtomicOrdering, | |
| 1788 | sync_scope: Builder.SyncScope, | |
| 1789 | }; | |
| 1790 | ||
| 1791 | pub const DebugLoc = struct { | |
| 1792 | pub const ops = [_]AbbrevOp{ | |
| 1793 | .{ .literal = 35 }, | |
| 1794 | LineAbbrev, | |
| 1795 | ColumnAbbrev, | |
| 1796 | MetadataAbbrev, | |
| 1797 | MetadataAbbrev, | |
| 1798 | .{ .literal = 0 }, | |
| 1799 | }; | |
| 1800 | line: u32, | |
| 1801 | column: u32, | |
| 1802 | scope: Builder.Metadata, | |
| 1803 | inlined_at: Builder.Metadata, | |
| 1804 | }; | |
| 1805 | ||
| 1806 | pub const DebugLocAgain = struct { | |
| 1807 | pub const ops = [_]AbbrevOp{ | |
| 1808 | .{ .literal = 33 }, | |
| 1809 | }; | |
| 1810 | }; | |
| 1811 | ||
| 1812 | pub const ColdOperandBundle = struct { | |
| 1813 | pub const ops = [_]AbbrevOp{ | |
| 1814 | .{ .literal = 55 }, | |
| 1815 | .{ .literal = 0 }, | |
| 1816 | }; | |
| 1817 | }; | |
| 1818 | ||
| 1819 | pub const IndirectBr = struct { | |
| 1820 | pub const ops = [_]AbbrevOp{ | |
| 1821 | .{ .literal = 31 }, | |
| 1822 | .{ .fixed_runtime = Builder.Type }, | |
| 1823 | ValueAbbrev, | |
| 1824 | BlockArrayAbbrev, | |
| 1825 | }; | |
| 1826 | ty: Builder.Type, | |
| 1827 | addr: Builder.Value, | |
| 1828 | targets: []const Builder.Function.Block.Index, | |
| 1829 | }; | |
| 1830 | }; | |
| 1831 | ||
| 1832 | pub const FunctionValueSymbolTable = struct { | |
| 1833 | pub const id = 14; | |
| 1834 | ||
| 1835 | pub const abbrevs = [_]type{ | |
| 1836 | BlockEntry, | |
| 1837 | }; | |
| 1838 | ||
| 1839 | pub const BlockEntry = struct { | |
| 1840 | pub const ops = [_]AbbrevOp{ | |
| 1841 | .{ .literal = 2 }, | |
| 1842 | ValueAbbrev, | |
| 1843 | .{ .array_fixed = 8 }, | |
| 1844 | }; | |
| 1845 | value_id: u32, | |
| 1846 | string: []const u8, | |
| 1847 | }; | |
| 1848 | }; | |
| 1849 | ||
| 1850 | pub const Strtab = struct { | |
| 1851 | pub const id = 23; | |
| 1852 | ||
| 1853 | pub const abbrevs = [_]type{Blob}; | |
| 1854 | ||
| 1855 | 2291 | pub const Blob = struct { |
| 1856 | 2292 | pub const ops = [_]AbbrevOp{ |
| 1857 | .{ .literal = 1 }, | |
| 2293 | .{ .literal = @intFromEnum(StrtabBlock.Code.BLOB) }, | |
| 1858 | 2294 | .blob, |
| 1859 | 2295 | }; |
| 1860 | 2296 | blob: []const u8, |
src/codegen/llvm.zig+182-197| ... | ... | @@ -508,16 +508,16 @@ pub const Object = struct { |
| 508 | 508 | gpa: Allocator, |
| 509 | 509 | builder: Builder, |
| 510 | 510 | |
| 511 | debug_compile_unit: Builder.Metadata, | |
| 511 | debug_compile_unit: Builder.Metadata.Optional, | |
| 512 | 512 | |
| 513 | debug_enums_fwd_ref: Builder.Metadata, | |
| 514 | debug_globals_fwd_ref: Builder.Metadata, | |
| 513 | debug_enums_fwd_ref: Builder.Metadata.Optional, | |
| 514 | debug_globals_fwd_ref: Builder.Metadata.Optional, | |
| 515 | 515 | |
| 516 | 516 | debug_enums: std.ArrayListUnmanaged(Builder.Metadata), |
| 517 | 517 | debug_globals: std.ArrayListUnmanaged(Builder.Metadata), |
| 518 | 518 | |
| 519 | 519 | debug_file_map: std.AutoHashMapUnmanaged(Zcu.File.Index, Builder.Metadata), |
| 520 | debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata), | |
| 520 | debug_type_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Metadata), | |
| 521 | 521 | |
| 522 | 522 | debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata), |
| 523 | 523 | |
| ... | ... | @@ -630,9 +630,13 @@ pub const Object = struct { |
| 630 | 630 | .{ .optimized = comp.root_mod.optimize_mode != .Debug }, |
| 631 | 631 | ); |
| 632 | 632 | |
| 633 | try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit}); | |
| 634 | break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref }; | |
| 635 | } else .{.none} ** 3; | |
| 633 | try builder.addNamedMetadata(try builder.string("llvm.dbg.cu"), &.{debug_compile_unit}); | |
| 634 | break :debug_info .{ | |
| 635 | debug_compile_unit.toOptional(), | |
| 636 | debug_enums_fwd_ref.toOptional(), | |
| 637 | debug_globals_fwd_ref.toOptional(), | |
| 638 | }; | |
| 639 | } else .{Builder.Metadata.Optional.none} ** 3; | |
| 636 | 640 | |
| 637 | 641 | const obj = try arena.create(Object); |
| 638 | 642 | obj.* = .{ |
| ... | ... | @@ -816,17 +820,17 @@ pub const Object = struct { |
| 816 | 820 | const namespace = zcu.namespacePtr(namespace_index); |
| 817 | 821 | const debug_type = try o.lowerDebugType(pt, Type.fromInterned(namespace.owner_type)); |
| 818 | 822 | |
| 819 | o.builder.debugForwardReferenceSetType(fwd_ref, debug_type); | |
| 823 | o.builder.resolveDebugForwardReference(fwd_ref, debug_type); | |
| 820 | 824 | } |
| 821 | 825 | } |
| 822 | 826 | |
| 823 | o.builder.debugForwardReferenceSetType( | |
| 824 | o.debug_enums_fwd_ref, | |
| 827 | o.builder.resolveDebugForwardReference( | |
| 828 | o.debug_enums_fwd_ref.unwrap().?, | |
| 825 | 829 | try o.builder.metadataTuple(o.debug_enums.items), |
| 826 | 830 | ); |
| 827 | 831 | |
| 828 | o.builder.debugForwardReferenceSetType( | |
| 829 | o.debug_globals_fwd_ref, | |
| 832 | o.builder.resolveDebugForwardReference( | |
| 833 | o.debug_globals_fwd_ref.unwrap().?, | |
| 830 | 834 | try o.builder.metadataTuple(o.debug_globals.items), |
| 831 | 835 | ); |
| 832 | 836 | } |
| ... | ... | @@ -842,36 +846,34 @@ pub const Object = struct { |
| 842 | 846 | const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8)); |
| 843 | 847 | |
| 844 | 848 | if (target_util.llvmMachineAbi(&comp.root_mod.resolved_target.result)) |abi| { |
| 845 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 849 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 846 | 850 | behavior_error, |
| 847 | try o.builder.metadataString("target-abi"), | |
| 848 | try o.builder.metadataConstant( | |
| 849 | try o.builder.stringConst(try o.builder.string(abi)), | |
| 850 | ), | |
| 851 | )); | |
| 851 | (try o.builder.metadataString("target-abi")).toMetadata(), | |
| 852 | (try o.builder.metadataString(abi)).toMetadata(), | |
| 853 | })); | |
| 852 | 854 | } |
| 853 | 855 | |
| 854 | 856 | const pic_level = target_util.picLevel(&comp.root_mod.resolved_target.result); |
| 855 | 857 | if (comp.root_mod.pic) { |
| 856 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 858 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 857 | 859 | behavior_min, |
| 858 | try o.builder.metadataString("PIC Level"), | |
| 860 | (try o.builder.metadataString("PIC Level")).toMetadata(), | |
| 859 | 861 | try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)), |
| 860 | )); | |
| 862 | })); | |
| 861 | 863 | } |
| 862 | 864 | |
| 863 | 865 | if (comp.config.pie) { |
| 864 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 866 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 865 | 867 | behavior_max, |
| 866 | try o.builder.metadataString("PIE Level"), | |
| 868 | (try o.builder.metadataString("PIE Level")).toMetadata(), | |
| 867 | 869 | try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)), |
| 868 | )); | |
| 870 | })); | |
| 869 | 871 | } |
| 870 | 872 | |
| 871 | 873 | if (comp.root_mod.code_model != .default) { |
| 872 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 874 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 873 | 875 | behavior_error, |
| 874 | try o.builder.metadataString("Code Model"), | |
| 876 | (try o.builder.metadataString("Code Model")).toMetadata(), | |
| 875 | 877 | try o.builder.metadataConstant(try o.builder.intConst(.i32, @as( |
| 876 | 878 | i32, |
| 877 | 879 | switch (codeModel(comp.root_mod.code_model, &comp.root_mod.resolved_target.result)) { |
| ... | ... | @@ -883,39 +885,39 @@ pub const Object = struct { |
| 883 | 885 | .large => 4, |
| 884 | 886 | }, |
| 885 | 887 | ))), |
| 886 | )); | |
| 888 | })); | |
| 887 | 889 | } |
| 888 | 890 | |
| 889 | 891 | if (!o.builder.strip) { |
| 890 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 892 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 891 | 893 | behavior_warning, |
| 892 | try o.builder.metadataString("Debug Info Version"), | |
| 894 | (try o.builder.metadataString("Debug Info Version")).toMetadata(), | |
| 893 | 895 | try o.builder.metadataConstant(try o.builder.intConst(.i32, 3)), |
| 894 | )); | |
| 896 | })); | |
| 895 | 897 | |
| 896 | 898 | switch (comp.config.debug_format) { |
| 897 | 899 | .strip => unreachable, |
| 898 | 900 | .dwarf => |f| { |
| 899 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 901 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 900 | 902 | behavior_max, |
| 901 | try o.builder.metadataString("Dwarf Version"), | |
| 903 | (try o.builder.metadataString("Dwarf Version")).toMetadata(), | |
| 902 | 904 | try o.builder.metadataConstant(try o.builder.intConst(.i32, 4)), |
| 903 | )); | |
| 905 | })); | |
| 904 | 906 | |
| 905 | 907 | if (f == .@"64") { |
| 906 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 908 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 907 | 909 | behavior_max, |
| 908 | try o.builder.metadataString("DWARF64"), | |
| 910 | (try o.builder.metadataString("DWARF64")).toMetadata(), | |
| 909 | 911 | try o.builder.metadataConstant(.@"1"), |
| 910 | )); | |
| 912 | })); | |
| 911 | 913 | } |
| 912 | 914 | }, |
| 913 | 915 | .code_view => { |
| 914 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 916 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 915 | 917 | behavior_warning, |
| 916 | try o.builder.metadataString("CodeView"), | |
| 918 | (try o.builder.metadataString("CodeView")).toMetadata(), | |
| 917 | 919 | try o.builder.metadataConstant(.@"1"), |
| 918 | )); | |
| 920 | })); | |
| 919 | 921 | }, |
| 920 | 922 | } |
| 921 | 923 | } |
| ... | ... | @@ -925,14 +927,14 @@ pub const Object = struct { |
| 925 | 927 | // Add the "RegCallv4" flag so that any functions using `x86_regcallcc` use regcall |
| 926 | 928 | // v4, which is essentially a requirement on Windows. See corresponding logic in |
| 927 | 929 | // `toLlvmCallConvTag`. |
| 928 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | |
| 930 | module_flags.appendAssumeCapacity(try o.builder.metadataTuple(&.{ | |
| 929 | 931 | behavior_max, |
| 930 | try o.builder.metadataString("RegCallv4"), | |
| 932 | (try o.builder.metadataString("RegCallv4")).toMetadata(), | |
| 931 | 933 | try o.builder.metadataConstant(.@"1"), |
| 932 | )); | |
| 934 | })); | |
| 933 | 935 | } |
| 934 | 936 | |
| 935 | try o.builder.metadataNamed(try o.builder.metadataString("llvm.module.flags"), module_flags.items); | |
| 937 | try o.builder.addNamedMetadata(try o.builder.string("llvm.module.flags"), module_flags.items); | |
| 936 | 938 | } |
| 937 | 939 | |
| 938 | 940 | const target_triple_sentinel = |
| ... | ... | @@ -1477,11 +1479,11 @@ pub const Object = struct { |
| 1477 | 1479 | .LocalToUnit = is_internal_linkage, |
| 1478 | 1480 | }, |
| 1479 | 1481 | }, |
| 1480 | o.debug_compile_unit, | |
| 1482 | o.debug_compile_unit.unwrap().?, | |
| 1481 | 1483 | ); |
| 1482 | 1484 | function_index.setSubprogram(subprogram, &o.builder); |
| 1483 | 1485 | break :debug_info .{ file, subprogram }; |
| 1484 | } else .{.none} ** 2; | |
| 1486 | } else .{undefined} ** 2; | |
| 1485 | 1487 | |
| 1486 | 1488 | const fuzz: ?FuncGen.Fuzz = f: { |
| 1487 | 1489 | if (!owner_mod.fuzz) break :f null; |
| ... | ... | @@ -1807,7 +1809,7 @@ pub const Object = struct { |
| 1807 | 1809 | const zcu = pt.zcu; |
| 1808 | 1810 | const ip = &zcu.intern_pool; |
| 1809 | 1811 | |
| 1810 | if (o.debug_type_map.get(ty)) |debug_type| return debug_type; | |
| 1812 | if (o.debug_type_map.get(ty.toIntern())) |debug_type| return debug_type; | |
| 1811 | 1813 | |
| 1812 | 1814 | switch (ty.zigTypeTag(zcu)) { |
| 1813 | 1815 | .void, |
| ... | ... | @@ -1817,7 +1819,7 @@ pub const Object = struct { |
| 1817 | 1819 | try o.builder.metadataString("void"), |
| 1818 | 1820 | 0, |
| 1819 | 1821 | ); |
| 1820 | try o.debug_type_map.put(gpa, ty, debug_void_type); | |
| 1822 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_void_type); | |
| 1821 | 1823 | return debug_void_type; |
| 1822 | 1824 | }, |
| 1823 | 1825 | .int => { |
| ... | ... | @@ -1831,13 +1833,13 @@ pub const Object = struct { |
| 1831 | 1833 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), |
| 1832 | 1834 | .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits), |
| 1833 | 1835 | }; |
| 1834 | try o.debug_type_map.put(gpa, ty, debug_int_type); | |
| 1836 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_int_type); | |
| 1835 | 1837 | return debug_int_type; |
| 1836 | 1838 | }, |
| 1837 | 1839 | .@"enum" => { |
| 1838 | 1840 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1839 | 1841 | const debug_enum_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 1840 | try o.debug_type_map.put(gpa, ty, debug_enum_type); | |
| 1842 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_enum_type); | |
| 1841 | 1843 | return debug_enum_type; |
| 1842 | 1844 | } |
| 1843 | 1845 | |
| ... | ... | @@ -1884,7 +1886,7 @@ pub const Object = struct { |
| 1884 | 1886 | try o.builder.metadataTuple(enumerators), |
| 1885 | 1887 | ); |
| 1886 | 1888 | |
| 1887 | try o.debug_type_map.put(gpa, ty, debug_enum_type); | |
| 1889 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_enum_type); | |
| 1888 | 1890 | try o.debug_enums.append(gpa, debug_enum_type); |
| 1889 | 1891 | return debug_enum_type; |
| 1890 | 1892 | }, |
| ... | ... | @@ -1896,7 +1898,7 @@ pub const Object = struct { |
| 1896 | 1898 | try o.builder.metadataString(name), |
| 1897 | 1899 | bits, |
| 1898 | 1900 | ); |
| 1899 | try o.debug_type_map.put(gpa, ty, debug_float_type); | |
| 1901 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_float_type); | |
| 1900 | 1902 | return debug_float_type; |
| 1901 | 1903 | }, |
| 1902 | 1904 | .bool => { |
| ... | ... | @@ -1904,7 +1906,7 @@ pub const Object = struct { |
| 1904 | 1906 | try o.builder.metadataString("bool"), |
| 1905 | 1907 | 8, // lldb cannot handle non-byte sized types |
| 1906 | 1908 | ); |
| 1907 | try o.debug_type_map.put(gpa, ty, debug_bool_type); | |
| 1909 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_bool_type); | |
| 1908 | 1910 | return debug_bool_type; |
| 1909 | 1911 | }, |
| 1910 | 1912 | .pointer => { |
| ... | ... | @@ -1936,14 +1938,14 @@ pub const Object = struct { |
| 1936 | 1938 | }, |
| 1937 | 1939 | }); |
| 1938 | 1940 | const debug_ptr_type = try o.lowerDebugType(pt, bland_ptr_ty); |
| 1939 | try o.debug_type_map.put(gpa, ty, debug_ptr_type); | |
| 1941 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_ptr_type); | |
| 1940 | 1942 | return debug_ptr_type; |
| 1941 | 1943 | } |
| 1942 | 1944 | |
| 1943 | 1945 | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 1944 | 1946 | |
| 1945 | 1947 | // Set as forward reference while the type is lowered in case it references itself |
| 1946 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | |
| 1948 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref); | |
| 1947 | 1949 | |
| 1948 | 1950 | if (ty.isSlice(zcu)) { |
| 1949 | 1951 | const ptr_ty = ty.slicePtrFieldType(zcu); |
| ... | ... | @@ -1962,7 +1964,7 @@ pub const Object = struct { |
| 1962 | 1964 | |
| 1963 | 1965 | const debug_ptr_type = try o.builder.debugMemberType( |
| 1964 | 1966 | try o.builder.metadataString("ptr"), |
| 1965 | .none, // File | |
| 1967 | null, // File | |
| 1966 | 1968 | debug_fwd_ref, |
| 1967 | 1969 | 0, // Line |
| 1968 | 1970 | try o.lowerDebugType(pt, ptr_ty), |
| ... | ... | @@ -1973,7 +1975,7 @@ pub const Object = struct { |
| 1973 | 1975 | |
| 1974 | 1976 | const debug_len_type = try o.builder.debugMemberType( |
| 1975 | 1977 | try o.builder.metadataString("len"), |
| 1976 | .none, // File | |
| 1978 | null, // File | |
| 1977 | 1979 | debug_fwd_ref, |
| 1978 | 1980 | 0, // Line |
| 1979 | 1981 | try o.lowerDebugType(pt, len_ty), |
| ... | ... | @@ -1984,10 +1986,10 @@ pub const Object = struct { |
| 1984 | 1986 | |
| 1985 | 1987 | const debug_slice_type = try o.builder.debugStructType( |
| 1986 | 1988 | try o.builder.metadataString(name), |
| 1987 | .none, // File | |
| 1988 | o.debug_compile_unit, // Scope | |
| 1989 | null, // File | |
| 1990 | o.debug_compile_unit.unwrap().?, // Scope | |
| 1989 | 1991 | line, |
| 1990 | .none, // Underlying type | |
| 1992 | null, // Underlying type | |
| 1991 | 1993 | ty.abiSize(zcu) * 8, |
| 1992 | 1994 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 1993 | 1995 | try o.builder.metadataTuple(&.{ |
| ... | ... | @@ -1996,10 +1998,10 @@ pub const Object = struct { |
| 1996 | 1998 | }), |
| 1997 | 1999 | ); |
| 1998 | 2000 | |
| 1999 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type); | |
| 2001 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_slice_type); | |
| 2000 | 2002 | |
| 2001 | 2003 | // Set to real type now that it has been lowered fully |
| 2002 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2004 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2003 | 2005 | map_ptr.* = debug_slice_type; |
| 2004 | 2006 | |
| 2005 | 2007 | return debug_slice_type; |
| ... | ... | @@ -2012,8 +2014,8 @@ pub const Object = struct { |
| 2012 | 2014 | |
| 2013 | 2015 | const debug_ptr_type = try o.builder.debugPointerType( |
| 2014 | 2016 | try o.builder.metadataString(name), |
| 2015 | .none, // File | |
| 2016 | .none, // Scope | |
| 2017 | null, // File | |
| 2018 | null, // Scope | |
| 2017 | 2019 | 0, // Line |
| 2018 | 2020 | debug_elem_ty, |
| 2019 | 2021 | target.ptrBitWidth(), |
| ... | ... | @@ -2021,10 +2023,10 @@ pub const Object = struct { |
| 2021 | 2023 | 0, // Offset |
| 2022 | 2024 | ); |
| 2023 | 2025 | |
| 2024 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_ptr_type); | |
| 2026 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_ptr_type); | |
| 2025 | 2027 | |
| 2026 | 2028 | // Set to real type now that it has been lowered fully |
| 2027 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2029 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2028 | 2030 | map_ptr.* = debug_ptr_type; |
| 2029 | 2031 | |
| 2030 | 2032 | return debug_ptr_type; |
| ... | ... | @@ -2035,7 +2037,7 @@ pub const Object = struct { |
| 2035 | 2037 | try o.builder.metadataString("anyopaque"), |
| 2036 | 2038 | 0, |
| 2037 | 2039 | ); |
| 2038 | try o.debug_type_map.put(gpa, ty, debug_opaque_type); | |
| 2040 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_opaque_type); | |
| 2039 | 2041 | return debug_opaque_type; |
| 2040 | 2042 | } |
| 2041 | 2043 | |
| ... | ... | @@ -2053,19 +2055,19 @@ pub const Object = struct { |
| 2053 | 2055 | file, |
| 2054 | 2056 | scope, |
| 2055 | 2057 | ty.typeDeclSrcLine(zcu).? + 1, // Line |
| 2056 | .none, // Underlying type | |
| 2058 | null, // Underlying type | |
| 2057 | 2059 | 0, // Size |
| 2058 | 2060 | 0, // Align |
| 2059 | .none, // Fields | |
| 2061 | null, // Fields | |
| 2060 | 2062 | ); |
| 2061 | try o.debug_type_map.put(gpa, ty, debug_opaque_type); | |
| 2063 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_opaque_type); | |
| 2062 | 2064 | return debug_opaque_type; |
| 2063 | 2065 | }, |
| 2064 | 2066 | .array => { |
| 2065 | 2067 | const debug_array_type = try o.builder.debugArrayType( |
| 2066 | .none, // Name | |
| 2067 | .none, // File | |
| 2068 | .none, // Scope | |
| 2068 | null, // Name | |
| 2069 | null, // File | |
| 2070 | null, // Scope | |
| 2069 | 2071 | 0, // Line |
| 2070 | 2072 | try o.lowerDebugType(pt, ty.childType(zcu)), |
| 2071 | 2073 | ty.abiSize(zcu) * 8, |
| ... | ... | @@ -2077,7 +2079,7 @@ pub const Object = struct { |
| 2077 | 2079 | ), |
| 2078 | 2080 | }), |
| 2079 | 2081 | ); |
| 2080 | try o.debug_type_map.put(gpa, ty, debug_array_type); | |
| 2082 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_array_type); | |
| 2081 | 2083 | return debug_array_type; |
| 2082 | 2084 | }, |
| 2083 | 2085 | .vector => { |
| ... | ... | @@ -2106,9 +2108,9 @@ pub const Object = struct { |
| 2106 | 2108 | }; |
| 2107 | 2109 | |
| 2108 | 2110 | const debug_vector_type = try o.builder.debugVectorType( |
| 2109 | .none, // Name | |
| 2110 | .none, // File | |
| 2111 | .none, // Scope | |
| 2111 | null, // Name | |
| 2112 | null, // File | |
| 2113 | null, // Scope | |
| 2112 | 2114 | 0, // Line |
| 2113 | 2115 | debug_elem_type, |
| 2114 | 2116 | ty.abiSize(zcu) * 8, |
| ... | ... | @@ -2121,7 +2123,7 @@ pub const Object = struct { |
| 2121 | 2123 | }), |
| 2122 | 2124 | ); |
| 2123 | 2125 | |
| 2124 | try o.debug_type_map.put(gpa, ty, debug_vector_type); | |
| 2126 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_vector_type); | |
| 2125 | 2127 | return debug_vector_type; |
| 2126 | 2128 | }, |
| 2127 | 2129 | .optional => { |
| ... | ... | @@ -2133,22 +2135,22 @@ pub const Object = struct { |
| 2133 | 2135 | try o.builder.metadataString(name), |
| 2134 | 2136 | 8, |
| 2135 | 2137 | ); |
| 2136 | try o.debug_type_map.put(gpa, ty, debug_bool_type); | |
| 2138 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_bool_type); | |
| 2137 | 2139 | return debug_bool_type; |
| 2138 | 2140 | } |
| 2139 | 2141 | |
| 2140 | 2142 | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2141 | 2143 | |
| 2142 | 2144 | // Set as forward reference while the type is lowered in case it references itself |
| 2143 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | |
| 2145 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref); | |
| 2144 | 2146 | |
| 2145 | 2147 | if (ty.optionalReprIsPayload(zcu)) { |
| 2146 | 2148 | const debug_optional_type = try o.lowerDebugType(pt, child_ty); |
| 2147 | 2149 | |
| 2148 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); | |
| 2150 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_optional_type); | |
| 2149 | 2151 | |
| 2150 | 2152 | // Set to real type now that it has been lowered fully |
| 2151 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2153 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2152 | 2154 | map_ptr.* = debug_optional_type; |
| 2153 | 2155 | |
| 2154 | 2156 | return debug_optional_type; |
| ... | ... | @@ -2163,7 +2165,7 @@ pub const Object = struct { |
| 2163 | 2165 | |
| 2164 | 2166 | const debug_data_type = try o.builder.debugMemberType( |
| 2165 | 2167 | try o.builder.metadataString("data"), |
| 2166 | .none, // File | |
| 2168 | null, // File | |
| 2167 | 2169 | debug_fwd_ref, |
| 2168 | 2170 | 0, // Line |
| 2169 | 2171 | try o.lowerDebugType(pt, child_ty), |
| ... | ... | @@ -2174,7 +2176,7 @@ pub const Object = struct { |
| 2174 | 2176 | |
| 2175 | 2177 | const debug_some_type = try o.builder.debugMemberType( |
| 2176 | 2178 | try o.builder.metadataString("some"), |
| 2177 | .none, | |
| 2179 | null, | |
| 2178 | 2180 | debug_fwd_ref, |
| 2179 | 2181 | 0, |
| 2180 | 2182 | try o.lowerDebugType(pt, non_null_ty), |
| ... | ... | @@ -2185,10 +2187,10 @@ pub const Object = struct { |
| 2185 | 2187 | |
| 2186 | 2188 | const debug_optional_type = try o.builder.debugStructType( |
| 2187 | 2189 | try o.builder.metadataString(name), |
| 2188 | .none, // File | |
| 2189 | o.debug_compile_unit, // Scope | |
| 2190 | null, // File | |
| 2191 | o.debug_compile_unit.unwrap().?, // Scope | |
| 2190 | 2192 | 0, // Line |
| 2191 | .none, // Underlying type | |
| 2193 | null, // Underlying type | |
| 2192 | 2194 | ty.abiSize(zcu) * 8, |
| 2193 | 2195 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2194 | 2196 | try o.builder.metadataTuple(&.{ |
| ... | ... | @@ -2197,10 +2199,10 @@ pub const Object = struct { |
| 2197 | 2199 | }), |
| 2198 | 2200 | ); |
| 2199 | 2201 | |
| 2200 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); | |
| 2202 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_optional_type); | |
| 2201 | 2203 | |
| 2202 | 2204 | // Set to real type now that it has been lowered fully |
| 2203 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2205 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2204 | 2206 | map_ptr.* = debug_optional_type; |
| 2205 | 2207 | |
| 2206 | 2208 | return debug_optional_type; |
| ... | ... | @@ -2210,7 +2212,7 @@ pub const Object = struct { |
| 2210 | 2212 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2211 | 2213 | // TODO: Maybe remove? |
| 2212 | 2214 | const debug_error_union_type = try o.lowerDebugType(pt, Type.anyerror); |
| 2213 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); | |
| 2215 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_error_union_type); | |
| 2214 | 2216 | return debug_error_union_type; |
| 2215 | 2217 | } |
| 2216 | 2218 | |
| ... | ... | @@ -2243,7 +2245,7 @@ pub const Object = struct { |
| 2243 | 2245 | var fields: [2]Builder.Metadata = undefined; |
| 2244 | 2246 | fields[error_index] = try o.builder.debugMemberType( |
| 2245 | 2247 | try o.builder.metadataString("tag"), |
| 2246 | .none, // File | |
| 2248 | null, // File | |
| 2247 | 2249 | debug_fwd_ref, |
| 2248 | 2250 | 0, // Line |
| 2249 | 2251 | try o.lowerDebugType(pt, Type.anyerror), |
| ... | ... | @@ -2253,7 +2255,7 @@ pub const Object = struct { |
| 2253 | 2255 | ); |
| 2254 | 2256 | fields[payload_index] = try o.builder.debugMemberType( |
| 2255 | 2257 | try o.builder.metadataString("value"), |
| 2256 | .none, // File | |
| 2258 | null, // File | |
| 2257 | 2259 | debug_fwd_ref, |
| 2258 | 2260 | 0, // Line |
| 2259 | 2261 | try o.lowerDebugType(pt, payload_ty), |
| ... | ... | @@ -2264,18 +2266,18 @@ pub const Object = struct { |
| 2264 | 2266 | |
| 2265 | 2267 | const debug_error_union_type = try o.builder.debugStructType( |
| 2266 | 2268 | try o.builder.metadataString(name), |
| 2267 | .none, // File | |
| 2268 | o.debug_compile_unit, // Sope | |
| 2269 | null, // File | |
| 2270 | o.debug_compile_unit.unwrap().?, // Sope | |
| 2269 | 2271 | 0, // Line |
| 2270 | .none, // Underlying type | |
| 2272 | null, // Underlying type | |
| 2271 | 2273 | ty.abiSize(zcu) * 8, |
| 2272 | 2274 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2273 | 2275 | try o.builder.metadataTuple(&fields), |
| 2274 | 2276 | ); |
| 2275 | 2277 | |
| 2276 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type); | |
| 2278 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_error_union_type); | |
| 2277 | 2279 | |
| 2278 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); | |
| 2280 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_error_union_type); | |
| 2279 | 2281 | return debug_error_union_type; |
| 2280 | 2282 | }, |
| 2281 | 2283 | .error_set => { |
| ... | ... | @@ -2283,7 +2285,7 @@ pub const Object = struct { |
| 2283 | 2285 | try o.builder.metadataString("anyerror"), |
| 2284 | 2286 | 16, |
| 2285 | 2287 | ); |
| 2286 | try o.debug_type_map.put(gpa, ty, debug_error_set); | |
| 2288 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_error_set); | |
| 2287 | 2289 | return debug_error_set; |
| 2288 | 2290 | }, |
| 2289 | 2291 | .@"struct" => { |
| ... | ... | @@ -2299,7 +2301,7 @@ pub const Object = struct { |
| 2299 | 2301 | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8), |
| 2300 | 2302 | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8), |
| 2301 | 2303 | }; |
| 2302 | try o.debug_type_map.put(gpa, ty, debug_int_type); | |
| 2304 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_int_type); | |
| 2303 | 2305 | return debug_int_type; |
| 2304 | 2306 | } |
| 2305 | 2307 | } |
| ... | ... | @@ -2329,7 +2331,7 @@ pub const Object = struct { |
| 2329 | 2331 | |
| 2330 | 2332 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2331 | 2333 | try o.builder.metadataString(field_name), |
| 2332 | .none, // File | |
| 2334 | null, // File | |
| 2333 | 2335 | debug_fwd_ref, |
| 2334 | 2336 | 0, |
| 2335 | 2337 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| ... | ... | @@ -2341,18 +2343,18 @@ pub const Object = struct { |
| 2341 | 2343 | |
| 2342 | 2344 | const debug_struct_type = try o.builder.debugStructType( |
| 2343 | 2345 | try o.builder.metadataString(name), |
| 2344 | .none, // File | |
| 2345 | o.debug_compile_unit, // Scope | |
| 2346 | null, // File | |
| 2347 | o.debug_compile_unit.unwrap().?, // Scope | |
| 2346 | 2348 | 0, // Line |
| 2347 | .none, // Underlying type | |
| 2349 | null, // Underlying type | |
| 2348 | 2350 | ty.abiSize(zcu) * 8, |
| 2349 | 2351 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2350 | 2352 | try o.builder.metadataTuple(fields.items), |
| 2351 | 2353 | ); |
| 2352 | 2354 | |
| 2353 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type); | |
| 2355 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_struct_type); | |
| 2354 | 2356 | |
| 2355 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | |
| 2357 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_struct_type); | |
| 2356 | 2358 | return debug_struct_type; |
| 2357 | 2359 | }, |
| 2358 | 2360 | .struct_type => { |
| ... | ... | @@ -2365,7 +2367,7 @@ pub const Object = struct { |
| 2365 | 2367 | // rather than changing the frontend to unnecessarily resolve the |
| 2366 | 2368 | // struct field types. |
| 2367 | 2369 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2368 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | |
| 2370 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_struct_type); | |
| 2369 | 2371 | return debug_struct_type; |
| 2370 | 2372 | } |
| 2371 | 2373 | }, |
| ... | ... | @@ -2374,7 +2376,7 @@ pub const Object = struct { |
| 2374 | 2376 | |
| 2375 | 2377 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2376 | 2378 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2377 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | |
| 2379 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_struct_type); | |
| 2378 | 2380 | return debug_struct_type; |
| 2379 | 2381 | } |
| 2380 | 2382 | |
| ... | ... | @@ -2388,7 +2390,7 @@ pub const Object = struct { |
| 2388 | 2390 | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2389 | 2391 | |
| 2390 | 2392 | // Set as forward reference while the type is lowered in case it references itself |
| 2391 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | |
| 2393 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref); | |
| 2392 | 2394 | |
| 2393 | 2395 | comptime assert(struct_layout_version == 2); |
| 2394 | 2396 | var it = struct_type.iterateRuntimeOrder(ip); |
| ... | ... | @@ -2402,7 +2404,7 @@ pub const Object = struct { |
| 2402 | 2404 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 2403 | 2405 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2404 | 2406 | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2405 | .none, // File | |
| 2407 | null, // File | |
| 2406 | 2408 | debug_fwd_ref, |
| 2407 | 2409 | 0, // Line |
| 2408 | 2410 | try o.lowerDebugType(pt, field_ty), |
| ... | ... | @@ -2414,19 +2416,19 @@ pub const Object = struct { |
| 2414 | 2416 | |
| 2415 | 2417 | const debug_struct_type = try o.builder.debugStructType( |
| 2416 | 2418 | try o.builder.metadataString(name), |
| 2417 | .none, // File | |
| 2418 | o.debug_compile_unit, // Scope | |
| 2419 | null, // File | |
| 2420 | o.debug_compile_unit.unwrap().?, // Scope | |
| 2419 | 2421 | 0, // Line |
| 2420 | .none, // Underlying type | |
| 2422 | null, // Underlying type | |
| 2421 | 2423 | ty.abiSize(zcu) * 8, |
| 2422 | 2424 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2423 | 2425 | try o.builder.metadataTuple(fields.items), |
| 2424 | 2426 | ); |
| 2425 | 2427 | |
| 2426 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type); | |
| 2428 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_struct_type); | |
| 2427 | 2429 | |
| 2428 | 2430 | // Set to real type now that it has been lowered fully |
| 2429 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2431 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2430 | 2432 | map_ptr.* = debug_struct_type; |
| 2431 | 2433 | |
| 2432 | 2434 | return debug_struct_type; |
| ... | ... | @@ -2441,7 +2443,7 @@ pub const Object = struct { |
| 2441 | 2443 | !union_type.haveLayout(ip)) |
| 2442 | 2444 | { |
| 2443 | 2445 | const debug_union_type = try o.makeEmptyNamespaceDebugType(pt, ty); |
| 2444 | try o.debug_type_map.put(gpa, ty, debug_union_type); | |
| 2446 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_union_type); | |
| 2445 | 2447 | return debug_union_type; |
| 2446 | 2448 | } |
| 2447 | 2449 | |
| ... | ... | @@ -2450,15 +2452,15 @@ pub const Object = struct { |
| 2450 | 2452 | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2451 | 2453 | |
| 2452 | 2454 | // Set as forward reference while the type is lowered in case it references itself |
| 2453 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | |
| 2455 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_fwd_ref); | |
| 2454 | 2456 | |
| 2455 | 2457 | if (layout.payload_size == 0) { |
| 2456 | 2458 | const debug_union_type = try o.builder.debugStructType( |
| 2457 | 2459 | try o.builder.metadataString(name), |
| 2458 | .none, // File | |
| 2459 | o.debug_compile_unit, // Scope | |
| 2460 | null, // File | |
| 2461 | o.debug_compile_unit.unwrap().?, // Scope | |
| 2460 | 2462 | 0, // Line |
| 2461 | .none, // Underlying type | |
| 2463 | null, // Underlying type | |
| 2462 | 2464 | ty.abiSize(zcu) * 8, |
| 2463 | 2465 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2464 | 2466 | try o.builder.metadataTuple( |
| ... | ... | @@ -2467,7 +2469,7 @@ pub const Object = struct { |
| 2467 | 2469 | ); |
| 2468 | 2470 | |
| 2469 | 2471 | // Set to real type now that it has been lowered fully |
| 2470 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2472 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2471 | 2473 | map_ptr.* = debug_union_type; |
| 2472 | 2474 | |
| 2473 | 2475 | return debug_union_type; |
| ... | ... | @@ -2498,7 +2500,7 @@ pub const Object = struct { |
| 2498 | 2500 | const field_name = tag_type.names.get(ip)[field_index]; |
| 2499 | 2501 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2500 | 2502 | try o.builder.metadataString(field_name.toSlice(ip)), |
| 2501 | .none, // File | |
| 2503 | null, // File | |
| 2502 | 2504 | debug_union_fwd_ref, |
| 2503 | 2505 | 0, // Line |
| 2504 | 2506 | try o.lowerDebugType(pt, Type.fromInterned(field_ty)), |
| ... | ... | @@ -2517,20 +2519,20 @@ pub const Object = struct { |
| 2517 | 2519 | |
| 2518 | 2520 | const debug_union_type = try o.builder.debugUnionType( |
| 2519 | 2521 | try o.builder.metadataString(union_name), |
| 2520 | .none, // File | |
| 2521 | o.debug_compile_unit, // Scope | |
| 2522 | null, // File | |
| 2523 | o.debug_compile_unit.unwrap().?, // Scope | |
| 2522 | 2524 | 0, // Line |
| 2523 | .none, // Underlying type | |
| 2525 | null, // Underlying type | |
| 2524 | 2526 | layout.payload_size * 8, |
| 2525 | 2527 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2526 | 2528 | try o.builder.metadataTuple(fields.items), |
| 2527 | 2529 | ); |
| 2528 | 2530 | |
| 2529 | o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type); | |
| 2531 | o.builder.resolveDebugForwardReference(debug_union_fwd_ref, debug_union_type); | |
| 2530 | 2532 | |
| 2531 | 2533 | if (layout.tag_size == 0) { |
| 2532 | 2534 | // Set to real type now that it has been lowered fully |
| 2533 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2535 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2534 | 2536 | map_ptr.* = debug_union_type; |
| 2535 | 2537 | |
| 2536 | 2538 | return debug_union_type; |
| ... | ... | @@ -2548,7 +2550,7 @@ pub const Object = struct { |
| 2548 | 2550 | |
| 2549 | 2551 | const debug_tag_type = try o.builder.debugMemberType( |
| 2550 | 2552 | try o.builder.metadataString("tag"), |
| 2551 | .none, // File | |
| 2553 | null, // File | |
| 2552 | 2554 | debug_fwd_ref, |
| 2553 | 2555 | 0, // Line |
| 2554 | 2556 | try o.lowerDebugType(pt, Type.fromInterned(union_type.enum_tag_ty)), |
| ... | ... | @@ -2559,7 +2561,7 @@ pub const Object = struct { |
| 2559 | 2561 | |
| 2560 | 2562 | const debug_payload_type = try o.builder.debugMemberType( |
| 2561 | 2563 | try o.builder.metadataString("payload"), |
| 2562 | .none, // File | |
| 2564 | null, // File | |
| 2563 | 2565 | debug_fwd_ref, |
| 2564 | 2566 | 0, // Line |
| 2565 | 2567 | debug_union_type, |
| ... | ... | @@ -2576,19 +2578,19 @@ pub const Object = struct { |
| 2576 | 2578 | |
| 2577 | 2579 | const debug_tagged_union_type = try o.builder.debugStructType( |
| 2578 | 2580 | try o.builder.metadataString(name), |
| 2579 | .none, // File | |
| 2580 | o.debug_compile_unit, // Scope | |
| 2581 | null, // File | |
| 2582 | o.debug_compile_unit.unwrap().?, // Scope | |
| 2581 | 2583 | 0, // Line |
| 2582 | .none, // Underlying type | |
| 2584 | null, // Underlying type | |
| 2583 | 2585 | ty.abiSize(zcu) * 8, |
| 2584 | 2586 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2585 | 2587 | try o.builder.metadataTuple(&full_fields), |
| 2586 | 2588 | ); |
| 2587 | 2589 | |
| 2588 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type); | |
| 2590 | o.builder.resolveDebugForwardReference(debug_fwd_ref, debug_tagged_union_type); | |
| 2589 | 2591 | |
| 2590 | 2592 | // Set to real type now that it has been lowered fully |
| 2591 | const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable; | |
| 2593 | const map_ptr = o.debug_type_map.getPtr(ty.toIntern()) orelse unreachable; | |
| 2592 | 2594 | map_ptr.* = debug_tagged_union_type; |
| 2593 | 2595 | |
| 2594 | 2596 | return debug_tagged_union_type; |
| ... | ... | @@ -2636,7 +2638,7 @@ pub const Object = struct { |
| 2636 | 2638 | try o.builder.metadataTuple(debug_param_types.items), |
| 2637 | 2639 | ); |
| 2638 | 2640 | |
| 2639 | try o.debug_type_map.put(gpa, ty, debug_function_type); | |
| 2641 | try o.debug_type_map.put(gpa, ty.toIntern(), debug_function_type); | |
| 2640 | 2642 | return debug_function_type; |
| 2641 | 2643 | }, |
| 2642 | 2644 | .comptime_int => unreachable, |
| ... | ... | @@ -2676,10 +2678,10 @@ pub const Object = struct { |
| 2676 | 2678 | file, |
| 2677 | 2679 | scope, |
| 2678 | 2680 | ty.typeDeclSrcLine(zcu).? + 1, |
| 2679 | .none, | |
| 2681 | null, | |
| 2680 | 2682 | 0, |
| 2681 | 2683 | 0, |
| 2682 | .none, | |
| 2684 | null, | |
| 2683 | 2685 | ); |
| 2684 | 2686 | } |
| 2685 | 2687 | |
| ... | ... | @@ -4687,7 +4689,7 @@ pub const FuncGen = struct { |
| 4687 | 4689 | file: Builder.Metadata, |
| 4688 | 4690 | scope: Builder.Metadata, |
| 4689 | 4691 | |
| 4690 | inlined: Builder.DebugLocation = .no_location, | |
| 4692 | inlined_at: Builder.Metadata.Optional = .none, | |
| 4691 | 4693 | |
| 4692 | 4694 | base_line: u32, |
| 4693 | 4695 | prev_dbg_line: c_uint, |
| ... | ... | @@ -5156,16 +5158,18 @@ pub const FuncGen = struct { |
| 5156 | 5158 | ) Error!void { |
| 5157 | 5159 | if (self.wip.strip) return self.genBody(body, coverage_point); |
| 5158 | 5160 | |
| 5161 | const old_debug_location = self.wip.debug_location; | |
| 5159 | 5162 | const old_file = self.file; |
| 5160 | const old_inlined = self.inlined; | |
| 5163 | const old_inlined_at = self.inlined_at; | |
| 5161 | 5164 | const old_base_line = self.base_line; |
| 5162 | const old_scope = self.scope; | |
| 5163 | 5165 | defer if (maybe_inline_func) |_| { |
| 5164 | self.wip.debug_location = self.inlined; | |
| 5166 | self.wip.debug_location = old_debug_location; | |
| 5165 | 5167 | self.file = old_file; |
| 5166 | self.inlined = old_inlined; | |
| 5168 | self.inlined_at = old_inlined_at; | |
| 5167 | 5169 | self.base_line = old_base_line; |
| 5168 | 5170 | }; |
| 5171 | ||
| 5172 | const old_scope = self.scope; | |
| 5169 | 5173 | defer self.scope = old_scope; |
| 5170 | 5174 | |
| 5171 | 5175 | if (maybe_inline_func) |inline_func| { |
| ... | ... | @@ -5181,8 +5185,9 @@ pub const FuncGen = struct { |
| 5181 | 5185 | |
| 5182 | 5186 | self.file = try o.getDebugFile(pt, file_scope); |
| 5183 | 5187 | |
| 5184 | const line_number = zcu.navSrcLine(func.owner_nav) + 1; | |
| 5185 | self.inlined = self.wip.debug_location; | |
| 5188 | self.base_line = zcu.navSrcLine(func.owner_nav); | |
| 5189 | const line_number = self.base_line + 1; | |
| 5190 | self.inlined_at = try self.wip.debug_location.toMetadata(&o.builder); | |
| 5186 | 5191 | |
| 5187 | 5192 | const fn_ty = try pt.funcType(.{ |
| 5188 | 5193 | .param_types = &.{}, |
| ... | ... | @@ -5201,23 +5206,11 @@ pub const FuncGen = struct { |
| 5201 | 5206 | .sp_flags = .{ |
| 5202 | 5207 | .Optimized = mod.optimize_mode != .Debug, |
| 5203 | 5208 | .Definition = true, |
| 5204 | // TODO: we can't know this at this point, since the function could be exported later! | |
| 5205 | .LocalToUnit = true, | |
| 5209 | .LocalToUnit = true, // inline functions cannot be exported | |
| 5206 | 5210 | }, |
| 5207 | 5211 | }, |
| 5208 | o.debug_compile_unit, | |
| 5212 | o.debug_compile_unit.unwrap().?, | |
| 5209 | 5213 | ); |
| 5210 | ||
| 5211 | self.base_line = zcu.navSrcLine(func.owner_nav); | |
| 5212 | const inlined_at_location = try self.wip.debug_location.toMetadata(&o.builder); | |
| 5213 | self.wip.debug_location = .{ | |
| 5214 | .location = .{ | |
| 5215 | .line = line_number, | |
| 5216 | .column = 0, | |
| 5217 | .scope = self.scope, | |
| 5218 | .inlined_at = inlined_at_location, | |
| 5219 | }, | |
| 5220 | }; | |
| 5221 | 5214 | } |
| 5222 | 5215 | |
| 5223 | 5216 | self.scope = try self.ng.object.builder.debugLexicalBlock( |
| ... | ... | @@ -5226,15 +5219,12 @@ pub const FuncGen = struct { |
| 5226 | 5219 | self.prev_dbg_line, |
| 5227 | 5220 | self.prev_dbg_column, |
| 5228 | 5221 | ); |
| 5229 | ||
| 5230 | switch (self.wip.debug_location) { | |
| 5231 | .location => |*l| l.scope = self.scope, | |
| 5232 | .no_location => {}, | |
| 5233 | } | |
| 5234 | defer switch (self.wip.debug_location) { | |
| 5235 | .location => |*l| l.scope = old_scope, | |
| 5236 | .no_location => {}, | |
| 5237 | }; | |
| 5222 | self.wip.debug_location = .{ .location = .{ | |
| 5223 | .line = self.prev_dbg_line, | |
| 5224 | .column = self.prev_dbg_column, | |
| 5225 | .scope = self.scope.toOptional(), | |
| 5226 | .inlined_at = self.inlined_at, | |
| 5227 | } }; | |
| 5238 | 5228 | |
| 5239 | 5229 | try self.genBody(body, coverage_point); |
| 5240 | 5230 | } |
| ... | ... | @@ -6516,8 +6506,13 @@ pub const FuncGen = struct { |
| 6516 | 6506 | break :llvm_cases_len len; |
| 6517 | 6507 | }; |
| 6518 | 6508 | |
| 6519 | var weights = try self.gpa.alloc(Builder.Metadata, llvm_cases_len + 1); | |
| 6509 | var weights = try self.gpa.alloc(Builder.Metadata, 1 + llvm_cases_len + 1); | |
| 6520 | 6510 | defer self.gpa.free(weights); |
| 6511 | var weight_idx: usize = 0; | |
| 6512 | ||
| 6513 | const branch_weights_str = try o.builder.metadataString("branch_weights"); | |
| 6514 | weights[weight_idx] = branch_weights_str.toMetadata(); | |
| 6515 | weight_idx += 1; | |
| 6521 | 6516 | |
| 6522 | 6517 | const else_weight: u32 = switch (switch_br.getElseHint()) { |
| 6523 | 6518 | .unpredictable => unreachable, |
| ... | ... | @@ -6525,9 +6520,9 @@ pub const FuncGen = struct { |
| 6525 | 6520 | .likely => 2000, |
| 6526 | 6521 | .unlikely => 1, |
| 6527 | 6522 | }; |
| 6528 | weights[0] = try o.builder.metadataConstant(try o.builder.intConst(.i32, else_weight)); | |
| 6523 | weights[weight_idx] = try o.builder.metadataConstant(try o.builder.intConst(.i32, else_weight)); | |
| 6524 | weight_idx += 1; | |
| 6529 | 6525 | |
| 6530 | var weight_idx: usize = 1; | |
| 6531 | 6526 | var it = switch_br.iterateCases(); |
| 6532 | 6527 | while (it.next()) |case| { |
| 6533 | 6528 | const weight_val: u32 = switch (switch_br.getHint(case.idx)) { |
| ... | ... | @@ -6542,10 +6537,7 @@ pub const FuncGen = struct { |
| 6542 | 6537 | } |
| 6543 | 6538 | |
| 6544 | 6539 | assert(weight_idx == weights.len); |
| 6545 | ||
| 6546 | const branch_weights_str = try o.builder.metadataString("branch_weights"); | |
| 6547 | const tuple = try o.builder.strTuple(branch_weights_str, weights); | |
| 6548 | break :weights @enumFromInt(@intFromEnum(tuple)); | |
| 6540 | break :weights .fromMetadata(try o.builder.metadataTuple(weights)); | |
| 6549 | 6541 | }; |
| 6550 | 6542 | |
| 6551 | 6543 | const dispatch_info: SwitchDispatchInfo = .{ |
| ... | ... | @@ -7102,14 +7094,12 @@ pub const FuncGen = struct { |
| 7102 | 7094 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); |
| 7103 | 7095 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); |
| 7104 | 7096 | |
| 7105 | self.wip.debug_location = .{ | |
| 7106 | .location = .{ | |
| 7107 | .line = self.prev_dbg_line, | |
| 7108 | .column = self.prev_dbg_column, | |
| 7109 | .scope = self.scope, | |
| 7110 | .inlined_at = try self.inlined.toMetadata(self.wip.builder), | |
| 7111 | }, | |
| 7112 | }; | |
| 7097 | self.wip.debug_location = .{ .location = .{ | |
| 7098 | .line = self.prev_dbg_line, | |
| 7099 | .column = self.prev_dbg_column, | |
| 7100 | .scope = self.scope.toOptional(), | |
| 7101 | .inlined_at = self.inlined_at, | |
| 7102 | } }; | |
| 7113 | 7103 | |
| 7114 | 7104 | return .none; |
| 7115 | 7105 | } |
| ... | ... | @@ -7167,9 +7157,10 @@ pub const FuncGen = struct { |
| 7167 | 7157 | const operand = try self.resolveInst(pl_op.operand); |
| 7168 | 7158 | const operand_ty = self.typeOf(pl_op.operand); |
| 7169 | 7159 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| 7170 | ||
| 7160 | const name_slice = name.toSlice(self.air); | |
| 7161 | const metadata_name = if (name_slice.len > 0) try o.builder.metadataString(name_slice) else null; | |
| 7171 | 7162 | const debug_local_var = if (is_arg) try o.builder.debugParameter( |
| 7172 | try o.builder.metadataString(name.toSlice(self.air)), | |
| 7163 | metadata_name, | |
| 7173 | 7164 | self.file, |
| 7174 | 7165 | self.scope, |
| 7175 | 7166 | self.prev_dbg_line, |
| ... | ... | @@ -7179,7 +7170,7 @@ pub const FuncGen = struct { |
| 7179 | 7170 | break :arg_no self.arg_inline_index; |
| 7180 | 7171 | }, |
| 7181 | 7172 | ) else try o.builder.debugLocalVar( |
| 7182 | try o.builder.metadataString(name.toSlice(self.air)), | |
| 7173 | metadata_name, | |
| 7183 | 7174 | self.file, |
| 7184 | 7175 | self.scope, |
| 7185 | 7176 | self.prev_dbg_line, |
| ... | ... | @@ -9547,7 +9538,7 @@ pub const FuncGen = struct { |
| 9547 | 9538 | const lbrace_col = func.lbrace_column + 1; |
| 9548 | 9539 | |
| 9549 | 9540 | const debug_parameter = try o.builder.debugParameter( |
| 9550 | try o.builder.metadataString(name), | |
| 9541 | if (name.len > 0) try o.builder.metadataString(name) else null, | |
| 9551 | 9542 | self.file, |
| 9552 | 9543 | self.scope, |
| 9553 | 9544 | lbrace_line, |
| ... | ... | @@ -9556,14 +9547,12 @@ pub const FuncGen = struct { |
| 9556 | 9547 | ); |
| 9557 | 9548 | |
| 9558 | 9549 | const old_location = self.wip.debug_location; |
| 9559 | self.wip.debug_location = .{ | |
| 9560 | .location = .{ | |
| 9561 | .line = lbrace_line, | |
| 9562 | .column = lbrace_col, | |
| 9563 | .scope = self.scope, | |
| 9564 | .inlined_at = .none, | |
| 9565 | }, | |
| 9566 | }; | |
| 9550 | self.wip.debug_location = .{ .location = .{ | |
| 9551 | .line = lbrace_line, | |
| 9552 | .column = lbrace_col, | |
| 9553 | .scope = self.scope.toOptional(), | |
| 9554 | .inlined_at = .none, | |
| 9555 | } }; | |
| 9567 | 9556 | |
| 9568 | 9557 | if (isByRef(inst_ty, zcu)) { |
| 9569 | 9558 | _ = try self.wip.callIntrinsic( |
| ... | ... | @@ -12614,11 +12603,7 @@ fn iterateParamTypes(object: *Object, pt: Zcu.PerThread, fn_info: InternPool.Key |
| 12614 | 12603 | }; |
| 12615 | 12604 | } |
| 12616 | 12605 | |
| 12617 | fn ccAbiPromoteInt( | |
| 12618 | cc: std.builtin.CallingConvention, | |
| 12619 | zcu: *Zcu, | |
| 12620 | ty: Type, | |
| 12621 | ) ?std.builtin.Signedness { | |
| 12606 | fn ccAbiPromoteInt(cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type) ?std.builtin.Signedness { | |
| 12622 | 12607 | const target = zcu.getTarget(); |
| 12623 | 12608 | switch (cc) { |
| 12624 | 12609 | .auto, .@"inline", .async => return null, |