Package soot

Examples of soot.Body


     *  has no side effects if it does not assign the value to any
     *  fields.
     */
    public static void _removeSideEffectFreeMethodCalls(SootMethod method,
            CallGraph callGraph, SideEffectAnalysis analysis) {
        Body body = method.retrieveActiveBody();
        CompleteUnitGraph unitGraph = new CompleteUnitGraph(body);

        // this will help us figure out where locals are defined.
        /*SimpleLocalDefs localDefs = */new SimpleLocalDefs(unitGraph);
        SimpleLiveLocals liveLocals = new SimpleLiveLocals(unitGraph);

        for (Iterator units = body.getUnits().snapshotIterator(); units
                .hasNext();) {
            Unit unit = (Unit) units.next();
            Value useValue;

            // Find a method invocation that doesn't have a return
            // value, or whose return value is dead.
            if (unit instanceof DefinitionStmt) {
                DefinitionStmt stmt = (DefinitionStmt) unit;
                Value left = stmt.getLeftOp();

                // If this statement defines a local that is later used,
                // then we cannot remove it.
                if (liveLocals.getLiveLocalsAfter(stmt).contains(left)) {
                    continue;
                }

                useValue = stmt.getRightOp();
            } else if (unit instanceof InvokeStmt) {
                useValue = ((InvokeStmt) unit).getInvokeExpr();
            } else {
                continue;
            }

            // Special invokes don't get removed.  This is because
            // special invokes are used for super method calls.  We
            // really do want to get rid of constructors to objects
            // that aren't used, but we have to be smarter about the
            // whole business (we have to remove the New as well, for
            // instance)
            if (useValue instanceof VirtualInvokeExpr
                    || useValue instanceof StaticInvokeExpr) {
                //InvokeExpr invokeExpr = (InvokeExpr) useValue;

                // If any targets of the invocation have side effects,
                // then they cannot be removed.
                boolean removable = true;

                for (Iterator i = new Targets(callGraph.edgesOutOf(unit)); i
                        .hasNext()
                        && removable;) {
                    SootMethod targetMethod = (SootMethod) i.next();

                    // System.out.println("Checking Target = " + targetMethod);
                    if (analysis.hasSideEffects(targetMethod)) {
                        removable = false;
                    }
                }

                if (removable) {
                    // Otherwise we've found an invocation we can remove.
                    // Remove it.
                    // System.out.println("SEFIR: removing " + unit);
                    body.getUnits().remove(unit);
                }
            }
        }
    }
