[meta] Have bind() be a method of {Bound,}Instruction instead of a static method;

This commit is contained in:
Benjamin Bouvier
2019-05-23 12:01:25 +02:00
parent 724d1cd2a1
commit 6935033c9e
4 changed files with 23 additions and 19 deletions

View File

@@ -574,7 +574,7 @@ macro_rules! def_rhs {
// inst.type(a, b, c) // inst.type(a, b, c)
($inst:ident.$type:ident($($src:expr),*)) => { ($inst:ident.$type:ident($($src:expr),*)) => {
ExprBuilder::apply(bind($inst, $type).into(), vec![$($src.clone().into()),*]) ExprBuilder::apply($inst.bind($type).into(), vec![$($src.clone().into()),*])
}; };
} }

View File

@@ -143,6 +143,10 @@ impl Instruction {
None => Vec::new(), None => Vec::new(),
} }
} }
pub fn bind(&self, lane_type: impl Into<LaneType>) -> BoundInstruction {
bind(self.clone(), lane_type.into(), Vec::new())
}
} }
impl fmt::Display for Instruction { impl fmt::Display for Instruction {
@@ -341,6 +345,12 @@ pub struct BoundInstruction {
pub value_types: Vec<ValueType>, pub value_types: Vec<ValueType>,
} }
impl BoundInstruction {
pub fn bind(self, lane_type: impl Into<LaneType>) -> BoundInstruction {
bind(self.inst, lane_type.into(), self.value_types)
}
}
/// Check if this instruction is polymorphic, and verify its use of type variables. /// Check if this instruction is polymorphic, and verify its use of type variables.
fn verify_polymorphic( fn verify_polymorphic(
operands_in: &Vec<Operand>, operands_in: &Vec<Operand>,
@@ -626,18 +636,13 @@ impl Into<InstSpec> for BoundInstruction {
} }
} }
pub fn bind(target: impl Into<InstSpec>, lane_type: impl Into<LaneType>) -> BoundInstruction { /// Helper bind reused by {Bound,}Instruction::bind.
let value_type = ValueType::from(lane_type.into()); fn bind(
inst: Instruction,
let (inst, value_types) = match target.into() { lane_type: LaneType,
InstSpec::Inst(inst) => (inst, vec![value_type]), mut value_types: Vec<ValueType>,
InstSpec::Bound(bound_inst) => { ) -> BoundInstruction {
let mut new_value_types = bound_inst.value_types; value_types.push(ValueType::from(lane_type));
new_value_types.push(value_type);
(bound_inst.inst, new_value_types)
}
};
match &inst.polymorphic_info { match &inst.polymorphic_info {
Some(poly) => { Some(poly) => {
assert!( assert!(
@@ -652,6 +657,5 @@ pub fn bind(target: impl Into<InstSpec>, lane_type: impl Into<LaneType>) -> Boun
)); ));
} }
} }
BoundInstruction { inst, value_types } BoundInstruction { inst, value_types }
} }

View File

@@ -1,5 +1,5 @@
use crate::cdsl::ast::{var, ExprBuilder, Literal}; use crate::cdsl::ast::{var, ExprBuilder, Literal};
use crate::cdsl::inst::{bind, InstructionGroup}; use crate::cdsl::inst::InstructionGroup;
use crate::cdsl::xform::TransformGroupBuilder; use crate::cdsl::xform::TransformGroupBuilder;
use crate::shared::types::Int::{I32, I64}; use crate::shared::types::Int::{I32, I64};

View File

@@ -1,5 +1,5 @@
use crate::cdsl::ast::{var, ExprBuilder, Literal}; use crate::cdsl::ast::{var, ExprBuilder, Literal};
use crate::cdsl::inst::{bind, Instruction, InstructionGroup}; use crate::cdsl::inst::{Instruction, InstructionGroup};
use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups}; use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups};
use crate::shared::OperandKinds; use crate::shared::OperandKinds;
@@ -352,7 +352,7 @@ pub fn define(insts: &InstructionGroup, immediates: &OperandKinds) -> TransformG
for &extend_op in &[uextend, sextend] { for &extend_op in &[uextend, sextend] {
// The sign extension operators have two typevars: the result has one and controls the // The sign extension operators have two typevars: the result has one and controls the
// instruction, then the input has one. // instruction, then the input has one.
let bound = bind(bind(extend_op, I16), I8); let bound = extend_op.bind(I16).bind(I8);
widen.legalize( widen.legalize(
def!(a = bound(b)), def!(a = bound(b)),
vec![def!(c = extend_op.I32(b)), def!(a = ireduce(c))], vec![def!(c = extend_op.I32(b)), def!(a = ireduce(c))],
@@ -520,7 +520,7 @@ pub fn define(insts: &InstructionGroup, immediates: &OperandKinds) -> TransformG
// group. // group.
for &dest_ty in &[F32, F64] { for &dest_ty in &[F32, F64] {
for &src_ty in &[I8, I16] { for &src_ty in &[I8, I16] {
let bound_inst = bind(bind(fcvt_from_uint, dest_ty), src_ty); let bound_inst = fcvt_from_uint.bind(dest_ty).bind(src_ty);
expand.legalize( expand.legalize(
def!(a = bound_inst(b)), def!(a = bound_inst(b)),
vec![ vec![
@@ -529,7 +529,7 @@ pub fn define(insts: &InstructionGroup, immediates: &OperandKinds) -> TransformG
], ],
); );
let bound_inst = bind(bind(fcvt_from_sint, dest_ty), src_ty); let bound_inst = fcvt_from_sint.bind(dest_ty).bind(src_ty);
expand.legalize( expand.legalize(
def!(a = bound_inst(b)), def!(a = bound_inst(b)),
vec![ vec![