Giter VIP home page Giter VIP logo

Comments (6)

zhangt2333 avatar zhangt2333 commented on September 18, 2024 1

Sorry for this mistake.

I have just forgotten the method pascal.taie.analysis.graph.cfg.StmtCFG#getIndex which will take care of that:

@Override
public int getIndex(Stmt stmt) {
if (isEntry(stmt)) {
return 0;
} else if (isExit(stmt)) {
return ir.getStmts().size() + 1;
} else {
return stmt.getIndex() + 1;
}
}

To replace s1.getIndex() with stmtToCFG.get(s1).getIndex(s1) (same for s2).

from tai-e.

anabioticsoul avatar anabioticsoul commented on September 18, 2024

Are the CFGs in ICFG built with random orders?

from tai-e.

zhangt2333 avatar zhangt2333 commented on September 18, 2024

In Tai-e, ICFG construction uses unordered collections (e.g., java.util.HashSet), so that traversals are unordered. Our practice tells that the correctness of many algorithms is usually orthogonal to the traversal sequence.

I agree with you that the same traversal sequence can help bug reproduction and debug.

Currently, one workaround to solve your issue is to modify the source code of pascal.taie.analysis.graph.icfg.DefaultICFG, particularly its methods in which return value is a collection, so that they return ordered collection.

I give you some demos below (updated according to #12 (comment)):

    @Override
    public Set<ICFGEdge<Stmt>> getInEdgesOf(Stmt stmt) {
-        return inEdges.get(stmt);
+        var results = new TreeSet<ICFGEdge<Stmt>>((e1, e2) -> {
+            Stmt s1 = e1.getSource();
+            Stmt s2 = e2.getSource();
+            JMethod m1 = getContainingMethodOf(s1);
+            JMethod m2 = getContainingMethodOf(s2);
+            if (!m1.equals(m2)) {
+                return m1.toString().compareTo(m2.toString());
+            }
+            return Integer.compare(stmtToCFG.get(s1).getIndex(s1), stmtToCFG.get(s2).getIndex(s2));
+        });
+        results.addAll(this.inEdges.get(stmt));
+        return results;
    }

    @Override
    public Set<ICFGEdge<Stmt>> getOutEdgesOf(Stmt stmt) {
-        return outEdges.get(stmt);
+        var results = new TreeSet<ICFGEdge<Stmt>>((e1, e2) -> {
+            Stmt s1 = e1.getTarget();
+            Stmt s2 = e2.getTarget();
+            JMethod m1 = getContainingMethodOf(s1);
+            JMethod m2 = getContainingMethodOf(s2);
+            if (!m1.equals(m2)) {
+                return m1.toString().compareTo(m2.toString());
+            }
+            return Integer.compare(stmtToCFG.get(s1).getIndex(s1), stmtToCFG.get(s2).getIndex(s2));
+        });
+        results.addAll(this.outEdges.get(stmt));
+        return results;
    }

    @Override
    public Set<Stmt> getNodes() {
-        return Collections.unmodifiableSet(stmtToCFG.keySet());
+        var results = new TreeSet<Stmt>((s1, s2) -> {
+            JMethod m1 = getContainingMethodOf(s1);
+            JMethod m2 = getContainingMethodOf(s2);
+            if (!m1.equals(m2)) {
+                return m1.toString().compareTo(m2.toString());
+            }
+            return Integer.compare(stmtToCFG.get(s1).getIndex(s1), stmtToCFG.get(s2).getIndex(s2));
+        });
+        results.addAll(stmtToCFG.keySet());
+        return results;
    }

from tai-e.

anabioticsoul avatar anabioticsoul commented on September 18, 2024

That's really helpful. Thank you very much!

from tai-e.

anabioticsoul avatar anabioticsoul commented on September 18, 2024

This method will lose some statements. I find out that it is caused by the statement nop both at the entry and the exit of the CFG, whose index and line number are -1.

from tai-e.

anabioticsoul avatar anabioticsoul commented on September 18, 2024

To replace s1.getIndex() with stmtToCFG.get(s1).getIndex(s1) (same for s2).

It does work, sincerely thanks!

from tai-e.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.