Add ConstantPool

This commit is contained in:
Andrew Brown
2019-07-23 10:38:29 -07:00
committed by Dan Gohman
parent ea9ee202bb
commit c20b13d5a9
4 changed files with 252 additions and 3 deletions

View File

@@ -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");
}
}