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