Package soot.jimple

Examples of soot.jimple.Stmt


    public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException {
        _debug(node);

        if (node.isConstant() && node.isEvaluated()) {
            Stmt insertPoint = Jimple.v().newNopStmt();
            _units.insertBefore(insertPoint, _insertPoint);

            Local local = PtolemyUtilities.buildConstantTokenLocal(_body,
                    insertPoint, node.getToken(), "token");
            _nodeToLocal.put(node, local);
            return;
        }

        Local local;

        try {
            local = _getLocalForName(node.getName());
        } catch (IllegalActionException ex) {
            // Must be a constant.  FIXME: Catching the exception is a
            // lousy way to figure this out.
            // Look up for constants.
            if (ptolemy.data.expr.Constants.get(node.getName()) != null) {
                //System.err.println("tested!");
                // A named constant that is recognized by the parser.
                Stmt insertPoint = Jimple.v().newNopStmt();
                _units.insertBefore(insertPoint, _insertPoint);
                local = PtolemyUtilities.buildConstantTokenLocal(_body,
                        insertPoint, ptolemy.data.expr.Constants.get(node
                                .getName()), "token");
            } else {
View Full Code Here


        _body.getLocals().add(booleanTokenLocal);

        Local flagLocal = Jimple.v().newLocal("result", BooleanType.v());
        _body.getLocals().add(flagLocal);

        Stmt failedStmt = Jimple.v().newNopStmt();
        Stmt satisfiedStmt = Jimple.v().newNopStmt();

        // Determine if we are doing AND or OR
        Constant conditionConstant = node.isLogicalAnd() ? IntConstant.v(1)
                : IntConstant.v(0);
        _units.insertBefore(Jimple.v().newAssignStmt(conditionLocal,
View Full Code Here

    // Replace any Ptolemy exception constructor
    // or initializer with a plain old RuntimeException.
    private void _replaceExceptions(JimpleBody body) {
        for (Iterator units = body.getUnits().snapshotIterator(); units
                .hasNext();) {
            Stmt unit = (Stmt) units.next();

            // If any box is removable, then remove the statement.
            for (Iterator boxes = unit.getUseBoxes().iterator(); boxes
                    .hasNext();) {
                ValueBox box = (ValueBox) boxes.next();

                // FIXME: This is currently way too simple.
                Value value = box.getValue();
View Full Code Here

            }

            //  System.out.println("method = " + method);
            JimpleBody body = (JimpleBody) method.retrieveActiveBody();
            Chain units = body.getUnits();
            Stmt insertPoint = (Stmt) units.getLast();
            Local modelLocal = Jimple.v().newLocal(
                    "_CGTemp" + modelField.getName(), modelField.getType());

            body.getLocals().add(modelLocal);
            units.insertBefore(Jimple.v().newAssignStmt(modelLocal,
                    Jimple.v().newNewExpr(RefType.v(modelClass))), insertPoint);

            // the arguments
            List args = new LinkedList();
            SootMethod constructor = SootUtilities.getMatchingMethod(
                    modelClass, "<init>", args);
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newSpecialInvokeExpr(modelLocal,
                            constructor.makeRef(), args)), insertPoint);

            FieldRef fieldRef = Jimple.v().newInstanceFieldRef(
                    body.getThisLocal(), modelField.makeRef());
            units.insertBefore(Jimple.v().newAssignStmt(fieldRef, modelLocal),
                    insertPoint);

            // Set the name.
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newVirtualInvokeExpr(modelLocal,
                            PtolemyUtilities.setNameMethod.makeRef(),
                            StringConstant.v(_model.getName()))), insertPoint);

            // Set the hardcoded iteration limit, if necessary.
            int iterationLimit = PhaseOptions.getInt(options, "iterations");

            if (iterationLimit != Integer.MAX_VALUE) {
                units.insertBefore(Jimple.v().newAssignStmt(
                        Jimple.v().newInstanceFieldRef(
                                body.getThisLocal(),
                                mainClass.getFieldByName("_iterationLimit")
                                        .makeRef()),
                        IntConstant.v(iterationLimit)), insertPoint);
            }
        }

        try {
            // unroll places where the list of models is used.
            // We put this in a try block so that we can exclude it
            // if necessary
            LinkedList modelList = new LinkedList();
            modelList.add(modelField);

            SootField modelsField = mainClass.getFieldByName("_models");

            if (modelsField != null) {
                SootUtilities.unrollIteratorInstances(mainClass, modelsField,
                        modelList);
            }
        } catch (RuntimeException ex) {
            System.out.println("Warning: did not find _models field: " + ex);

            for (Iterator methods = mainClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();
                System.out.println("clt: " + method + " " + body);
            }

            /*
             SootUtilities.createAndSetFieldFromLocal(
             body,
             modelField,
             mainClass,
             modelField.getType(),
             "_model");
             */
        }

        // Find calls to Manager.startRun() and replace it with
        // iteration code.
        // Note: It would be nice if we could inline the manager
        // code and optimize it, but in this case, the amount of code
        // we would want to throw away is fairly large.  This
        // just seems simpler here.
        //SootClass managerClass = Scene.v()
        //       .getSootClass("ptolemy.actor.Manager");
        //SootMethod managerStartRunMethod = managerClass
        //       .getMethodByName("startRun");
        SootMethod mainStartRunMethod = mainClass.getMethodByName("startRun");

        for (Iterator methods = mainClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();
            JimpleBody body = (JimpleBody) method.retrieveActiveBody();

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

                if (!stmt.containsInvokeExpr()) {
                    continue;
                }

                ValueBox box = stmt.getInvokeExprBox();
                Value value = box.getValue();

                if (value instanceof InstanceInvokeExpr) {
                    InstanceInvokeExpr expr = (InstanceInvokeExpr) value;

View Full Code Here

                        modelLocal,
                        SootUtilities.searchForMethodByName(modelClass,
                                "initialize").makeRef())), unit);

        // A jump point for the start of the iteration.
        Stmt iterationStartStmt = Jimple.v().newNopStmt();

        // A jump point for the end of the iteration.
        // we don't actually insertBefore this until later in the sequence.
        Stmt iterationEndStmt = Jimple.v().newNopStmt();

        units.insertBefore(iterationStartStmt, unit);

        // call fire on the model
        units.insertBefore(Jimple.v().newInvokeStmt(
View Full Code Here

                            JimpleBody body = (JimpleBody) method
                                    .retrieveActiveBody();

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

                                if (unit instanceof IdentityStmt) {
                                    IdentityStmt identityStmt = (IdentityStmt) unit;
                                    Value value = identityStmt.getRightOp();

                                    if (value instanceof ParameterRef) {
                                        ParameterRef parameterRef = (ParameterRef) value;

                                        if (parameterRef.getIndex() == 0) {
                                            ValueBox box = identityStmt
                                                    .getRightOpBox();
                                            box
                                                    .setValue(Jimple
                                                            .v()
                                                            .newParameterRef(
                                                                    method
                                                                            .getParameterType(0),
                                                                    0));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Keep track of the modification, so we know to
                    // modify invocations of that constructor.
                    modifiedConstructorClassList.add(theClass);
                }
            }
        }

        // Reset the hierarchy, since we've changed superclasses and such.
        Scene.v().setActiveHierarchy(new Hierarchy());
        Scene.v().setFastHierarchy(new FastHierarchy());

        // Fix the specialInvokes.
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {

            SootClass theClass = (SootClass) i.next();
            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();
                    if (unit.containsInvokeExpr()) {
                        ValueBox box = unit.getInvokeExprBox();
                        Value value = box.getValue();

                        if (value instanceof SpecialInvokeExpr) {
                            // System.out.println("invoke = " + unit);
View Full Code Here

    }

    protected void flowThrough(Object inValue, Object d, Object outValue) {
        Map in = (Map) inValue;
        Map out = (Map) outValue;
        Stmt stmt = (Stmt) d;

        // System.out.println("flowing " + d + " " + in);
        // By default, the out is equal to the in.
        copy(inValue, outValue);
View Full Code Here

                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                // Loop over all the statements.
                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    if (!unit.containsInvokeExpr()) {
                        continue;
                    }

                    ValueBox box = unit.getInvokeExprBox();
                    InvokeExpr r = (InvokeExpr) box.getValue();

                    if (r.getMethod().getSubSignature().equals(
                            PtolemyUtilities.invalidateResolvedTypesMethod
                                    .getSubSignature())) {
View Full Code Here

            // This will help us figure out where locals are defined.
            SimpleLocalDefs localDefs = new SimpleLocalDefs(unitGraph);

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

                if (!unit.containsInvokeExpr()) {
                    continue;
                }

                ValueBox box = unit.getInvokeExprBox();
                Value value = box.getValue();

                if (value instanceof InstanceInvokeExpr) {
                    InstanceInvokeExpr r = (InstanceInvokeExpr) value;
View Full Code Here

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

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

                if (!unit.containsInvokeExpr()) {
                    continue;
                }

                ValueBox box = unit.getInvokeExprBox();
                Value value = box.getValue();

                if (value instanceof InstanceInvokeExpr) {
                    InstanceInvokeExpr r = (InstanceInvokeExpr) value;
View Full Code Here

TOP

Related Classes of soot.jimple.Stmt

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.