View Full Code Here


    // Create the communication buffers for communication between
    // actors in the model.
    private void _createBuffers() {
        // First create the circular buffers for communication.
        SootMethod clinitMethod;
        Body clinitBody;

        if (_modelClass.declaresMethodByName("<clinit>")) {
            clinitMethod = _modelClass.getMethodByName("<clinit>");
            clinitBody = clinitMethod.retrieveActiveBody();
        } else {
            clinitMethod = new SootMethod("<clinit>", Collections.EMPTY_LIST,
                    VoidType.v(), Modifier.PUBLIC | Modifier.STATIC);
            _modelClass.addMethod(clinitMethod);
            clinitBody = Jimple.v().newBody(clinitMethod);
            clinitMethod.setActiveBody(clinitBody);
            clinitBody.getUnits().add(Jimple.v().newReturnVoidStmt());
        }

        Chain clinitUnits = clinitBody.getUnits();

        // Loop over all the relations, creating buffers for each channel.
        for (Iterator relations = _model.relationList().iterator(); relations
                .hasNext();) {
            TypedIORelation relation = (TypedIORelation) relations.next();

            // Determine the types that the relation is connected to.
            Map typeMap = new HashMap();
            List destinationPortList = relation.linkedDestinationPortList();

            for (Iterator destinationPorts = destinationPortList.iterator(); destinationPorts
                    .hasNext();) {
                TypedIOPort port = (TypedIOPort) destinationPorts.next();
                ptolemy.data.type.Type type = port.getType();
                typeMap.put(type.toString(), type);
            }

            for (Iterator types = typeMap.keySet().iterator(); types.hasNext();) {
                ptolemy.data.type.Type type = (ptolemy.data.type.Type) typeMap
                        .get(types.next());
                RefType tokenType = PtolemyUtilities
                        .getSootTypeForTokenType(type);

                String fieldName = relation.getName() + "_bufferLocal";
                Local arrayLocal = Jimple.v().newLocal(fieldName, tokenType);
                clinitBody.getLocals().add(arrayLocal);

                for (int i = 0; i < relation.getWidth(); i++) {
                    SootField field = new SootField(InlinePortTransformer
                            .getBufferFieldName(relation, i, type), tokenType,
                            Modifier.PUBLIC | Modifier.STATIC);
View Full Code Here

            if (debug) {
                System.out.println("updating types for " + method);
            }

            Body body = method.retrieveActiveBody();

            for (Iterator units = body.getUnits().snapshotIterator(); units
                    .hasNext();) {
                Unit unit = (Unit) units.next();

                //System.out.println("unit = " + unit);
                Iterator boxes = unit.getUseBoxes().iterator();

                while (boxes.hasNext()) {
                    ValueBox box = (ValueBox) boxes.next();
                    /*Value value = */box.getValue();

                    // Replace Array creations with a more specific
                    // type, if possible.
                    if (box.getValue() instanceof NewArrayExpr) {
                        NewArrayExpr newArrayExpr = (NewArrayExpr) box
                                .getValue();

                        if (debug) {
                            System.out
                                    .println("newArrayExpr = " + newArrayExpr);
                        }

                        Type baseType = newArrayExpr.getBaseType();
                        Type newType = typeAnalysis
                                .getSpecializedSootType(newArrayExpr);

                        if ((newType != null) && !newType.equals(baseType)) {
                            if (debug) {
                                System.out.println("replacing with " + newType);
                            }

                            box.setValue(Jimple.v().newNewArrayExpr(newType,
                                    newArrayExpr.getSize()));
                        }
                    }
                }

                // Ignore anything that isn't an assignment.
                if (!(unit instanceof AssignStmt)) {
                    continue;
                }

                AssignStmt assignStmt = (AssignStmt) unit;

                // Ignore anything that isn't an assignment to a field.
                if (assignStmt.getRightOp() instanceof FieldRef) {
                    FieldRef ref = (FieldRef) assignStmt.getRightOp();
                    SootFieldRef fieldRef = ref.getFieldRef();
                    SootField field = ref.getField();

                    Type type = field.getType();

                    if (!PtolemyUtilities.isTokenType(type)) {
                        continue;
                    }
                    // Things that aren't token types are ignored.
                    // Things that are already the same type are ignored.
                    Type newType = typeAnalysis.getSpecializedSootType(field);
                    if ((newType != null) && !newType.equals(type)) {

                        ref.setFieldRef(Scene.v().makeFieldRef(
                                fieldRef.declaringClass(), fieldRef.name(),
                                newType, fieldRef.isStatic()));
                    }
                    continue;
                }
                if (!(assignStmt.getLeftOp() instanceof FieldRef)) {
                    continue;
                }

                if (!PtolemyUtilities.isTokenType(assignStmt.getLeftOp()
                        .getType())) {
                    continue;
                }

                if (debug) {
                    System.out.println("checking assignment " + assignStmt);
                }

                // FIXME: We need to figure out a way to insert casts where appropriate.
                // See RampFiringLimitSDF
                //                 ptolemy.data.type.Type leftType, rightType;
                //                 leftType = _getReplacementTokenType(
                //                         assignStmt.getLeftOp(), typeAnalysis);
                //                 rightType = _getReplacementTokenType(
                //                         assignStmt.getRightOp(), typeAnalysis);
                //                 if (leftType != null && rightType != null && !leftType.equals(rightType)) {
                //                     if (debug) System.out.println("inserting conversion: leftType = " +
                //                             leftType + ", rightType = " + rightType);
                //                     // insert a call to convert(), and a cast.
                //                     FieldRef ref = (FieldRef)assignStmt.getLeftOp();
                //                     SootField field = ref.getField();
                //                     Type newType =
                //                         typeAnalysis.getSpecializedSootType(field);
                //                     Local tempLocal =
                //                         Jimple.v().newLocal("fieldUpdateLocal", newType);
                //                     body.getLocals().add(tempLocal);
                //                     Local tokenLocal =
                //                         Jimple.v().newLocal("tokenLocal", PtolemyUtilities.tokenType);
                //                     body.getLocals().add(tokenLocal);
                //                     Local typeLocal =
                //                         PtolemyUtilities.buildConstantTypeLocal(body, unit, leftType);
                //                     body.getUnits().insertBefore(
                //                             Jimple.v().newAssignStmt(tokenLocal,
                //                                     Jimple.v().newVirtualInvokeExpr(
                //                                             typeLocal,
                //                                             PtolemyUtilities.typeConvertMethod,
                //                                             assignStmt.getRightOp())),
                //                             unit);
                //                     body.getUnits().insertBefore(
                //                             Jimple.v().newAssignStmt(tempLocal,
                //                                     Jimple.v().newCastExpr(
                //                                             tokenLocal,
                //                                             newType)),
                //                             unit);
                //                     assignStmt.setRightOp(tempLocal);
                //                 } else {
                FieldRef ref = (FieldRef) assignStmt.getLeftOp();
                SootFieldRef fieldRef = ref.getFieldRef();
                SootField field = ref.getField();

                Type type = field.getType();

                // Things that aren't token types are ignored.
                // Things that are already the same type are ignored.
                Type newType = typeAnalysis.getSpecializedSootType(field);

                if ((newType != null) && !newType.equals(type)) {
                    if (debug) {
                        System.out.println("inserting cast");
                    }

                    Local tempLocal = Jimple.v().newLocal("fieldUpdateLocal",
                            newType);
                    body.getLocals().add(tempLocal);
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    tempLocal,
                                    Jimple.v().newCastExpr(
                                            assignStmt.getRightOp(), newType)),
                            unit);
View Full Code Here

            if (debug) {
                System.out.println("updating types for " + method);
            }

            Body body = method.retrieveActiveBody();

            // First split local variables that are used in
            // multiple places.
            LocalSplitter.v().transform(body, "ls");
View Full Code Here

        // Loop through all the methods.
        for (Iterator methods = entityClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();
            Body body = method.retrieveActiveBody();

            if (debug) {
                System.out.println("collecting constraints for " + method);
            }

            CompleteUnitGraph unitGraph = new CompleteUnitGraph(body);

            // this will help us figure out where locals are defined.
            SimpleLocalDefs localDefs = new SimpleLocalDefs(unitGraph);
            SimpleLocalUses localUses = new SimpleLocalUses(unitGraph,
                    localDefs);

            //   System.out.println("done computing aliases for " + method);
            for (Iterator locals = body.getLocals().iterator(); locals
                    .hasNext();) {
                Local local = (Local) locals.next();

                if (_unsafeLocals.contains(local)) {
                    continue;
                }

                // Ignore things that aren't reference types.
                Type type = local.getType();
                _createInequalityTerm(debug, local, type,
                        _objectToInequalityTerm);
            }

            for (Iterator units = body.getUnits().iterator(); units.hasNext();) {
                Stmt stmt = (Stmt) units.next();

                if (debug) {
                    System.out.println("stmt = " + stmt);
                }
View Full Code Here

    // Create the communication buffers for communication between
    // actors in the model.
    private void _createBuffers() {
        // First create the circular buffers for communication.
        SootMethod clinitMethod;
        Body clinitBody;

        if (_modelClass.declaresMethodByName("<clinit>")) {
            clinitMethod = _modelClass.getMethodByName("<clinit>");
            clinitBody = clinitMethod.retrieveActiveBody();
        } else {
            clinitMethod = new SootMethod("<clinit>", Collections.EMPTY_LIST,
                    VoidType.v(), Modifier.PUBLIC | Modifier.STATIC);
            _modelClass.addMethod(clinitMethod);
            clinitBody = Jimple.v().newBody(clinitMethod);
            clinitMethod.setActiveBody(clinitBody);
            clinitBody.getUnits().add(Jimple.v().newReturnVoidStmt());
        }

        //Chain clinitUnits = clinitBody.getUnits();

        // Loop over all the relations, creating buffers for each channel.
View Full Code Here

 
  public Set<SootMethod> findForMethod(SootMethod method){
    if(method.isConcrete() == false){
      return new HashSet<SootMethod>();
    }
    Body body = method.getActiveBody();
    return findForBody(body);
  }
View Full Code Here

      return;
    }
    if(method.hasActiveBody() == false){
      return;
    }
    Body body = method.getActiveBody();
    if(body == null)
      return;
    inspectBody(body);
   
    FindMethodCalls finder = new FindMethodCalls();
View Full Code Here

  Collection<SootClass> classes = Scene.v().getApplicationClasses();
    for (SootClass sootClass : classes) {
      Collection<SootMethod> methods = sootClass.getMethods();
      for (SootMethod method : methods) {
        if (method.hasActiveBody()) {
          Body body = method.getActiveBody();
          Collection<Unit> uc = body.getUnits();
          for (Unit u : uc) {
            if (u instanceof Stmt) {
              Stmt stmt = (Stmt)u;
              List boxes = stmt.getUseAndDefBoxes();
              for (Object o : boxes) {
View Full Code Here

    for (SootClass sootClass : classes) {
      Collection<SootMethod> methods = sootClass.getMethods();
      for (SootMethod method : methods) {
        currentMethod = method;
        if (method.hasActiveBody()) {
          Body body = method.getActiveBody();
          Collection<Unit> uc = body.getUnits();
          for (Unit u : uc) {
            if (u instanceof Stmt) {
              Stmt stmt = (Stmt)u;
              stmt.apply(this);
              if (stmt.containsInvokeExpr()) {
View Full Code Here

TOP

Related Classes of soot.Body

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.