const Value = union(enum) generic: addr_typeregval_type: struct { // Offset of DW_TAG_base_type DIE type_offset: addr_type, type_size: u8, value: addr_type, }Typed value with a maximum size of a register
const_type: struct { // Offset of DW_TAG_base_type DIE type_offset: addr_type, // Backed by the instruction stream value_bytes: []const u8, }Typed value specified directly in the instruction stream
pub fn asIntegral(self: Value) !addr_type121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 const Value = union(enum) {
generic: addr_type,
// Typed value with a maximum size of a register
regval_type: struct {
// Offset of DW_TAG_base_type DIE
type_offset: addr_type,
type_size: u8,
value: addr_type,
},
// Typed value specified directly in the instruction stream
const_type: struct {
// Offset of DW_TAG_base_type DIE
type_offset: addr_type,
// Backed by the instruction stream
value_bytes: []const u8,
},
pub fn asIntegral(self: Value) !addr_type {
return switch (self) {
.generic => |v| v,
// TODO: For these two prongs, look up the type and assert it's integral?
.regval_type => |regval_type| regval_type.value,
.const_type => |const_type| {
const value: u64 = switch (const_type.value_bytes.len) {
1 => mem.readInt(u8, const_type.value_bytes[0..1], native_endian),
2 => mem.readInt(u16, const_type.value_bytes[0..2], native_endian),
4 => mem.readInt(u32, const_type.value_bytes[0..4], native_endian),
8 => mem.readInt(u64, const_type.value_bytes[0..8], native_endian),
else => return error.InvalidIntegralTypeSize,
};
return std.math.cast(addr_type, value) orelse error.TruncatedIntegralType;
},
};
}
}