|
| 1 | +package org.usvm |
| 2 | + |
| 3 | +import org.usvm.ps.ExceptionPropagationPathSelector |
| 4 | +import org.usvm.ps.GNNPathSelector |
| 5 | +import org.usvm.statistics.CoverageStatistics |
| 6 | +import org.usvm.statistics.StateVisitsStatistics |
| 7 | + |
| 8 | +fun <Method, Statement, BasicBlock, State : UState<*, Method, Statement, *, *, State>> createPathSelector( |
| 9 | + initialState: State, |
| 10 | + options: MLMachineOptions, |
| 11 | + applicationGraph: ApplicationBlockGraph<Method, BasicBlock, Statement>, |
| 12 | + stateVisitsStatistics: StateVisitsStatistics<Method, Statement, State>, |
| 13 | + coverageStatistics: CoverageStatistics<Method, Statement, State>, |
| 14 | +): UPathSelector<State> { |
| 15 | + val selector = when (options.pathSelectionStrategy) { |
| 16 | + MLPathSelectionStrategy.GNN -> createGNNPathSelector( |
| 17 | + stateVisitsStatistics, |
| 18 | + coverageStatistics, applicationGraph, options.heteroGNNModelPath |
| 19 | + ) |
| 20 | + |
| 21 | + else -> { |
| 22 | + throw NotImplementedError() |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + val propagateExceptions = options.basicOptions.exceptionsPropagation |
| 27 | + |
| 28 | + val resultSelector = selector.wrapIfRequired(propagateExceptions) |
| 29 | + resultSelector.add(listOf(initialState)) |
| 30 | + |
| 31 | + return selector |
| 32 | +} |
| 33 | + |
| 34 | +private fun <State : UState<*, *, *, *, *, State>> UPathSelector<State>.wrapIfRequired(propagateExceptions: Boolean) = |
| 35 | + if (propagateExceptions && this !is ExceptionPropagationPathSelector<State>) { |
| 36 | + ExceptionPropagationPathSelector(this) |
| 37 | + } else { |
| 38 | + this |
| 39 | + } |
| 40 | + |
| 41 | +private fun <Method, Statement, BasicBlock, State : UState<*, Method, Statement, *, *, State>> createGNNPathSelector( |
| 42 | + stateVisitsStatistics: StateVisitsStatistics<Method, Statement, State>, |
| 43 | + coverageStatistics: CoverageStatistics<Method, Statement, State>, |
| 44 | + applicationGraph: ApplicationBlockGraph<Method, BasicBlock, Statement>, |
| 45 | + heteroGNNModelPath: String, |
| 46 | +): UPathSelector<State> { |
| 47 | + return GNNPathSelector( |
| 48 | + coverageStatistics, |
| 49 | + stateVisitsStatistics, |
| 50 | + applicationGraph, |
| 51 | + heteroGNNModelPath |
| 52 | + ) |
| 53 | +} |
0 commit comments