#[non_exhaustive]pub enum Type {
Show 13 variants
Bool,
I8,
I16,
I32,
I64,
U8,
U16,
U32,
U64,
F32,
F64,
Ptr,
Ref,
}Expand description
The type of an SSA value.
Integers are sized and carry their signedness, mirroring the value domains of the
operation semantics (specs/OPS.md §1): every signedness-dependent operation
(overflow detection, division, right shift, ordering, conversions) takes its
signedness from its operand type, so an instruction cannot disagree with the
domain it computes in. Ptr is an untraced address; Ref
is a garbage-collected reference that a moving collector may relocate at a
safepoint (see the safepoint rules in specs/IR.md §9).
Aggregates are memory types only (MemType): they live in stack slots and
globals and are reached through addresses, never held in an SSA value.
Vector types are reserved; the enum is #[non_exhaustive] so they can be added
in a minor release.
§Examples
use ir_lang::{PointerWidth, Type};
assert!(Type::I32.is_signed_int());
assert!(Type::U8.is_unsigned_int());
assert_eq!(Type::I16.int_bits(), Some(16));
assert_eq!(Type::Ptr.size(PointerWidth::P64), 8);
assert_eq!(Type::F32.to_string(), "f32");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Bool
A boolean: false or true (one byte in memory, 0 or 1).
I8
A signed 8-bit integer.
I16
A signed 16-bit integer.
I32
A signed 32-bit integer.
I64
A signed 64-bit integer.
U8
An unsigned 8-bit integer.
U16
An unsigned 16-bit integer.
U32
An unsigned 32-bit integer.
U64
An unsigned 64-bit integer.
F32
An IEEE 754 binary32 float.
F64
An IEEE 754 binary64 float.
Ptr
An untraced address, as wide as the module’s PointerWidth.
Ref
A garbage-collected reference, as wide as the module’s PointerWidth.
Implementations§
Source§impl Type
impl Type
Sourcepub const ALL: [Type; 13]
pub const ALL: [Type; 13]
Every value type, in a fixed order (useful for generators and tables).
Sourcepub const fn is_int(self) -> bool
pub const fn is_int(self) -> bool
Whether this is an integer type (signed or unsigned).
§Examples
use ir_lang::Type;
assert!(Type::U64.is_int());
assert!(!Type::Bool.is_int());Sourcepub const fn is_signed_int(self) -> bool
pub const fn is_signed_int(self) -> bool
Whether this is a signed integer type.
§Examples
use ir_lang::Type;
assert!(Type::I8.is_signed_int());
assert!(!Type::U8.is_signed_int());Sourcepub const fn is_unsigned_int(self) -> bool
pub const fn is_unsigned_int(self) -> bool
Whether this is an unsigned integer type.
§Examples
use ir_lang::Type;
assert!(Type::U16.is_unsigned_int());
assert!(!Type::I16.is_unsigned_int());Sourcepub const fn is_float(self) -> bool
pub const fn is_float(self) -> bool
Whether this is a float type.
§Examples
use ir_lang::Type;
assert!(Type::F64.is_float());
assert!(!Type::I64.is_float());Sourcepub const fn is_numeric(self) -> bool
pub const fn is_numeric(self) -> bool
Whether this is an integer or float type.
§Examples
use ir_lang::Type;
assert!(Type::F32.is_numeric());
assert!(!Type::Ptr.is_numeric());Sourcepub const fn int_bits(self) -> Option<u32>
pub const fn int_bits(self) -> Option<u32>
The width of an integer type in bits, or None for other types.
§Examples
use ir_lang::Type;
assert_eq!(Type::U32.int_bits(), Some(32));
assert_eq!(Type::F32.int_bits(), None);Sourcepub const fn bits(self, ptr: PointerWidth) -> u32
pub const fn bits(self, ptr: PointerWidth) -> u32
The width of the type’s value in bits, for the given pointer width
(Bool is 1 bit).
§Examples
use ir_lang::{PointerWidth, Type};
assert_eq!(Type::Bool.bits(PointerWidth::P64), 1);
assert_eq!(Type::Ref.bits(PointerWidth::P32), 32);Sourcepub const fn size(self, ptr: PointerWidth) -> u32
pub const fn size(self, ptr: PointerWidth) -> u32
The size of the type in memory, in bytes (also its natural alignment).
§Examples
use ir_lang::{PointerWidth, Type};
assert_eq!(Type::Bool.size(PointerWidth::P64), 1);
assert_eq!(Type::I16.size(PointerWidth::P64), 2);
assert_eq!(Type::Ptr.size(PointerWidth::P32), 4);Sourcepub const fn int(bits: u32, signed: bool) -> Option<Type>
pub const fn int(bits: u32, signed: bool) -> Option<Type>
The integer type of the given width and signedness, if there is one.
§Examples
use ir_lang::Type;
assert_eq!(Type::int(32, true), Some(Type::I32));
assert_eq!(Type::int(12, false), None);