com.ibm.wala.ssa
Class IR

java.lang.Object
  extended by com.ibm.wala.ssa.IR
Direct Known Subclasses:
AstIRFactory.AstIR, SyntheticIR

public abstract class IR
extends java.lang.Object

An SSA IR


Nested Class Summary
static interface IR.SSA2LocalMap
           
 
Constructor Summary
protected IR(IMethod method, SSAInstruction[] instructions, SymbolTable symbolTable, SSACFG cfg, SSAOptions options)
          Create an SSA form from a method created by the AstTranslator front end This entrypoint is used by the JavaScript -> WALA conversion.
 
Method Summary
 IBasicBlock getBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)
           
 IBasicBlock getBasicBlockForInstruction(SSAInstruction s)
          This is space-inefficient.
 IBasicBlock[] getBasicBlocksForCall(CallSiteReference site)
           
 IntSet getCallInstructionIndices(CallSiteReference site)
           
 SSAAbstractInvokeInstruction[] getCalls(CallSiteReference site)
           
 SSACFG getControlFlowGraph()
          Return the CFG for the method.
 SSACFG.BasicBlock getExitBlock()
           
 SSAInstruction[] getInstructions()
          Returns the instructions.
protected abstract  IR.SSA2LocalMap getLocalMap()
          subclasses must provide a source name mapping, if they want one (or null otherwise)
 java.lang.String[] getLocalNames(int index, int vn)
           
 IMethod getMethod()
           
 SSANewInstruction getNew(NewSiteReference site)
           
 int getNewInstructionIndex(NewSiteReference site)
           
 int getNumberOfParameters()
          Method getNumberOfParameters.
 SSAOptions getOptions()
           
 int getParameter(int i)
           
 TypeReference getParameterType(int i)
          Get the type reference that describes the ith parameter to this method.
 int[] getParameterValueNumbers()
          Method getParameterValueNumbers.
 SSAInstruction getPEI(ProgramCounter pc)
           
 SymbolTable getSymbolTable()
          Returns the symbolTable.
protected abstract  java.lang.String instructionPosition(int instructionIndex)
           
 boolean isEmptyIR()
          TODO: why do we need this? We should enforce instructions == null if necessary, I think.
 java.util.Iterator<SSAInstruction> iterateAllInstructions()
           
 java.util.Iterator<CallSiteReference> iterateCallSites()
           
 java.util.Iterator<SSAInstruction> iterateCatchInstructions()
           
 java.util.Iterator<NewSiteReference> iterateNewSites()
           
 java.util.Iterator<SSAInstruction> iterateNormalInstructions()
           
 java.util.Iterator<? extends SSAInstruction> iteratePhis()
          Return an iterator of all phis for this IR.
 java.util.Iterator<? extends SSAInstruction> iteratePis()
          Return an iterator of all pis for this IR.
protected  void setupLocationMap()
          create mappings from callsites, new sites, and PEIs to instruction index
 java.lang.String toString()
           
 java.lang.String toString(ValueDecorator d)
          Create a string representation, with decoration for each variable
 void visitAllInstructions(SSAInstruction.Visitor v)
          visit each instruction in this IR
 void visitNormalInstructions(SSAInstruction.Visitor v)
          visit each normal (non-phi, non-pi, non-catch) instruction in this IR
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IR

protected IR(IMethod method,
             SSAInstruction[] instructions,
             SymbolTable symbolTable,
             SSACFG cfg,
             SSAOptions options)
Create an SSA form from a method created by the AstTranslator front end This entrypoint is used by the JavaScript -> WALA conversion. It performs traditional SSA conversion, introducing phi nodes, etc. keep this package private: all calls should be through SSACache

Parameters:
method - the method to construct SSA form for
options - governing ssa construction options
Method Detail

getLocalMap

protected abstract IR.SSA2LocalMap getLocalMap()
subclasses must provide a source name mapping, if they want one (or null otherwise)


setupLocationMap

protected void setupLocationMap()
create mappings from callsites, new sites, and PEIs to instruction index


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

instructionPosition

protected abstract java.lang.String instructionPosition(int instructionIndex)

toString

public java.lang.String toString(ValueDecorator d)
Create a string representation, with decoration for each variable

Parameters:
d - an object which provides string decorators for variables in the IR

getInstructions

public SSAInstruction[] getInstructions()
Returns the instructions.

