Class SimulationEngine
- java.lang.Object
-
- com.tonic.analysis.simulation.core.SimulationEngine
-
public class SimulationEngine extends Object
Main simulation engine for executing abstract interpretation.
-
-
Constructor Summary
Constructors Constructor Description SimulationEngine(SimulationContext context)Creates a new simulation engine with the given context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimulationEngineaddListener(SimulationListener listener)Registers a listener to receive simulation events.SimulationEngineaddListeners(SimulationListener... listenerArray)Registers several listeners in one call.SimulationContextgetContext()<T extends SimulationListener>
TgetListener(Class<T> type)Looks up a registered listener by its class.SimulationEngineremoveListener(SimulationListener listener)Unregisters a listener.SimulationResultsimulate(IRMethod method)Simulates execution of a method.SimulationResultsimulate(MethodEntry method)Lifts a class file method to IR and simulates it.SimulationResultsimulatePath(IRMethod method, List<IRBlock> path)Simulates one fixed block sequence instead of the whole method.SimulationStatestep(SimulationState state, IRInstruction instr)Executes one instruction without recording it in a result.SimulationStatestepBlock(SimulationState state, IRBlock block)Executes a block's phis and instructions, firing the block entry and exit events.
-
-
-
Constructor Detail
-
SimulationEngine
public SimulationEngine(SimulationContext context)
Creates a new simulation engine with the given context.- Parameters:
context- the configuration and state the simulation runs under
-
-
Method Detail
-
addListener
public SimulationEngine addListener(SimulationListener listener)
Registers a listener to receive simulation events.- Parameters:
listener- the listener to register- Returns:
- this engine
-
addListeners
public SimulationEngine addListeners(SimulationListener... listenerArray)
Registers several listeners in one call.- Parameters:
listenerArray- the listeners to register- Returns:
- this engine
-
removeListener
public SimulationEngine removeListener(SimulationListener listener)
Unregisters a listener.- Parameters:
listener- the listener to drop- Returns:
- this engine
-
getListener
public <T extends SimulationListener> T getListener(Class<T> type)
Looks up a registered listener by its class.- Type Parameters:
T- the listener type- Parameters:
type- the listener class to match- Returns:
- the first registered listener of that type, or null if none is registered
-
getContext
public SimulationContext getContext()
- Returns:
- the context this engine simulates under
-
simulate
public SimulationResult simulate(IRMethod method)
Simulates execution of a method.- Parameters:
method- the IR method to simulate- Returns:
- the simulation result
-
simulate
public SimulationResult simulate(MethodEntry method)
Lifts a class file method to IR and simulates it.- Parameters:
method- the method to lift and simulate- Returns:
- the simulation result
- Throws:
IllegalArgumentException- if the method has no code attribute
-
step
public SimulationState step(SimulationState state, IRInstruction instr)
Executes one instruction without recording it in a result.- Parameters:
state- the state to execute againstinstr- the instruction to execute- Returns:
- the state after the instruction
-
stepBlock
public SimulationState stepBlock(SimulationState state, IRBlock block)
Executes a block's phis and instructions, firing the block entry and exit events.- Parameters:
state- the state to enter the block withblock- the block to execute- Returns:
- the state after the last instruction
-
simulatePath
public SimulationResult simulatePath(IRMethod method, List<IRBlock> path)
Simulates one fixed block sequence instead of the whole method.- Parameters:
method- the method the path belongs topath- the blocks to execute in order- Returns:
- the simulation result for that path
-
-