WALA/com.ibm.wala.shrike/src/com/ibm/wala/shrikeBT/UnaryOpInstruction.java

104 lines
2.7 KiB
Java

/*******************************************************************************
* Copyright (c) 2002,2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.wala.shrikeBT;
/**
* This class represents unary operators where the result is the same type as
* the operand.
*/
public final class UnaryOpInstruction extends Instruction {
public interface IOperator {}
public static enum Operator implements IOperator {
NEG;
@Override
public String toString() {
return super.toString().toLowerCase();
}
}
protected UnaryOpInstruction(short opcode) {
this.opcode = opcode;
}
private final static UnaryOpInstruction[] preallocated = preallocate();
private static UnaryOpInstruction[] preallocate() {
UnaryOpInstruction[] r = new UnaryOpInstruction[OP_dneg - OP_ineg + 1];
for (int i = 0; i < r.length; i++) {
r[i] = new UnaryOpInstruction((short) (OP_ineg + i));
}
return r;
}
public static UnaryOpInstruction make(String type, Operator operator) throws IllegalArgumentException {
int t = Util.getTypeIndex(type);
if (t < 0 || t > TYPE_double_index) {
throw new IllegalArgumentException("Type " + type + " cannot have a unary operator applied");
}
return preallocated[t];
}
@Override
public boolean equals(Object o) {
if (o instanceof UnaryOpInstruction) {
UnaryOpInstruction i = (UnaryOpInstruction) o;
return i.opcode == opcode;
} else {
return false;
}
}
public Operator getOperator() {
return Operator.NEG;
}
@Override
public int hashCode() {
return opcode;
}
@Override
public int getPoppedCount() {
return 1;
}
@Override
public String getPushedType(String[] types) {
return getType();
}
@Override
public byte getPushedWordSize() {
return Util.getWordSize(getType());
}
public String getType() {
return indexedTypes[opcode - OP_ineg];
}
@Override
public void visit(Visitor v) throws NullPointerException {
v.visitUnaryOp(this);
}
@Override
public String toString() {
return "UnaryOp(" + getType() + "," + getOperator() + ")";
}
/* (non-Javadoc)
* @see com.ibm.domo.cfg.IInstruction#isPEI()
*/
public boolean isPEI() {
return false;
}
}