Returns:
Instruction[]

getSymbolTable

public SymbolTable getSymbolTable()
Returns the symbolTable.

Returns:
SymbolTable

getControlFlowGraph

public SSACFG getControlFlowGraph()
Return the CFG for the method.

Returns:
the CFG for the method.

iteratePhis

public java.util.Iterator<? extends SSAInstruction> iteratePhis()
Return an iterator of all phis for this IR.


iteratePis

public java.util.Iterator<? extends SSAInstruction> iteratePis()
Return an iterator of all pis for this IR.


getParameterValueNumbers

public int[] getParameterValueNumbers()
Method getParameterValueNumbers.

Returns:
array of value numbers representing parameters to this method

getParameter

public int getParameter(int i)
Parameters:
i -
Returns:
the value number of the ith parameter

getParameterType

public TypeReference getParameterType(int i)
Get the type reference that describes the ith parameter to this method. By convention, for a non-static method, the 0th parameter is "this".

Parameters:
i -
Returns:
TypeReference

getNumberOfParameters

public int getNumberOfParameters()
Method getNumberOfParameters.

Returns:
int

getMethod

public IMethod getMethod()
Returns:
the method this IR represents

iterateCatchInstructions

public java.util.Iterator<SSAInstruction> iterateCatchInstructions()
Returns:
iterator of the catch instructions in this IR

visitNormalInstructions

public void visitNormalInstructions(SSAInstruction.Visitor v)
visit each normal (non-phi, non-pi, non-catch) instruction in this IR

Parameters:
v - a visitor

visitAllInstructions

public void visitAllInstructions(SSAInstruction.Visitor v)
visit each instruction in this IR

Parameters:
v - a visitor

iterateNormalInstructions

public java.util.Iterator<SSAInstruction> iterateNormalInstructions()
Returns:
an iterator of all "normal" instructions on this IR

iterateAllInstructions

public java.util.Iterator<SSAInstruction> iterateAllInstructions()
Returns:
an Iterator of allinstructions (Normal, Phi, and Catch)

getExitBlock

public SSACFG.BasicBlock getExitBlock()
Returns:
the exit basic block

getCalls

public SSAAbstractInvokeInstruction[] getCalls(CallSiteReference site)
Parameters:
site -
Returns:
the invoke instructions corresponding to this call site
Throws:
java.lang.IllegalArgumentException - if site is null

getCallInstructionIndices

public IntSet getCallInstructionIndices(CallSiteReference site)
Parameters:
site -
Returns:
the instruction indices corresponding to this call site
Throws:
java.lang.IllegalArgumentException - if site is null

getNew

public SSANewInstruction getNew(NewSiteReference site)
Parameters:
site -
Returns:
the new instruction corresponding to this site

getNewInstructionIndex

public int getNewInstructionIndex(NewSiteReference site)
Parameters:
site -
Returns:
the instruction index corresponding to this site.

getPEI

public SSAInstruction getPEI(ProgramCounter pc)
Parameters:
pc - a program counter
Returns:
the instruction (a PEI) at this program counter

iterateNewSites

public java.util.Iterator<NewSiteReference> iterateNewSites()

iterateCallSites

public java.util.Iterator<CallSiteReference> iterateCallSites()

getBasicBlocksForCall

public IBasicBlock[] getBasicBlocksForCall(CallSiteReference site)
Parameters:
site - a call site in this method
Returns:
the basic block corresponding to this instruction
Throws:
java.lang.IllegalArgumentException - if site is null

getBasicBlockForInstruction

public IBasicBlock getBasicBlockForInstruction(SSAInstruction s)
This is space-inefficient. Use with care. Be very careful; note the strange identity semantics of SSAInstruction, using ==. You can't mix SSAInstructions and IRs freely.


isEmptyIR

public boolean isEmptyIR()
TODO: why do we need this? We should enforce instructions == null if necessary, I think.

Returns:
true iff every instruction is null

getLocalNames

public java.lang.String[] getLocalNames(int index,
                                        int vn)
Parameters:
index - an index into the IR instruction array
vn - a value number
Returns:
if we know that immediately after the given program counter, v_vn corresponds to one or more locals and local variable names are available, the name of the locals which v_vn represents. Otherwise, null.

getBasicBlockForCatch

public IBasicBlock getBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)

getOptions

public SSAOptions getOptions()
Returns:
Returns the options.