Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cranelift/codegen/src/ir/memflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ impl MemFlags {
/// Set endianness of the memory access.
pub fn set_endianness(&mut self, endianness: Endianness) {
*self = self.with_endianness(endianness);
assert!(!(self.read(FlagBit::LittleEndian) && self.read(FlagBit::BigEndian)));
}

/// Set endianness of the memory access, returning new flags.
pub const fn with_endianness(self, endianness: Endianness) -> Self {
match endianness {
let res = match endianness {
Endianness::Little => self.with(FlagBit::LittleEndian),
Endianness::Big => self.with(FlagBit::BigEndian),
}
};
assert!(!(res.read(FlagBit::LittleEndian) && res.read(FlagBit::BigEndian)));
res
}

/// Test if the `notrap` flag is set.
Expand Down Expand Up @@ -214,12 +215,12 @@ impl MemFlags {
/// Set the `heap` bit. See the notes about mutual exclusion with
/// other bits in `heap()`.
pub fn set_heap(&mut self) {
assert!(!self.table() && !self.vmctx());
*self = self.with_heap();
}

/// Set the `heap` bit, returning new flags.
pub const fn with_heap(self) -> Self {
assert!(!self.table() && !self.vmctx());
self.with(FlagBit::Heap)
}

Expand All @@ -238,12 +239,12 @@ impl MemFlags {
/// Set the `table` bit. See the notes about mutual exclusion with
/// other bits in `table()`.
pub fn set_table(&mut self) {
assert!(!self.heap() && !self.vmctx());
*self = self.with_table();
}

/// Set the `table` bit, returning new flags.
pub const fn with_table(self) -> Self {
assert!(!self.heap() && !self.vmctx());
self.with(FlagBit::Table)
}

Expand All @@ -262,12 +263,12 @@ impl MemFlags {
/// Set the `vmctx` bit. See the notes about mutual exclusion with
/// other bits in `vmctx()`.
pub fn set_vmctx(&mut self) {
assert!(!self.heap() && !self.table());
*self = self.with_vmctx();
}

/// Set the `vmctx` bit, returning new flags.
pub const fn with_vmctx(self) -> Self {
assert!(!self.heap() && !self.table());
self.with(FlagBit::Vmctx)
}

Expand Down