[meta] Rename ApplyTarget to InstSpec;

This commit is contained in:
Benjamin Bouvier
2019-05-23 11:53:06 +02:00
parent a46b2d7173
commit 724d1cd2a1
2 changed files with 20 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
use crate::cdsl::formats::FormatRegistry; use crate::cdsl::formats::FormatRegistry;
use crate::cdsl::inst::{ApplyTarget, Instruction, InstructionPredicate}; use crate::cdsl::inst::{InstSpec, Instruction, InstructionPredicate};
use crate::cdsl::operands::{OperandKind, OperandKindFields}; use crate::cdsl::operands::{OperandKind, OperandKindFields};
use crate::cdsl::types::ValueType; use crate::cdsl::types::ValueType;
use crate::cdsl::typevar::{TypeSetBuilder, TypeVar}; use crate::cdsl::typevar::{TypeSetBuilder, TypeVar};
@@ -375,10 +375,10 @@ pub struct Apply {
} }
impl Apply { impl Apply {
pub fn new(target: ApplyTarget, args: Vec<Expr>) -> Self { pub fn new(target: InstSpec, args: Vec<Expr>) -> Self {
let (inst, value_types) = match target.into() { let (inst, value_types) = match target.into() {
ApplyTarget::Inst(inst) => (inst, Vec::new()), InstSpec::Inst(inst) => (inst, Vec::new()),
ApplyTarget::Bound(bound_inst) => (bound_inst.inst, bound_inst.value_types), InstSpec::Bound(bound_inst) => (bound_inst.inst, bound_inst.value_types),
}; };
// Basic check on number of arguments. // Basic check on number of arguments.
@@ -520,7 +520,7 @@ impl Apply {
pub enum DummyExpr { pub enum DummyExpr {
Var(DummyVar), Var(DummyVar),
Literal(Literal), Literal(Literal),
Apply(ApplyTarget, Vec<DummyExpr>), Apply(InstSpec, Vec<DummyExpr>),
} }
#[derive(Clone)] #[derive(Clone)]
@@ -553,7 +553,7 @@ pub struct ExprBuilder {
} }
impl ExprBuilder { impl ExprBuilder {
pub fn apply(inst: ApplyTarget, args: Vec<DummyExpr>) -> Self { pub fn apply(inst: InstSpec, args: Vec<DummyExpr>) -> Self {
let expr = DummyExpr::Apply(inst, args); let expr = DummyExpr::Apply(inst, args);
Self { expr } Self { expr }
} }

View File

@@ -599,38 +599,39 @@ impl InstructionPredicate {
} }
} }
pub enum ApplyTarget { /// An instruction specification, containing an instruction that has bound types or not.
pub enum InstSpec {
Inst(Instruction), Inst(Instruction),
Bound(BoundInstruction), Bound(BoundInstruction),
} }
impl ApplyTarget { impl InstSpec {
pub fn inst(&self) -> &Instruction { pub fn inst(&self) -> &Instruction {
match &self { match &self {
ApplyTarget::Inst(inst) => inst, InstSpec::Inst(inst) => inst,
ApplyTarget::Bound(bound_inst) => &bound_inst.inst, InstSpec::Bound(bound_inst) => &bound_inst.inst,
} }
} }
} }
impl Into<ApplyTarget> for &Instruction { impl Into<InstSpec> for &Instruction {
fn into(self) -> ApplyTarget { fn into(self) -> InstSpec {
ApplyTarget::Inst(self.clone()) InstSpec::Inst(self.clone())
} }
} }
impl Into<ApplyTarget> for BoundInstruction { impl Into<InstSpec> for BoundInstruction {
fn into(self) -> ApplyTarget { fn into(self) -> InstSpec {
ApplyTarget::Bound(self) InstSpec::Bound(self)
} }
} }
pub fn bind(target: impl Into<ApplyTarget>, lane_type: impl Into<LaneType>) -> BoundInstruction { pub fn bind(target: impl Into<InstSpec>, lane_type: impl Into<LaneType>) -> BoundInstruction {
let value_type = ValueType::from(lane_type.into()); let value_type = ValueType::from(lane_type.into());
let (inst, value_types) = match target.into() { let (inst, value_types) = match target.into() {
ApplyTarget::Inst(inst) => (inst, vec![value_type]), InstSpec::Inst(inst) => (inst, vec![value_type]),
ApplyTarget::Bound(bound_inst) => { InstSpec::Bound(bound_inst) => {
let mut new_value_types = bound_inst.value_types; let mut new_value_types = bound_inst.value_types;
new_value_types.push(value_type); new_value_types.push(value_type);
(bound_inst.inst, new_value_types) (bound_inst.inst, new_value_types)