View Javadoc

1   package org.kit.furia.fragment.asm;
2   
3   import java.util.Iterator;
4   import java.util.List;
5   
6   import org.objectweb.asm.tree.AbstractInsnNode;
7   import org.objectweb.asm.tree.analysis.BasicInterpreter;
8   import org.objectweb.asm.tree.analysis.Value;
9   
10  
11  
12  public class FragmentInterpreter
13          extends BasicInterpreter {
14      
15      public Value binaryOperation(AbstractInsnNode insn, Value value1, Value value2){
16          FunctionValue res = new FunctionValue(insn);
17          res.addParam(value1);
18          res.addParam(value2);
19          return res;
20      }
21      
22      public Value  naryOperation(AbstractInsnNode insn, List values){
23          FunctionValue res = new FunctionValue(insn);
24          Iterator<Value> it = values.iterator();
25          while(it.hasNext()){
26              Value n = it.next();
27              res.addParam(n);
28          }
29          return res;
30      }
31      
32      public Value ternaryOperation(AbstractInsnNode insn, Value value1, Value value2, Value value3){
33          FunctionValue res = new FunctionValue(insn);
34          res.addParam(value1);
35          res.addParam(value2);
36          res.addParam(value3);
37          return res;
38      }
39      
40      public Value  unaryOperation(AbstractInsnNode insn, Value value){
41          FunctionValue res = new FunctionValue(insn);
42          res.addParam(value);
43          return res;        
44      }
45      
46      /**
47       * A new phi function is created from the two values. If either v or w are phis, we just create one
48       * phi function from all the values.
49       */
50      public Value merge(Value v, Value w){
51          PhiFunctionValue res = null;
52          if(v instanceof PhiFunctionValue && w instanceof PhiFunctionValue){
53              res =  (PhiFunctionValue)v;
54              res.merge((PhiFunctionValue)w);
55          }else if(v instanceof PhiFunctionValue){
56              res =  (PhiFunctionValue)v;
57              res.addParam(w);
58          }else if(w instanceof PhiFunctionValue){
59              res =  (PhiFunctionValue)w;
60              res.addParam(v);
61          }else{
62              res = new PhiFunctionValue();
63              res.addParam(v);
64              res.addParam(w);
65          }
66          return res;
67      }
68  
69  }