Don't renumber entities in the parser.

This makes it easier to debug testcases:
 - the entity numbers in a .cton file match the entity numbers used
   within Cretonne.
 - serializing and deserializing doesn't cause indices to change.

One disadvantage is that if a .cton file uses sparse entity numbers,
deserializing to the in-memory form doesn't compact it. However, the
text format is not intended to be performance-critical, so this isn't
expected to be a big burden.
This commit is contained in:
Dan Gohman
2018-02-15 21:13:25 -08:00
parent c846ec1626
commit a5b00b173e
22 changed files with 677 additions and 650 deletions

View File

@@ -65,6 +65,19 @@ entity_impl!(Inst, "inst");
pub struct StackSlot(u32);
entity_impl!(StackSlot, "ss");
impl StackSlot {
/// Create a new stack slot reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<StackSlot> {
if n < u32::MAX {
Some(StackSlot(n))
} else {
None
}
}
}
/// An opaque reference to a global variable.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct GlobalVar(u32);
@@ -88,21 +101,61 @@ impl GlobalVar {
pub struct JumpTable(u32);
entity_impl!(JumpTable, "jt");
impl JumpTable {
/// Create a new jump table reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<JumpTable> {
if n < u32::MAX {
Some(JumpTable(n))
} else {
None
}
}
}
/// A reference to an external function.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct FuncRef(u32);
entity_impl!(FuncRef, "fn");
impl FuncRef {
/// Create a new external function reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<FuncRef> {
if n < u32::MAX { Some(FuncRef(n)) } else { None }
}
}
/// A reference to a function signature.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct SigRef(u32);
entity_impl!(SigRef, "sig");
impl SigRef {
/// Create a new function signature reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<SigRef> {
if n < u32::MAX { Some(SigRef(n)) } else { None }
}
}
/// A reference to a heap.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Heap(u32);
entity_impl!(Heap, "heap");
impl Heap {
/// Create a new heap reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Heap> {
if n < u32::MAX { Some(Heap(n)) } else { None }
}
}
/// A reference to any of the entities defined in this module.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub enum AnyEntity {