Search in sources :

Example 1 with UnitPrinter

use of soot.UnitPrinter in project soot by Sable.

the class RunVeryBusyAnalysis method main.

public static void main(String[] args) {
    args = new String[] { "testers.VeryBusyClass" };
    if (args.length == 0) {
        System.out.println("Usage: java RunVeryBusyAnalysis class_to_analyse");
        System.exit(0);
    }
    String sep = File.separator;
    String pathSep = File.pathSeparator;
    String path = System.getProperty("java.home") + sep + "lib" + sep + "rt.jar";
    path += pathSep + "." + sep + "tutorial" + sep + "guide" + sep + "examples" + sep + "analysis_framework" + sep + "src";
    Options.v().set_soot_classpath(path);
    SootClass sClass = Scene.v().loadClassAndSupport(args[0]);
    sClass.setApplicationClass();
    Scene.v().loadNecessaryClasses();
    for (SootMethod m : sClass.getMethods()) {
        Body b = m.retrieveActiveBody();
        System.out.println("=======================================");
        System.out.println(m.toString());
        UnitGraph graph = new ExceptionalUnitGraph(b);
        VeryBusyExpressions vbe = new SimpleVeryBusyExpressions(graph);
        for (Unit u : graph) {
            List<AbstractBinopExpr> before = vbe.getBusyExpressionsBefore(u);
            List<AbstractBinopExpr> after = vbe.getBusyExpressionsAfter(u);
            UnitPrinter up = new NormalUnitPrinter(b);
            up.setIndent("");
            System.out.println("---------------------------------------");
            u.toString(up);
            System.out.println(up.output());
            System.out.print("Busy in: {");
            sep = "";
            for (AbstractBinopExpr e : before) {
                System.out.print(sep);
                System.out.print(e.toString());
                sep = ", ";
            }
            System.out.println("}");
            System.out.print("Busy out: {");
            sep = "";
            for (AbstractBinopExpr e : after) {
                System.out.print(sep);
                System.out.print(e.toString());
                sep = ", ";
            }
            System.out.println("}");
            System.out.println("---------------------------------------");
        }
        System.out.println("=======================================");
    }
}
Also used : NormalUnitPrinter(soot.NormalUnitPrinter) SimpleVeryBusyExpressions(dk.brics.soot.analyses.SimpleVeryBusyExpressions) SootClass(soot.SootClass) Unit(soot.Unit) SimpleVeryBusyExpressions(dk.brics.soot.analyses.SimpleVeryBusyExpressions) VeryBusyExpressions(dk.brics.soot.analyses.VeryBusyExpressions) ExceptionalUnitGraph(soot.toolkits.graph.ExceptionalUnitGraph) ExceptionalUnitGraph(soot.toolkits.graph.ExceptionalUnitGraph) UnitGraph(soot.toolkits.graph.UnitGraph) NormalUnitPrinter(soot.NormalUnitPrinter) UnitPrinter(soot.UnitPrinter) SootMethod(soot.SootMethod) Body(soot.Body)

Example 2 with UnitPrinter

use of soot.UnitPrinter in project soot by Sable.

the class DavaPrinter method printStatementsInBody.

private void printStatementsInBody(Body body, java.io.PrintWriter out) {
    if (Options.v().verbose())
        System.out.println("Printing " + body.getMethod().getName());
    Chain<Unit> units = ((DavaBody) body).getUnits();
    if (units.size() != 1) {
        throw new RuntimeException("DavaBody AST doesn't have single root.");
    }
    UnitPrinter up = new DavaUnitPrinter((DavaBody) body);
    ((ASTNode) units.getFirst()).toString(up);
    out.print(up.toString());
}
Also used : UnitPrinter(soot.UnitPrinter) ASTNode(soot.dava.internal.AST.ASTNode) Unit(soot.Unit)

Aggregations

Unit (soot.Unit)2 UnitPrinter (soot.UnitPrinter)2 SimpleVeryBusyExpressions (dk.brics.soot.analyses.SimpleVeryBusyExpressions)1 VeryBusyExpressions (dk.brics.soot.analyses.VeryBusyExpressions)1 Body (soot.Body)1 NormalUnitPrinter (soot.NormalUnitPrinter)1 SootClass (soot.SootClass)1 SootMethod (soot.SootMethod)1 ASTNode (soot.dava.internal.AST.ASTNode)1 ExceptionalUnitGraph (soot.toolkits.graph.ExceptionalUnitGraph)1 UnitGraph (soot.toolkits.graph.UnitGraph)1