diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs index 819b553ce4..1d2fefc2b3 100644 --- a/cranelift/codegen/meta/src/gen_inst.rs +++ b/cranelift/codegen/meta/src/gen_inst.rs @@ -405,7 +405,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) { 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( r#"#[cfg_attr( @@ -572,24 +572,6 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) { fmt.empty_line(); } -fn gen_try_from(all_inst: &AllInstructions, fmt: &mut Formatter) { - fmt.line("impl core::convert::TryFrom for Opcode {"); - fmt.indent(|fmt| { - fmt.line("type Error = ();"); - fmt.line("#[inline]"); - fmt.line("fn try_from(x: u16) -> Result {"); - 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 /// `ctrl_typevar` is the controlling type variable. /// @@ -1420,8 +1402,6 @@ pub(crate) fn generate( gen_opcodes(all_inst, &mut fmt); fmt.empty_line(); gen_type_constraints(all_inst, &mut fmt); - fmt.empty_line(); - gen_try_from(all_inst, &mut fmt); fmt.update_file(opcode_filename, out_dir)?; // ISLE DSL. diff --git a/cranelift/codegen/src/ir/instructions.rs b/cranelift/codegen/src/ir/instructions.rs index 2f84525041..a147816e42 100644 --- a/cranelift/codegen/src/ir/instructions.rs +++ b/cranelift/codegen/src/ir/instructions.rs @@ -7,9 +7,7 @@ //! directory. use alloc::vec::Vec; -use core::convert::{TryFrom, TryInto}; use core::fmt::{self, Display, Formatter}; -use core::num::NonZeroU32; use core::ops::{Deref, DerefMut}; use core::str::FromStr; @@ -77,24 +75,6 @@ impl Opcode { } } -impl TryFrom for Opcode { - type Error = (); - - #[inline] - fn try_from(x: NonZeroU32) -> Result { - let x: u16 = x.get().try_into().map_err(|_| ())?; - Self::try_from(x) - } -} - -impl From 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 // 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