001: package net.sf.jdec.jvminstructions.commands;
002:
003: import net.sf.jdec.blockhelpers.IFHelper;
004: import net.sf.jdec.core.JvmOpCodes;
005: import net.sf.jdec.core.Operand;
006: import net.sf.jdec.core.OperandStack;
007: import net.sf.jdec.core.ShortcutAnalyser;
008: import net.sf.jdec.reflection.Behaviour;
009: import net.sf.jdec.util.Constants;
010:
011: public class FcmplCommand extends AbstractInstructionCommand {
012:
013: public FcmplCommand(Behaviour context) {
014: super (context);
015:
016: }
017:
018: public int getSkipBytes() {
019: return 0;
020: }
021:
022: public void execute() {
023: int currentForIndex = getCurrentInstPosInCode();
024: OperandStack stack = getStack();
025: int i = currentForIndex;
026: Operand op = (Operand) stack.pop();
027: Operand op1 = (Operand) stack.pop();
028: Operand op2 = new Operand();
029: // op2.setCategory(Constants.CATEGORY1);
030: op2.setOperandType(Constants.IS_CONSTANT_INT);
031: int j = i + 1;
032: byte[] info = getCode();
033: int nextInstruction = info[j];
034: boolean sh = IFHelper.isIFShortcutORComp(info, j);
035: ShortcutAnalyser sanalyser = getContext().getShortCutAnalyser();
036: boolean invert = sanalyser.isLastIfInChain(j);
037: if (!invert) {
038: java.lang.String connector = sanalyser.getConnector(j);
039: if (connector != null
040: && connector.trim().equals(ShortcutAnalyser.AND)) {
041: invert = true;
042: }
043: }
044: if (!sh) {
045: if (getGenericFinder().isThisInstrStart(
046: (currentForIndex + 1))) {
047: if (getBranchFinder().isInstructionIF(
048: (currentForIndex + 1))) {
049: int ifclose = IFHelper.getIfCloseNumberForThisIF(
050: info, (currentForIndex + 1));
051: ifclose = ifclose - 3;
052: if (getGenericFinder().isThisInstrStart(ifclose)) {
053: if (getBranchFinder().isInstructionIF(ifclose)
054: && ifclose != j) {
055: sh = true;
056: }
057: }
058: }
059: }
060:
061: }
062: switch (nextInstruction) {
063: case JvmOpCodes.IFEQ:
064: if (!sh)
065: op2.setOperandValue(op1.getOperandValue() + "!="
066: + op.getOperandValue());
067: else {
068: if (!invert)
069: op2.setOperandValue(op1.getOperandValue() + "=="
070: + op.getOperandValue());
071: else
072: op2.setOperandValue(op1.getOperandValue() + "!="
073: + op.getOperandValue());
074: }
075: break;
076: case JvmOpCodes.IFNE:
077: if (!sh)
078: op2.setOperandValue(op1.getOperandValue() + "=="
079: + op.getOperandValue());
080: else {
081: if (!invert)
082: op2.setOperandValue(op1.getOperandValue() + "!="
083: + op.getOperandValue());
084: else
085: op2.setOperandValue(op1.getOperandValue() + "=="
086: + op.getOperandValue());
087: }
088: break;
089: case JvmOpCodes.IFLT:
090: if (!sh)
091: op2.setOperandValue(op1.getOperandValue() + ">="
092: + op.getOperandValue());
093: else {
094: if (!invert)
095: op2.setOperandValue(op1.getOperandValue() + "<"
096: + op.getOperandValue());
097: else
098: op2.setOperandValue(op1.getOperandValue() + ">="
099: + op.getOperandValue());
100: }
101: break;
102: case JvmOpCodes.IFGE:
103: if (!sh)
104: op2.setOperandValue(op1.getOperandValue() + "<"
105: + op.getOperandValue());
106: else {
107: if (!invert)
108: op2.setOperandValue(op1.getOperandValue() + ">="
109: + op.getOperandValue());
110: else
111: op2.setOperandValue(op1.getOperandValue() + "<"
112: + op.getOperandValue());
113: }
114: break;
115: case JvmOpCodes.IFGT:
116: if (!sh)
117: op2.setOperandValue(op1.getOperandValue() + "<="
118: + op.getOperandValue());
119: else {
120: if (!invert)
121: op2.setOperandValue(op1.getOperandValue() + ">"
122: + op.getOperandValue());
123: else
124: op2.setOperandValue(op1.getOperandValue() + "<="
125: + op.getOperandValue());
126: }
127: break;
128: case JvmOpCodes.IFLE:
129: if (!sh)
130: op2.setOperandValue(op1.getOperandValue() + ">"
131: + op.getOperandValue());
132: else {
133: if (!invert)
134: op2.setOperandValue(op1.getOperandValue() + "<="
135: + op.getOperandValue());
136: else
137: op2.setOperandValue(op1.getOperandValue() + ">"
138: + op.getOperandValue());
139: }
140: break;
141: }
142:
143: stack.push(op2);
144: }
145:
146: }
|