From b9deeb5bd7fb07267f4cec849b4a06c3f03ae8b7 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Tue, 17 Dec 2019 16:41:51 -0800 Subject: [PATCH] add module for calculating C ABI layout of datatypes --- tools/witx/src/layout.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/witx/src/layout.rs b/tools/witx/src/layout.rs index 626ac67b..9aa1df68 100644 --- a/tools/witx/src/layout.rs +++ b/tools/witx/src/layout.rs @@ -125,7 +125,22 @@ mod test { impl UnionDatatype { pub fn layout(&self, cache: &mut HashMap) -> SizeAlign { - unimplemented!() + let sas = self + .variants + .iter() + .map(|v| v.tref.layout(cache)) + .collect::>(); + 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 } } }