private static void updateForInstruction(Map<Integer, ConstantValue> constants, SymbolTable symbolTable, SSAInstruction s) { for (int j = 0; j < s.getNumberOfDefs(); j++) { symbolTable.ensureSymbol(s.getDef(j)); } for (int j = 0; j < s.getNumberOfUses(); j++) { int vn = s.getUse(j); symbolTable.ensureSymbol(vn); if (constants != null && constants.containsKey(Integer.valueOf(vn))) symbolTable.setConstantValue(vn, constants.get(Integer.valueOf(vn))); } }
SSAInstruction instr = ir.getInstructions()[i]; if (instr == null) continue; // Some instructions are null (padding NoOps) LOG(DEBUG, "DEBUG", "\tinst: " + instr.toString()); int derefValueNumber = -1; if (instr instanceof SSAGetInstruction && !((SSAGetInstruction) instr).isStatic()) {
public RelevantVariableFinder(SSAInstruction instrcution) { this.varNumNew = -1; instrcution.visit(this); this.varNum = this.varNumNew; }
private void emitInstruction(SSAInstruction s) { if (s != null) { instructions[getCurrentInstructionIndex()] = s; for (int i = 0; i < s.getNumberOfDefs(); i++) { if (creators.length < (s.getDef(i) + 1)) { creators = Arrays.copyOf(creators, 2 * s.getDef(i)); } assert s.getDef(i) != -1 : "invalid def " + i + " for " + s; creators[s.getDef(i)] = s; } } }
@Override protected String[] makeNameMap(CAstEntity n, Set<Scope> scopes, SSAInstruction[] insts) { String[] names = super.makeNameMap(n, scopes, insts); for(SSAInstruction inst : insts) { if (inst instanceof PrototypeLookup) { if (names[ inst.getUse(0)] != null) { names[ inst.getDef() ] = names[ inst.getUse(0) ]; } } } return names; }
public static int getArgumentsArrayVn(IR ir) { for(int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction inst = ir.getInstructions()[i]; if (inst != null) { for(int v = 0; v < inst.getNumberOfUses(); v++) { String[] names = ir.getLocalNames(i, inst.getUse(v)); if (names != null && names.length == 1 && "arguments".equals(names[0])) { return inst.getUse(v); } } } } return -1; }
/** * Create a dataflow equation induced by a given instruction */ private void makeEquationForInstruction(OperatorFactory<T> opFactory, SSAInstruction s) { if (s != null && s.hasDef()) { AbstractOperator<T> op = opFactory.get(s); if (op != null) { T def = getVariable(s.getDef()); if (op instanceof NullaryOperator) { newStatement(def, (NullaryOperator<T>) op, false, false); } else { int n = s.getNumberOfUses(); T[] uses = makeStmtRHS(n); for (int j = 0; j < n; j++) { if (s.getUse(j) > -1) { uses[j] = getVariable(s.getUse(j)); assert uses[j] != null; } } newStatement(def, op, uses, false, false); } } } }
.append(call.getDeclaredTarget().getName()); result.append(" exc:").append(call.getException()); for (int i = 0; i < s.getNumberOfUses(); i++) { result.append(' ').append(s.getUse(i)); return s.toString();
/** * What is the ith value number defined by instruction s? */ protected int getDef(SSAInstruction s, int i) { return s.getDef(i); }
@Override public String toString() { StringBuilder name = new StringBuilder(); if (getInstruction().hasDef()) { String[] names = getNode().getIR().getLocalNames(getInstructionIndex(), getInstruction().getDef()); if (names != null && names.length > 0) { name = new StringBuilder("[").append(names[0]); for (int i = 1; i < names.length; i++) { name.append(", ").append(names[i]); } name.append("]: "); } } return "NORMAL " + getNode().getMethod().getName() + ':' + name + getInstruction().toString() + ' ' + getNode(); }
/** * What is the ith value number used by instruction s? */ protected int getUse(SSAInstruction s, int i) { return s.getUse(i); }
/** * If we've already created the current instruction, return the value number def'ed by the current instruction. Else, create a * new symbol. */ private int reuseOrCreateDef() { if (getCurrentInstruction() == null || !getCurrentInstruction().hasDef()) { return symbolTable.newSymbol(); } else { return getCurrentInstruction().getDef(); } }
/** * How many value numbers does instruction s use? */ protected int getNumberOfUses(SSAInstruction s) { return s.getNumberOfUses(); }
/** * How many value numbers does instruction s def? */ protected int getNumberOfDefs(SSAInstruction s) { return s.getNumberOfDefs(); }
private void emitInstruction(SSAInstruction s) { instructions[getCurrentInstructionIndex()] = s; for (int i = 0; i < s.getNumberOfDefs(); i++) { if (creators.length < (s.getDef(i) + 1)) { creators = Arrays.copyOf(creators, 2 * s.getDef(i)); } assert s.getDef(i) != -1 : "invalid def " + i + " for " + s; creators[s.getDef(i)] = s; } }
public static int getArgumentsArrayVn(IR ir) { for(int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction inst = ir.getInstructions()[i]; if (inst != null) { for(int v = 0; v < inst.getNumberOfUses(); v++) { String[] names = ir.getLocalNames(i, inst.getUse(v)); if (names != null && names.length == 1 && "arguments".equals(names[0])) { return inst.getUse(v); } } } } return -1; }
/** * Create a dataflow equation induced by a given instruction */ private void makeEquationForInstruction(OperatorFactory<T> opFactory, SSAInstruction s) { if (s != null && s.hasDef()) { AbstractOperator<T> op = opFactory.get(s); if (op != null) { T def = getVariable(s.getDef()); if (op instanceof NullaryOperator) { newStatement(def, (NullaryOperator<T>) op, false, false); } else { int n = s.getNumberOfUses(); T[] uses = makeStmtRHS(n); for (int j = 0; j < n; j++) { if (s.getUse(j) > -1) { uses[j] = getVariable(s.getUse(j)); assert uses[j] != null; } } newStatement(def, op, uses, false, false); } } } }
@Test public void testMultiNewArray1() throws IOException, ClassHierarchyException { AnalysisScope scope = null; scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, (new FileProvider()).getFile("J2SEClassHierarchyExclusions.txt"), MY_CLASSLOADER); ClassHierarchy cha = ClassHierarchyFactory.make(scope); IClass klass = cha.lookupClass(TypeReference.findOrCreate(ClassLoaderReference.Application, TestConstants.MULTI_DIM_MAIN)); Assert.assertTrue(klass != null); IMethod m = klass.getMethod(Selector.make(Language.JAVA, "testNewMultiArray()V")); Assert.assertTrue(m != null); IAnalysisCacheView cache = new AnalysisCacheImpl(); IR ir = cache.getIRFactory().makeIR(m, Everywhere.EVERYWHERE, new SSAOptions()); Assert.assertTrue(ir != null); SSAInstruction[] instructions = ir.getInstructions(); for (SSAInstruction instr : instructions) { if (instr instanceof SSANewInstruction) { System.err.println(instr.toString(ir.getSymbolTable())); Assert.assertTrue(instr.getNumberOfUses() == 2); Assert.assertTrue(ir.getSymbolTable().getIntValue(instr.getUse(0)) == 3); Assert.assertTrue(ir.getSymbolTable().getIntValue(instr.getUse(1)) == 4); } } } }
/** * What is the ith value number defined by instruction s? */ protected int getDef(SSAInstruction s, int i) { return s.getDef(i); }
@Override public String toString() { StringBuilder name = new StringBuilder(); if (getInstruction().hasDef()) { String[] names = getNode().getIR().getLocalNames(getInstructionIndex(), getInstruction().getDef()); if (names != null && names.length > 0) { name = new StringBuilder("[").append(names[0]); for (int i = 1; i < names.length; i++) { name.append(", ").append(names[i]); } name.append("]: "); } } return "NORMAL " + getNode().getMethod().getName() + ':' + name + getInstruction().toString() + ' ' + getNode(); }