Skip to content

Commit

Permalink
add tilib struct layout dump mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed Jan 15, 2025
1 parent fcbea39 commit d6cb76b
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 101 deletions.
15 changes: 9 additions & 6 deletions src/til/size_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a> TILTypeSizeSolver<'a> {
if !til_struct.is_unaligned {
let align = match (
first_member.alignment.map(|x| x.get().into()),
self.alignemnt(
self.type_align_bytes(
&first_member.member_type,
field_size,
),
Expand Down Expand Up @@ -185,30 +185,33 @@ impl<'a> TILTypeSizeSolver<'a> {
}
let inner_type = self.section.get_type_by_idx(*idx);
let result = self.inner_type_size_bytes(&inner_type.tinfo);
self.solving.remove(&idx);
self.solving.remove(idx);
if let Some(result) = result {
assert!(self.solved.insert(*idx, result).is_none());
}
result
}

fn alignemnt(&mut self, til: &Type, til_size: u64) -> Option<u64> {
pub fn type_align_bytes(
&mut self,
til: &Type,
til_size: u64,
) -> Option<u64> {
match &til.type_variant {
// TODO basic types have a inherited alignment?
TypeVariant::Basic(_)
| TypeVariant::Enum(_)
| TypeVariant::Pointer(_) => Some(til_size),
TypeVariant::Array(array) => {
let size = self.inner_type_size_bytes(&array.elem_type);
self.alignemnt(&array.elem_type, size.unwrap_or(1))
self.type_align_bytes(&array.elem_type, size.unwrap_or(1))
}
TypeVariant::Typeref(ty) => {
let TyperefValue::Ref(idx) = &ty.typeref_value else {
return None;
};
let ty = &self.section.types[*idx].tinfo;
let size = self.inner_type_size_bytes(ty).unwrap_or(1);
self.alignemnt(ty, size)
self.type_align_bytes(ty, size)
}
_ => None,
}
Expand Down
Loading

0 comments on commit d6cb76b

Please sign in to comment.