Skip to content

Commit

Permalink
Merge branch 'xcfa-refactor' into interproc
Browse files Browse the repository at this point in the history
  • Loading branch information
s0mark committed Nov 22, 2023
2 parents b1d8c26 + 8ba915a commit 53cdcff
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 86 deletions.
34 changes: 17 additions & 17 deletions .github/actions/build-archive/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ runs:
- name: Create folder structure
shell: bash
run: |
mkdir -p ${{ inputs.name }}/theta/
mkdir -p ${{ inputs.name }}/theta/solvers
cp lib ${{ inputs.name }}/theta/lib -r
cp CONTRIBUTORS.md ${{ inputs.name }}/theta/
cp lib/README.md ${{ inputs.name }}/theta/LIB_LICENSES.md
cp LICENSE ${{ inputs.name }}/theta/
cp README.md ${{ inputs.name }}/theta/GENERAL_README.md
cp scripts/theta-start.sh ${{ inputs.name }}/theta/theta-start.sh
chmod +x ${{ inputs.name }}/theta/theta-start.sh
sed "s/COMMIT_ID/$GITHUB_SHA/g" $GITHUB_ACTION_PATH/README.md > ${{ inputs.name }}/theta/README.md
sed -i 's/TOOL_NAME/${{ inputs.name }}/g' ${{ inputs.name }}/theta/README.md
sed -i 's/INPUT_FLAG/${{ inputs.inputflag }}/g' ${{ inputs.name }}/theta/README.md
mkdir -p ${{ inputs.name }}/${{ inputs.name }}/
mkdir -p ${{ inputs.name }}/${{ inputs.name }}/solvers
cp lib ${{ inputs.name }}/${{ inputs.name }}/lib -r
cp CONTRIBUTORS.md ${{ inputs.name }}/${{ inputs.name }}/
cp lib/README.md ${{ inputs.name }}/${{ inputs.name }}/LIB_LICENSES.md
cp LICENSE ${{ inputs.name }}/${{ inputs.name }}/
cp README.md ${{ inputs.name }}/${{ inputs.name }}/GENERAL_README.md
cp scripts/theta-start.sh ${{ inputs.name }}/${{ inputs.name }}/theta-start.sh
chmod +x ${{ inputs.name }}/${{ inputs.name }}/theta-start.sh
sed "s/COMMIT_ID/$GITHUB_SHA/g" $GITHUB_ACTION_PATH/README.md > ${{ inputs.name }}/${{ inputs.name }}/README.md
sed -i 's/TOOL_NAME/${{ inputs.name }}/g' ${{ inputs.name }}/${{ inputs.name }}/README.md
sed -i 's/INPUT_FLAG/${{ inputs.inputflag }}/g' ${{ inputs.name }}/${{ inputs.name }}/README.md
- name: Extract theta-xcfa-cli and theta-smtlib-cli
shell: bash
run: |
mv jar/xcfa/xcfa-cli/build/libs/*-all.jar ${{ inputs.name }}/theta/theta.jar
mv jar/solver/solver-smtlib-cli/build/libs/*-all.jar ${{ inputs.name }}/theta/theta-smtlib.jar
mv jar/xcfa/xcfa-cli/build/libs/*-all.jar ${{ inputs.name }}/${{ inputs.name }}/theta.jar
mv jar/solver/solver-smtlib-cli/build/libs/*-all.jar ${{ inputs.name }}/${{ inputs.name }}/theta-smtlib.jar
- name: Setup java 17
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
Expand All @@ -44,15 +44,15 @@ runs:
run: |
for i in $(cat $GITHUB_ACTION_PATH/necessary-solvers.txt)
do
java -jar ${{ inputs.name }}/theta/theta-smtlib.jar --home ${{ inputs.name }}/theta/solvers install $i
java -jar ${{ inputs.name }}/${{ inputs.name }}/theta-smtlib.jar --home ${{ inputs.name }}/${{ inputs.name }}/solvers install $i
done
- name: ZIP archive
shell: bash
run: |
cd ${{ inputs.name }}
zip theta.zip theta -r
zip ${{ inputs.name }}.zip ${{ inputs.name }} -r
- name: Upload results
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ inputs.name }}_SV-COMP
path: ${{ inputs.name }}/theta.zip
path: ${{ inputs.name }}/${{ inputs.name }}.zip
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import hu.bme.mit.theta.core.type.bvtype.BvSModExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr;
import hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSignChangeExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSubExpr;
import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr;
import hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr;
Expand Down Expand Up @@ -255,6 +256,8 @@ private ExprWriter() {

.addCase(BvPosExpr.class, e -> prefixUnary(e, "bvpos"))

.addCase(BvSignChangeExpr.class, e -> prefixUnary(e, "bvsign"))

.addCase(BvNegExpr.class, e -> prefixUnary(e, "bvneg"))

.addCase(BvAndExpr.class, e -> infixMultiary(e, " bvand "))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2023 Budapest University of Technology and Economics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package hu.bme.mit.theta.core.type.bvtype;

import hu.bme.mit.theta.core.model.Valuation;
import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.core.type.abstracttype.PosExpr;

import static hu.bme.mit.theta.core.utils.TypeUtils.castBv;

public final class BvSignChangeExpr extends PosExpr<BvType> {

private static final int HASH_SEED = 8963;
private static final String OPERATOR_LABEL = "bvpos";

private final BvType newType;

private BvSignChangeExpr(final Expr<BvType> op, final BvType newType) {
super(op);
this.newType = newType;
}

public static BvSignChangeExpr of(final Expr<BvType> op, final BvType newType) {
return new BvSignChangeExpr(op, newType);
}

public static BvSignChangeExpr create(final Expr<?> op, final BvType newType) {
final Expr<BvType> newOp = castBv(op);
return BvSignChangeExpr.of(newOp, newType);
}

@Override
public BvType getType() {
return newType;
}

@Override
public BvLitExpr eval(final Valuation val) {
final BvLitExpr opVal = (BvLitExpr) getOp().eval(val);
return opVal.pos();
}

@Override
public BvSignChangeExpr with(final Expr<BvType> op) {
if (op == getOp()) {
return this;
} else {
return BvSignChangeExpr.of(op, newType);
}
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
} else if (obj != null && this.getClass() == obj.getClass()) {
final BvSignChangeExpr that = (BvSignChangeExpr) obj;
return this.getOp().equals(that.getOp()) && this.getType().equals(that.getType());
} else {
return false;
}
}

@Override
protected int getHashSeed() {
return HASH_SEED;
}

@Override
public String getOperatorLabel() {
return OPERATOR_LABEL;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,94 @@
package hu.bme.mit.theta.core.utils;

import hu.bme.mit.theta.common.DispatchTable;
import hu.bme.mit.theta.common.Utils;
import hu.bme.mit.theta.core.model.Valuation;
import hu.bme.mit.theta.core.type.*;
import hu.bme.mit.theta.core.type.BinaryExpr;
import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.core.type.MultiaryExpr;
import hu.bme.mit.theta.core.type.Type;
import hu.bme.mit.theta.core.type.anytype.IteExpr;
import hu.bme.mit.theta.core.type.anytype.RefExpr;
import hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr;
import hu.bme.mit.theta.core.type.arraytype.ArrayType;
import hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr;
import hu.bme.mit.theta.core.type.booltype.*;
import hu.bme.mit.theta.core.type.bvtype.*;
import hu.bme.mit.theta.core.type.inttype.*;
import hu.bme.mit.theta.core.type.rattype.*;

import java.util.*;
import hu.bme.mit.theta.core.type.booltype.AndExpr;
import hu.bme.mit.theta.core.type.booltype.BoolType;
import hu.bme.mit.theta.core.type.booltype.IffExpr;
import hu.bme.mit.theta.core.type.booltype.ImplyExpr;
import hu.bme.mit.theta.core.type.booltype.NotExpr;
import hu.bme.mit.theta.core.type.booltype.OrExpr;
import hu.bme.mit.theta.core.type.booltype.XorExpr;
import hu.bme.mit.theta.core.type.bvtype.BvAddExpr;
import hu.bme.mit.theta.core.type.bvtype.BvAndExpr;
import hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr;
import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr;
import hu.bme.mit.theta.core.type.bvtype.BvEqExpr;
import hu.bme.mit.theta.core.type.bvtype.BvExtractExpr;
import hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr;
import hu.bme.mit.theta.core.type.bvtype.BvMulExpr;
import hu.bme.mit.theta.core.type.bvtype.BvNegExpr;
import hu.bme.mit.theta.core.type.bvtype.BvNeqExpr;
import hu.bme.mit.theta.core.type.bvtype.BvNotExpr;
import hu.bme.mit.theta.core.type.bvtype.BvOrExpr;
import hu.bme.mit.theta.core.type.bvtype.BvPosExpr;
import hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr;
import hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSExtExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSGtExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSLtExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSModExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr;
import hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSignChangeExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSubExpr;
import hu.bme.mit.theta.core.type.bvtype.BvType;
import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr;
import hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr;
import hu.bme.mit.theta.core.type.bvtype.BvUGtExpr;
import hu.bme.mit.theta.core.type.bvtype.BvULeqExpr;
import hu.bme.mit.theta.core.type.bvtype.BvULtExpr;
import hu.bme.mit.theta.core.type.bvtype.BvURemExpr;
import hu.bme.mit.theta.core.type.bvtype.BvXorExpr;
import hu.bme.mit.theta.core.type.bvtype.BvZExtExpr;
import hu.bme.mit.theta.core.type.inttype.IntAddExpr;
import hu.bme.mit.theta.core.type.inttype.IntDivExpr;
import hu.bme.mit.theta.core.type.inttype.IntEqExpr;
import hu.bme.mit.theta.core.type.inttype.IntExprs;
import hu.bme.mit.theta.core.type.inttype.IntGeqExpr;
import hu.bme.mit.theta.core.type.inttype.IntGtExpr;
import hu.bme.mit.theta.core.type.inttype.IntLeqExpr;
import hu.bme.mit.theta.core.type.inttype.IntLtExpr;
import hu.bme.mit.theta.core.type.inttype.IntModExpr;
import hu.bme.mit.theta.core.type.inttype.IntMulExpr;
import hu.bme.mit.theta.core.type.inttype.IntNegExpr;
import hu.bme.mit.theta.core.type.inttype.IntNeqExpr;
import hu.bme.mit.theta.core.type.inttype.IntPosExpr;
import hu.bme.mit.theta.core.type.inttype.IntSubExpr;
import hu.bme.mit.theta.core.type.inttype.IntToRatExpr;
import hu.bme.mit.theta.core.type.inttype.IntType;
import hu.bme.mit.theta.core.type.rattype.RatAddExpr;
import hu.bme.mit.theta.core.type.rattype.RatDivExpr;
import hu.bme.mit.theta.core.type.rattype.RatEqExpr;
import hu.bme.mit.theta.core.type.rattype.RatExprs;
import hu.bme.mit.theta.core.type.rattype.RatGeqExpr;
import hu.bme.mit.theta.core.type.rattype.RatGtExpr;
import hu.bme.mit.theta.core.type.rattype.RatLeqExpr;
import hu.bme.mit.theta.core.type.rattype.RatLtExpr;
import hu.bme.mit.theta.core.type.rattype.RatMulExpr;
import hu.bme.mit.theta.core.type.rattype.RatNegExpr;
import hu.bme.mit.theta.core.type.rattype.RatNeqExpr;
import hu.bme.mit.theta.core.type.rattype.RatPosExpr;
import hu.bme.mit.theta.core.type.rattype.RatSubExpr;
import hu.bme.mit.theta.core.type.rattype.RatToIntExpr;
import hu.bme.mit.theta.core.type.rattype.RatType;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not;

public final class ExprCanonizer {

Expand Down Expand Up @@ -132,6 +203,8 @@ public final class ExprCanonizer {

.addCase(BvPosExpr.class, ExprCanonizer::canonizeBvPos)

.addCase(BvSignChangeExpr.class, ExprCanonizer::canonizeBvSignChange)

.addCase(BvNegExpr.class, ExprCanonizer::canonizeBvNeg)

.addCase(BvMulExpr.class, ExprCanonizer::canonizeBvMul)
Expand Down Expand Up @@ -502,6 +575,10 @@ private static Expr<BvType> canonizeBvPos(final BvPosExpr expr) {
throw new UnsupportedOperationException();
}

private static Expr<BvType> canonizeBvSignChange(final BvSignChangeExpr expr) {
throw new UnsupportedOperationException();
}

private static Expr<BvType> canonizeBvNeg(final BvNegExpr expr) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import hu.bme.mit.theta.core.type.bvtype.BvSModExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr;
import hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSignChangeExpr;
import hu.bme.mit.theta.core.type.bvtype.BvSubExpr;
import hu.bme.mit.theta.core.type.bvtype.BvType;
import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr;
Expand Down Expand Up @@ -264,6 +265,8 @@ public static ExprSimplifier create(final SimplifierLevel level) {

.addCase(BvPosExpr.class, this::simplifyBvPos)

.addCase(BvSignChangeExpr.class, this::simplifyBvSignChange)

.addCase(BvNegExpr.class, this::simplifyBvNeg)

.addCase(BvMulExpr.class, this::simplifyBvMul)
Expand Down Expand Up @@ -1286,6 +1289,10 @@ private Expr<BvType> simplifyBvPos(final BvPosExpr expr, final Valuation val) {
return simplify(expr.getOp(), val);
}

private Expr<BvType> simplifyBvSignChange(final BvSignChangeExpr expr, final Valuation val) {
return simplify(expr.getOp(), val);
}

private Expr<BvType> simplifyBvNeg(final BvNegExpr expr, final Valuation val) {
final Expr<BvType> op = simplify(expr.getOp(), val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,15 @@ private Expr<?> createIntDiv(Expr<?> a, Expr<?> b) {
*/
private Expr<?> createIntMod(Expr<?> a, Expr<?> b) {
ModExpr<?> aModB = Mod(a, b);
return Ite(Geq(a, Int(0)), // if (a >= 0)
aModB, // a mod b
// else
Ite(Geq(b, Int(0)), // if (b >= 0)
Sub(aModB, b), // a mod b - b
Add(aModB, b) // a mod b + b
)
);
return Ite(Eq(aModB, Int(0)), aModB,
Ite(Geq(a, Int(0)), // if (a >= 0)
aModB, // a mod b
// else
Ite(Geq(b, Int(0)), // if (b >= 0)
Sub(aModB, b), // a mod b - b
Add(aModB, b) // a mod b + b
)
));
}

