Skip to content

Commit

Permalink
Ported FrontendXcfaBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Jul 21, 2022
1 parent 40301b6 commit 73fdca0
Show file tree
Hide file tree
Showing 13 changed files with 1,160 additions and 14 deletions.
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ include(
"sts/sts-cli",

"xcfa/xcfa",
"xcfa/c2xcfa",

"xcfa-old/xcfa-analysis",
"xcfa-old/xcfa-cli",
"xcfa-old/cat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ else if(regDeclCtx != null && regDeclCtx.Amp() == null) {
locations.putIfAbsent(id, new LinkedHashMap<>());
final XcfaProcess.Builder process = XcfaProcess.builder();
final XcfaProcedure.Builder procedure = XcfaProcedure.builder();
final XcfaLocation location = XcfaLocation.create("initial" + XcfaLocation.uniqeCounter());
final XcfaLocation location = XcfaLocation.create("initial" + XcfaLocation.uniqueCounter());
procedure.addLoc(location);
process.addProcedure(procedure);
process.setMainProcedure(procedure);
Expand Down Expand Up @@ -143,7 +143,7 @@ private VarDecl<BvType> getGlobalFromReg(final String name) {
}

private XcfaLocation newAnonymousLoc() {
return getOrCreateLoc("loc" + XcfaLocation.uniqeCounter());
return getOrCreateLoc("loc" + XcfaLocation.uniqueCounter());
}

private XcfaLocation getOrCreateLoc(final String name) {
Expand Down Expand Up @@ -234,7 +234,7 @@ public XcfaLabel visitArith64(LitmusAArch64Parser.Arith64Context ctx) {
@Override
public XcfaLabel visitLoad32(LitmusAArch64Parser.Load32Context ctx) {
final VarDecl<BvType> var = getOrCreateVar(ctx.rD32.getText(), 32);
final VarDecl<BvType> tmp = getOrCreateVar("tmp" + XcfaLocation.uniqeCounter(), 64);
final VarDecl<BvType> tmp = getOrCreateVar("tmp" + XcfaLocation.uniqueCounter(), 64);
StmtXcfaLabel cast = Stmt(Assign(var, Extract(tmp.getRef(), Int(0), Int(32))));
LoadXcfaLabel<BvType> load = Load(getGlobalFromReg(ctx.address().r.getText()), tmp, true, ctx.loadInstruction().mo);
return Sequence(List.of(load, cast));
Expand All @@ -248,7 +248,7 @@ public XcfaLabel visitLoad64(LitmusAArch64Parser.Load64Context ctx) {
@Override
public XcfaLabel visitStore32(LitmusAArch64Parser.Store32Context ctx) {
final VarDecl<BvType> var = getOrCreateVar(ctx.rV32.getText(), 32);
final VarDecl<BvType> tmp = getOrCreateVar("tmp" + XcfaLocation.uniqeCounter(), 64);
final VarDecl<BvType> tmp = getOrCreateVar("tmp" + XcfaLocation.uniqueCounter(), 64);
StmtXcfaLabel cast = Stmt(Assign(tmp, ZExt(var.getRef(), BvType(64))));
StoreXcfaLabel<BvType> store = Store(getGlobalFromReg(ctx.address().r.getText()), tmp, true, ctx.storeInstruction().mo);
return Sequence(List.of(cast, store));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public static XcfaLocation create(final String name) {

private static int counter = 0;

public static int uniqeCounter() {
public static int uniqueCounter() {
return counter++;
}

public static XcfaLocation uniqeCopyOf(final XcfaLocation from) {
XcfaLocation xcfaLocation = create(from.getName() + uniqeCounter());
XcfaLocation xcfaLocation = create(from.getName() + uniqueCounter());
FrontendMetadata.lookupMetadata(from).forEach((s, o) -> {
FrontendMetadata.create(xcfaLocation, s, o);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private XcfaLocation getLoc(final XcfaProcedure.Builder builder, final String na
}

private XcfaLocation getAnonymousLoc(final XcfaProcedure.Builder builder) {
return getLoc(builder, "__loc_" + XcfaLocation.uniqeCounter());
return getLoc(builder, "__loc_" + XcfaLocation.uniqueCounter());
}

protected <T> void propagateMetadata(CStatement source, T newOwner) {
Expand Down Expand Up @@ -327,7 +327,7 @@ public XcfaLocation visit(CBreak statement, ParamPack param) {
builder.addEdge(edge);
propagateMetadata(statement, edge);
edge = XcfaEdge.of(initLoc, breakLoc, List.of());
XcfaLocation unreachableLoc = XcfaLocation.create("Unreachable" + XcfaLocation.uniqeCounter());
XcfaLocation unreachableLoc = XcfaLocation.create("Unreachable" + XcfaLocation.uniqueCounter());
builder.addLoc(unreachableLoc);
propagateMetadata(statement, unreachableLoc);
builder.addEdge(edge);
Expand Down Expand Up @@ -425,7 +425,7 @@ public XcfaLocation visit(CContinue statement, ParamPack param) {
builder.addEdge(edge);
propagateMetadata(statement, edge);
edge = XcfaEdge.of(initLoc, continueLoc, List.of());
XcfaLocation unreachableLoc = XcfaLocation.create("Unreachable" + XcfaLocation.uniqeCounter());
XcfaLocation unreachableLoc = XcfaLocation.create("Unreachable" + XcfaLocation.uniqueCounter());
builder.addLoc(unreachableLoc);
propagateMetadata(statement, unreachableLoc);
builder.addEdge(edge);
Expand Down Expand Up @@ -591,7 +591,7 @@ public XcfaLocation visit(CGoto statement, ParamPack param) {
propagateMetadata(statement, edge);
edge = XcfaEdge.of(initLoc, getLoc(builder, statement.getLabel()), List.of());
builder.addLoc(getLoc(builder, statement.getLabel()));
XcfaLocation unreachableLoc = XcfaLocation.create("Unreachable" + XcfaLocation.uniqeCounter());
XcfaLocation unreachableLoc = XcfaLocation.create("Unreachable" + XcfaLocation.uniqueCounter());
builder.addLoc(unreachableLoc);
propagateMetadata(statement, unreachableLoc);
builder.addEdge(edge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public XcfaProcedure.Builder run(XcfaProcedure.Builder builder) {
removed = true;
}
if (newLabels.size() > 0) {
XcfaLocation tmp = XcfaLocation.create("tmp" + XcfaLocation.uniqeCounter());
XcfaLocation tmp = XcfaLocation.create("tmp" + XcfaLocation.uniqueCounter());
builder.addLoc(tmp);
builder.addEdge(edge.withSource(source).withLabels(newLabels).withTarget(tmp));
source = tmp;
newLabels.clear();
}
XcfaLocation tmp = XcfaLocation.create("tmp" + XcfaLocation.uniqeCounter());
XcfaLocation tmp = XcfaLocation.create("tmp" + XcfaLocation.uniqueCounter());
builder.addLoc(tmp);
builder.addEdge(edge.withSource(source).withLabels(List.of(label)).withTarget(tmp));
source = tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void splitAndInlineEdges(XcfaProcess.Builder oldBuilder, XcfaProcedure.B
XcfaLocation start = xcfaEdge.getSource();
XcfaLocation end = xcfaEdge.getTarget();
if (i > 0) {
XcfaLocation loc1 = XcfaLocation.create("inline" + XcfaLocation.uniqeCounter());
XcfaLocation loc1 = XcfaLocation.create("inline" + XcfaLocation.uniqueCounter());
FrontendMetadata.lookupMetadata(xcfaEdge).forEach((s, o) -> {
FrontendMetadata.create(loc1, s, o);
});
Expand All @@ -182,7 +182,7 @@ private void splitAndInlineEdges(XcfaProcess.Builder oldBuilder, XcfaProcedure.B
start = loc1;
}
if (i < xcfaEdge.getLabels().size() - 1) {
XcfaLocation loc1 = XcfaLocation.create("inline" + XcfaLocation.uniqeCounter());
XcfaLocation loc1 = XcfaLocation.create("inline" + XcfaLocation.uniqueCounter());
FrontendMetadata.lookupMetadata(xcfaEdge).forEach((s, o) -> {
FrontendMetadata.create(loc1, s, o);
});
Expand Down
10 changes: 10 additions & 0 deletions subprojects/xcfa/c2xcfa/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("kotlin-common")
}

dependencies {
implementation(project(":theta-common"))
implementation(project(":theta-core"))
implementation(project(":theta-xcfa"))
implementation(project(":theta-c-frontend"))
}
Loading

0 comments on commit 73fdca0

Please sign in to comment.