cranelift_codegen/
value_label.rs1use crate::ir::{SourceLoc, ValueLabel};
2use crate::machinst::Reg;
3use crate::HashMap;
4use alloc::vec::Vec;
5use core::cmp::Ordering;
6use core::convert::From;
7use core::ops::Deref;
8
9#[cfg(feature = "enable-serde")]
10use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
15pub struct ValueLocRange {
16 pub loc: LabelValueLoc,
18 pub start: u32,
20 pub end: u32,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
27pub enum LabelValueLoc {
28 Reg(Reg),
30 SPOffset(i64),
32}
33
34pub type ValueLabelsRanges = HashMap<ValueLabel, Vec<ValueLocRange>>;
36
37#[derive(Eq, Clone, Copy)]
38pub struct ComparableSourceLoc(SourceLoc);
39
40impl From<SourceLoc> for ComparableSourceLoc {
41 fn from(s: SourceLoc) -> Self {
42 Self(s)
43 }
44}
45
46impl Deref for ComparableSourceLoc {
47 type Target = SourceLoc;
48 fn deref(&self) -> &SourceLoc {
49 &self.0
50 }
51}
52
53impl PartialOrd for ComparableSourceLoc {
54 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
55 Some(self.cmp(other))
56 }
57}
58
59impl Ord for ComparableSourceLoc {
60 fn cmp(&self, other: &Self) -> Ordering {
61 self.0.bits().cmp(&other.0.bits())
62 }
63}
64
65impl PartialEq for ComparableSourceLoc {
66 fn eq(&self, other: &Self) -> bool {
67 self.0 == other.0
68 }
69}