[meta] Use a type alias for Instruction;
... instead of embedding a Rc<InstructionContent>, just make it a type alias.
This commit is contained in:
@@ -3,7 +3,6 @@ use cranelift_entity::{entity_impl, PrimaryMap};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::{Display, Error, Formatter};
|
use std::fmt::{Display, Error, Formatter};
|
||||||
use std::ops;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::cdsl::camel_case;
|
use crate::cdsl::camel_case;
|
||||||
@@ -152,19 +151,7 @@ pub(crate) struct InstructionContent {
|
|||||||
pub writes_cpu_flags: bool,
|
pub writes_cpu_flags: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
impl InstructionContent {
|
||||||
pub(crate) struct Instruction {
|
|
||||||
content: Rc<InstructionContent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ops::Deref for Instruction {
|
|
||||||
type Target = InstructionContent;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instruction {
|
|
||||||
pub fn snake_name(&self) -> &str {
|
pub fn snake_name(&self) -> &str {
|
||||||
if &self.name == "return" {
|
if &self.name == "return" {
|
||||||
"return_"
|
"return_"
|
||||||
@@ -185,13 +172,15 @@ impl Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) type Instruction = Rc<InstructionContent>;
|
||||||
|
|
||||||
impl Bindable for Instruction {
|
impl Bindable for Instruction {
|
||||||
fn bind(&self, parameter: impl Into<BindParameter>) -> BoundInstruction {
|
fn bind(&self, parameter: impl Into<BindParameter>) -> BoundInstruction {
|
||||||
BoundInstruction::new(self).bind(parameter)
|
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> {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
if self.operands_out.len() > 0 {
|
if self.operands_out.len() > 0 {
|
||||||
let operands_out = self
|
let operands_out = self
|
||||||
@@ -352,8 +341,7 @@ impl InstructionBuilder {
|
|||||||
|
|
||||||
let camel_name = camel_case(&self.name);
|
let camel_name = camel_case(&self.name);
|
||||||
|
|
||||||
Instruction {
|
Rc::new(InstructionContent {
|
||||||
content: Rc::new(InstructionContent {
|
|
||||||
name: self.name,
|
name: self.name,
|
||||||
camel_name,
|
camel_name,
|
||||||
opcode_number,
|
opcode_number,
|
||||||
@@ -377,8 +365,7 @@ impl InstructionBuilder {
|
|||||||
can_trap: self.can_trap,
|
can_trap: self.can_trap,
|
||||||
other_side_effects: self.other_side_effects,
|
other_side_effects: self.other_side_effects,
|
||||||
writes_cpu_flags,
|
writes_cpu_flags,
|
||||||
}),
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user