[meta] Use a type alias for Instruction;

... instead of embedding a Rc<InstructionContent>, just make it a type
alias.
This commit is contained in:
Benjamin Bouvier
2019-10-18 15:25:33 +02:00
parent d102bf9b61
commit 8fece43aa1

View File

@@ -3,7 +3,6 @@ use cranelift_entity::{entity_impl, PrimaryMap};
use std::collections::HashMap;
use std::fmt;
use std::fmt::{Display, Error, Formatter};
use std::ops;
use std::rc::Rc;
use crate::cdsl::camel_case;
@@ -152,19 +151,7 @@ pub(crate) struct InstructionContent {
pub writes_cpu_flags: bool,
}
#[derive(Clone, Debug)]
pub(crate) struct Instruction {
content: Rc<InstructionContent>,
}
impl ops::Deref for Instruction {
type Target = InstructionContent;
fn deref(&self) -> &Self::Target {
&*self.content
}
}
impl Instruction {
impl InstructionContent {
pub fn snake_name(&self) -> &str {
if &self.name == "return" {
"return_"
@@ -185,13 +172,15 @@ impl Instruction {
}
}
pub(crate) type Instruction = Rc<InstructionContent>;
impl Bindable for Instruction {
fn bind(&self, parameter: impl Into<BindParameter>) -> BoundInstruction {
BoundInstruction::new(self).bind(parameter)
}
}
impl fmt::Display for Instruction {
impl fmt::Display for InstructionContent {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
if self.operands_out.len() > 0 {
let operands_out = self
@@ -352,8 +341,7 @@ impl InstructionBuilder {
let camel_name = camel_case(&self.name);
Instruction {
content: Rc::new(InstructionContent {
Rc::new(InstructionContent {
name: self.name,
camel_name,
opcode_number,
@@ -377,8 +365,7 @@ impl InstructionBuilder {
can_trap: self.can_trap,
other_side_effects: self.other_side_effects,
writes_cpu_flags,
}),
}
})
}
}