All Downloads are FREE. Search and download functionalities are using the official Maven repository.

soot.toolkits.graph.ArrayRefBlockGraph Maven / Gradle / Ivy

package soot.toolkits.graph;

/*-
 * #%L
 * Soot - a J*va Optimization Framework
 * %%
 * Copyright (C) 1999 Patrice Pominville, Raja Vallee-Rai
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.util.Iterator;
import java.util.Set;

import soot.Body;
import soot.Trap;
import soot.Unit;
import soot.baf.Inst;
import soot.jimple.Stmt;

/**
 * A CFG where the nodes are {@link Block} instances, and where {@link Unit}s which include array references start new
 * blocks. Exceptional control flow is ignored, so the graph will be a forest where each exception handler constitutes a
 * disjoint subgraph.
 */
public class ArrayRefBlockGraph extends BlockGraph {
  /**
   * 

* Constructs an {@link ArrayRefBlockGraph} from the given {@link Body}. *

* *

* Note that this constructor builds a {@link BriefUnitGraph} internally when splitting body's {@link Unit}s into * {@link Block}s. Callers who need both a {@link BriefUnitGraph} and an {@link ArrayRefBlockGraph} should use the * constructor taking the BriefUnitGraph as a parameter, as a minor optimization. *

* * @param the * Body instance from which the graph is built. */ public ArrayRefBlockGraph(Body body) { this(new BriefUnitGraph(body)); } /** * Constructs an ArrayRefBlockGraph corresponding to the Unit-level control flow represented by the * passed {@link BriefUnitGraph}. * * @param unitGraph * The BriefUnitGraph for which to build an ArrayRefBlockGraph. */ public ArrayRefBlockGraph(BriefUnitGraph unitGraph) { super(unitGraph); soot.util.PhaseDumper.v().dumpGraph(this, mBody); } /** *

* Utility method for computing the basic block leaders for a {@link Body}, given its {@link UnitGraph} (i.e., the * instructions which begin new basic blocks). *

* *

* This implementation chooses as block leaders all the Units that {@link BlockGraph.computerLeaders()}, and adds: * *

    * *
  • All Units which contain an array reference, as defined by {@link Stmt.containsArrayRef()} and * {@link Inst.containsArrayRef()}. * *
  • The first Unit not covered by each {@link Trap} (i.e., the Unit returned by * {@link Trap.getLastUnit()}.
  • * *
*

* * @param unitGraph * is the Unit-level CFG which is to be split into basic blocks. * * @return the {@link Set} of {@link Unit}s in unitGraph which are block leaders. */ protected Set computeLeaders(UnitGraph unitGraph) { Body body = unitGraph.getBody(); if (body != mBody) { throw new RuntimeException( "ArrayRefBlockGraph.computeLeaders() called with a UnitGraph that doesn't match its mBody."); } Set leaders = super.computeLeaders(unitGraph); for (Iterator it = body.getUnits().iterator(); it.hasNext();) { Unit unit = it.next(); if (((unit instanceof Stmt) && ((Stmt) unit).containsArrayRef()) || ((unit instanceof Inst) && ((Inst) unit).containsArrayRef())) { leaders.add(unit); } } return leaders; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy