Package soot

Examples of soot.Local


                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,
View Full Code Here


            JimpleBody body = Jimple.v().newBody(initMethod);
            initMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            // create attributes for those in the class
            ModelTransformer.createAttributes(body, entity, thisLocal, entity,
                    thisLocal, entityInstanceClass, tempCreatedMap);
View Full Code Here

                + "times and is self dependent...  A bug in one place tends "
                + "to propagate to a method inline, which propagates to another "
                + "type analysis....";

        if (expr.getMethod().equals(tokenTokenCompareMethod)) {
            Local tokenLocal1 = (Local) expr.getArg(0);
            Local tokenLocal2 = (Local) expr.getArg(1);
            type1 = getSpecializedType(tokenLocal1);
            type2 = getSpecializedType(tokenLocal2);
            if (type1 == null || type2 == null) {
                System.out.println(nullTypeMessage
                        + "\n\t tokentokenCompare: type1 = " + type1
                        + " type2 = " + type2);
            }
        } else if (expr.getMethod().equals(typeTokenCompareMethod)) {
            Local typeLocal = (Local) expr.getArg(0);
            Local tokenLocal = (Local) expr.getArg(1);
            //             type1 = PtolemyUtilities.getTypeValue(method, typeLocal, unit,
            //                     localDefs, localUses);
            type1 = getSpecializedType(typeLocal);
            type2 = getSpecializedType(tokenLocal);
            if (type1 == null || type2 == null || type1 == BaseType.UNKNOWN) {
                System.out.println("Contents of _objectToInequalityTerm");
                Iterator terms = _objectToInequalityTerm.entrySet().iterator();
                while (terms.hasNext()) {
                    Map.Entry pairs = (Map.Entry) terms.next();
                    System.out.println(pairs.getKey() + " = "
                            + (InequalityTerm) (pairs.getValue()));
                }
                System.out.println(nullTypeMessage
                        + "\n\t typetokenCompare: type1 = " + type1
                        + " type2 = " + type2);
                //System.exit(2);
            }
        } else if (expr.getMethod().equals(tokenTypeCompareMethod)) {
            Local tokenLocal = (Local) expr.getArg(0);
            Local typeLocal = (Local) expr.getArg(1);
            type1 = getSpecializedType(tokenLocal);
            type2 = getSpecializedType(typeLocal);
            if (type1 == null || type2 == null || type2 == BaseType.UNKNOWN) {
                System.out.println(nullTypeMessage
                        + "\n\t tokentypeCompare: type1 = " + type1
                        + "type2 = " + type2);
            }
            //             type2 = PtolemyUtilities.getTypeValue(method, typeLocal, unit,
            //                     localDefs, localUses);
        } else if (expr.getMethod().equals(typeTypeCompareMethod)) {
            Local typeLocal1 = (Local) expr.getArg(0);
            Local typeLocal2 = (Local) expr.getArg(1);
            type1 = getSpecializedType(typeLocal1);
            type2 = getSpecializedType(typeLocal2);
            if (type1 == null || type2 == null || type1 == BaseType.UNKNOWN
                    || type2 == BaseType.UNKNOWN) {
                System.out
                        .println(nullTypeMessage
                                + "\n\t typetypeCompare: type1 = " + "type2 = "
                                + type2);
            }
            //             type1 = PtolemyUtilities.getTypeValue(method, typeLocal1, unit,
            //                     localDefs, localUses);
            //             type2 = PtolemyUtilities.getTypeValue(method, typeLocal2, unit,
            //                     localDefs, localUses);
        } else if (expr.getMethod().equals(leastUpperBoundMethod)) {
            if (_debug) {
                System.out.println("Found LUB method!");
            }

            Local typeLocal1 = (Local) expr.getArg(0);
            Local typeLocal2 = (Local) expr.getArg(1);
            type1 = getSpecializedType(typeLocal1);
            type2 = getSpecializedType(typeLocal2);
            //             type1 = PtolemyUtilities.getTypeValue(method, typeLocal1, unit,
            //                     localDefs, localUses);
            //             type2 = PtolemyUtilities.getTypeValue(method, typeLocal2, unit,
            //                     localDefs, localUses);

            Local newTypeLocal = PtolemyUtilities.buildConstantTypeLocal(method
                    .getActiveBody(), unit, TypeLattice.leastUpperBound(type1,
                    type2));
            box.setValue(newTypeLocal);

            if (_debug) {
View Full Code Here

                    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();) {
View Full Code Here

                            // NOTE: broadcast is legal on a zero
                            // width port.
                            // If we try to get on a port with
                            // zero width, then throw a runtime
                            // exception.
                            Local local = SootUtilities
                                    .createRuntimeException(
                                            body,
                                            stmt,
                                            methodName
                                                    + "() called on a port with zero width: "
View Full Code Here

            JimpleBody body = Jimple.v().newBody(initMethod);
            initMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            // Populate...
            // Initialize attributes that already exist in the class.
            //  System.out.println("initializing attributes");
            ModelTransformer.createAttributes(body, entity, thisLocal, entity,
                    thisLocal, entityInstanceClass, tempCreatedMap);

            // Create and initialize ports
            // System.out.println("initializing ports");
            ModelTransformer.createPorts(body, thisLocal, entity, thisLocal,
                    entity, entityInstanceClass, tempCreatedMap);

            // return void
            units.add(Jimple.v().newReturnVoidStmt());
        }

        // Add fields to contain the tokens for each port.
        Map nameToField = new HashMap();
        Map nameToType = new HashMap();

        {
            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());
                String name = port.getName(entity);
                Type type = PtolemyUtilities.tokenType;
                nameToType.put(name, port.getType());

                // PtolemyUtilities.getSootTypeForTokenType(
                //  port.getType());
                SootField field = new SootField(StringUtilities
                        .sanitizeName(name)
                        + "Token", type);
                entityInstanceClass.addField(field);
                nameToField.put(name, field);

                field = new SootField(StringUtilities.sanitizeName(name)
                        + "IsPresent", type);
                entityInstanceClass.addField(field);
                nameToField.put(name + "_isPresent", field);
            }
        }

        {
            SootMethod preinitializeMethod = new SootMethod("preinitialize",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(preinitializeMethod);

            JimpleBody body = Jimple.v().newBody(preinitializeMethod);
            preinitializeMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Stmt insertPoint = Jimple.v().newReturnVoidStmt();
            body.getUnits().add(insertPoint);
            ModelTransformer.initializeAttributesBefore(body, insertPoint,
                    entity, body.getThisLocal(), entity, body.getThisLocal(),
                    entityInstanceClass);
        }

        // Add a field to keep track of the current state.
        SootField currentStateField = new SootField("_currentState", IntType
                .v());
        entityInstanceClass.addField(currentStateField);

        SootField nextTransitionField = new SootField("_nextTransition",
                IntType.v());
        entityInstanceClass.addField(nextTransitionField);
        // populate the initialize method.
        {
            System.out.println("create initialize()");

            SootMethod initializeMethod = new SootMethod("initialize",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(initializeMethod);

            JimpleBody body = Jimple.v().newBody(initializeMethod);
            initializeMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            // Set the initial state.
            String initialStateName = ((StringAttribute) entity
                    .getAttribute("initialStateName")).getExpression();
            int initialStateIndex = entity.entityList().indexOf(
                    entity.getEntity(initialStateName));
            units.add(Jimple.v().newAssignStmt(
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            currentStateField.makeRef()),
                    IntConstant.v(initialStateIndex)));

            // return void
            units.add(Jimple.v().newReturnVoidStmt());

            LocalNameStandardizer.v().transform(body, "at.lns");
            LocalSplitter.v().transform(body, "at.ls");
        }
        // populate the fire method.
        {
            System.out.println("create fire()");

            SootMethod fireMethod = new SootMethod("fire",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(fireMethod);

            JimpleBody body = Jimple.v().newBody(fireMethod);
            fireMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            Local hasTokenLocal = Jimple.v().newLocal("hasTokenLocal",
                    BooleanType.v());
            body.getLocals().add(hasTokenLocal);

            Local tokenLocal = Jimple.v().newLocal("tokenLocal",
                    PtolemyUtilities.tokenType);
            body.getLocals().add(tokenLocal);

            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());

                // FIXME: Handle multiports
                if (port.getWidth() > 0) {
                    String name = port.getName(entity);

                    // Create an if statement.
                    //
                    Local portLocal = Jimple.v().newLocal("port",
                            PtolemyUtilities.componentPortType);
                    body.getLocals().add(portLocal);

                    SootField portField = entityInstanceClass
                            .getFieldByName(StringUtilities.sanitizeName(name));
                    units.add(Jimple.v().newAssignStmt(
                            portLocal,
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    portField.makeRef())));
                    units.add(Jimple.v().newAssignStmt(
                            hasTokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.hasTokenMethod.makeRef(),
                                    IntConstant.v(0))));

                    Local hasTokenToken = PtolemyUtilities.addTokenLocal(body,
                            "token", PtolemyUtilities.booleanTokenClass,
                            PtolemyUtilities.booleanTokenConstructor,
                            hasTokenLocal);

                    // store the isPresent
                    SootField tokenIsPresentField = (SootField) nameToField
                            .get(name + "_isPresent");
                    units.add(Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    tokenIsPresentField.makeRef()),
                            hasTokenToken));

                    Stmt target = Jimple.v().newNopStmt();
                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(hasTokenLocal,
                                    IntConstant.v(0)), target));
                    units.add(Jimple.v().newAssignStmt(
                            tokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.getMethod.makeRef(),
                                    IntConstant.v(0))));

                    SootField tokenField = (SootField) nameToField.get(name);
                    units.add(Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    tokenField.makeRef()), tokenLocal));
                    units.add(target);
                }
            }

            Map stateToStartStmt = new HashMap();
            List stateStmtList = new LinkedList();
            int numberOfStates = entity.entityList().size();

            // Figure out what state we are in.
            for (Iterator states = entity.entityList().iterator(); states
                    .hasNext();) {
                State state = (State) states.next();
                Stmt startStmt = Jimple.v().newNopStmt();

                stateToStartStmt.put(state, startStmt);
                stateStmtList.add(startStmt);
            }

            Local currentStateLocal = Jimple.v().newLocal("currentStateLocal",
                    IntType.v());
            body.getLocals().add(currentStateLocal);

            Local nextStateLocal = Jimple.v().newLocal("nextStateLocal",
                    IntType.v());
            body.getLocals().add(nextStateLocal);

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

            Local transitionTakenLocal = Jimple.v().newLocal(
                    "transitionTakenLocal", BooleanType.v());
            body.getLocals().add(transitionTakenLocal);

            Local nextTransitionLocal = Jimple.v().newLocal(
                    "nextTransitionLocal", IntType.v());
            body.getLocals().add(nextTransitionLocal);

            units.add(Jimple.v().newAssignStmt(
                    currentStateLocal,
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            currentStateField.makeRef())));

            // Start by doing nothing.
            units.add(Jimple.v().newAssignStmt(transitionTakenLocal,
                    IntConstant.v(0)));
            units.add(Jimple.v().newAssignStmt(nextTransitionLocal,
                    IntConstant.v(-1)));

            // If no transition is taken, then stay in this state.
            units.add(Jimple.v().newAssignStmt(nextStateLocal,
                    currentStateLocal));

            Stmt finishedStmt = Jimple.v().newNopStmt();
            Stmt errorStmt = Jimple.v().newNopStmt();

            // Get the current state.
            units.add(Jimple.v().newTableSwitchStmt(currentStateLocal, 0,
                    numberOfStates - 1, stateStmtList, errorStmt));

            // Generate code for each state.
            for (Iterator states = entity.entityList().iterator(); states
                    .hasNext();) {
                State state = (State) states.next();
                System.out.println("state " + state.getName());

                Stmt startStmt = (Stmt) stateToStartStmt.get(state);
                units.add(startStmt);

                // Fire the refinement actor.
                TypedActor[] refinements = null;

                try {
                    refinements = state.getRefinement();
                } catch (Exception ex) {
                    throw new RuntimeException(ex.getMessage());
                }

                if (refinements != null) {
                    for (int i = 0; i < refinements.length; i++) {
                        TypedActor refinement = refinements[i];

                        Local containerLocal = Jimple.v().newLocal("container",
                                RefType.v(PtolemyUtilities.namedObjClass));
                        body.getLocals().add(containerLocal);

                        Local entityLocal = Jimple.v().newLocal("entity",
                                RefType.v(PtolemyUtilities.entityClass));
                        body.getLocals().add(entityLocal);

                        NamedObj containerModel = entity.getContainer();
                        String deepName = ((NamedObj) refinement)
                                .getName(containerModel);

                        units.add(Jimple.v().newAssignStmt(
                                containerLocal,
                                Jimple.v().newInterfaceInvokeExpr(
                                        thisLocal,
                                        PtolemyUtilities.getContainerMethod
                                                .makeRef())));
                        units
                                .add(Jimple
                                        .v()
                                        .newAssignStmt(
                                                containerLocal,
                                                Jimple
                                                        .v()
                                                        .newCastExpr(
                                                                containerLocal,
                                                                RefType
                                                                        .v(PtolemyUtilities.compositeActorClass))));
                        units.add(Jimple.v().newAssignStmt(
                                entityLocal,
                                Jimple.v().newVirtualInvokeExpr(
                                        containerLocal,
                                        PtolemyUtilities.getEntityMethod
                                                .makeRef(),
                                        StringConstant.v(deepName))));

                        units
                                .add(Jimple
                                        .v()
                                        .newAssignStmt(
                                                entityLocal,
                                                Jimple
                                                        .v()
                                                        .newCastExpr(
                                                                entityLocal,
                                                                RefType
                                                                        .v(PtolemyUtilities.compositeActorClass))));

                        SootMethod rprefireMethod;
                        SootMethod rfireMethod;
                        SootMethod rpostfireMethod;

                        if (refinement instanceof CompositeActor) {
                            rprefireMethod = SootUtilities
                                    .searchForMethodByName(
                                            PtolemyUtilities.compositeActorClass,
                                            "prefire");
                            rfireMethod = SootUtilities.searchForMethodByName(
                                    PtolemyUtilities.compositeActorClass,
                                    "fire");
                            rpostfireMethod = SootUtilities
                                    .searchForMethodByName(
                                            PtolemyUtilities.compositeActorClass,
                                            "postfire");
                        } else {
                            throw new RuntimeException();
                        }

                        units.add(Jimple.v().newInvokeStmt(
                                Jimple.v().newVirtualInvokeExpr(entityLocal,
                                        rprefireMethod.makeRef())));
                        units.add(Jimple.v().newInvokeStmt(
                                Jimple.v().newVirtualInvokeExpr(entityLocal,
                                        rfireMethod.makeRef())));
                        units.add(Jimple.v().newInvokeStmt(
                                Jimple.v().newVirtualInvokeExpr(entityLocal,
                                        rpostfireMethod.makeRef())));
                    }
                }

                // Determine the next state in this state.
                for (Iterator transitions = state.outgoingPort
                        .linkedRelationList().iterator(); transitions.hasNext();) {
                    Transition transition = (Transition) transitions.next();
                    System.out.println("transition = " + transition);

                    String guardExpression = transition.getGuardExpression();

                    Local guardLocal = DataUtilities.generateExpressionCode(
                            entity, entityInstanceClass, guardExpression,
                            nameToField, nameToType, body);

                    // Test the guard.
                    units
                            .add(Jimple
                                    .v()
                                    .newAssignStmt(
                                            tokenLocal,
                                            Jimple
                                                    .v()
                                                    .newCastExpr(
                                                            guardLocal,
                                                            RefType
                                                                    .v(PtolemyUtilities.booleanTokenClass))));
                    units.add(Jimple.v().newAssignStmt(
                            flagLocal,
                            Jimple.v().newVirtualInvokeExpr(
                                    tokenLocal,
                                    PtolemyUtilities.booleanValueMethod
                                            .makeRef())));

                    Stmt skipStmt = Jimple.v().newNopStmt();

                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(flagLocal, IntConstant.v(0)),
                            skipStmt));
                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(transitionTakenLocal,
                                    IntConstant.v(1)), errorStmt));

                    // If transition taken, then store the next state
                    units.add(Jimple.v().newAssignStmt(transitionTakenLocal,
                            IntConstant.v(1)));
                    units.add(Jimple.v().newAssignStmt(
                            nextTransitionLocal,
                            IntConstant.v(entity.relationList().indexOf(
                                    transition))));

                    int nextStateIndex = entity.entityList().indexOf(
                            transition.destinationState());
                    units.add(Jimple.v().newAssignStmt(nextStateLocal,
                            IntConstant.v(nextStateIndex)));

                    // Generate code for the outputExpression of the guard.
                    for (Iterator actions = transition.choiceActionList()
                            .iterator(); actions.hasNext();) {
                        AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                                .next();
                        System.out.println("action = " + action);
                        _generateActionCode(entity, entityInstanceClass,
                                nameToField, nameToType, body, action);
                    }

                    units.add(skipStmt);
                }

                units.add(Jimple.v().newGotoStmt(finishedStmt));
            }

            units.add(errorStmt);

            // throw an exception.
            units.add(finishedStmt);

            Local exceptionLocal = SootUtilities.createRuntimeException(body,
                    errorStmt, "state error");
            units.insertBefore(Jimple.v().newThrowStmt(exceptionLocal),
                    errorStmt);

            // Store the next state.
            units.add(Jimple.v().newAssignStmt(
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            currentStateField.makeRef()), nextStateLocal));

            // And the next Transition.
            units.add(Jimple.v()
                    .newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    nextTransitionField.makeRef()),
                            nextTransitionLocal));

            // return void
            units.add(Jimple.v().newReturnVoidStmt());

            LocalNameStandardizer.v().transform(body, "at.lns");
            LocalSplitter.v().transform(body, "at.ls");
        }
        // populate the postfire method.
        {
            System.out.println("create postfire()");

            SootMethod postfireMethod = new SootMethod("postfire",
                    Collections.EMPTY_LIST, BooleanType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(postfireMethod);

            JimpleBody body = Jimple.v().newBody(postfireMethod);
            postfireMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            Map transitionToStartStmt = new HashMap();
            List transitionStmtList = new LinkedList();
            int numberOfTransitions = entity.relationList().size();

            // Figure out what transition we are in.
            for (Iterator transitions = entity.relationList().iterator(); transitions
                    .hasNext();) {
                Transition transition = (Transition) transitions.next();
                Stmt startStmt = Jimple.v().newNopStmt();

                transitionToStartStmt.put(transition, startStmt);
                transitionStmtList.add(startStmt);
            }

            Local nextTransitionLocal = Jimple.v().newLocal(
                    "nextTransitionLocal", IntType.v());
            body.getLocals().add(nextTransitionLocal);

            units.add(Jimple.v().newAssignStmt(
                    nextTransitionLocal,
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            nextTransitionField.makeRef())));

            Stmt finishedStmt = Jimple.v().newNopStmt();
            Stmt errorStmt = Jimple.v().newNopStmt();

            // Get the current transition..
            units.add(Jimple.v().newTableSwitchStmt(nextTransitionLocal, 0,
                    numberOfTransitions - 1, transitionStmtList, errorStmt));

            // Generate code for each transition
            for (Iterator transitions = entity.relationList().iterator(); transitions
                    .hasNext();) {
                Transition transition = (Transition) transitions.next();
                Stmt startStmt = (Stmt) transitionToStartStmt.get(transition);
                units.add(startStmt);

                // Generate code for the commitExpression of the guard.
                for (Iterator actions = transition.commitActionList()
                        .iterator(); actions.hasNext();) {
                    AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                            .next();
                    _generateActionCode(entity, entityInstanceClass,
                            nameToField, nameToType, body, action);
                }

                // Generate code to reinitialize the target state, if
                // reset is true.
                TypedActor[] refinements = null;

                try {
                    BooleanToken resetToken = (BooleanToken) transition.reset
                            .getToken();

                    if (resetToken.booleanValue()) {
                        refinements = (transition.destinationState())
                                .getRefinement();
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex.getMessage());
                }

                if (refinements != null) {
                    for (int i = 0; i < refinements.length; i++) {
                        TypedActor refinement = refinements[i];

                        Local containerLocal = Jimple.v().newLocal("container",
                                RefType.v(PtolemyUtilities.namedObjClass));
                        body.getLocals().add(containerLocal);

                        Local entityLocal = Jimple.v().newLocal("entity",
                                RefType.v(PtolemyUtilities.entityClass));
                        body.getLocals().add(entityLocal);

                        NamedObj containerModel = entity.getContainer();
                        String deepName = ((NamedObj) refinement)
View Full Code Here

            JimpleBody body, AbstractActionsAttribute action) {
        for (Iterator names = action.getDestinationNameList().iterator(); names
                .hasNext();) {
            String name = (String) names.next();
            String actionExpression = action.getExpression(name);
            Local outputTokenLocal = DataUtilities.generateExpressionCode(
                    entity, entityClass, actionExpression, nameToField,
                    nameToType, body);

            try {
                NamedObj destination = action.getDestination(name);

                if (destination instanceof TypedIOPort) {
                    // send the computed token
                    Local portLocal = Jimple.v().newLocal("port",
                            PtolemyUtilities.componentPortType);
                    body.getLocals().add(portLocal);

                    SootField portField = entityClass.getFieldByName(name);

                    body.getUnits().add(
                            Jimple.v().newAssignStmt(
                                    portLocal,
                                    Jimple.v().newInstanceFieldRef(
                                            body.getThisLocal(),
                                            portField.makeRef())));
                    body.getUnits().add(
                            Jimple.v()
                                    .newInvokeStmt(
                                            Jimple.v().newVirtualInvokeExpr(
                                                    portLocal,
                                                    PtolemyUtilities.sendMethod
                                                            .makeRef(),
                                                    IntConstant.v(0),
                                                    outputTokenLocal)));
                } else if (destination instanceof Parameter) {
                    // set the computed token
                    Local paramLocal = Jimple.v().newLocal("param",
                            RefType.v(PtolemyUtilities.variableClass));
                    body.getLocals().add(paramLocal);

                    Local containerLocal = Jimple.v().newLocal("container",
                            RefType.v(PtolemyUtilities.namedObjClass));
                    body.getLocals().add(containerLocal);

                    Local attributeLocal = Jimple.v().newLocal("attribute",
                            RefType.v(PtolemyUtilities.attributeClass));
                    body.getLocals().add(attributeLocal);

                    // Get a ref to the parameter through the container,
                    // since the parameter we are assigning to may be
View Full Code Here

     *  at the given unit in the
     *  given body with a circular array reference.
     */
    public void inlineBroadcast(JimpleBody body, Stmt stmt, InvokeExpr expr,
            TypedIOPort port) {
        Local bufferLocal = Jimple.v().newLocal("buffer",
                ArrayType.v(PtolemyUtilities.tokenType, 1));
        body.getLocals().add(bufferLocal);

        Local returnArrayLocal = Jimple.v().newLocal("returnArray",
                ArrayType.v(PtolemyUtilities.tokenType, 1));
        body.getLocals().add(returnArrayLocal);

        Local returnLocal = Jimple.v().newLocal("return",
                PtolemyUtilities.tokenType);
        body.getLocals().add(returnLocal);

        // Refer directly to the buffer in the _model
        int channel = 0;
View Full Code Here

     *  at the given unit in the
     *  given body with an array reference.
     */
    public void inlineGet(JimpleBody body, Stmt stmt, ValueBox box,
            InvokeExpr expr, TypedIOPort port) {
        Local bufferLocal = Jimple.v().newLocal("buffer",
                ArrayType.v(PtolemyUtilities.tokenType, 1));
        body.getLocals().add(bufferLocal);

        Local returnArrayLocal = Jimple.v().newLocal("returnArray",
                ArrayType.v(PtolemyUtilities.tokenType, 1));
        body.getLocals().add(returnArrayLocal);

        Local returnLocal = Jimple.v().newLocal("return",
                PtolemyUtilities.tokenType);
        body.getLocals().add(returnLocal);

        Value channelValue = expr.getArg(0);

        _getBuffer(_modelClass, body, stmt, port, port.getType(), bufferLocal,
                _portToTypeNameToBufferField);

        // If we are calling with just a channel, then read the value.
        if (expr.getArgCount() == 1) {
            // We may be calling get without setting the return value
            // to anything.
            if (stmt instanceof DefinitionStmt) {
                // Replace the get() with an array read.
                box.setValue(Jimple.v().newArrayRef(bufferLocal, channelValue));
            } else {
                body.getUnits().remove(stmt);
            }
        } else {
            // We must return an array of tokens.
            // Create an array of the appropriate length.
            body.getUnits().insertBefore(
                    Jimple.v()
                            .newAssignStmt(
                                    returnArrayLocal,
                                    Jimple.v().newNewArrayExpr(
                                            PtolemyUtilities.tokenType,
                                            expr.getArg(1))), stmt);

            Value countValue = expr.getArg(1);

            // If the count is specified statically
            // FIXME: constant loop unroller should take care of this.
            if (Evaluator.isValueConstantValued(countValue)) {
                int argCount = ((IntConstant) Evaluator
                        .getConstantValueOf(countValue)).value;

                for (int k = 0; k < argCount; k++) {
                    // Get the value.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    returnLocal,
                                    Jimple.v().newArrayRef(bufferLocal,
                                            channelValue)), stmt);

                    // Store in the return array.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    Jimple.v().newArrayRef(returnArrayLocal,
                                            IntConstant.v(k)), returnLocal),
                            stmt);
                }

                // Replace the get() call.
                box.setValue(returnArrayLocal);
            } else {
                // we don't know the size beforehand,
                // so build a loop into the code.
                // The loop counter
                Local counterLocal = Jimple.v()
                        .newLocal("counter", IntType.v());
                body.getLocals().add(counterLocal);

                // The list of initializer instructions.
                List initializerList = new LinkedList();
View Full Code Here

     *  at the given unit in the
     *  given body with a circular array reference.
     */
    public void inlineGetInside(JimpleBody body, Stmt stmt, ValueBox box,
            InvokeExpr expr, TypedIOPort port) {
        Local bufferLocal = Jimple.v().newLocal("buffer",
                ArrayType.v(PtolemyUtilities.tokenType, 1));
        body.getLocals().add(bufferLocal);

        Local returnArrayLocal = Jimple.v().newLocal("returnArray",
                ArrayType.v(PtolemyUtilities.tokenType, 1));
        body.getLocals().add(returnArrayLocal);

        Local returnLocal = Jimple.v().newLocal("return",
                PtolemyUtilities.tokenType);
        body.getLocals().add(returnLocal);

        Value channelValue = expr.getArg(0);

        _getBuffer(_modelClass, body, stmt, port, port.getType(), bufferLocal,
                _portToTypeNameToInsideBufferField);

        // If we are calling with just a channel, then read the value.
        if (expr.getArgCount() == 1) {
            // We may be calling get without setting the return value
            // to anything.
            if (stmt instanceof DefinitionStmt) {
                // Replace the get() with an array read.
                box.setValue(Jimple.v().newArrayRef(bufferLocal, channelValue));
            } else {
                body.getUnits().remove(stmt);
            }
        } else {
            // We must return an array of tokens.
            // Create an array of the appropriate length.
            body.getUnits().insertBefore(
                    Jimple.v()
                            .newAssignStmt(
                                    returnArrayLocal,
                                    Jimple.v().newNewArrayExpr(
                                            PtolemyUtilities.tokenType,
                                            expr.getArg(1))), stmt);

            Value countValue = expr.getArg(1);

            // If the count is specified statically
            // FIXME: constant loop unroller should take care of this.
            if (Evaluator.isValueConstantValued(countValue)) {
                int argCount = ((IntConstant) Evaluator
                        .getConstantValueOf(countValue)).value;

                for (int k = 0; k < argCount; k++) {
                    // Get the value.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    returnLocal,
                                    Jimple.v().newArrayRef(bufferLocal,
                                            channelValue)), stmt);

                    // Store in the return array.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    Jimple.v().newArrayRef(returnArrayLocal,
                                            IntConstant.v(k)), returnLocal),
                            stmt);
                }

                // Replace the get() call.
                box.setValue(returnArrayLocal);
            } else {
                // we don't know the size beforehand,
                // so build a loop into the code.
                // The loop counter
                Local counterLocal = Jimple.v()
                        .newLocal("counter", IntType.v());
                body.getLocals().add(counterLocal);

                // The list of initializer instructions.
                List initializerList = new LinkedList();
View Full Code Here

TOP

Related Classes of soot.Local

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.