|
2 | 2 | // an API wrapper for a collection of SMT solvers:
|
3 | 3 | // https://github.com/sosy-lab/java-smt
|
4 | 4 | //
|
5 |
| -// SPDX-FileCopyrightText: 2022 Dirk Beyer <https://www.sosy-lab.org> |
| 5 | +// SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org> |
6 | 6 | //
|
7 | 7 | // SPDX-License-Identifier: Apache-2.0
|
8 | 8 |
|
9 | 9 | package org.sosy_lab.java_smt.solvers.cvc5;
|
10 | 10 |
|
11 | 11 | import com.google.common.annotations.VisibleForTesting;
|
12 | 12 | import com.google.common.base.Preconditions;
|
| 13 | +import com.google.common.base.Splitter; |
| 14 | +import com.google.common.base.Splitter.MapSplitter; |
| 15 | +import com.google.common.collect.ImmutableMap; |
| 16 | +import io.github.cvc5.CVC5ApiRecoverableException; |
13 | 17 | import io.github.cvc5.Solver;
|
| 18 | +import java.util.Map.Entry; |
14 | 19 | import java.util.Set;
|
15 | 20 | import java.util.function.Consumer;
|
16 | 21 | import org.sosy_lab.common.ShutdownNotifier;
|
@@ -38,8 +43,30 @@ private static class CVC5Settings {
|
38 | 43 | description = "apply additional validation checks for interpolation results")
|
39 | 44 | private boolean validateInterpolants = false;
|
40 | 45 |
|
| 46 | + @Option( |
| 47 | + secure = true, |
| 48 | + description = |
| 49 | + "Further options that will be passed to CVC5 in addition to the default options. " |
| 50 | + + "Format is 'key1=value1,key2=value2'") |
| 51 | + private String furtherOptions = ""; |
| 52 | + |
| 53 | + private final ImmutableMap<String, String> furtherOptionsMap; |
| 54 | + |
41 | 55 | private CVC5Settings(Configuration config) throws InvalidConfigurationException {
|
42 | 56 | config.inject(this);
|
| 57 | + |
| 58 | + MapSplitter optionSplitter = |
| 59 | + Splitter.on(',') |
| 60 | + .trimResults() |
| 61 | + .omitEmptyStrings() |
| 62 | + .withKeyValueSeparator(Splitter.on('=').limit(2).trimResults()); |
| 63 | + |
| 64 | + try { |
| 65 | + furtherOptionsMap = ImmutableMap.copyOf(optionSplitter.split(furtherOptions)); |
| 66 | + } catch (IllegalArgumentException e) { |
| 67 | + throw new InvalidConfigurationException( |
| 68 | + "Invalid CVC5 option in \"" + furtherOptions + "\": " + e.getMessage(), e); |
| 69 | + } |
43 | 70 | }
|
44 | 71 | }
|
45 | 72 |
|
@@ -94,7 +121,11 @@ public static SolverContext create(
|
94 | 121 | // We keep this instance available until the whole context is closed.
|
95 | 122 | Solver newSolver = new Solver();
|
96 | 123 |
|
97 |
| - setSolverOptions(newSolver, randomSeed); |
| 124 | + try { |
| 125 | + setSolverOptions(newSolver, randomSeed, settings.furtherOptionsMap); |
| 126 | + } catch (CVC5ApiRecoverableException e) { // we do not want to recover after invalid options. |
| 127 | + throw new InvalidConfigurationException(e.getMessage(), e); |
| 128 | + } |
98 | 129 |
|
99 | 130 | CVC5FormulaCreator pCreator = new CVC5FormulaCreator(newSolver);
|
100 | 131 |
|
@@ -133,11 +164,21 @@ public static SolverContext create(
|
133 | 164 | pCreator, manager, pShutdownNotifier, newSolver, randomSeed, settings);
|
134 | 165 | }
|
135 | 166 |
|
136 |
| - /** Set common options for a CVC5 solver. */ |
137 |
| - private static void setSolverOptions(Solver pSolver, int randomSeed) { |
| 167 | + /** |
| 168 | + * Set common options for a CVC5 solver. |
| 169 | + * |
| 170 | + * @throws CVC5ApiRecoverableException from native code. |
| 171 | + */ |
| 172 | + private static void setSolverOptions( |
| 173 | + Solver pSolver, int randomSeed, ImmutableMap<String, String> furtherOptions) |
| 174 | + throws CVC5ApiRecoverableException { |
138 | 175 | pSolver.setOption("seed", String.valueOf(randomSeed));
|
139 | 176 | pSolver.setOption("output-language", "smtlib2");
|
140 | 177 |
|
| 178 | + for (Entry<String, String> option : furtherOptions.entrySet()) { |
| 179 | + pSolver.setOption(option.getKey(), option.getValue()); |
| 180 | + } |
| 181 | + |
141 | 182 | // Set Strings option to enable all String features (such as lessOrEquals).
|
142 | 183 | // This should not have any effect for non-string theories.
|
143 | 184 | // pSolver.setOption("strings-exp", "true");
|
|
0 commit comments