Representation of comparison expression, e.g., cmp.
| 29 | * Representation of comparison expression, e.g., cmp. |
| 30 | */ |
| 31 | public class ComparisonExp extends AbstractBinaryExp { |
| 32 | |
| 33 | public enum Op implements BinaryExp.Op { |
| 34 | |
| 35 | CMP("cmp"), |
| 36 | CMPL("cmpl"), |
| 37 | CMPG("cmpg"), |
| 38 | ; |
| 39 | |
| 40 | private final String instruction; |
| 41 | |
| 42 | Op(String instruction) { |
| 43 | this.instruction = instruction; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public String toString() { |
| 48 | return instruction; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | private final Op op; |
| 53 | |
| 54 | public ComparisonExp(Op op, Var value1, Var value2) { |
| 55 | super(value1, value2); |
| 56 | this.op = op; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | protected void validate() { |
| 61 | Type v1type = operand1.getType(); |
| 62 | assert v1type.equals(operand2.getType()); |
| 63 | assert v1type.equals(PrimitiveType.LONG) || |
| 64 | v1type.equals(PrimitiveType.FLOAT) || |
| 65 | v1type.equals(PrimitiveType.DOUBLE); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public Op getOperator() { |
| 70 | return op; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public PrimitiveType getType() { |
| 75 | return PrimitiveType.INT; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public <T> T accept(ExpVisitor<T> visitor) { |
| 80 | return visitor.visit(this); |
| 81 | } |
| 82 | } |
nothing calls this directly
no outgoing calls
no test coverage detected