Rewrite interpreter generically (#2323)
* Rewrite interpreter generically This change re-implements the Cranelift interpreter to use generic values; this makes it possible to do abstract interpretation of Cranelift instructions. In doing so, the interpretation state is extracted from the `Interpreter` structure and is accessed via a `State` trait; this makes it possible to not only more clearly observe the interpreter's state but also to interpret using a dummy state (e.g. `ImmutableRegisterState`). This addition made it possible to implement more of the Cranelift instructions (~70%, ignoring the x86-specific instructions). * Replace macros with closures
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
//! `cranelift-codegen/meta/src/shared/immediates` crate in the meta language.
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::str::FromStr;
|
||||
use core::{i32, u32};
|
||||
@@ -739,6 +740,17 @@ impl Ieee32 {
|
||||
pub fn bits(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Check if the value is a NaN.
|
||||
pub fn is_nan(&self) -> bool {
|
||||
f32::from_bits(self.0).is_nan()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Ieee32 {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
f32::from_bits(self.0).partial_cmp(&f32::from_bits(other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Ieee32 {
|
||||
@@ -812,6 +824,18 @@ impl Ieee64 {
|
||||
pub fn bits(self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Check if the value is a NaN. For [Ieee64], this means checking that the 11 exponent bits are
|
||||
/// all set.
|
||||
pub fn is_nan(&self) -> bool {
|
||||
f64::from_bits(self.0).is_nan()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Ieee64 {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
f64::from_bits(self.0).partial_cmp(&f64::from_bits(other.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Ieee64 {
|
||||
|
||||
Reference in New Issue
Block a user