1 use serde::{Deserialize, Serialize}; 2 3 /// A map for determining where live GC references live in a stack frame. 4 /// 5 /// Note that this is currently primarily documented as cranelift's 6 /// `binemit::StackMap`, so for detailed documentation about this please read 7 /// the docs over there. 8 #[derive(Debug, Serialize, Deserialize)] 9 pub struct StackMap { 10 bits: Box<[u32]>, 11 mapped_words: u32, 12 } 13 14 impl StackMap { 15 /// Creates a new `StackMap`, typically from a preexisting 16 /// `binemit::StackMap`. 17 pub fn new(mapped_words: u32, bits: impl Iterator<Item = u32>) -> StackMap { 18 StackMap { 19 bits: bits.collect(), 20 mapped_words, 21 } 22 } 23 24 /// Returns a specified bit. 25 pub fn get_bit(&self, bit_index: usize) -> bool { 26 assert!(bit_index < 32 * self.bits.len()); 27 let word_index = bit_index / 32; 28 let word_offset = bit_index % 32; 29 (self.bits[word_index] & (1 << word_offset)) != 0 30 } 31 32 /// Returns the number of words represented by this stack map. 33 pub fn mapped_words(&self) -> u32 { 34 self.mapped_words 35 } 36 } 37