2006-11-22 17:38:46 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.ibm.wala.classLoader;
|
|
|
|
|
|
|
|
import com.ibm.wala.cfg.ControlFlowGraph;
|
|
|
|
import com.ibm.wala.cfg.ShrikeCFG;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Context;
|
|
|
|
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
|
|
|
import com.ibm.wala.ssa.IR;
|
|
|
|
import com.ibm.wala.ssa.IRFactory;
|
|
|
|
import com.ibm.wala.ssa.SSABuilder;
|
|
|
|
import com.ibm.wala.ssa.SSACFG;
|
|
|
|
import com.ibm.wala.ssa.SSAInstruction;
|
|
|
|
import com.ibm.wala.ssa.SSAOptions;
|
2009-05-20 18:59:53 +00:00
|
|
|
import com.ibm.wala.ssa.ShrikeIndirectionData;
|
2006-11-22 17:38:46 +00:00
|
|
|
import com.ibm.wala.ssa.SymbolTable;
|
|
|
|
import com.ibm.wala.ssa.analysis.DeadAssignmentElimination;
|
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
|
|
|
|
/**
|
2009-04-21 19:31:33 +00:00
|
|
|
* An {@link IRFactory} that for methods that originate from Shrike.
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
2009-03-24 17:07:44 +00:00
|
|
|
public class ShrikeIRFactory implements IRFactory<IBytecodeMethod> {
|
2006-11-22 17:38:46 +00:00
|
|
|
|
|
|
|
public final static boolean buildLocalMap = true;
|
|
|
|
|
2009-03-24 17:07:44 +00:00
|
|
|
public ControlFlowGraph makeCFG(final IBytecodeMethod method, Context C) {
|
2011-12-28 17:03:27 +00:00
|
|
|
return ShrikeCFG.make(method);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
2009-03-24 17:07:44 +00:00
|
|
|
public IR makeIR(final IBytecodeMethod method, Context C, final SSAOptions options) throws IllegalArgumentException {
|
2006-11-22 17:38:46 +00:00
|
|
|
|
2009-03-11 19:33:02 +00:00
|
|
|
if (method == null) {
|
|
|
|
throw new IllegalArgumentException("null method");
|
|
|
|
}
|
2009-02-19 15:58:31 +00:00
|
|
|
com.ibm.wala.shrikeBT.IInstruction[] shrikeInstructions = null;
|
2006-11-22 17:38:46 +00:00
|
|
|
try {
|
2007-09-01 14:41:14 +00:00
|
|
|
shrikeInstructions = method.getInstructions();
|
2006-11-22 17:38:46 +00:00
|
|
|
} catch (InvalidClassFileException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
Assertions.UNREACHABLE();
|
|
|
|
}
|
2007-07-06 22:08:13 +00:00
|
|
|
final ShrikeCFG shrikeCFG = (ShrikeCFG) makeCFG(method, C);
|
2006-11-22 17:38:46 +00:00
|
|
|
|
|
|
|
final SymbolTable symbolTable = new SymbolTable(method.getNumberOfParameters());
|
|
|
|
final SSAInstruction[] newInstrs = new SSAInstruction[shrikeInstructions.length];
|
|
|
|
|
2007-07-06 22:08:13 +00:00
|
|
|
final SSACFG newCfg = new SSACFG(method, shrikeCFG, newInstrs);
|
2006-11-22 17:38:46 +00:00
|
|
|
|
|
|
|
return new IR(method, newInstrs, symbolTable, newCfg, options) {
|
|
|
|
private final SSA2LocalMap localMap;
|
|
|
|
|
2009-05-20 18:59:53 +00:00
|
|
|
private final ShrikeIndirectionData indirectionData;
|
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
/**
|
|
|
|
* Remove any phis that are dead assignments.
|
|
|
|
*
|
|
|
|
* TODO: move this elsewhere?
|
|
|
|
*/
|
|
|
|
private void eliminateDeadPhis() {
|
|
|
|
DeadAssignmentElimination.perform(this);
|
|
|
|
}
|
|
|
|
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2007-01-08 14:53:10 +00:00
|
|
|
protected String instructionPosition(int instructionIndex) {
|
2007-04-26 20:35:25 +00:00
|
|
|
try {
|
2007-09-01 14:41:14 +00:00
|
|
|
int bcIndex = method.getBytecodeIndex(instructionIndex);
|
|
|
|
int lineNumber = method.getLineNumber(bcIndex);
|
2007-04-26 20:35:25 +00:00
|
|
|
|
|
|
|
if (lineNumber == -1) {
|
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
return "(line " + lineNumber + ")";
|
|
|
|
}
|
|
|
|
} catch (InvalidClassFileException e) {
|
|
|
|
return "";
|
|
|
|
}
|
2007-01-08 14:53:10 +00:00
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public SSA2LocalMap getLocalMap() {
|
2007-04-26 20:35:25 +00:00
|
|
|
return localMap;
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2007-09-01 14:41:14 +00:00
|
|
|
SSABuilder builder = SSABuilder.make(method, newCfg, shrikeCFG, newInstrs, symbolTable, buildLocalMap, options
|
2008-01-16 22:25:34 +00:00
|
|
|
.getPiNodePolicy());
|
2006-11-22 17:38:46 +00:00
|
|
|
builder.build();
|
|
|
|
if (buildLocalMap)
|
|
|
|
localMap = builder.getLocalMap();
|
2007-04-26 20:35:25 +00:00
|
|
|
else
|
|
|
|
localMap = null;
|
2006-11-22 17:38:46 +00:00
|
|
|
|
2009-05-20 18:59:53 +00:00
|
|
|
indirectionData = builder.getIndirectionData();
|
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
eliminateDeadPhis();
|
|
|
|
|
|
|
|
setupLocationMap();
|
|
|
|
}
|
2009-05-20 18:59:53 +00:00
|
|
|
|
2009-05-29 15:26:35 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2009-05-20 18:59:53 +00:00
|
|
|
@Override
|
2009-05-29 15:26:35 +00:00
|
|
|
protected ShrikeIndirectionData getIndirectionData() {
|
2009-05-20 18:59:53 +00:00
|
|
|
return indirectionData;
|
|
|
|
}
|
2006-11-22 17:38:46 +00:00
|
|
|
};
|
|
|
|
}
|
2008-05-12 13:34:35 +00:00
|
|
|
|
2009-03-24 17:07:44 +00:00
|
|
|
public boolean contextIsIrrelevant(IBytecodeMethod method) {
|
2008-05-12 13:34:35 +00:00
|
|
|
// this factory always returns the same IR for a method
|
|
|
|
return true;
|
|
|
|
}
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|