Commit 16dde904 authored by qinsoon's avatar qinsoon

keep adding comments to ast crate

parent bfd95a82
This diff is collapsed.
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
pub enum BinOp {
// Int(n) BinOp Int(n) -> Int(n)
// BinOp Int(n) Int(n) -> Int(n)
Add,
Sub,
Mul,
......@@ -12,12 +12,12 @@ pub enum BinOp {
Or,
Xor,
// Int(n) BinOp Int(m) -> Int(n)
// BinOp Int(n) Int(m) -> Int(n)
Shl,
Lshr,
Ashr,
// FP BinOp FP -> FP
// BinOp FP FP -> FP
FAdd,
FSub,
FMul,
......@@ -59,7 +59,7 @@ pub enum CmpOp {
}
impl CmpOp {
// Returns the CmpOp c, such that (a self b) is equivelent to (b c a)
/// returns the CmpOp X for CmpOp Y, such that (a Y b) is equivalent to (b X a)
pub fn swap_operands(self) -> CmpOp {
use op::CmpOp::*;
match self {
......@@ -86,6 +86,8 @@ impl CmpOp {
_ => self, // all other comparisons are reflexive
}
}
/// returns the CmpOp X for CmpOp Y, such that (a Y b) is equivalent to NOT(a X b)
pub fn invert(self) -> CmpOp {
use op::CmpOp::*;
match self {
......@@ -129,6 +131,7 @@ impl CmpOp {
FTRUE => FFALSE,
}
}
pub fn is_signed(self) -> bool {
use op::CmpOp::*;
match self {
......@@ -136,6 +139,23 @@ impl CmpOp {
_ => false
}
}
pub fn is_int_cmp(self) -> bool {
use op::CmpOp::*;
match self {
EQ
| NE
| SGE
| SGT
| SLE
| SLT
| UGE
| UGT
| ULE
| ULT => true,
_ => false
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
......@@ -167,20 +187,4 @@ pub enum AtomicRMWOp {
MIN,
UMAX,
UMIN
}
pub fn is_int_cmp(op: CmpOp) -> bool {
match op {
CmpOp::EQ
| CmpOp::NE
| CmpOp::SGE
| CmpOp::SGT
| CmpOp::SLE
| CmpOp::SLT
| CmpOp::UGE
| CmpOp::UGT
| CmpOp::ULE
| CmpOp::ULT => true,
_ => false
}
}
\ No newline at end of file
......@@ -2880,7 +2880,7 @@ impl <'a> InstructionSelection {
}
use std;
let mut swap = false; // Whether op1 and op2 have been swapped
if op::is_int_cmp(op) {
if op.is_int_cmp() {
let n = node_type(op1).get_int_length().unwrap();
let mut imm_val = 0 as u64;
......
......@@ -2872,7 +2872,7 @@ impl <'a> InstructionSelection {
let op1 = &ops[op1];
let op2 = &ops[op2];
if op::is_int_cmp(op) {
if op.is_int_cmp() {
if self.match_iimm(op1) && self.match_iimm(op2) {
let ty : &P<MuType> = match op1.clone_value().ty.get_int_length() {
Some(64) => &UINT64_TYPE,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment