#[non_exhaustive]pub enum Aggregate {
Struct {
fields: Vec<MemType>,
packed: bool,
},
Array {
elem: MemType,
len: u64,
},
}Expand description
An aggregate memory type: a struct or a fixed-length array.
An aggregate may name only aggregates declared before it, so layouts are computed
in declaration order and a recursive aggregate is impossible (recursion goes
through ptr, which is opaque).
§Examples
use ir_lang::{Aggregate, MemType, Module, Type};
let mut m = Module::new("demo");
let pair = m.declare_aggregate(Aggregate::structure(&[Type::U8.into(), Type::I64.into()]))?;
let layout = m.layout(pair.into()).unwrap();
assert_eq!((layout.size(), layout.align()), (16, 8));
assert_eq!(m.field_offset(pair, 1), Some(8));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Struct
Fields laid out in order. Unless packed, each field is placed at the next
multiple of its alignment and the size is rounded up to the struct’s
alignment (the C rule); a packed struct has alignment 1 and no padding.
Array
len elements of elem, each at a stride of the element’s size.
Implementations§
Source§impl Aggregate
impl Aggregate
Sourcepub fn structure(fields: &[MemType]) -> Aggregate
pub fn structure(fields: &[MemType]) -> Aggregate
A (non-packed) struct with the given fields.
§Examples
use ir_lang::{Aggregate, Type};
let s = Aggregate::structure(&[Type::I32.into()]);
assert!(matches!(s, Aggregate::Struct { packed: false, .. }));Trait Implementations§
impl Eq for Aggregate
impl StructuralPartialEq for Aggregate
Auto Trait Implementations§
impl Freeze for Aggregate
impl RefUnwindSafe for Aggregate
impl Send for Aggregate
impl Sync for Aggregate
impl Unpin for Aggregate
impl UnsafeUnpin for Aggregate
impl UnwindSafe for Aggregate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more