Class StackState
- java.lang.Object
-
- com.tonic.analysis.simulation.state.StackState
-
public final class StackState extends Object
Immutable operand stack snapshot used during simulation.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StackStateclear()Drops every value, as an exception handler entry does.intdepth()StackStatedup()Pushes a copy of the top slot (dup).StackStatedup2()Pushes a copy of the top two slots (dup2).StackStatedup2X1()Duplicates the top two slots and inserts the copies below the third (dup2_x1).StackStatedup2X2()Duplicates the top two slots and inserts the copies below the fourth (dup2_x2).StackStatedupX1()Duplicates the top slot and inserts the copy below the second (dup_x1).StackStatedupX2()Duplicates the top slot and inserts the copy below the third (dup_x2).static StackStateempty()booleanequals(Object o)List<SimValue>getValues()inthashCode()booleanisEmpty()intmaxDepth()StackStatemerge(StackState other)Joins two stacks at a control flow convergence, keeping this stack's values and the larger recorded maximum depth.static StackStateof(List<SimValue> values)Creates a stack preloaded with slots.SimValuepeek()Reads the top slot without removing it.SimValuepeek(int depth)Reads a slot without removing it.SimValuepeekValue()Reads the topmost value, stepping past a wide second slot to the value it belongs to.SimValuepeekValue(int depth)Reads a value at the given depth, stepping past a wide second slot to the value it belongs to.StackStatepop()Removes the top slot.StackStatepop(int count)Removes several slots at once.StackStatepopWide()Removes the two slots holding a long or double.StackStatepush(SimValue value)Adds a value on top of the stack.StackStatepushWide(SimValue value)Pushes a long or double, adding the filler second slot after it.StackStateswap()Exchanges the top two slots (swap).StringtoString()
-
-
-
Method Detail
-
empty
public static StackState empty()
- Returns:
- a stack with no slots and a maximum depth of zero
-
of
public static StackState of(List<SimValue> values)
Creates a stack preloaded with slots.- Parameters:
values- the slot contents, bottom to top- Returns:
- a stack holding a copy of them, with its maximum depth set to their count
-
push
public StackState push(SimValue value)
Adds a value on top of the stack.- Parameters:
value- the value to push- Returns:
- the resulting stack, one slot deeper
-
pushWide
public StackState pushWide(SimValue value)
Pushes a long or double, adding the filler second slot after it.- Parameters:
value- the wide value to push- Returns:
- the resulting stack, two slots deeper
-
pop
public StackState pop()
Removes the top slot.- Returns:
- the resulting stack
- Throws:
IllegalStateException- if the stack is empty
-
pop
public StackState pop(int count)
Removes several slots at once.- Parameters:
count- how many slots to drop; zero leaves the stack unchanged- Returns:
- the resulting stack
- Throws:
IllegalStateException- if the stack holds fewer than count slots
-
popWide
public StackState popWide()
Removes the two slots holding a long or double.- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than two slots are on the stack
-
peek
public SimValue peek()
Reads the top slot without removing it.- Returns:
- the value in the top slot
- Throws:
IllegalStateException- if the stack is empty
-
peek
public SimValue peek(int depth)
Reads a slot without removing it.- Parameters:
depth- the slot offset from the top, 0 being the topmost slot- Returns:
- the value in that slot
- Throws:
IllegalStateException- if the depth is outside the stack
-
peekValue
public SimValue peekValue()
Reads the topmost value, stepping past a wide second slot to the value it belongs to.- Returns:
- the value on top of the stack
- Throws:
IllegalStateException- if the stack is empty, or holds only a wide second slot
-
peekValue
public SimValue peekValue(int depth)
Reads a value at the given depth, stepping past a wide second slot to the value it belongs to.- Parameters:
depth- the slot offset from the top, 0 being the topmost slot- Returns:
- the value occupying that slot
- Throws:
IllegalStateException- if the slot, or the one below a wide second slot, is out of range
-
depth
public int depth()
- Returns:
- the number of occupied slots, counting both halves of a wide value
-
maxDepth
public int maxDepth()
- Returns:
- the greatest slot count reached by any predecessor of this state
-
isEmpty
public boolean isEmpty()
- Returns:
- true if no slot is occupied
-
getValues
public List<SimValue> getValues()
- Returns:
- an unmodifiable view of the slots, bottom to top
-
dup
public StackState dup()
Pushes a copy of the top slot (dup).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if the stack is empty
-
dupX1
public StackState dupX1()
Duplicates the top slot and inserts the copy below the second (dup_x1).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than two slots are on the stack
-
dupX2
public StackState dupX2()
Duplicates the top slot and inserts the copy below the third (dup_x2).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than three slots are on the stack
-
dup2
public StackState dup2()
Pushes a copy of the top two slots (dup2).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than two slots are on the stack
-
dup2X1
public StackState dup2X1()
Duplicates the top two slots and inserts the copies below the third (dup2_x1).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than three slots are on the stack
-
dup2X2
public StackState dup2X2()
Duplicates the top two slots and inserts the copies below the fourth (dup2_x2).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than four slots are on the stack
-
swap
public StackState swap()
Exchanges the top two slots (swap).- Returns:
- the resulting stack
- Throws:
IllegalStateException- if fewer than two slots are on the stack
-
merge
public StackState merge(StackState other)
Joins two stacks at a control flow convergence, keeping this stack's values and the larger recorded maximum depth.- Parameters:
other- the incoming stack, or null to keep this one unchanged- Returns:
- the merged stack
- Throws:
IllegalStateException- if the two stacks hold a different number of slots
-
clear
public StackState clear()
Drops every value, as an exception handler entry does.- Returns:
- an empty stack that keeps the recorded maximum depth
-
-