Package com.tonic.analysis.ssa.lift
Class AbstractState
- java.lang.Object
-
- com.tonic.analysis.ssa.lift.AbstractState
-
public class AbstractState extends Object
The simulated operand stack and local slots at one point of bytecode lifting.
-
-
Constructor Summary
Constructors Constructor Description AbstractState()Creates an empty state.AbstractState(AbstractState other)Creates a deep copy of another state.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearStack()Removes all values from the stack, leaving locals untouched.AbstractStatecopy()Creates a deep copy of this state.ValuegetLocal(int index)Set<Integer>getLocalIndices()intgetStackSize()List<Value>getStackValues()booleanhasLocal(int index)booleanisStackEmpty()voidmerge(AbstractState other)Adopts locals from another state for slots this state does not yet hold; the stack is untouched.Valuepeek()Returns the top stack value without popping it.Valuepeek(int depth)Returns the stack value a given depth below the top without popping.Valuepop()Pops the top stack value.voidpush(Value value)Pushes a value onto the simulated stack.static voidsetDebugContext(String blockName, int offset)Records the block and offset reported by stack-underflow errors.voidsetLocal(int index, Value value)voidsetStackValue(int index, Value value)Replaces the value at a stack slot in place.StringtoString()
-
-
-
Constructor Detail
-
AbstractState
public AbstractState()
Creates an empty state.
-
AbstractState
public AbstractState(AbstractState other)
Creates a deep copy of another state.- Parameters:
other- the state to copy
-
-
Method Detail
-
push
public void push(Value value)
Pushes a value onto the simulated stack.- Parameters:
value- the value to push
-
setDebugContext
public static void setDebugContext(String blockName, int offset)
Records the block and offset reported by stack-underflow errors.- Parameters:
blockName- the name of the block being liftedoffset- the bytecode offset being lifted
-
pop
public Value pop()
Pops the top stack value.- Returns:
- the popped value
- Throws:
IllegalStateException- if the stack is empty
-
peek
public Value peek()
Returns the top stack value without popping it.- Returns:
- the top value
- Throws:
IllegalStateException- if the stack is empty
-
peek
public Value peek(int depth)
Returns the stack value a given depth below the top without popping.- Parameters:
depth- the number of values below the top, 0 being the top- Returns:
- the value at that depth
- Throws:
IllegalStateException- if the stack has no value at that depth
-
getStackSize
public int getStackSize()
- Returns:
- the number of values on the stack
-
isStackEmpty
public boolean isStackEmpty()
- Returns:
- true if the stack is empty
-
setLocal
public void setLocal(int index, Value value)- Parameters:
index- the local slotvalue- the value the slot now holds
-
getLocal
public Value getLocal(int index)
- Parameters:
index- the local slot- Returns:
- the value in the slot, or null if unset
-
hasLocal
public boolean hasLocal(int index)
- Parameters:
index- the local slot- Returns:
- true if the slot holds a value
-
getLocalIndices
public Set<Integer> getLocalIndices()
- Returns:
- a copy of the set of occupied local slots
-
clearStack
public void clearStack()
Removes all values from the stack, leaving locals untouched.
-
copy
public AbstractState copy()
Creates a deep copy of this state.- Returns:
- the copy
-
merge
public void merge(AbstractState other)
Adopts locals from another state for slots this state does not yet hold; the stack is untouched.- Parameters:
other- the state to merge from
-
setStackValue
public void setStackValue(int index, Value value)Replaces the value at a stack slot in place.- Parameters:
index- stack slot indexvalue- replacement value
-
-