Skip to content

Commit 40aa09a

Browse files
Pat Hickeypchickey
authored andcommitted
add module for calculating C ABI layout of datatypes
1 parent 0152ed7 commit 40aa09a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

tools/witx/src/layout.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,22 @@ mod test {
125125

126126
impl UnionDatatype {
127127
pub fn layout(&self, cache: &mut HashMap<TypeRef, SizeAlign>) -> SizeAlign {
128-
unimplemented!()
128+
let sas = self
129+
.variants
130+
.iter()
131+
.map(|v| v.tref.layout(cache))
132+
.collect::<Vec<SizeAlign>>();
133+
let size = sas
134+
.iter()
135+
.map(|sa| sa.size)
136+
.max()
137+
.expect("nonzero variants");
138+
let align = sas
139+
.iter()
140+
.map(|sa| sa.align)
141+
.max()
142+
.expect("nonzero variants");
143+
SizeAlign { size, align }
129144
}
130145
}
131146

0 commit comments

Comments
 (0)