Struct lc3_ensemble::ast::Offset
source · pub struct Offset<OFF, const N: u32>(/* private fields */);Expand description
A value representing an offset or an immediate value.
The OFF type represents the backing type of this offset.
The signedness of this offset type is dependent on the signedness of the OFF type:
Offset<i16, _>: signed offsetOffset<u16, _>: unsigned offset
N indicates the maximum bit size of this offset/immediate value.
For example, Offset<i16, 5> is used to represent ADD/AND’s imm5 operand.
Implementations§
source§impl<OFF: OffsetBacking, const N: u32> Offset<OFF, N>
impl<OFF: OffsetBacking, const N: u32> Offset<OFF, N>
sourcepub fn new(n: OFF) -> Result<Self, OffsetNewErr>
pub fn new(n: OFF) -> Result<Self, OffsetNewErr>
Creates a new offset value.
This must fit within N bits of the representation, otherwise an error is raised.
§Panics
This will panic if N is larger than the offset backing (e.g., for backing u16, larger than 16).
sourcepub fn new_trunc(n: OFF) -> Self
pub fn new_trunc(n: OFF) -> Self
Creates a new offset by extending the first N bits of the integer, and discarding the rest.
The extension is considered sign-extended if the offset’s backing is signed, and it is considered zero-extended if the offset’s backing is unsigned.
§Panics
This will panic if N is larger than the offset backing (e.g., for backing u16, larger than 16).