Cranelift: Make Opcode represented as a u8 instead of u16 and remove vestigial conversion impls (#5042)
* Cranelift: Make `Opcode` represented as a `u8` instead of `u16` * Cranelift: Remove unused conversion impls for `Opcode` These are vestigial, left over from Peepmatic.
This commit is contained in:
@@ -405,7 +405,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
|||||||
All instructions from all supported ISAs are present.
|
All instructions from all supported ISAs are present.
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
fmt.line("#[repr(u16)]");
|
fmt.line("#[repr(u8)]");
|
||||||
fmt.line("#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]");
|
fmt.line("#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]");
|
||||||
fmt.line(
|
fmt.line(
|
||||||
r#"#[cfg_attr(
|
r#"#[cfg_attr(
|
||||||
@@ -572,24 +572,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
|||||||
fmt.empty_line();
|
fmt.empty_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_try_from(all_inst: &AllInstructions, fmt: &mut Formatter) {
|
|
||||||
fmt.line("impl core::convert::TryFrom<u16> for Opcode {");
|
|
||||||
fmt.indent(|fmt| {
|
|
||||||
fmt.line("type Error = ();");
|
|
||||||
fmt.line("#[inline]");
|
|
||||||
fmt.line("fn try_from(x: u16) -> Result<Self, ()> {");
|
|
||||||
fmt.indent(|fmt| {
|
|
||||||
fmtln!(fmt, "if 0 < x && x <= {} {{", all_inst.len());
|
|
||||||
fmt.indent(|fmt| fmt.line("Ok(unsafe { core::mem::transmute(x) })"));
|
|
||||||
fmt.line("} else {");
|
|
||||||
fmt.indent(|fmt| fmt.line("Err(())"));
|
|
||||||
fmt.line("}");
|
|
||||||
});
|
|
||||||
fmt.line("}");
|
|
||||||
});
|
|
||||||
fmt.line("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the value type constraint for an SSA value operand, where
|
/// Get the value type constraint for an SSA value operand, where
|
||||||
/// `ctrl_typevar` is the controlling type variable.
|
/// `ctrl_typevar` is the controlling type variable.
|
||||||
///
|
///
|
||||||
@@ -1420,8 +1402,6 @@ pub(crate) fn generate(
|
|||||||
gen_opcodes(all_inst, &mut fmt);
|
gen_opcodes(all_inst, &mut fmt);
|
||||||
fmt.empty_line();
|
fmt.empty_line();
|
||||||
gen_type_constraints(all_inst, &mut fmt);
|
gen_type_constraints(all_inst, &mut fmt);
|
||||||
fmt.empty_line();
|
|
||||||
gen_try_from(all_inst, &mut fmt);
|
|
||||||
fmt.update_file(opcode_filename, out_dir)?;
|
fmt.update_file(opcode_filename, out_dir)?;
|
||||||
|
|
||||||
// ISLE DSL.
|
// ISLE DSL.
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
//! directory.
|
//! directory.
|
||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::convert::{TryFrom, TryInto};
|
|
||||||
use core::fmt::{self, Display, Formatter};
|
use core::fmt::{self, Display, Formatter};
|
||||||
use core::num::NonZeroU32;
|
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
|
|
||||||
@@ -77,24 +75,6 @@ impl Opcode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<NonZeroU32> for Opcode {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn try_from(x: NonZeroU32) -> Result<Self, ()> {
|
|
||||||
let x: u16 = x.get().try_into().map_err(|_| ())?;
|
|
||||||
Self::try_from(x)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Opcode> for NonZeroU32 {
|
|
||||||
#[inline]
|
|
||||||
fn from(op: Opcode) -> NonZeroU32 {
|
|
||||||
let x = op as u8;
|
|
||||||
NonZeroU32::new(x as u32).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This trait really belongs in cranelift-reader where it is used by the `.clif` file parser, but since
|
// This trait really belongs in cranelift-reader where it is used by the `.clif` file parser, but since
|
||||||
// it critically depends on the `opcode_name()` function which is needed here anyway, it lives in
|
// it critically depends on the `opcode_name()` function which is needed here anyway, it lives in
|
||||||
// this module. This also saves us from running the build script twice to generate code for the two
|
// this module. This also saves us from running the build script twice to generate code for the two
|
||||||
|
|||||||
Reference in New Issue
Block a user