From 9860dd475ab754f85f2f8c96039255bda8721002 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Aug 2025 23:30:16 -0700 Subject: std: delete most remaining uses of GenericWriter --- lib/std/debug/Dwarf/expression.zig | 201 +++++++++++++++++++------------------ 1 file changed, 101 insertions(+), 100 deletions(-) (limited to 'lib/std/debug/Dwarf/expression.zig') diff --git a/lib/std/debug/Dwarf/expression.zig b/lib/std/debug/Dwarf/expression.zig index c123cdb30b..1c849489ad 100644 --- a/lib/std/debug/Dwarf/expression.zig +++ b/lib/std/debug/Dwarf/expression.zig @@ -8,6 +8,8 @@ const OP = std.dwarf.OP; const abi = std.debug.Dwarf.abi; const mem = std.mem; const assert = std.debug.assert; +const testing = std.testing; +const Writer = std.Io.Writer; /// Expressions can be evaluated in different contexts, each requiring its own set of inputs. /// Callers should specify all the fields relevant to their context. If a field is required @@ -782,7 +784,7 @@ pub fn Builder(comptime options: Options) type { return struct { /// Zero-operand instructions - pub fn writeOpcode(writer: anytype, comptime opcode: u8) !void { + pub fn writeOpcode(writer: *Writer, comptime opcode: u8) !void { if (options.call_frame_context and !comptime isOpcodeValidInCFA(opcode)) return error.InvalidCFAOpcode; switch (opcode) { OP.dup, @@ -823,14 +825,14 @@ pub fn Builder(comptime options: Options) type { } // 2.5.1.1: Literal Encodings - pub fn writeLiteral(writer: anytype, literal: u8) !void { + pub fn writeLiteral(writer: *Writer, literal: u8) !void { switch (literal) { 0...31 => |n| try writer.writeByte(n + OP.lit0), else => return error.InvalidLiteral, } } - pub fn writeConst(writer: anytype, comptime T: type, value: T) !void { + pub fn writeConst(writer: *Writer, comptime T: type, value: T) !void { if (@typeInfo(T) != .int) @compileError("Constants must be integers"); switch (T) { @@ -852,7 +854,7 @@ pub fn Builder(comptime options: Options) type { else => switch (@typeInfo(T).int.signedness) { .unsigned => { try writer.writeByte(OP.constu); - try leb.writeUleb128(writer, value); + try writer.writeUleb128(value); }, .signed => { try writer.writeByte(OP.consts); @@ -862,105 +864,105 @@ pub fn Builder(comptime options: Options) type { } } - pub fn writeConstx(writer: anytype, debug_addr_offset: anytype) !void { + pub fn writeConstx(writer: *Writer, debug_addr_offset: anytype) !void { try writer.writeByte(OP.constx); - try leb.writeUleb128(writer, debug_addr_offset); + try writer.writeUleb128(debug_addr_offset); } - pub fn writeConstType(writer: anytype, die_offset: anytype, value_bytes: []const u8) !void { + pub fn writeConstType(writer: *Writer, die_offset: anytype, value_bytes: []const u8) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; if (value_bytes.len > 0xff) return error.InvalidTypeLength; try writer.writeByte(OP.const_type); - try leb.writeUleb128(writer, die_offset); + try writer.writeUleb128(die_offset); try writer.writeByte(@intCast(value_bytes.len)); try writer.writeAll(value_bytes); } - pub fn writeAddr(writer: anytype, value: addr_type) !void { + pub fn writeAddr(writer: *Writer, value: addr_type) !void { try writer.writeByte(OP.addr); try writer.writeInt(addr_type, value, options.endian); } - pub fn writeAddrx(writer: anytype, debug_addr_offset: anytype) !void { + pub fn writeAddrx(writer: *Writer, debug_addr_offset: anytype) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; try writer.writeByte(OP.addrx); - try leb.writeUleb128(writer, debug_addr_offset); + try writer.writeUleb128(debug_addr_offset); } // 2.5.1.2: Register Values - pub fn writeFbreg(writer: anytype, offset: anytype) !void { + pub fn writeFbreg(writer: *Writer, offset: anytype) !void { try writer.writeByte(OP.fbreg); try leb.writeIleb128(writer, offset); } - pub fn writeBreg(writer: anytype, register: u8, offset: anytype) !void { + pub fn writeBreg(writer: *Writer, register: u8, offset: anytype) !void { if (register > 31) return error.InvalidRegister; try writer.writeByte(OP.breg0 + register); try leb.writeIleb128(writer, offset); } - pub fn writeBregx(writer: anytype, register: anytype, offset: anytype) !void { + pub fn writeBregx(writer: *Writer, register: anytype, offset: anytype) !void { try writer.writeByte(OP.bregx); - try leb.writeUleb128(writer, register); + try writer.writeUleb128(register); try leb.writeIleb128(writer, offset); } - pub fn writeRegvalType(writer: anytype, register: anytype, offset: anytype) !void { + pub fn writeRegvalType(writer: *Writer, register: anytype, offset: anytype) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; try writer.writeByte(OP.regval_type); - try leb.writeUleb128(writer, register); - try leb.writeUleb128(writer, offset); + try writer.writeUleb128(register); + try writer.writeUleb128(offset); } // 2.5.1.3: Stack Operations - pub fn writePick(writer: anytype, index: u8) !void { + pub fn writePick(writer: *Writer, index: u8) !void { try writer.writeByte(OP.pick); try writer.writeByte(index); } - pub fn writeDerefSize(writer: anytype, size: u8) !void { + pub fn writeDerefSize(writer: *Writer, size: u8) !void { try writer.writeByte(OP.deref_size); try writer.writeByte(size); } - pub fn writeXDerefSize(writer: anytype, size: u8) !void { + pub fn writeXDerefSize(writer: *Writer, size: u8) !void { try writer.writeByte(OP.xderef_size); try writer.writeByte(size); } - pub fn writeDerefType(writer: anytype, size: u8, die_offset: anytype) !void { + pub fn writeDerefType(writer: *Writer, size: u8, die_offset: anytype) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; try writer.writeByte(OP.deref_type); try writer.writeByte(size); - try leb.writeUleb128(writer, die_offset); + try writer.writeUleb128(die_offset); } - pub fn writeXDerefType(writer: anytype, size: u8, die_offset: anytype) !void { + pub fn writeXDerefType(writer: *Writer, size: u8, die_offset: anytype) !void { try writer.writeByte(OP.xderef_type); try writer.writeByte(size); - try leb.writeUleb128(writer, die_offset); + try writer.writeUleb128(die_offset); } // 2.5.1.4: Arithmetic and Logical Operations - pub fn writePlusUconst(writer: anytype, uint_value: anytype) !void { + pub fn writePlusUconst(writer: *Writer, uint_value: anytype) !void { try writer.writeByte(OP.plus_uconst); - try leb.writeUleb128(writer, uint_value); + try writer.writeUleb128(uint_value); } // 2.5.1.5: Control Flow Operations - pub fn writeSkip(writer: anytype, offset: i16) !void { + pub fn writeSkip(writer: *Writer, offset: i16) !void { try writer.writeByte(OP.skip); try writer.writeInt(i16, offset, options.endian); } - pub fn writeBra(writer: anytype, offset: i16) !void { + pub fn writeBra(writer: *Writer, offset: i16) !void { try writer.writeByte(OP.bra); try writer.writeInt(i16, offset, options.endian); } - pub fn writeCall(writer: anytype, comptime T: type, offset: T) !void { + pub fn writeCall(writer: *Writer, comptime T: type, offset: T) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; switch (T) { u16 => try writer.writeByte(OP.call2), @@ -971,45 +973,45 @@ pub fn Builder(comptime options: Options) type { try writer.writeInt(T, offset, options.endian); } - pub fn writeCallRef(writer: anytype, comptime is_64: bool, value: if (is_64) u64 else u32) !void { + pub fn writeCallRef(writer: *Writer, comptime is_64: bool, value: if (is_64) u64 else u32) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; try writer.writeByte(OP.call_ref); try writer.writeInt(if (is_64) u64 else u32, value, options.endian); } - pub fn writeConvert(writer: anytype, die_offset: anytype) !void { + pub fn writeConvert(writer: *Writer, die_offset: anytype) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; try writer.writeByte(OP.convert); - try leb.writeUleb128(writer, die_offset); + try writer.writeUleb128(die_offset); } - pub fn writeReinterpret(writer: anytype, die_offset: anytype) !void { + pub fn writeReinterpret(writer: *Writer, die_offset: anytype) !void { if (options.call_frame_context) return error.InvalidCFAOpcode; try writer.writeByte(OP.reinterpret); - try leb.writeUleb128(writer, die_offset); + try writer.writeUleb128(die_offset); } // 2.5.1.7: Special Operations - pub fn writeEntryValue(writer: anytype, expression: []const u8) !void { + pub fn writeEntryValue(writer: *Writer, expression: []const u8) !void { try writer.writeByte(OP.entry_value); - try leb.writeUleb128(writer, expression.len); + try writer.writeUleb128(expression.len); try writer.writeAll(expression); } // 2.6: Location Descriptions - pub fn writeReg(writer: anytype, register: u8) !void { + pub fn writeReg(writer: *Writer, register: u8) !void { try writer.writeByte(OP.reg0 + register); } - pub fn writeRegx(writer: anytype, register: anytype) !void { + pub fn writeRegx(writer: *Writer, register: anytype) !void { try writer.writeByte(OP.regx); - try leb.writeUleb128(writer, register); + try writer.writeUleb128(register); } - pub fn writeImplicitValue(writer: anytype, value_bytes: []const u8) !void { + pub fn writeImplicitValue(writer: *Writer, value_bytes: []const u8) !void { try writer.writeByte(OP.implicit_value); - try leb.writeUleb128(writer, value_bytes.len); + try writer.writeUleb128(value_bytes.len); try writer.writeAll(value_bytes); } }; @@ -1042,8 +1044,7 @@ fn isOpcodeRegisterLocation(opcode: u8) bool { }; } -const testing = std.testing; -test "DWARF expressions" { +test "basics" { const allocator = std.testing.allocator; const options = Options{}; @@ -1052,10 +1053,10 @@ test "DWARF expressions" { const b = Builder(options); - var program = std.array_list.Managed(u8).init(allocator); + var program: std.Io.Writer.Allocating = .init(allocator); defer program.deinit(); - const writer = program.writer(); + const writer = &program.writer; // Literals { @@ -1064,7 +1065,7 @@ test "DWARF expressions" { try b.writeLiteral(writer, @intCast(i)); } - _ = try stack_machine.run(program.items, allocator, context, 0); + _ = try stack_machine.run(program.written(), allocator, context, 0); for (0..32) |i| { const expected = 31 - i; @@ -1108,16 +1109,16 @@ test "DWARF expressions" { var mock_compile_unit: std.debug.Dwarf.CompileUnit = undefined; mock_compile_unit.addr_base = 1; - var mock_debug_addr = std.array_list.Managed(u8).init(allocator); + var mock_debug_addr: std.Io.Writer.Allocating = .init(allocator); defer mock_debug_addr.deinit(); - try mock_debug_addr.writer().writeInt(u16, 0, native_endian); - try mock_debug_addr.writer().writeInt(usize, input[11], native_endian); - try mock_debug_addr.writer().writeInt(usize, input[12], native_endian); + try mock_debug_addr.writer.writeInt(u16, 0, native_endian); + try mock_debug_addr.writer.writeInt(usize, input[11], native_endian); + try mock_debug_addr.writer.writeInt(usize, input[12], native_endian); - const context = Context{ + const context: Context = .{ .compile_unit = &mock_compile_unit, - .debug_addr = mock_debug_addr.items, + .debug_addr = mock_debug_addr.written(), }; try b.writeConstx(writer, @as(usize, 1)); @@ -1127,7 +1128,7 @@ test "DWARF expressions" { const type_bytes: []const u8 = &.{ 1, 2, 3, 4 }; try b.writeConstType(writer, die_offset, type_bytes); - _ = try stack_machine.run(program.items, allocator, context, 0); + _ = try stack_machine.run(program.written(), allocator, context, 0); const const_type = stack_machine.stack.pop().?.const_type; try testing.expectEqual(die_offset, const_type.type_offset); @@ -1185,7 +1186,7 @@ test "DWARF expressions" { try b.writeBregx(writer, abi.ipRegNum(native_arch).?, @as(usize, 300)); try b.writeRegvalType(writer, @as(u8, 0), @as(usize, 400)); - _ = try stack_machine.run(program.items, allocator, context, 0); + _ = try stack_machine.run(program.written(), allocator, context, 0); const regval_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(@as(usize, 400), regval_type.type_offset); @@ -1214,7 +1215,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConst(writer, u8, 1); try b.writeOpcode(writer, OP.dup); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic); @@ -1222,7 +1223,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConst(writer, u8, 1); try b.writeOpcode(writer, OP.drop); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expect(stack_machine.stack.pop() == null); stack_machine.reset(); @@ -1231,7 +1232,7 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 5); try b.writeConst(writer, u8, 6); try b.writePick(writer, 2); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1240,7 +1241,7 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 5); try b.writeConst(writer, u8, 6); try b.writeOpcode(writer, OP.over); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1248,7 +1249,7 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 5); try b.writeConst(writer, u8, 6); try b.writeOpcode(writer, OP.swap); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic); @@ -1258,7 +1259,7 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 5); try b.writeConst(writer, u8, 6); try b.writeOpcode(writer, OP.rot); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic); @@ -1269,7 +1270,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeOpcode(writer, OP.deref); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1277,14 +1278,14 @@ test "DWARF expressions" { try b.writeLiteral(writer, 0); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeOpcode(writer, OP.xderef); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeDerefSize(writer, 1); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1292,7 +1293,7 @@ test "DWARF expressions" { try b.writeLiteral(writer, 0); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeXDerefSize(writer, 1); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic); const type_offset: usize = @truncate(0xaabbaabb_aabbaabb); @@ -1301,7 +1302,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeDerefType(writer, 1, type_offset); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); const deref_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(type_offset, deref_type.type_offset); try testing.expectEqual(@as(u8, 1), deref_type.type_size); @@ -1312,7 +1313,7 @@ test "DWARF expressions" { try b.writeLiteral(writer, 0); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeXDerefType(writer, 1, type_offset); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); const xderef_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(type_offset, xderef_type.type_offset); try testing.expectEqual(@as(u8, 1), xderef_type.type_size); @@ -1323,7 +1324,7 @@ test "DWARF expressions" { stack_machine.reset(); program.clearRetainingCapacity(); try b.writeOpcode(writer, OP.push_object_address); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.pop().?.generic); // TODO: Test OP.form_tls_address @@ -1333,7 +1334,7 @@ test "DWARF expressions" { stack_machine.reset(); program.clearRetainingCapacity(); try b.writeOpcode(writer, OP.call_frame_cfa); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(context.cfa.?, stack_machine.stack.pop().?.generic); } @@ -1345,7 +1346,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConst(writer, i16, -4096); try b.writeOpcode(writer, OP.abs); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 4096), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1353,7 +1354,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xff0f); try b.writeConst(writer, u16, 0xf0ff); try b.writeOpcode(writer, OP.@"and"); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1361,7 +1362,7 @@ test "DWARF expressions" { try b.writeConst(writer, i16, -404); try b.writeConst(writer, i16, 100); try b.writeOpcode(writer, OP.div); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.pop().?.generic))); stack_machine.reset(); @@ -1369,7 +1370,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 200); try b.writeConst(writer, u16, 50); try b.writeOpcode(writer, OP.minus); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 150), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1377,7 +1378,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 123); try b.writeConst(writer, u16, 100); try b.writeOpcode(writer, OP.mod); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 23), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1385,7 +1386,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xff); try b.writeConst(writer, u16, 0xee); try b.writeOpcode(writer, OP.mul); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1394,7 +1395,7 @@ test "DWARF expressions" { try b.writeOpcode(writer, OP.neg); try b.writeConst(writer, i16, -6); try b.writeOpcode(writer, OP.neg); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.pop().?.generic))); @@ -1402,7 +1403,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConst(writer, u16, 0xff0f); try b.writeOpcode(writer, OP.not); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1410,7 +1411,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xff0f); try b.writeConst(writer, u16, 0xf0ff); try b.writeOpcode(writer, OP.@"or"); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1418,14 +1419,14 @@ test "DWARF expressions" { try b.writeConst(writer, i16, 402); try b.writeConst(writer, i16, 100); try b.writeOpcode(writer, OP.plus); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 502), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); try b.writeConst(writer, u16, 4096); try b.writePlusUconst(writer, @as(usize, 8192)); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1433,7 +1434,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xfff); try b.writeConst(writer, u16, 1); try b.writeOpcode(writer, OP.shl); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1441,7 +1442,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xfff); try b.writeConst(writer, u16, 1); try b.writeOpcode(writer, OP.shr); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1449,7 +1450,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xfff); try b.writeConst(writer, u16, 1); try b.writeOpcode(writer, OP.shr); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1457,7 +1458,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xf0ff); try b.writeConst(writer, u16, 0xff0f); try b.writeOpcode(writer, OP.xor); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.pop().?.generic); } @@ -1486,7 +1487,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 1); try b.writeConst(writer, u16, 0); try b.writeOpcode(writer, e[0]); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.pop().?.generic); @@ -1497,7 +1498,7 @@ test "DWARF expressions" { try b.writeLiteral(writer, 2); try b.writeSkip(writer, 1); try b.writeLiteral(writer, 3); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 2), stack_machine.stack.pop().?.generic); stack_machine.reset(); @@ -1509,7 +1510,7 @@ test "DWARF expressions" { try b.writeBra(writer, 1); try b.writeLiteral(writer, 4); try b.writeLiteral(writer, 5); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic); try testing.expect(stack_machine.stack.pop() == null); @@ -1535,7 +1536,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConstType(writer, @as(usize, 0), &value_bytes); try b.writeConvert(writer, @as(usize, 0)); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(value, stack_machine.stack.pop().?.generic); // Reinterpret to generic type @@ -1543,7 +1544,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConstType(writer, @as(usize, 0), &value_bytes); try b.writeReinterpret(writer, @as(usize, 0)); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(value, stack_machine.stack.pop().?.generic); // Reinterpret to new type @@ -1553,7 +1554,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeConstType(writer, @as(usize, 0), &value_bytes); try b.writeReinterpret(writer, die_offset); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); const const_type = stack_machine.stack.pop().?.const_type; try testing.expectEqual(die_offset, const_type.type_offset); @@ -1561,7 +1562,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeLiteral(writer, 0); try b.writeReinterpret(writer, die_offset); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); const regval_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(die_offset, regval_type.type_offset); } @@ -1573,20 +1574,20 @@ test "DWARF expressions" { stack_machine.reset(); program.clearRetainingCapacity(); try b.writeOpcode(writer, OP.nop); - _ = try stack_machine.run(program.items, allocator, context, null); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expect(stack_machine.stack.pop() == null); // Sub-expression { - var sub_program = std.array_list.Managed(u8).init(allocator); + var sub_program: std.Io.Writer.Allocating = .init(allocator); defer sub_program.deinit(); - const sub_writer = sub_program.writer(); + const sub_writer = &sub_program.writer; try b.writeLiteral(sub_writer, 3); stack_machine.reset(); program.clearRetainingCapacity(); - try b.writeEntryValue(writer, sub_program.items); - _ = try stack_machine.run(program.items, allocator, context, null); + try b.writeEntryValue(writer, sub_program.written()); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 3), stack_machine.stack.pop().?.generic); } @@ -1605,15 +1606,15 @@ test "DWARF expressions" { if (abi.regBytes(&thread_context, 0, reg_context)) |reg_bytes| { mem.writeInt(usize, reg_bytes[0..@sizeOf(usize)], 0xee, native_endian); - var sub_program = std.array_list.Managed(u8).init(allocator); + var sub_program: std.Io.Writer.Allocating = .init(allocator); defer sub_program.deinit(); - const sub_writer = sub_program.writer(); + const sub_writer = &sub_program.writer; try b.writeReg(sub_writer, 0); stack_machine.reset(); program.clearRetainingCapacity(); - try b.writeEntryValue(writer, sub_program.items); - _ = try stack_machine.run(program.items, allocator, context, null); + try b.writeEntryValue(writer, sub_program.written()); + _ = try stack_machine.run(program.written(), allocator, context, null); try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.pop().?.generic); } else |err| { switch (err) { -- cgit v1.2.3