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 {...@@ -318,6 +318,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
318318
319 const opcode = try stream.reader().readByte();319 const opcode = try stream.reader().readByte();
320 if (options.call_frame_context and !isOpcodeValidInCFA(opcode)) return error.InvalidCFAOpcode;320 if (options.call_frame_context and !isOpcodeValidInCFA(opcode)) return error.InvalidCFAOpcode;
321 const operand = try readOperand(stream, opcode, context);
321 switch (opcode) {322 switch (opcode) {
322323
323 // 2.5.1.1: Literal Encodings324 // 2.5.1.1: Literal Encodings
...@@ -333,10 +334,10 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -333,10 +334,10 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
333 OP.const8s,334 OP.const8s,
334 OP.constu,335 OP.constu,
335 OP.consts,336 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
338 OP.const_type => {339 OP.const_type => {
339 const const_type = (try readOperand(stream, opcode, context)).?.const_type;340 const const_type = operand.?.const_type;
340 try self.stack.append(allocator, .{ .const_type = .{341 try self.stack.append(allocator, .{ .const_type = .{
341 .type_offset = const_type.type_offset,342 .type_offset = const_type.type_offset,
342 .value_bytes = const_type.value_bytes,343 .value_bytes = const_type.value_bytes,
...@@ -348,7 +349,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -348,7 +349,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
348 => {349 => {
349 if (context.compile_unit == null) return error.IncompleteExpressionContext;350 if (context.compile_unit == null) return error.IncompleteExpressionContext;
350 if (context.debug_addr == null) return error.IncompleteExpressionContext;351 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;
352 const offset = context.compile_unit.?.addr_base + debug_addr_index;353 const offset = context.compile_unit.?.addr_base + debug_addr_index;
353 if (offset >= context.debug_addr.?.len) return error.InvalidExpression;354 if (offset >= context.debug_addr.?.len) return error.InvalidExpression;
354 const value = mem.readIntSliceNative(usize, context.debug_addr.?[offset..][0..@sizeOf(usize)]);355 const value = mem.readIntSliceNative(usize, context.debug_addr.?[offset..][0..@sizeOf(usize)]);
...@@ -360,7 +361,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -360,7 +361,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
360 if (context.compile_unit == null) return error.IncompleteExpressionContext;361 if (context.compile_unit == null) return error.IncompleteExpressionContext;
361 if (context.compile_unit.?.frame_base == null) return error.IncompleteExpressionContext;362 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);
364 _ = offset;365 _ = offset;
365366
366 switch (context.compile_unit.?.frame_base.?.*) {367 switch (context.compile_unit.?.frame_base.?.*) {
...@@ -384,7 +385,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -384,7 +385,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
384 => {385 => {
385 if (context.thread_context == null) return error.IncompleteExpressionContext;386 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;
388 var value: i64 = @intCast(mem.readIntSliceNative(usize, try abi.regBytes(389 var value: i64 = @intCast(mem.readIntSliceNative(usize, try abi.regBytes(
389 context.thread_context.?,390 context.thread_context.?,
390 base_register.base_register,391 base_register.base_register,
...@@ -394,7 +395,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -394,7 +395,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
394 try self.stack.append(allocator, .{ .generic = @intCast(value) });395 try self.stack.append(allocator, .{ .generic = @intCast(value) });
395 },396 },
396 OP.regval_type => {397 OP.regval_type => {
397 const register_type = (try readOperand(stream, opcode, context)).?.register_type;398 const register_type = operand.?.register_type;
398 const value = mem.readIntSliceNative(usize, try abi.regBytes(399 const value = mem.readIntSliceNative(usize, try abi.regBytes(
399 context.thread_context.?,400 context.thread_context.?,
400 register_type.register,401 register_type.register,
...@@ -418,7 +419,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -418,7 +419,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
418 _ = self.stack.pop();419 _ = self.stack.pop();
419 },420 },
420 OP.pick, OP.over => {421 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;
422 if (stack_index >= self.stack.items.len) return error.InvalidExpression;423 if (stack_index >= self.stack.items.len) return error.InvalidExpression;
423 try self.stack.append(allocator, self.stack.items[self.stack.items.len - 1 - stack_index]);424 try self.stack.append(allocator, self.stack.items[self.stack.items.len - 1 - stack_index]);
424 },425 },
...@@ -459,8 +460,6 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -459,8 +460,6 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
459 _ = addr_space_identifier;460 _ = addr_space_identifier;
460461
461 if (context.isValidMemory) |isValidMemory| if (!isValidMemory(addr)) return error.InvalidExpression;462 if (context.isValidMemory) |isValidMemory| if (!isValidMemory(addr)) return error.InvalidExpression;
462
463 const operand = try readOperand(stream, opcode, context);
464 const size = switch (opcode) {463 const size = switch (opcode) {
465 OP.deref,464 OP.deref,
466 OP.xderef,465 OP.xderef,
...@@ -594,7 +593,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -594,7 +593,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
594 },593 },
595 OP.plus_uconst => {594 OP.plus_uconst => {
596 if (self.stack.items.len == 0) return error.InvalidExpression;595 if (self.stack.items.len == 0) return error.InvalidExpression;
597 const constant = (try readOperand(stream, opcode, context)).?.generic;596 const constant = operand.?.generic;
598 self.stack.items[self.stack.items.len - 1] = .{597 self.stack.items[self.stack.items.len - 1] = .{
599 .generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), constant),598 .generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), constant),
600 };599 };
...@@ -663,7 +662,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -663,7 +662,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
663 }662 }
664 },663 },
665 OP.skip, OP.bra => {664 OP.skip, OP.bra => {
666 const branch_offset = (try readOperand(stream, opcode, context)).?.branch_offset;665 const branch_offset = operand.?.branch_offset;
667 const condition = if (opcode == OP.bra) blk: {666 const condition = if (opcode == OP.bra) blk: {
668 if (self.stack.items.len == 0) return error.InvalidExpression;667 if (self.stack.items.len == 0) return error.InvalidExpression;
669 break :blk try self.stack.pop().asIntegral() != 0;668 break :blk try self.stack.pop().asIntegral() != 0;
...@@ -683,7 +682,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -683,7 +682,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
683 OP.call4,682 OP.call4,
684 OP.call_ref,683 OP.call_ref,
685 => {684 => {
686 const debug_info_offset = (try readOperand(stream, opcode, context)).?.generic;685 const debug_info_offset = operand.?.generic;
687 _ = debug_info_offset;686 _ = debug_info_offset;
688687
689 // TODO: Load a DIE entry at debug_info_offset in a .debug_info section (the spec says that it688 // 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 {...@@ -696,7 +695,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
696 // 2.5.1.6: Type Conversions695 // 2.5.1.6: Type Conversions
697 OP.convert => {696 OP.convert => {
698 if (self.stack.items.len == 0) return error.InvalidExpression;697 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
701 // TODO: Load the DW_TAG_base_type entries in context.compile_unit and verify both types are the same size700 // TODO: Load the DW_TAG_base_type entries in context.compile_unit and verify both types are the same size
702 const value = self.stack.items[self.stack.items.len - 1];701 const value = self.stack.items[self.stack.items.len - 1];
...@@ -710,7 +709,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -710,7 +709,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
710 },709 },
711 OP.reinterpret => {710 OP.reinterpret => {
712 if (self.stack.items.len == 0) return error.InvalidExpression;711 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
715 // TODO: Load the DW_TAG_base_type entries in context.compile_unit and verify both types are the same size714 // TODO: Load the DW_TAG_base_type entries in context.compile_unit and verify both types are the same size
716 const value = self.stack.items[self.stack.items.len - 1];715 const value = self.stack.items[self.stack.items.len - 1];
...@@ -745,7 +744,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {...@@ -745,7 +744,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
745 // 2.5.1.7: Special Operations744 // 2.5.1.7: Special Operations
746 OP.nop => {},745 OP.nop => {},
747 OP.entry_value => {746 OP.entry_value => {
748 const block = (try readOperand(stream, opcode, context)).?.block;747 const block = operand.?.block;
749 if (block.len == 0) return error.InvalidSubExpression;748 if (block.len == 0) return error.InvalidSubExpression;
750749
751 // TODO: The spec states that this sub-expression needs to observe the state (ie. registers)750 // TODO: The spec states that this sub-expression needs to observe the state (ie. registers)