Define a Variable struct so that frontends don't have to.
Frontends can still use their own types with `ILBuilder` and `FunctionBuilder`. This just provides a basic `Variable` struct for frontends that want it.
This commit is contained in:
24
lib/frontend/src/variable.rs
Normal file
24
lib/frontend/src/variable.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
//! A basic `Variable` implementation.
|
||||
//!
|
||||
//! `ILBuilder`, `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 EntityRef for Variable {
|
||||
fn new(index: usize) -> Self {
|
||||
assert!(index < (u32::MAX as usize));
|
||||
Variable(index as u32)
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
self.0 as usize
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user