Skip to content

Commit 80d86c2

Browse files
Princess: Add special case treatment for bv_extract and bv_concat in getFormulaType()
Both operations seem to be "abstract" in Princess and we need to manually calculate the bitsize of the resulting vector
1 parent c72861b commit 80d86c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/org/sosy_lab/java_smt/solvers/princess/PrincessEnvironment.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static scala.collection.JavaConverters.collectionAsScalaIterableConverter;
1313

1414
import ap.api.SimpleAPI;
15+
import ap.basetypes.IdealInt;
1516
import ap.parameters.GlobalSettings;
1617
import ap.parser.BooleanCompactifier;
1718
import ap.parser.Environment.EnvironmentException;
@@ -22,6 +23,7 @@
2223
import ap.parser.IFunApp;
2324
import ap.parser.IFunction;
2425
import ap.parser.IIntFormula;
26+
import ap.parser.IIntLit;
2527
import ap.parser.IIntRelation;
2628
import ap.parser.IPlus;
2729
import ap.parser.ITerm;
@@ -590,6 +592,18 @@ static FormulaType<?> getFormulaType(IExpression pFormula) {
590592
FormulaType<?> t1 = getFormulaType(plus.left());
591593
FormulaType<?> t2 = getFormulaType(plus.right());
592594
return mergeFormulaTypes(t1, t2);
595+
} else if (pFormula instanceof IFunApp
596+
&& ((IFunApp) pFormula).fun().equals(ModuloArithmetic.bv_extract())) {
597+
IIntLit upper = (IIntLit) pFormula.apply(0);
598+
IIntLit lower = (IIntLit) pFormula.apply(1);
599+
IdealInt bwResult = upper.value().$minus(lower.value());
600+
return FormulaType.getBitvectorTypeWithSize(bwResult.intValue());
601+
} else if (pFormula instanceof IFunApp
602+
&& ((IFunApp) pFormula).fun().equals(ModuloArithmetic.bv_concat())) {
603+
IIntLit upper = (IIntLit) pFormula.apply(0);
604+
IIntLit lower = (IIntLit) pFormula.apply(1);
605+
IdealInt bwResult = upper.value().$plus(lower.value());
606+
return FormulaType.getBitvectorTypeWithSize(bwResult.intValue());
593607
} else {
594608
final Sort sort = Sort$.MODULE$.sortOf((ITerm) pFormula);
595609
try {

0 commit comments

Comments
 (0)