authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-25 10:26:01-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-25 10:28:03-04:00
log8e4cc0ce5a21d743bc59def79efa75584d06fee4
treea8837aa4461ab1f080de9f708d1597ffb4503350
parent49fa3a987f0b5309d629072def14ae6c6793d0b1

dwarf: small code size reduction in expression runner


1 files changed, 14 insertions(+), 15 deletions(-)

lib/std/dwarf/expressions.zig+14-15
......@@ -318,6 +318,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
318318
319319 const opcode = try stream.reader().readByte();
320320 if (options.call_frame_context and !isOpcodeValidInCFA(opcode)) return error.InvalidCFAOpcode;
321 const operand = try readOperand(stream, opcode, context);
321322 switch (opcode) {
322323
323324 // 2.5.1.1: Literal Encodings
......@@ -333,10 +334,10 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
333334 OP.const8s,
334335 OP.constu,
335336 OP.consts,
336 => try self.stack.append(allocator, .{ .generic = (try readOperand(stream, opcode, context)).?.generic }),
337 => try self.stack.append(allocator, .{ .generic = operand.?.generic }),
337338
338339 OP.const_type => {
339 const const_type = (try readOperand(stream, opcode, context)).?.const_type;
340 const const_type = operand.?.const_type;
340341 try self.stack.append(allocator, .{ .const_type = .{
341342 .type_offset = const_type.type_offset,
342343 .value_bytes = const_type.value_bytes,
......@@ -348,7 +349,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
348349 => {
349350 if (context.compile_unit == null) return error.IncompleteExpressionContext;
350351 if (context.debug_addr == null) return error.IncompleteExpressionContext;
351 const debug_addr_index = (try readOperand(stream, opcode, context)).?.generic;
352 const debug_addr_index = operand.?.generic;
352353 const offset = context.compile_unit.?.addr_base + debug_addr_index;
353354 if (offset >= context.debug_addr.?.len) return error.InvalidExpression;
354355 const value = mem.readIntSliceNative(usize, context.debug_addr.?[offset..][0..@sizeOf(usize)]);
......@@ -360,7 +361,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
360361 if (context.compile_unit == null) return error.IncompleteExpressionContext;
361362 if (context.compile_unit.?.frame_base == null) return error.IncompleteExpressionContext;
362363
363 const offset: i64 = @intCast((try readOperand(stream, opcode, context)).?.generic);
364 const offset: i64 = @intCast(operand.?.generic);
364365 _ = offset;
365366
366367 switch (context.compile_unit.?.frame_base.?.*) {
......@@ -384,7 +385,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
384385 => {
385386 if (context.thread_context == null) return error.IncompleteExpressionContext;
386387
387 const base_register = (try readOperand(stream, opcode, context)).?.base_register;
388 const base_register = operand.?.base_register;
388389 var value: i64 = @intCast(mem.readIntSliceNative(usize, try abi.regBytes(
389390 context.thread_context.?,
390391 base_register.base_register,
......@@ -394,7 +395,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
394395 try self.stack.append(allocator, .{ .generic = @intCast(value) });
395396 },
396397 OP.regval_type => {
397 const register_type = (try readOperand(stream, opcode, context)).?.register_type;
398 const register_type = operand.?.register_type;
398399 const value = mem.readIntSliceNative(usize, try abi.regBytes(
399400 context.thread_context.?,
400401 register_type.register,
......@@ -418,7 +419,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
418419 _ = self.stack.pop();
419420 },
420421 OP.pick, OP.over => {
421 const stack_index = if (opcode == OP.over) 1 else (try readOperand(stream, opcode, context)).?.generic;
422 const stack_index = if (opcode == OP.over) 1 else operand.?.generic;
422423 if (stack_index >= self.stack.items.len) return error.InvalidExpression;
423424 try self.stack.append(allocator, self.stack.items[self.stack.items.len - 1 - stack_index]);
424425 },
......@@ -459,8 +460,6 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
459460 _ = addr_space_identifier;
460461
461462 if (context.isValidMemory) |isValidMemory| if (!isValidMemory(addr)) return error.InvalidExpression;
462
463 const operand = try readOperand(stream, opcode, context);
464463 const size = switch (opcode) {
465464 OP.deref,
466465 OP.xderef,
......@@ -594,7 +593,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
594593 },
595594 OP.plus_uconst => {
596595 if (self.stack.items.len == 0) return error.InvalidExpression;
597 const constant = (try readOperand(stream, opcode, context)).?.generic;
596 const constant = operand.?.generic;
598597 self.stack.items[self.stack.items.len - 1] = .{
599598 .generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), constant),
600599 };
......@@ -663,7 +662,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
663662 }
664663 },
665664 OP.skip, OP.bra => {
666 const branch_offset = (try readOperand(stream, opcode, context)).?.branch_offset;
665 const branch_offset = operand.?.branch_offset;
667666 const condition = if (opcode == OP.bra) blk: {
668667 if (self.stack.items.len == 0) return error.InvalidExpression;
669668 break :blk try self.stack.pop().asIntegral() != 0;
......@@ -683,7 +682,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
683682 OP.call4,
684683 OP.call_ref,
685684 => {
686 const debug_info_offset = (try readOperand(stream, opcode, context)).?.generic;
685 const debug_info_offset = operand.?.generic;
687686 _ = debug_info_offset;
688687
689688 // TODO: Load a DIE entry at debug_info_offset in a .debug_info section (the spec says that it
......@@ -696,7 +695,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
696695 // 2.5.1.6: Type Conversions
697696 OP.convert => {
698697 if (self.stack.items.len == 0) return error.InvalidExpression;
699 const type_offset = (try readOperand(stream, opcode, context)).?.generic;
698 const type_offset = operand.?.generic;
700699
701700 // TODO: Load the DW_TAG_base_type entries in context.compile_unit and verify both types are the same size
702701 const value = self.stack.items[self.stack.items.len - 1];
......@@ -710,7 +709,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
710709 },
711710 OP.reinterpret => {
712711 if (self.stack.items.len == 0) return error.InvalidExpression;
713 const type_offset = (try readOperand(stream, opcode, context)).?.generic;
712 const type_offset = operand.?.generic;
714713
715714 // TODO: Load the DW_TAG_base_type entries in context.compile_unit and verify both types are the same size
716715 const value = self.stack.items[self.stack.items.len - 1];
......@@ -745,7 +744,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
745744 // 2.5.1.7: Special Operations
746745 OP.nop => {},
747746 OP.entry_value => {
748 const block = (try readOperand(stream, opcode, context)).?.block;
747 const block = operand.?.block;
749748 if (block.len == 0) return error.InvalidSubExpression;
750749
751750 // TODO: The spec states that this sub-expression needs to observe the state (ie. registers)