@Override
Expand Down Expand Up @@ -484,7 +485,7 @@ public Expr<?> visitUnaryExpressionSizeOrAlignOf(CParser.UnaryExpressionSizeOrAl
.or(() -> Optional.ofNullable(CComplexType.getType(getVar(ctx.typeName().getText()).getRef(), parseContext)));

if (type.isPresent()) {
LitExpr<?> value = CComplexType.getSignedInt(parseContext).getValue("" + parseContext.getArchitecture().getBitWidth(type.get().getTypeName()) / 8);
LitExpr<?> value = CComplexType.getSignedInt(parseContext).getValue("" + type.get().width() / 8);
return value;
} else {
uniqueWarningLogger.write(Level.INFO, "WARNING: sizeof got unknown type, using a literal 0 instead.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
package hu.bme.mit.theta.frontend.transformation.grammar.preprocess;

public enum ArithmeticTrait {
LIN_INT, NONLIN_INT, BITWISE, FLOAT, ARR,
LIN_INT, NONLIN_INT, BITWISE, FLOAT, ARR, MULTITHREAD
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static CComplexType getType(String s, ParseContext parseContext) {
if (s.endsWith("*")) {
yield new CPointer(null, null, parseContext);
} else {
throw new RuntimeException("Type not known: " + s);
yield null;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public <T, R> R accept(CComplexTypeVisitor<T, R> visitor, T param) {
return visitor.visit(this, param);
}

@Override
public int width() {
return parseContext.getArchitecture().getBitWidth("int");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public <T, R> R accept(CComplexTypeVisitor<T, R> visitor, T param) {
return visitor.visit(this, param);
}

@Override
public int width() {
return parseContext.getArchitecture().getBitWidth(getTypeName() + "_s") +
parseContext.getArchitecture().getBitWidth(getTypeName() + "_e");
}

@Override
public CComplexType getSmallestCommonType(CComplexType type) {
if (!(type instanceof CReal) || ((CReal) type).rank <= rank) {
Expand Down
Loading

0 comments on commit 53cdcff

Please sign in to comment.