| ... | ... | @@ -24,14 +24,18 @@ attributes_extra: std.ArrayListUnmanaged(u32), |
| 24 | 24 | |
| 25 | 25 | function_attributes_set: std.AutoArrayHashMapUnmanaged(FunctionAttributes, void), |
| 26 | 26 | |
| 27 | | globals: std.AutoArrayHashMapUnmanaged(String, Global), |
| 28 | | next_unnamed_global: String, |
| 29 | | next_replaced_global: String, |
| 30 | | next_unique_global_id: std.AutoHashMapUnmanaged(String, u32), |
| 27 | globals: std.AutoArrayHashMapUnmanaged(StrtabString, Global), |
| 28 | next_unnamed_global: StrtabString, |
| 29 | next_replaced_global: StrtabString, |
| 30 | next_unique_global_id: std.AutoHashMapUnmanaged(StrtabString, u32), |
| 31 | 31 | aliases: std.ArrayListUnmanaged(Alias), |
| 32 | 32 | variables: std.ArrayListUnmanaged(Variable), |
| 33 | 33 | functions: std.ArrayListUnmanaged(Function), |
| 34 | 34 | |
| 35 | strtab_string_map: std.AutoArrayHashMapUnmanaged(void, void), |
| 36 | strtab_string_indices: std.ArrayListUnmanaged(u32), |
| 37 | strtab_string_bytes: std.ArrayListUnmanaged(u8), |
| 38 | |
| 35 | 39 | constant_map: std.AutoArrayHashMapUnmanaged(void, void), |
| 36 | 40 | constant_items: std.MultiArrayList(Constant.Item), |
| 37 | 41 | constant_extra: std.ArrayListUnmanaged(u32), |
| ... | ... | @@ -194,11 +198,6 @@ pub const CmpPredicate = enum(u6) { |
| 194 | 198 | icmp_sle = 41, |
| 195 | 199 | }; |
| 196 | 200 | |
| 197 | | pub const StrtabString = struct { |
| 198 | | offset: usize, |
| 199 | | size: usize, |
| 200 | | }; |
| 201 | | |
| 202 | 201 | pub const Type = enum(u32) { |
| 203 | 202 | void, |
| 204 | 203 | half, |
| ... | ... | @@ -2136,6 +2135,122 @@ pub const CallConv = enum(u10) { |
| 2136 | 2135 | } |
| 2137 | 2136 | }; |
| 2138 | 2137 | |
| 2138 | pub const StrtabString = enum(u32) { |
| 2139 | none = std.math.maxInt(u31), |
| 2140 | empty, |
| 2141 | _, |
| 2142 | |
| 2143 | pub fn isAnon(self: StrtabString) bool { |
| 2144 | assert(self != .none); |
| 2145 | return self.toIndex() == null; |
| 2146 | } |
| 2147 | |
| 2148 | pub fn slice(self: StrtabString, builder: *const Builder) ?[]const u8 { |
| 2149 | const index = self.toIndex() orelse return null; |
| 2150 | const start = builder.strtab_string_indices.items[index]; |
| 2151 | const end = builder.strtab_string_indices.items[index + 1]; |
| 2152 | return builder.strtab_string_bytes.items[start..end]; |
| 2153 | } |
| 2154 | |
| 2155 | const FormatData = struct { |
| 2156 | string: StrtabString, |
| 2157 | builder: *const Builder, |
| 2158 | }; |
| 2159 | fn format( |
| 2160 | data: FormatData, |
| 2161 | comptime fmt_str: []const u8, |
| 2162 | _: std.fmt.FormatOptions, |
| 2163 | writer: anytype, |
| 2164 | ) @TypeOf(writer).Error!void { |
| 2165 | if (comptime std.mem.indexOfNone(u8, fmt_str, "\"r")) |_| |
| 2166 | @compileError("invalid format string: '" ++ fmt_str ++ "'"); |
| 2167 | assert(data.string != .none); |
| 2168 | const string_slice = data.string.slice(data.builder) orelse |
| 2169 | return writer.print("{d}", .{@intFromEnum(data.string)}); |
| 2170 | if (comptime std.mem.indexOfScalar(u8, fmt_str, 'r')) |_| |
| 2171 | return writer.writeAll(string_slice); |
| 2172 | try printEscapedString( |
| 2173 | string_slice, |
| 2174 | if (comptime std.mem.indexOfScalar(u8, fmt_str, '"')) |_| |
| 2175 | .always_quote |
| 2176 | else |
| 2177 | .quote_unless_valid_identifier, |
| 2178 | writer, |
| 2179 | ); |
| 2180 | } |
| 2181 | pub fn fmt(self: StrtabString, builder: *const Builder) std.fmt.Formatter(format) { |
| 2182 | return .{ .data = .{ .string = self, .builder = builder } }; |
| 2183 | } |
| 2184 | |
| 2185 | fn fromIndex(index: ?usize) StrtabString { |
| 2186 | return @enumFromInt(@as(u32, @intCast((index orelse return .none) + |
| 2187 | @intFromEnum(StrtabString.empty)))); |
| 2188 | } |
| 2189 | |
| 2190 | fn toIndex(self: StrtabString) ?usize { |
| 2191 | return std.math.sub(u32, @intFromEnum(self), @intFromEnum(StrtabString.empty)) catch null; |
| 2192 | } |
| 2193 | |
| 2194 | const Adapter = struct { |
| 2195 | builder: *const Builder, |
| 2196 | pub fn hash(_: Adapter, key: []const u8) u32 { |
| 2197 | return @truncate(std.hash.Wyhash.hash(0, key)); |
| 2198 | } |
| 2199 | pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool { |
| 2200 | return std.mem.eql(u8, lhs_key, StrtabString.fromIndex(rhs_index).slice(ctx.builder).?); |
| 2201 | } |
| 2202 | }; |
| 2203 | }; |
| 2204 | |
| 2205 | pub fn strtabString(self: *Builder, bytes: []const u8) Allocator.Error!StrtabString { |
| 2206 | try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len); |
| 2207 | try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 2208 | try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 2209 | |
| 2210 | const gop = self.strtab_string_map.getOrPutAssumeCapacityAdapted(bytes, StrtabString.Adapter{ .builder = self }); |
| 2211 | if (!gop.found_existing) { |
| 2212 | self.strtab_string_bytes.appendSliceAssumeCapacity(bytes); |
| 2213 | self.strtab_string_indices.appendAssumeCapacity(@intCast(self.strtab_string_bytes.items.len)); |
| 2214 | } |
| 2215 | return StrtabString.fromIndex(gop.index); |
| 2216 | } |
| 2217 | |
| 2218 | pub fn strtabStringIfExists(self: *const Builder, bytes: []const u8) ?StrtabString { |
| 2219 | return StrtabString.fromIndex( |
| 2220 | self.strtab_string_map.getIndexAdapted(bytes, StrtabString.Adapter{ .builder = self }) orelse return null, |
| 2221 | ); |
| 2222 | } |
| 2223 | |
| 2224 | pub fn strtabStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!StrtabString { |
| 2225 | try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 2226 | try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args))); |
| 2227 | try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 2228 | return self.strtabStringFmtAssumeCapacity(fmt_str, fmt_args); |
| 2229 | } |
| 2230 | |
| 2231 | pub fn strtabStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) StrtabString { |
| 2232 | self.strtab_string_bytes.writer(undefined).print(fmt_str, fmt_args) catch unreachable; |
| 2233 | return self.trailingStrtabStringAssumeCapacity(); |
| 2234 | } |
| 2235 | |
| 2236 | pub fn trailingStrtabString(self: *Builder) Allocator.Error!StrtabString { |
| 2237 | try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 2238 | try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 2239 | return self.trailingStrtabStringAssumeCapacity(); |
| 2240 | } |
| 2241 | |
| 2242 | pub fn trailingStrtabStringAssumeCapacity(self: *Builder) StrtabString { |
| 2243 | const start = self.strtab_string_indices.getLast(); |
| 2244 | const bytes: []const u8 = self.strtab_string_bytes.items[start..]; |
| 2245 | const gop = self.strtab_string_map.getOrPutAssumeCapacityAdapted(bytes, StrtabString.Adapter{ .builder = self }); |
| 2246 | if (gop.found_existing) { |
| 2247 | self.strtab_string_bytes.shrinkRetainingCapacity(start); |
| 2248 | } else { |
| 2249 | self.strtab_string_indices.appendAssumeCapacity(@intCast(self.strtab_string_bytes.items.len)); |
| 2250 | } |
| 2251 | return StrtabString.fromIndex(gop.index); |
| 2252 | } |
| 2253 | |
| 2139 | 2254 | pub const Global = struct { |
| 2140 | 2255 | linkage: Linkage = .external, |
| 2141 | 2256 | preemption: Preemption = .dso_preemptable, |
| ... | ... | @@ -2179,19 +2294,23 @@ pub const Global = struct { |
| 2179 | 2294 | return &builder.globals.values()[@intFromEnum(self.unwrap(builder))]; |
| 2180 | 2295 | } |
| 2181 | 2296 | |
| 2182 | | pub fn name(self: Index, builder: *const Builder) String { |
| 2297 | pub fn name(self: Index, builder: *const Builder) StrtabString { |
| 2183 | 2298 | return builder.globals.keys()[@intFromEnum(self.unwrap(builder))]; |
| 2184 | 2299 | } |
| 2185 | 2300 | |
| 2186 | | pub fn strtab(self: Index, builder: *const Builder) StrtabString { |
| 2301 | pub fn strtab(self: Index, builder: *const Builder) struct { |
| 2302 | offset: u32, |
| 2303 | size: u32, |
| 2304 | } { |
| 2187 | 2305 | const name_index = self.name(builder).toIndex() orelse return .{ |
| 2188 | 2306 | .offset = 0, |
| 2189 | 2307 | .size = 0, |
| 2190 | 2308 | }; |
| 2191 | 2309 | |
| 2192 | 2310 | return .{ |
| 2193 | | .offset = builder.string_indices.items[name_index], |
| 2194 | | .size = builder.string_indices.items[name_index + 1] - builder.string_indices.items[name_index], |
| 2311 | .offset = builder.strtab_string_indices.items[name_index], |
| 2312 | .size = builder.strtab_string_indices.items[name_index + 1] - |
| 2313 | builder.strtab_string_indices.items[name_index], |
| 2195 | 2314 | }; |
| 2196 | 2315 | } |
| 2197 | 2316 | |
| ... | ... | @@ -2243,7 +2362,7 @@ pub const Global = struct { |
| 2243 | 2362 | return .{ .data = .{ .global = self, .builder = builder } }; |
| 2244 | 2363 | } |
| 2245 | 2364 | |
| 2246 | | pub fn rename(self: Index, new_name: String, builder: *Builder) Allocator.Error!void { |
| 2365 | pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void { |
| 2247 | 2366 | try builder.ensureUnusedGlobalCapacity(new_name); |
| 2248 | 2367 | self.renameAssumeCapacity(new_name, builder); |
| 2249 | 2368 | } |
| ... | ... | @@ -2282,7 +2401,7 @@ pub const Global = struct { |
| 2282 | 2401 | } |
| 2283 | 2402 | } |
| 2284 | 2403 | |
| 2285 | | fn renameAssumeCapacity(self: Index, new_name: String, builder: *Builder) void { |
| 2404 | fn renameAssumeCapacity(self: Index, new_name: StrtabString, builder: *Builder) void { |
| 2286 | 2405 | const old_name = self.name(builder); |
| 2287 | 2406 | if (new_name == old_name) return; |
| 2288 | 2407 | const index = @intFromEnum(self.unwrap(builder)); |
| ... | ... | @@ -2333,11 +2452,11 @@ pub const Alias = struct { |
| 2333 | 2452 | return &builder.aliases.items[@intFromEnum(self)]; |
| 2334 | 2453 | } |
| 2335 | 2454 | |
| 2336 | | pub fn name(self: Index, builder: *const Builder) String { |
| 2455 | pub fn name(self: Index, builder: *const Builder) StrtabString { |
| 2337 | 2456 | return self.ptrConst(builder).global.name(builder); |
| 2338 | 2457 | } |
| 2339 | 2458 | |
| 2340 | | pub fn rename(self: Index, new_name: String, builder: *Builder) Allocator.Error!void { |
| 2459 | pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void { |
| 2341 | 2460 | return self.ptrConst(builder).global.rename(new_name, builder); |
| 2342 | 2461 | } |
| 2343 | 2462 | |
| ... | ... | @@ -2385,11 +2504,11 @@ pub const Variable = struct { |
| 2385 | 2504 | return &builder.variables.items[@intFromEnum(self)]; |
| 2386 | 2505 | } |
| 2387 | 2506 | |
| 2388 | | pub fn name(self: Index, builder: *const Builder) String { |
| 2507 | pub fn name(self: Index, builder: *const Builder) StrtabString { |
| 2389 | 2508 | return self.ptrConst(builder).global.name(builder); |
| 2390 | 2509 | } |
| 2391 | 2510 | |
| 2392 | | pub fn rename(self: Index, new_name: String, builder: *Builder) Allocator.Error!void { |
| 2511 | pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void { |
| 2393 | 2512 | return self.ptrConst(builder).global.rename(new_name, builder); |
| 2394 | 2513 | } |
| 2395 | 2514 | |
| ... | ... | @@ -3814,11 +3933,11 @@ pub const Function = struct { |
| 3814 | 3933 | return &builder.functions.items[@intFromEnum(self)]; |
| 3815 | 3934 | } |
| 3816 | 3935 | |
| 3817 | | pub fn name(self: Index, builder: *const Builder) String { |
| 3936 | pub fn name(self: Index, builder: *const Builder) StrtabString { |
| 3818 | 3937 | return self.ptrConst(builder).global.name(builder); |
| 3819 | 3938 | } |
| 3820 | 3939 | |
| 3821 | | pub fn rename(self: Index, new_name: String, builder: *Builder) Allocator.Error!void { |
| 3940 | pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void { |
| 3822 | 3941 | return self.ptrConst(builder).global.rename(new_name, builder); |
| 3823 | 3942 | } |
| 3824 | 3943 | |
| ... | ... | @@ -8331,6 +8450,10 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8331 | 8450 | .variables = .{}, |
| 8332 | 8451 | .functions = .{}, |
| 8333 | 8452 | |
| 8453 | .strtab_string_map = .{}, |
| 8454 | .strtab_string_indices = .{}, |
| 8455 | .strtab_string_bytes = .{}, |
| 8456 | |
| 8334 | 8457 | .constant_map = .{}, |
| 8335 | 8458 | .constant_items = .{}, |
| 8336 | 8459 | .constant_extra = .{}, |
| ... | ... | @@ -8351,6 +8474,9 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8351 | 8474 | try self.string_indices.append(self.gpa, 0); |
| 8352 | 8475 | assert(try self.string("") == .empty); |
| 8353 | 8476 | |
| 8477 | try self.strtab_string_indices.append(self.gpa, 0); |
| 8478 | assert(try self.strtabString("") == .empty); |
| 8479 | |
| 8354 | 8480 | if (options.name.len > 0) self.source_filename = try self.string(options.name); |
| 8355 | 8481 | |
| 8356 | 8482 | if (options.triple.len > 0) { |
| ... | ... | @@ -8423,6 +8549,10 @@ pub fn clearAndFree(self: *Builder) void { |
| 8423 | 8549 | for (self.functions.items) |*function| function.deinit(self.gpa); |
| 8424 | 8550 | self.functions.clearAndFree(self.gpa); |
| 8425 | 8551 | |
| 8552 | self.strtab_string_map.clearAndFree(self.gpa); |
| 8553 | self.strtab_string_indices.clearAndFree(self.gpa); |
| 8554 | self.strtab_string_bytes.clearAndFree(self.gpa); |
| 8555 | |
| 8426 | 8556 | self.constant_map.clearAndFree(self.gpa); |
| 8427 | 8557 | self.constant_items.shrinkAndFree(self.gpa, 0); |
| 8428 | 8558 | self.constant_extra.clearAndFree(self.gpa); |
| ... | ... | @@ -8467,6 +8597,10 @@ pub fn deinit(self: *Builder) void { |
| 8467 | 8597 | for (self.functions.items) |*function| function.deinit(self.gpa); |
| 8468 | 8598 | self.functions.deinit(self.gpa); |
| 8469 | 8599 | |
| 8600 | self.strtab_string_map.deinit(self.gpa); |
| 8601 | self.strtab_string_indices.deinit(self.gpa); |
| 8602 | self.strtab_string_bytes.deinit(self.gpa); |
| 8603 | |
| 8470 | 8604 | self.constant_map.deinit(self.gpa); |
| 8471 | 8605 | self.constant_items.deinit(self.gpa); |
| 8472 | 8606 | self.constant_extra.deinit(self.gpa); |
| ... | ... | @@ -8660,14 +8794,14 @@ pub fn fnAttrs(self: *Builder, fn_attributes: []const Attributes) Allocator.Erro |
| 8660 | 8794 | return function_attributes; |
| 8661 | 8795 | } |
| 8662 | 8796 | |
| 8663 | | pub fn addGlobal(self: *Builder, name: String, global: Global) Allocator.Error!Global.Index { |
| 8797 | pub fn addGlobal(self: *Builder, name: StrtabString, global: Global) Allocator.Error!Global.Index { |
| 8664 | 8798 | assert(!name.isAnon()); |
| 8665 | 8799 | try self.ensureUnusedTypeCapacity(1, NoExtra, 0); |
| 8666 | 8800 | try self.ensureUnusedGlobalCapacity(name); |
| 8667 | 8801 | return self.addGlobalAssumeCapacity(name, global); |
| 8668 | 8802 | } |
| 8669 | 8803 | |
| 8670 | | pub fn addGlobalAssumeCapacity(self: *Builder, name: String, global: Global) Global.Index { |
| 8804 | pub fn addGlobalAssumeCapacity(self: *Builder, name: StrtabString, global: Global) Global.Index { |
| 8671 | 8805 | _ = self.ptrTypeAssumeCapacity(global.addr_space); |
| 8672 | 8806 | var id = name; |
| 8673 | 8807 | if (name == .empty) { |
| ... | ... | @@ -8686,18 +8820,18 @@ pub fn addGlobalAssumeCapacity(self: *Builder, name: String, global: Global) Glo |
| 8686 | 8820 | |
| 8687 | 8821 | const unique_gop = self.next_unique_global_id.getOrPutAssumeCapacity(name); |
| 8688 | 8822 | if (!unique_gop.found_existing) unique_gop.value_ptr.* = 2; |
| 8689 | | id = self.fmtAssumeCapacity("{s}.{d}", .{ name.slice(self).?, unique_gop.value_ptr.* }); |
| 8823 | id = self.strtabStringFmtAssumeCapacity("{s}.{d}", .{ name.slice(self).?, unique_gop.value_ptr.* }); |
| 8690 | 8824 | unique_gop.value_ptr.* += 1; |
| 8691 | 8825 | } |
| 8692 | 8826 | } |
| 8693 | 8827 | |
| 8694 | | pub fn getGlobal(self: *const Builder, name: String) ?Global.Index { |
| 8828 | pub fn getGlobal(self: *const Builder, name: StrtabString) ?Global.Index { |
| 8695 | 8829 | return @enumFromInt(self.globals.getIndex(name) orelse return null); |
| 8696 | 8830 | } |
| 8697 | 8831 | |
| 8698 | 8832 | pub fn addAlias( |
| 8699 | 8833 | self: *Builder, |
| 8700 | | name: String, |
| 8834 | name: StrtabString, |
| 8701 | 8835 | ty: Type, |
| 8702 | 8836 | addr_space: AddrSpace, |
| 8703 | 8837 | aliasee: Constant, |
| ... | ... | @@ -8711,7 +8845,7 @@ pub fn addAlias( |
| 8711 | 8845 | |
| 8712 | 8846 | pub fn addAliasAssumeCapacity( |
| 8713 | 8847 | self: *Builder, |
| 8714 | | name: String, |
| 8848 | name: StrtabString, |
| 8715 | 8849 | ty: Type, |
| 8716 | 8850 | addr_space: AddrSpace, |
| 8717 | 8851 | aliasee: Constant, |
| ... | ... | @@ -8727,7 +8861,7 @@ pub fn addAliasAssumeCapacity( |
| 8727 | 8861 | |
| 8728 | 8862 | pub fn addVariable( |
| 8729 | 8863 | self: *Builder, |
| 8730 | | name: String, |
| 8864 | name: StrtabString, |
| 8731 | 8865 | ty: Type, |
| 8732 | 8866 | addr_space: AddrSpace, |
| 8733 | 8867 | ) Allocator.Error!Variable.Index { |
| ... | ... | @@ -8741,7 +8875,7 @@ pub fn addVariable( |
| 8741 | 8875 | pub fn addVariableAssumeCapacity( |
| 8742 | 8876 | self: *Builder, |
| 8743 | 8877 | ty: Type, |
| 8744 | | name: String, |
| 8878 | name: StrtabString, |
| 8745 | 8879 | addr_space: AddrSpace, |
| 8746 | 8880 | ) Variable.Index { |
| 8747 | 8881 | const variable_index: Variable.Index = @enumFromInt(self.variables.items.len); |
| ... | ... | @@ -8756,7 +8890,7 @@ pub fn addVariableAssumeCapacity( |
| 8756 | 8890 | pub fn addFunction( |
| 8757 | 8891 | self: *Builder, |
| 8758 | 8892 | ty: Type, |
| 8759 | | name: String, |
| 8893 | name: StrtabString, |
| 8760 | 8894 | addr_space: AddrSpace, |
| 8761 | 8895 | ) Allocator.Error!Function.Index { |
| 8762 | 8896 | assert(!name.isAnon()); |
| ... | ... | @@ -8769,7 +8903,7 @@ pub fn addFunction( |
| 8769 | 8903 | pub fn addFunctionAssumeCapacity( |
| 8770 | 8904 | self: *Builder, |
| 8771 | 8905 | ty: Type, |
| 8772 | | name: String, |
| 8906 | name: StrtabString, |
| 8773 | 8907 | addr_space: AddrSpace, |
| 8774 | 8908 | ) Function.Index { |
| 8775 | 8909 | assert(ty.isFunction(self)); |
| ... | ... | @@ -8803,10 +8937,10 @@ pub fn getIntrinsic( |
| 8803 | 8937 | const allocator = stack.get(); |
| 8804 | 8938 | |
| 8805 | 8939 | const name = name: { |
| 8806 | | const writer = self.string_bytes.writer(self.gpa); |
| 8940 | const writer = self.strtab_string_bytes.writer(self.gpa); |
| 8807 | 8941 | try writer.print("llvm.{s}", .{@tagName(id)}); |
| 8808 | 8942 | for (overload) |ty| try writer.print(".{m}", .{ty.fmt(self)}); |
| 8809 | | break :name try self.trailingString(); |
| 8943 | break :name try self.trailingStrtabString(); |
| 8810 | 8944 | }; |
| 8811 | 8945 | if (self.getGlobal(name)) |global| return global.ptrConst(self).kind.function; |
| 8812 | 8946 | |
| ... | ... | @@ -10366,13 +10500,13 @@ fn printEscapedString( |
| 10366 | 10500 | if (need_quotes) try writer.writeByte('"'); |
| 10367 | 10501 | } |
| 10368 | 10502 | |
| 10369 | | fn ensureUnusedGlobalCapacity(self: *Builder, name: String) Allocator.Error!void { |
| 10370 | | try self.string_map.ensureUnusedCapacity(self.gpa, 1); |
| 10503 | fn ensureUnusedGlobalCapacity(self: *Builder, name: StrtabString) Allocator.Error!void { |
| 10504 | try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 10371 | 10505 | if (name.slice(self)) |id| { |
| 10372 | 10506 | const count: usize = comptime std.fmt.count("{d}", .{std.math.maxInt(u32)}); |
| 10373 | | try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count); |
| 10507 | try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, id.len + count); |
| 10374 | 10508 | } |
| 10375 | | try self.string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 10509 | try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| 10376 | 10510 | try self.globals.ensureUnusedCapacity(self.gpa, 1); |
| 10377 | 10511 | try self.next_unique_global_id.ensureUnusedCapacity(self.gpa, 1); |
| 10378 | 10512 | } |
| ... | ... | @@ -11893,7 +12027,7 @@ pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!Metadat |
| 11893 | 12027 | return @enumFromInt(gop.index); |
| 11894 | 12028 | } |
| 11895 | 12029 | |
| 11896 | | pub fn metadataStringFromString(self: *Builder, str: String) Allocator.Error!MetadataString { |
| 12030 | pub fn metadataStringFromStrtabString(self: *Builder, str: StrtabString) Allocator.Error!MetadataString { |
| 11897 | 12031 | if (str == .none or str == .empty) return MetadataString.none; |
| 11898 | 12032 | return try self.metadataString(str.slice(self).?); |
| 11899 | 12033 | } |
| ... | ... | @@ -15059,7 +15193,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 15059 | 15193 | const Strtab = ir.Strtab; |
| 15060 | 15194 | var strtab_block = try bitcode.enterTopBlock(Strtab); |
| 15061 | 15195 | |
| 15062 | | try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.string_bytes.items }); |
| 15196 | try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items }); |
| 15063 | 15197 | |
| 15064 | 15198 | try strtab_block.end(); |
| 15065 | 15199 | } |