Skip to content

Commit

Permalink
add module for calculating C ABI layout of datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Hickey committed Dec 19, 2019
1 parent 0152ed7 commit b9deeb5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tools/witx/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,22 @@ mod test {

impl UnionDatatype {
pub fn layout(&self, cache: &mut HashMap<TypeRef, SizeAlign>) -> SizeAlign {
unimplemented!()
let sas = self
.variants
.iter()
.map(|v| v.tref.layout(cache))
.collect::<Vec<SizeAlign>>();
let size = sas
.iter()
.map(|sa| sa.size)
.max()
.expect("nonzero variants");
let align = sas
.iter()
.map(|sa| sa.align)
.max()
.expect("nonzero variants");
SizeAlign { size, align }
}
}

Expand Down

0 comments on commit b9deeb5

Please sign in to comment.