Files
wasmtime/lib/frontend/src/variable.rs
Afnan Enayet 9128290fb4 Rename ILBuilder to FunctionBuilderContext (#268)
* Rename `ILBuilder` to `FunctionBuilderContext` and update corresponding
code

* Refactor usages of ILBuilder to become FunctionBuilderContext,
update variable names to reflect this change

* Reformat to ensure that lines stay under 100 char limit

* Apply corrections from `rustfmt` to pass tests

* Rename variables to be more consistent with refactor of ILBuilder
2018-03-14 10:48:06 -07:00

33 lines
869 B
Rust

//! A basic `Variable` implementation.
//!
//! `FunctionBuilderContext`, `FunctionBuilder`, and related types have a `Variable`
//! type parameter, to allow frontends that identify variables with
//! their own index types to use them directly. Frontends which don't
//! can use the `Variable` defined here.
use cretonne::entity::EntityRef;
use std::u32;
///! An opaque reference to a variable.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Variable(u32);
impl Variable {
/// Create a new Variable with the given index.
pub fn with_u32(index: u32) -> Self {
debug_assert!(index < u32::MAX);
Variable(index)
}
}
impl EntityRef for Variable {
fn new(index: usize) -> Self {
debug_assert!(index < (u32::MAX as usize));
Variable(index as u32)
}
fn index(self) -> usize {
self.0 as usize
}
}