Define control flow instructions.

Rename 'br' to 'jump'. We'll use jump/br to mean unconditional/conditional
control transfer respectively.
This commit is contained in:
Jakob Stoklund Olesen
2016-05-18 16:28:21 -07:00
parent d85fda0346
commit ebe224a912
10 changed files with 244 additions and 79 deletions

View File

@@ -189,3 +189,34 @@ impl Default for StackSlot {
NO_STACK_SLOT
}
}
/// An opaque reference to a jump table.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct JumpTable(u32);
impl JumpTable {
pub fn new(index: usize) -> JumpTable {
assert!(index < (u32::MAX as usize));
JumpTable(index as u32)
}
pub fn index(&self) -> usize {
self.0 as usize
}
}
/// Display a `JumpTable` reference as "jt12".
impl Display for JumpTable {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "jt{}", self.0)
}
}
/// A guaranteed invalid jump table reference.
pub const NO_JUMP_TABLE: JumpTable = JumpTable(u32::MAX);
impl Default for JumpTable {
fn default() -> JumpTable {
NO_JUMP_TABLE
}
}