1 19 20 package jode.flow; 21 import jode.GlobalOptions; 22 import jode.expr.*; 23 24 34 public class CreateExpression { 35 36 41 public static boolean transform(InstructionContainer ic, 42 StructuredBlock last) { 43 int params = ic.getInstruction().getFreeOperandCount(); 44 if (params == 0) 45 return false; 46 47 if (!(last.outer instanceof SequentialBlock)) 48 return false; 49 SequentialBlock sequBlock = (SequentialBlock)last.outer; 50 51 53 Expression lastExpression = ic.getInstruction(); 54 while (true) { 55 if (!(sequBlock.subBlocks[0] instanceof InstructionBlock)) 56 return false; 57 58 Expression expr = 59 ((InstructionBlock) sequBlock.subBlocks[0]).getInstruction(); 60 61 if (!expr.isVoid()) 62 break; 63 64 if (expr.getFreeOperandCount() > 0 65 || !(expr instanceof CombineableOperator) 66 || lastExpression.canCombine((CombineableOperator) expr) <= 0) 67 return false; 68 69 78 SequentialBlock block = sequBlock; 79 while (block != last.outer) { 80 block = (SequentialBlock) block.subBlocks[1]; 81 if (((InstructionBlock)block.subBlocks[0]) 82 .getInstruction().hasSideEffects(expr)) 83 return false; 84 } 85 86 87 if (!(sequBlock.outer instanceof SequentialBlock)) 88 return false; 89 sequBlock = (SequentialBlock) sequBlock.outer; 90 } 91 92 94 sequBlock = (SequentialBlock) last.outer; 95 lastExpression = ic.getInstruction(); 96 while (true) { 97 98 Expression expr = 99 ((InstructionBlock) sequBlock.subBlocks[0]).getInstruction(); 100 101 if (!expr.isVoid()) { 102 lastExpression = lastExpression.addOperand(expr); 103 break; 104 } 105 106 lastExpression = lastExpression.combine 107 ((CombineableOperator) expr); 108 sequBlock = (SequentialBlock)sequBlock.outer; 109 } 110 111 if (GlobalOptions.verboseLevel > 0 112 && lastExpression.getFreeOperandCount() == 0) 113 GlobalOptions.err.print('x'); 114 115 ic.setInstruction(lastExpression); 116 ic.moveDefinitions(sequBlock, last); 117 last.replace(sequBlock); 118 return true; 119 } 120 } 121 | Popular Tags |