Add ConstantPool
This commit is contained in:
@@ -104,6 +104,24 @@ impl GlobalValue {
|
||||
}
|
||||
}
|
||||
|
||||
/// An opaque reference to a constant
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||
pub struct Constant(u32);
|
||||
entity_impl!(Constant, "const");
|
||||
|
||||
impl Constant {
|
||||
/// Create a const reference from its number.
|
||||
///
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(Constant(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An opaque reference to a jump table.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
@@ -195,7 +213,7 @@ impl Table {
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to any of the entities defined in this module.
|
||||
/// A reference to any of the entities defined in this module that can appear in CLIF IR.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AnyEntity {
|
||||
/// The whole function.
|
||||
@@ -331,4 +349,10 @@ mod tests {
|
||||
mem::size_of::<PackedOption<Value>>()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constant_with_number() {
|
||||
assert_eq!(Constant::with_number(0).unwrap().to_string(), "const0");
|
||||
assert_eq!(Constant::with_number(1).unwrap().to_string(), "const1");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user