| author | |
| committer | |
| log | fdb4cdfff1efb93eda20bf8033c7b3fd4366e688 |
| tree | a24596026154fda89008669134d9ad2aeed55bc2 |
| parent | 1c26a0e8dd32c38df5a751d33456c7ed0da29006 |
3 files changed, 50 insertions(+), 46 deletions(-)
lib/std/zig/llvm/BitcodeReader.zig+15-15| ... | @@ -60,40 +60,40 @@ pub const Record = struct { | ... | @@ -60,40 +60,40 @@ pub const Record = struct { |
| 60 | blob: []const u8, | 60 | blob: []const u8, |
| 61 | 61 | ||
| 62 | fn toOwnedAbbrev(record: Record, allocator: std.mem.Allocator) !Abbrev { | 62 | fn toOwnedAbbrev(record: Record, allocator: std.mem.Allocator) !Abbrev { |
| 63 | var operands = std.array_list.Managed(Abbrev.Operand).init(allocator); | 63 | var operands: std.ArrayList(Abbrev.Operand) = .empty; |
| 64 | defer operands.deinit(); | 64 | defer operands.deinit(allocator); |
| 65 | 65 | ||
| 66 | assert(record.id == Abbrev.Builtin.define_abbrev.toRecordId()); | 66 | assert(record.id == Abbrev.Builtin.define_abbrev.toRecordId()); |
| 67 | var i: usize = 0; | 67 | var i: usize = 0; |
| 68 | while (i < record.operands.len) switch (record.operands[i]) { | 68 | while (i < record.operands.len) switch (record.operands[i]) { |
| 69 | Abbrev.Operand.literal_id => { | 69 | Abbrev.Operand.literal_id => { |
| 70 | try operands.append(.{ .literal = record.operands[i + 1] }); | 70 | try operands.append(allocator, .{ .literal = record.operands[i + 1] }); |
| 71 | i += 2; | 71 | i += 2; |
| 72 | }, | 72 | }, |
| 73 | @backingInt(Abbrev.Operand.Encoding.fixed) => { | 73 | @backingInt(Abbrev.Operand.Encoding.fixed) => { |
| 74 | try operands.append(.{ .encoding = .{ .fixed = @intCast(record.operands[i + 1]) } }); | 74 | try operands.append(allocator, .{ .encoding = .{ .fixed = @intCast(record.operands[i + 1]) } }); |
| 75 | i += 2; | 75 | i += 2; |
| 76 | }, | 76 | }, |
| 77 | @backingInt(Abbrev.Operand.Encoding.vbr) => { | 77 | @backingInt(Abbrev.Operand.Encoding.vbr) => { |
| 78 | try operands.append(.{ .encoding = .{ .vbr = @intCast(record.operands[i + 1]) } }); | 78 | try operands.append(allocator, .{ .encoding = .{ .vbr = @intCast(record.operands[i + 1]) } }); |
| 79 | i += 2; | 79 | i += 2; |
| 80 | }, | 80 | }, |
| 81 | @backingInt(Abbrev.Operand.Encoding.array) => { | 81 | @backingInt(Abbrev.Operand.Encoding.array) => { |
| 82 | try operands.append(.{ .encoding = .{ .array = 6 } }); | 82 | try operands.append(allocator, .{ .encoding = .{ .array = 6 } }); |
| 83 | i += 1; | 83 | i += 1; |
| 84 | }, | 84 | }, |
| 85 | @backingInt(Abbrev.Operand.Encoding.char6) => { | 85 | @backingInt(Abbrev.Operand.Encoding.char6) => { |
| 86 | try operands.append(.{ .encoding = .char6 }); | 86 | try operands.append(allocator, .{ .encoding = .char6 }); |
| 87 | i += 1; | 87 | i += 1; |
| 88 | }, | 88 | }, |
| 89 | @backingInt(Abbrev.Operand.Encoding.blob) => { | 89 | @backingInt(Abbrev.Operand.Encoding.blob) => { |
| 90 | try operands.append(.{ .encoding = .{ .blob = 6 } }); | 90 | try operands.append(allocator, .{ .encoding = .{ .blob = 6 } }); |
| 91 | i += 1; | 91 | i += 1; |
| 92 | }, | 92 | }, |
| 93 | else => unreachable, | 93 | else => unreachable, |
| 94 | }; | 94 | }; |
| 95 | 95 | ||
| 96 | return .{ .operands = try operands.toOwnedSlice() }; | 96 | return .{ .operands = try operands.toOwnedSlice(allocator) }; |
| 97 | } | 97 | } |
| 98 | }; | 98 | }; |
| 99 | 99 | ||
| ... | @@ -198,8 +198,8 @@ fn nextRecord(bc: *BitcodeReader) !?Record { | ... | @@ -198,8 +198,8 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 198 | defer bc.record_arena = record_arena.state; | 198 | defer bc.record_arena = record_arena.state; |
| 199 | _ = record_arena.reset(.retain_capacity); | 199 | _ = record_arena.reset(.retain_capacity); |
| 200 | 200 | ||
| 201 | var operands = try std.array_list.Managed(u64).initCapacity(record_arena.allocator(), abbrev.operands.len); | 201 | var operands: std.ArrayList(u64) = try .initCapacity(record_arena.allocator(), abbrev.operands.len); |
| 202 | var blob = std.array_list.Managed(u8).init(record_arena.allocator()); | 202 | var blob: std.ArrayList(u8) = .empty; |
| 203 | for (abbrev.operands, 0..) |abbrev_operand, abbrev_operand_i| switch (abbrev_operand) { | 203 | for (abbrev.operands, 0..) |abbrev_operand, abbrev_operand_i| switch (abbrev_operand) { |
| 204 | .literal => |value| operands.appendAssumeCapacity(value), | 204 | .literal => |value| operands.appendAssumeCapacity(value), |
| 205 | .encoding => |abbrev_encoding| switch (abbrev_encoding) { | 205 | .encoding => |abbrev_encoding| switch (abbrev_encoding) { |
| ... | @@ -208,7 +208,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { | ... | @@ -208,7 +208,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 208 | .array => |len_width| { | 208 | .array => |len_width| { |
| 209 | assert(abbrev_operand_i + 2 == abbrev.operands.len); | 209 | assert(abbrev_operand_i + 2 == abbrev.operands.len); |
| 210 | const len: usize = @intCast(try bc.readVbr(u32, len_width)); | 210 | const len: usize = @intCast(try bc.readVbr(u32, len_width)); |
| 211 | try operands.ensureUnusedCapacity(len); | 211 | try operands.ensureUnusedCapacity(record_arena.allocator(), len); |
| 212 | for (0..len) |_| switch (abbrev.operands[abbrev.operands.len - 1]) { | 212 | for (0..len) |_| switch (abbrev.operands[abbrev.operands.len - 1]) { |
| 213 | .literal => |elem_value| operands.appendAssumeCapacity(elem_value), | 213 | .literal => |elem_value| operands.appendAssumeCapacity(elem_value), |
| 214 | .encoding => |elem_encoding| switch (elem_encoding) { | 214 | .encoding => |elem_encoding| switch (elem_encoding) { |
| ... | @@ -219,14 +219,14 @@ fn nextRecord(bc: *BitcodeReader) !?Record { | ... | @@ -219,14 +219,14 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 219 | }, | 219 | }, |
| 220 | .align_32_bits, .block_len => return error.UnsupportedArrayElement, | 220 | .align_32_bits, .block_len => return error.UnsupportedArrayElement, |
| 221 | .abbrev_op => switch (try bc.readFixed(u1, 1)) { | 221 | .abbrev_op => switch (try bc.readFixed(u1, 1)) { |
| 222 | 1 => try operands.appendSlice(&.{ | 222 | 1 => try operands.appendSlice(record_arena.allocator(), &.{ |
| 223 | Abbrev.Operand.literal_id, | 223 | Abbrev.Operand.literal_id, |
| 224 | try bc.readVbr(u64, 8), | 224 | try bc.readVbr(u64, 8), |
| 225 | }), | 225 | }), |
| 226 | 0 => { | 226 | 0 => { |
| 227 | const encoding: Abbrev.Operand.Encoding = | 227 | const encoding: Abbrev.Operand.Encoding = |
| 228 | @fromBackingInt(@intCast(try bc.readFixed(u3, 3))); | 228 | @fromBackingInt(@intCast(try bc.readFixed(u3, 3))); |
| 229 | try operands.append(@backingInt(encoding)); | 229 | try operands.append(record_arena.allocator(), @backingInt(encoding)); |
| 230 | switch (encoding) { | 230 | switch (encoding) { |
| 231 | .fixed, .vbr => try operands.append(try bc.readVbr(u7, 5)), | 231 | .fixed, .vbr => try operands.append(try bc.readVbr(u7, 5)), |
| 232 | .array, .char6, .blob => {}, | 232 | .array, .char6, .blob => {}, |
| ... | @@ -243,7 +243,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { | ... | @@ -243,7 +243,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 243 | const len = std.math.cast(usize, try bc.readVbr(u32, len_width)) orelse | 243 | const len = std.math.cast(usize, try bc.readVbr(u32, len_width)) orelse |
| 244 | return error.Overflow; | 244 | return error.Overflow; |
| 245 | bc.align32Bits(); | 245 | bc.align32Bits(); |
| 246 | try bc.readBytes(try blob.addManyAsSlice(len)); | 246 | try bc.readBytes(try blob.addManyAsSlice(record_arena.allocator(), len)); |
| 247 | bc.align32Bits(); | 247 | bc.align32Bits(); |
| 248 | }, | 248 | }, |
| 249 | }, | 249 | }, |
lib/std/zig/llvm/Builder.zig+25-25| ... | @@ -95,8 +95,8 @@ fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.F | ... | @@ -95,8 +95,8 @@ fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.F |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const u8 { | 97 | pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const u8 { |
| 98 | var llvm_triple = std.array_list.Managed(u8).init(allocator); | 98 | var llvm_triple: std.ArrayList(u8) = .empty; |
| 99 | defer llvm_triple.deinit(); | 99 | defer llvm_triple.deinit(allocator); |
| 100 | 100 | ||
| 101 | const llvm_arch = switch (target.cpu.arch) { | 101 | const llvm_arch = switch (target.cpu.arch) { |
| 102 | .arm => "arm", | 102 | .arm => "arm", |
| ... | @@ -168,7 +168,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const | ... | @@ -168,7 +168,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const |
| 168 | => unreachable, // Gated by hasLlvmSupport(). | 168 | => unreachable, // Gated by hasLlvmSupport(). |
| 169 | }; | 169 | }; |
| 170 | 170 | ||
| 171 | try llvm_triple.appendSlice(llvm_arch); | 171 | try llvm_triple.appendSlice(allocator, llvm_arch); |
| 172 | 172 | ||
| 173 | const llvm_sub_arch: ?[]const u8 = switch (target.cpu.arch) { | 173 | const llvm_sub_arch: ?[]const u8 = switch (target.cpu.arch) { |
| 174 | .arm, .armeb, .thumb, .thumbeb => subArchName(target, .arm, .{ | 174 | .arm, .armeb, .thumb, .thumbeb => subArchName(target, .arm, .{ |
| ... | @@ -223,10 +223,10 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const | ... | @@ -223,10 +223,10 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const |
| 223 | else => null, | 223 | else => null, |
| 224 | }; | 224 | }; |
| 225 | 225 | ||
| 226 | if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(sub); | 226 | if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(allocator, sub); |
| 227 | try llvm_triple.append('-'); | 227 | try llvm_triple.append(allocator, '-'); |
| 228 | 228 | ||
| 229 | try llvm_triple.appendSlice(switch (target.os.tag) { | 229 | try llvm_triple.appendSlice(allocator, switch (target.os.tag) { |
| 230 | .driverkit, | 230 | .driverkit, |
| 231 | .ios, | 231 | .ios, |
| 232 | .maccatalyst, | 232 | .maccatalyst, |
| ... | @@ -248,7 +248,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const | ... | @@ -248,7 +248,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const |
| 248 | => "mesa", | 248 | => "mesa", |
| 249 | else => "unknown", | 249 | else => "unknown", |
| 250 | }); | 250 | }); |
| 251 | try llvm_triple.append('-'); | 251 | try llvm_triple.append(allocator, '-'); |
| 252 | 252 | ||
| 253 | const llvm_os = switch (target.os.tag) { | 253 | const llvm_os = switch (target.os.tag) { |
| 254 | .dragonfly => "dragonfly", | 254 | .dragonfly => "dragonfly", |
| ... | @@ -298,28 +298,28 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const | ... | @@ -298,28 +298,28 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const |
| 298 | .ashetos, | 298 | .ashetos, |
| 299 | => "unknown", | 299 | => "unknown", |
| 300 | }; | 300 | }; |
| 301 | try llvm_triple.appendSlice(llvm_os); | 301 | try llvm_triple.appendSlice(allocator, llvm_os); |
| 302 | 302 | ||
| 303 | switch (target.os.versionRange()) { | 303 | switch (target.os.versionRange()) { |
| 304 | .none, | 304 | .none, |
| 305 | .windows, | 305 | .windows, |
| 306 | => {}, | 306 | => {}, |
| 307 | .semver => |ver| if (target.os.tag == .wasi and ver.min.major == 0) { | 307 | .semver => |ver| if (target.os.tag == .wasi and ver.min.major == 0) { |
| 308 | try llvm_triple.print("p{d}", .{ver.min.minor}); | 308 | try llvm_triple.print(allocator, "p{d}", .{ver.min.minor}); |
| 309 | } else if (target.os.tag != .amdhsa) { | 309 | } else if (target.os.tag != .amdhsa) { |
| 310 | try llvm_triple.print("{d}.{d}.{d}", .{ | 310 | try llvm_triple.print(allocator, "{d}.{d}.{d}", .{ |
| 311 | ver.min.major, | 311 | ver.min.major, |
| 312 | ver.min.minor, | 312 | ver.min.minor, |
| 313 | ver.min.patch, | 313 | ver.min.patch, |
| 314 | }); | 314 | }); |
| 315 | }, | 315 | }, |
| 316 | inline .linux, .hurd => |ver| try llvm_triple.print("{d}.{d}.{d}", .{ | 316 | inline .linux, .hurd => |ver| try llvm_triple.print(allocator, "{d}.{d}.{d}", .{ |
| 317 | ver.range.min.major, | 317 | ver.range.min.major, |
| 318 | ver.range.min.minor, | 318 | ver.range.min.minor, |
| 319 | ver.range.min.patch, | 319 | ver.range.min.patch, |
| 320 | }), | 320 | }), |
| 321 | } | 321 | } |
| 322 | try llvm_triple.append('-'); | 322 | try llvm_triple.append(allocator, '-'); |
| 323 | 323 | ||
| 324 | const llvm_abi = switch (target.abi) { | 324 | const llvm_abi = switch (target.abi) { |
| 325 | .none => if (target.os.tag == .maccatalyst) "macabi" else "unknown", | 325 | .none => if (target.os.tag == .maccatalyst) "macabi" else "unknown", |
| ... | @@ -357,7 +357,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const | ... | @@ -357,7 +357,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const |
| 357 | .ohos, .ohoseabi => "ohos", | 357 | .ohos, .ohoseabi => "ohos", |
| 358 | .call0 => "unknown", | 358 | .call0 => "unknown", |
| 359 | }; | 359 | }; |
| 360 | try llvm_triple.appendSlice(llvm_abi); | 360 | try llvm_triple.appendSlice(allocator, llvm_abi); |
| 361 | 361 | ||
| 362 | switch (target.os.versionRange()) { | 362 | switch (target.os.versionRange()) { |
| 363 | .none, | 363 | .none, |
| ... | @@ -365,17 +365,17 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const | ... | @@ -365,17 +365,17 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const |
| 365 | .windows, | 365 | .windows, |
| 366 | => {}, | 366 | => {}, |
| 367 | inline .hurd, .linux => |ver| if (target.abi.isGnu()) { | 367 | inline .hurd, .linux => |ver| if (target.abi.isGnu()) { |
| 368 | try llvm_triple.print("{d}.{d}.{d}", .{ | 368 | try llvm_triple.print(allocator, "{d}.{d}.{d}", .{ |
| 369 | ver.glibc.major, | 369 | ver.glibc.major, |
| 370 | ver.glibc.minor, | 370 | ver.glibc.minor, |
| 371 | ver.glibc.patch, | 371 | ver.glibc.patch, |
| 372 | }); | 372 | }); |
| 373 | } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) { | 373 | } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) { |
| 374 | try llvm_triple.print("{d}", .{ver.android}); | 374 | try llvm_triple.print(allocator, "{d}", .{ver.android}); |
| 375 | }, | 375 | }, |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | return llvm_triple.toOwnedSlice(); | 378 | return llvm_triple.toOwnedSlice(allocator); |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | pub const DataLayout = struct { | 381 | pub const DataLayout = struct { |
| ... | @@ -10442,24 +10442,24 @@ pub fn getIntrinsic( | ... | @@ -10442,24 +10442,24 @@ pub fn getIntrinsic( |
| 10442 | 10442 | ||
| 10443 | var attributes: struct { | 10443 | var attributes: struct { |
| 10444 | builder: *Builder, | 10444 | builder: *Builder, |
| 10445 | list: std.array_list.Managed(Attribute.Index), | 10445 | list: std.ArrayList(Attribute.Index), |
| 10446 | 10446 | ||
| 10447 | fn deinit(state: *@This()) void { | 10447 | fn deinit(state: *@This(), gpa: Allocator) void { |
| 10448 | state.list.deinit(); | 10448 | state.list.deinit(gpa); |
| 10449 | state.* = undefined; | 10449 | state.* = undefined; |
| 10450 | } | 10450 | } |
| 10451 | 10451 | ||
| 10452 | fn get(state: *@This(), attributes: []const Attribute) Allocator.Error!Attributes { | 10452 | fn get(state: *@This(), gpa: Allocator, attributes: []const Attribute) Allocator.Error!Attributes { |
| 10453 | try state.list.resize(attributes.len); | 10453 | try state.list.resize(gpa, attributes.len); |
| 10454 | for (state.list.items, attributes) |*item, attribute| | 10454 | for (state.list.items, attributes) |*item, attribute| |
| 10455 | item.* = try state.builder.attr(attribute); | 10455 | item.* = try state.builder.attr(attribute); |
| 10456 | return state.builder.attrs(state.list.items); | 10456 | return state.builder.attrs(state.list.items); |
| 10457 | } | 10457 | } |
| 10458 | } = .{ .builder = self, .list = std.array_list.Managed(Attribute.Index).init(allocator) }; | 10458 | } = .{ .builder = self, .list = .empty }; |
| 10459 | defer attributes.deinit(); | 10459 | defer attributes.deinit(allocator); |
| 10460 | 10460 | ||
| 10461 | var overload_index: usize = 0; | 10461 | var overload_index: usize = 0; |
| 10462 | function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs); | 10462 | function_attributes[FunctionAttributes.function_index] = try attributes.get(allocator, signature.attrs); |
| 10463 | function_attributes[FunctionAttributes.return_index] = .none; // needed for void return | 10463 | function_attributes[FunctionAttributes.return_index] = .none; // needed for void return |
| 10464 | for (0.., param_types, signature.params) |param_index, *param_type, signature_param| { | 10464 | for (0.., param_types, signature.params) |param_index, *param_type, signature_param| { |
| 10465 | switch (signature_param.kind) { | 10465 | switch (signature_param.kind) { |
| ... | @@ -10475,7 +10475,7 @@ pub fn getIntrinsic( | ... | @@ -10475,7 +10475,7 @@ pub fn getIntrinsic( |
| 10475 | FunctionAttributes.return_index | 10475 | FunctionAttributes.return_index |
| 10476 | else | 10476 | else |
| 10477 | FunctionAttributes.params_index + (param_index - signature.ret_len) | 10477 | FunctionAttributes.params_index + (param_index - signature.ret_len) |
| 10478 | ] = try attributes.get(signature_param.attrs); | 10478 | ] = try attributes.get(allocator, signature_param.attrs); |
| 10479 | } | 10479 | } |
| 10480 | assert(overload_index == overload.len); | 10480 | assert(overload_index == overload.len); |
| 10481 | for (param_types, signature.params) |*param_type, signature_param| { | 10481 | for (param_types, signature.params) |*param_type, signature_param| { |
lib/std/zig/llvm/bitcode_writer.zig+10-6| ... | @@ -19,7 +19,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { | ... | @@ -19,7 +19,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 19 | return struct { | 19 | return struct { |
| 20 | const BcWriter = @This(); | 20 | const BcWriter = @This(); |
| 21 | 21 | ||
| 22 | buffer: std.array_list.Managed(u32), | 22 | buffer: std.ArrayList(u32), |
| 23 | allocator: std.mem.Allocator, | ||
| 23 | bit_buffer: u32 = 0, | 24 | bit_buffer: u32 = 0, |
| 24 | bit_count: u5 = 0, | 25 | bit_count: u5 = 0, |
| 25 | 26 | ||
| ... | @@ -31,18 +32,19 @@ pub fn BitcodeWriter(comptime types: []const type) type { | ... | @@ -31,18 +32,19 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 31 | 32 | ||
| 32 | pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter { | 33 | pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter { |
| 33 | return .{ | 34 | return .{ |
| 34 | .buffer = std.array_list.Managed(u32).init(allocator), | 35 | .buffer = .empty, |
| 36 | .allocator = allocator, | ||
| 35 | .widths = widths, | 37 | .widths = widths, |
| 36 | }; | 38 | }; |
| 37 | } | 39 | } |
| 38 | 40 | ||
| 39 | pub fn deinit(self: BcWriter) void { | 41 | pub fn deinit(self: BcWriter) void { |
| 40 | self.buffer.deinit(); | 42 | self.buffer.deinit(self.allocator); |
| 41 | } | 43 | } |
| 42 | 44 | ||
| 43 | pub fn toOwnedSlice(self: *BcWriter) Error![]const u32 { | 45 | pub fn toOwnedSlice(self: *BcWriter) Error![]const u32 { |
| 44 | std.debug.assert(self.bit_count == 0); | 46 | std.debug.assert(self.bit_count == 0); |
| 45 | return self.buffer.toOwnedSlice(); | 47 | return self.buffer.toOwnedSlice(self.allocator); |
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | pub fn length(self: BcWriter) usize { | 50 | pub fn length(self: BcWriter) usize { |
| ... | @@ -53,6 +55,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { | ... | @@ -53,6 +55,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 53 | pub fn writeBits(self: *BcWriter, value: anytype, bits: u16) Error!void { | 55 | pub fn writeBits(self: *BcWriter, value: anytype, bits: u16) Error!void { |
| 54 | if (bits == 0) return; | 56 | if (bits == 0) return; |
| 55 | 57 | ||
| 58 | const allocator = self.allocator; | ||
| 59 | |||
| 56 | var in_buffer = bufValue(value, 32); | 60 | var in_buffer = bufValue(value, 32); |
| 57 | var in_bits = bits; | 61 | var in_bits = bits; |
| 58 | 62 | ||
| ... | @@ -68,13 +72,13 @@ pub fn BitcodeWriter(comptime types: []const type) type { | ... | @@ -68,13 +72,13 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 68 | in_bits -= n; | 72 | in_bits -= n; |
| 69 | 73 | ||
| 70 | if (self.bit_count != 0) return; | 74 | if (self.bit_count != 0) return; |
| 71 | try self.buffer.append(std.mem.nativeToLittle(u32, self.bit_buffer)); | 75 | try self.buffer.append(allocator, std.mem.nativeToLittle(u32, self.bit_buffer)); |
| 72 | self.bit_buffer = 0; | 76 | self.bit_buffer = 0; |
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | // Write 32-bit chunks of input bits | 79 | // Write 32-bit chunks of input bits |
| 76 | while (in_bits >= 32) { | 80 | while (in_bits >= 32) { |
| 77 | try self.buffer.append(std.mem.nativeToLittle(u32, @truncate(in_buffer))); | 81 | try self.buffer.append(allocator, std.mem.nativeToLittle(u32, @truncate(in_buffer))); |
| 78 | 82 | ||
| 79 | in_buffer >>= 31; | 83 | in_buffer >>= 31; |
| 80 | in_buffer >>= 1; | 84 | in_buffer >>= 1; |