1 use crate::ir::{SourceLoc, ValueLabel}; 2 use crate::HashMap; 3 use alloc::vec::Vec; 4 use core::cmp::Ordering; 5 use core::convert::From; 6 use core::ops::Deref; 7 use regalloc::Reg; 8 9 #[cfg(feature = "enable-serde")] 10 use serde::{Deserialize, Serialize}; 11 12 /// Value location range. 13 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 14 #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] 15 pub struct ValueLocRange { 16 /// The ValueLoc containing a ValueLabel during this range. 17 pub loc: LabelValueLoc, 18 /// The start of the range. It is an offset in the generated code. 19 pub start: u32, 20 /// The end of the range. It is an offset in the generated code. 21 pub end: u32, 22 } 23 24 /// The particular location for a value. 25 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 26 #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] 27 pub enum LabelValueLoc { 28 /// New-backend Reg. 29 Reg(Reg), 30 /// New-backend offset from stack pointer. 31 SPOffset(i64), 32 } 33 34 /// Resulting map of Value labels and their ranges/locations. 35 pub type ValueLabelsRanges = HashMap<ValueLabel, Vec<ValueLocRange>>; 36 37 #[derive(Eq, Clone, Copy)] 38 pub struct ComparableSourceLoc(SourceLoc); 39 40 impl From<SourceLoc> for ComparableSourceLoc { 41 fn from(s: SourceLoc) -> Self { 42 Self(s) 43 } 44 } 45 46 impl Deref for ComparableSourceLoc { 47 type Target = SourceLoc; 48 fn deref(&self) -> &SourceLoc { 49 &self.0 50 } 51 } 52 53 impl PartialOrd for ComparableSourceLoc { 54 fn partial_cmp(&self, other: &Self) -> Option<Ordering> { 55 Some(self.cmp(other)) 56 } 57 } 58 59 impl Ord for ComparableSourceLoc { 60 fn cmp(&self, other: &Self) -> Ordering { 61 self.0.bits().cmp(&other.0.bits()) 62 } 63 } 64 65 impl PartialEq for ComparableSourceLoc { 66 fn eq(&self, other: &Self) -> bool { 67 self.0 == other.0 68 } 69 } 70