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