Rename LogicOperator to CmpOperator
This commit is contained in:
parent
197f0b22f3
commit
257496aae2
@ -17,7 +17,7 @@ fn main() {
|
|||||||
// If N < 3
|
// If N < 3
|
||||||
Box::new(Expression(
|
Box::new(Expression(
|
||||||
ExprKind::BinOp(
|
ExprKind::BinOp(
|
||||||
BinaryOperator::Logic(LogicOperator::GT),
|
BinaryOperator::Cmp(CmpOperator::GT),
|
||||||
Box::new(Expression(
|
Box::new(Expression(
|
||||||
ExprKind::Variable(VariableReference(
|
ExprKind::Variable(VariableReference(
|
||||||
TypeKind::I32,
|
TypeKind::I32,
|
||||||
|
@ -150,12 +150,12 @@ impl ast::BinaryOperator {
|
|||||||
ast::BinaryOperator::Minus => mir::BinaryOperator::Minus,
|
ast::BinaryOperator::Minus => mir::BinaryOperator::Minus,
|
||||||
ast::BinaryOperator::Mult => mir::BinaryOperator::Mult,
|
ast::BinaryOperator::Mult => mir::BinaryOperator::Mult,
|
||||||
ast::BinaryOperator::And => mir::BinaryOperator::And,
|
ast::BinaryOperator::And => mir::BinaryOperator::And,
|
||||||
ast::BinaryOperator::LT => mir::BinaryOperator::Logic(mir::LogicOperator::LT),
|
ast::BinaryOperator::LT => mir::BinaryOperator::Cmp(mir::CmpOperator::LT),
|
||||||
ast::BinaryOperator::LE => mir::BinaryOperator::Logic(mir::LogicOperator::LE),
|
ast::BinaryOperator::LE => mir::BinaryOperator::Cmp(mir::CmpOperator::LE),
|
||||||
ast::BinaryOperator::GT => mir::BinaryOperator::Logic(mir::LogicOperator::GT),
|
ast::BinaryOperator::GT => mir::BinaryOperator::Cmp(mir::CmpOperator::GT),
|
||||||
ast::BinaryOperator::GE => mir::BinaryOperator::Logic(mir::LogicOperator::GE),
|
ast::BinaryOperator::GE => mir::BinaryOperator::Cmp(mir::CmpOperator::GE),
|
||||||
ast::BinaryOperator::EQ => mir::BinaryOperator::Logic(mir::LogicOperator::EQ),
|
ast::BinaryOperator::EQ => mir::BinaryOperator::Cmp(mir::CmpOperator::EQ),
|
||||||
ast::BinaryOperator::NE => mir::BinaryOperator::Logic(mir::LogicOperator::NE),
|
ast::BinaryOperator::NE => mir::BinaryOperator::Cmp(mir::CmpOperator::NE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ impl mir::Expression {
|
|||||||
mir::BinaryOperator::And => {
|
mir::BinaryOperator::And => {
|
||||||
scope.block.build(InstructionKind::And(lhs, rhs)).unwrap()
|
scope.block.build(InstructionKind::And(lhs, rhs)).unwrap()
|
||||||
}
|
}
|
||||||
mir::BinaryOperator::Logic(l) => scope
|
mir::BinaryOperator::Cmp(l) => scope
|
||||||
.block
|
.block
|
||||||
.build(InstructionKind::ICmp(l.int_predicate(), lhs, rhs))
|
.build(InstructionKind::ICmp(l.int_predicate(), lhs, rhs))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
@ -290,15 +290,15 @@ impl mir::Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl mir::LogicOperator {
|
impl mir::CmpOperator {
|
||||||
fn int_predicate(&self) -> CmpPredicate {
|
fn int_predicate(&self) -> CmpPredicate {
|
||||||
match self {
|
match self {
|
||||||
mir::LogicOperator::LT => CmpPredicate::LT,
|
mir::CmpOperator::LT => CmpPredicate::LT,
|
||||||
mir::LogicOperator::GT => CmpPredicate::GT,
|
mir::CmpOperator::GT => CmpPredicate::GT,
|
||||||
mir::LogicOperator::LE => CmpPredicate::LE,
|
mir::CmpOperator::LE => CmpPredicate::LE,
|
||||||
mir::LogicOperator::GE => CmpPredicate::GE,
|
mir::CmpOperator::GE => CmpPredicate::GE,
|
||||||
mir::LogicOperator::EQ => CmpPredicate::EQ,
|
mir::CmpOperator::EQ => CmpPredicate::EQ,
|
||||||
mir::LogicOperator::NE => CmpPredicate::NE,
|
mir::CmpOperator::NE => CmpPredicate::NE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,20 +179,20 @@ impl Display for BinaryOperator {
|
|||||||
BinaryOperator::Minus => write!(f, "-"),
|
BinaryOperator::Minus => write!(f, "-"),
|
||||||
BinaryOperator::Mult => write!(f, "*"),
|
BinaryOperator::Mult => write!(f, "*"),
|
||||||
BinaryOperator::And => write!(f, "&&"),
|
BinaryOperator::And => write!(f, "&&"),
|
||||||
BinaryOperator::Logic(op) => Display::fmt(op, f),
|
BinaryOperator::Cmp(op) => Display::fmt(op, f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for LogicOperator {
|
impl Display for CmpOperator {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
LogicOperator::LT => write!(f, "<"),
|
CmpOperator::LT => write!(f, "<"),
|
||||||
LogicOperator::LE => write!(f, "<="),
|
CmpOperator::LE => write!(f, "<="),
|
||||||
LogicOperator::GT => write!(f, ">"),
|
CmpOperator::GT => write!(f, ">"),
|
||||||
LogicOperator::GE => write!(f, ">="),
|
CmpOperator::GE => write!(f, ">="),
|
||||||
LogicOperator::EQ => write!(f, "=="),
|
CmpOperator::EQ => write!(f, "=="),
|
||||||
LogicOperator::NE => write!(f, "!="),
|
CmpOperator::NE => write!(f, "!="),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,11 +162,12 @@ pub enum BinaryOperator {
|
|||||||
Minus,
|
Minus,
|
||||||
Mult,
|
Mult,
|
||||||
And,
|
And,
|
||||||
Logic(LogicOperator),
|
Cmp(CmpOperator),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specifically the operators that LLVM likes to take in as "icmp" parameters
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum LogicOperator {
|
pub enum CmpOperator {
|
||||||
LT,
|
LT,
|
||||||
LE,
|
LE,
|
||||||
GT,
|
GT,
|
||||||
|
@ -302,7 +302,7 @@ impl TypeKind {
|
|||||||
BinaryOperator::Minus => res,
|
BinaryOperator::Minus => res,
|
||||||
BinaryOperator::Mult => res,
|
BinaryOperator::Mult => res,
|
||||||
BinaryOperator::And => res,
|
BinaryOperator::And => res,
|
||||||
BinaryOperator::Logic(_) => Bool,
|
BinaryOperator::Cmp(_) => Bool,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user