Package soot

Examples of soot.Local


                // } else {
                // Otherwise there is nothing to be done.
                //}
            } else if (rightOp instanceof Local) {
                Local local = (Local) rightOp;

                _updateTypeInAssignment(leftOp, in.get(local), out);
            } else if (rightOp instanceof NewExpr) {
                NewExpr newExpr = (NewExpr) rightOp;
                RefType type = newExpr.getBaseType();
View Full Code Here


        if (token instanceof ptolemy.data.ArrayToken) {
            ArrayToken arrayToken = (ArrayToken) token;
            RefType tokenType = getSootTypeForTokenType(arrayToken
                    .getElementType());
            Type tokenArrayType = ArrayType.v(tokenType, 1);
            Local tokenArrayLocal = Jimple.v().newLocal(localName + "Array",
                    tokenArrayType);
            body.getLocals().add(tokenArrayLocal);
            Local elementTypeLocal = buildConstantTypeLocal(body, insertPoint,
                    arrayToken.getElementType());

            // Create the array of tokens.
            units.insertBefore(Jimple.v().newAssignStmt(
                    tokenArrayLocal,
                    Jimple.v().newNewArrayExpr(tokenType,
                            IntConstant.v(arrayToken.length()))), insertPoint);

            // recurse
            for (int i = 0; i < arrayToken.length(); i++) {
                Local argLocal = buildConstantTokenLocal(body, insertPoint,
                        arrayToken.getElement(i), localName + "_" + i);
                units.insertBefore(Jimple.v().newAssignStmt(
                        Jimple.v().newArrayRef(tokenArrayLocal,
                                IntConstant.v(i)), argLocal), insertPoint);
            }

            Local tokenLocal = Jimple.v().newLocal(localName,
                    RefType.v(arrayTokenClass));
            body.getLocals().add(tokenLocal);
            units.insertBefore(Jimple.v().newAssignStmt(tokenLocal,
                    Jimple.v().newNewExpr(RefType.v(arrayTokenClass))),
                    insertPoint);
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newSpecialInvokeExpr(tokenLocal,
                            arrayTokenWithTypeConstructor.makeRef(),
                            elementTypeLocal, tokenArrayLocal)), insertPoint);
            return tokenLocal;
        } else if (token instanceof ptolemy.data.RecordToken) {
            throw new RuntimeException(
                    "Code Generation for RecordTokens is not supported.");

            //             RecordToken recordToken = (RecordToken)token;
            //             int size = recordToken.labelSet().size();
            //             Type stringArrayType =
            //                 ArrayType.v(RefType.v(PtolemyUtilities.stringClass), 1);
            //             Local stringArrayLocal = Jimple.v().newLocal(localName + "SArray",
            //                     stringArrayType);
            //             body.getLocals().add(stringArrayLocal);
            //             // Create the array of strings.
            //             units.insertBefore(
            //                     Jimple.v().newAssignStmt(stringArrayLocal,
            //                             Jimple.v().newNewArrayExpr(
            //                                     RefType.v(PtolemyUtilities.stringClass),
            //                                     IntConstant.v(size))),
            //                     insertPoint);
            //             Type tokenArrayType = ArrayType.v(tokenType, 1);
            //             Local tokenArrayLocal = Jimple.v().newLocal(localName + "TArray",
            //                     tokenArrayType);
            //             body.getLocals().add(tokenArrayLocal);
            //             // Create the array of tokens.
            //             units.insertBefore(Jimple.v().newAssignStmt(tokenArrayLocal,
            //                     Jimple.v().newNewArrayExpr(tokenType,
            //                             IntConstant.v(size))),
            //                     insertPoint);
            //             // recurse
            //             int i = 0;
            //             for (Iterator labels = recordToken.labelSet().iterator();
            //                  labels.hasNext(); i++) {
            //                 String label = (String)labels.next();
            //                 Local argLocal = buildConstantTokenLocal(body, insertPoint,
            //                         recordToken.get(label), localName + "_" + label);
            //                 units.insertBefore(
            //                         Jimple.v().newAssignStmt(
            //                                 Jimple.v().newArrayRef(stringArrayLocal,
            //                                         IntConstant.v(i)),
            //                                 StringConstant.v(label)),
            //                         insertPoint);
            //                 units.insertBefore(
            //                         Jimple.v().newAssignStmt(
            //                                 Jimple.v().newArrayRef(tokenArrayLocal,
            //                                         IntConstant.v(i)),
            //                                 argLocal),
            //                         insertPoint);
            //             }
            //             Local tokenLocal = Jimple.v().newLocal(localName,
            //                     RefType.v(recordTokenClass));
            //             body.getLocals().add(tokenLocal);
            //             units.insertBefore(Jimple.v().newAssignStmt(tokenLocal,
            //                     Jimple.v().newNewExpr(RefType.v(recordTokenClass))),
            //                     insertPoint);
            //             units.insertBefore(Jimple.v().newInvokeStmt(
            //                     Jimple.v().newSpecialInvokeExpr(tokenLocal,
            //                             recordTokenConstructor.makeRef(), stringArrayLocal,
            //                             tokenArrayLocal)),
            //                     insertPoint);
            //             return tokenLocal;
        } else if (token.getClass().equals(Token.class)) {
            // Token has no string constructor.
            SootClass tokenClass = Scene.v().loadClassAndSupport(
                    token.getClass().getName());
            SootMethod tokenConstructor = tokenClass.getMethod("void <init>()");

            Local tokenLocal = Jimple.v().newLocal(localName,
                    RefType.v(tokenClass));
            body.getLocals().add(tokenLocal);
            units.insertBefore(Jimple.v().newAssignStmt(tokenLocal,
                    Jimple.v().newNewExpr(RefType.v(tokenClass))), insertPoint);
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newSpecialInvokeExpr(tokenLocal,
                            tokenConstructor.makeRef())), insertPoint);
            return tokenLocal;
        } else if (token instanceof IntToken) {
            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, intTokenClass, intTokenConstructor, IntConstant
                            .v(((IntToken) token).intValue()));
            return tokenLocal;
        } else if (token instanceof UnsignedByteToken) {
            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, unsignedByteTokenClass,
                    unsignedByteTokenConstructor, IntConstant
                            .v(((UnsignedByteToken) token).byteValue()));
            return tokenLocal;
        } else if (token instanceof BooleanToken) {
            Value value;

            if (((BooleanToken) token).booleanValue()) {
                value = IntConstant.v(1);
            } else {
                value = IntConstant.v(0);
            }

            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, booleanTokenClass, booleanTokenConstructor,
                    value);
            return tokenLocal;
        } else if (token instanceof DoubleToken) {
            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, doubleTokenClass, doubleTokenConstructor,
                    DoubleConstant.v(((DoubleToken) token).doubleValue()));
            return tokenLocal;
        } else if (token instanceof ComplexToken) {
            Complex complex = ((ComplexToken) token).complexValue();

            // ComplexToken takes a Complex as a constructor.
            SootClass complexClass = Scene.v().loadClassAndSupport(
                    "ptolemy.math.Complex");
            SootMethod complexConstructor = complexClass
                    .getMethod("void <init>(double,double)");

            Local complexLocal = Jimple.v().newLocal(localName + "Arg",
                    RefType.v(complexClass));
            body.getLocals().add(complexLocal);
            units.insertBefore(Jimple.v().newAssignStmt(complexLocal,
                    Jimple.v().newNewExpr(RefType.v(complexClass))),
                    insertPoint);
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newSpecialInvokeExpr(complexLocal,
                            complexConstructor.makeRef(),
                            DoubleConstant.v(complex.real),
                            DoubleConstant.v(complex.imag))), insertPoint);

            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, complexTokenClass, complexTokenConstructor,
                    complexLocal);
            return tokenLocal;
        } else if (token instanceof StringToken) {
            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, stringTokenClass, stringTokenConstructor,
                    StringConstant.v(((StringToken) token).stringValue()));
            return tokenLocal;
        } else if (token instanceof FixToken) {
            FixToken fixToken = (FixToken) token;
            FixPoint fixValue = fixToken.fixValue();
            List args = new ArrayList(3);

            // Some possible loss of precision?
            args.add(DoubleConstant.v(fixValue.doubleValue()));
            args.add(IntConstant.v(fixValue.getPrecision().getNumberOfBits()));
            args.add(IntConstant.v(fixValue.getPrecision()
                    .getIntegerBitLength()));

            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, fixTokenClass, fixTokenThreeArgConstructor, args);
            return tokenLocal;
        } else if (token instanceof FloatToken) {
            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, floatTokenClass, floatTokenConstructor,
                    FloatConstant.v(((FloatToken) token).floatValue()));
            return tokenLocal;
        } else if (token instanceof FunctionToken) {
            // Function tokens are partially supported, but cannot be
            // type specialized.  This can be folded into the case
            // below, if you are interested in trying it.
            throw new RuntimeException(
                    "Unboxing is not supported for FunctionTokens.");
        } else if (token instanceof MatrixToken) {
            // Can't do this for all tokens, because it causes an
            // infinite loop!
            String expression = token.toString();
            Local tokenLocal = DataUtilities.generateExpressionCodeBefore(null,
                    null, expression, new HashMap(), new HashMap(), body,
                    insertPoint);
            return tokenLocal;
        } else {
            // We want to avoid doing this for all tokens, because
            // string constructors are expensive..
            SootClass tokenClass = Scene.v().loadClassAndSupport(
                    token.getClass().getName());
            SootMethod tokenConstructor = tokenClass
                    .getMethod("void <init>(java.lang.String)");
            Local tokenLocal = Jimple.v().newLocal(localName,
                    RefType.v(tokenClass));
            body.getLocals().add(tokenLocal);
            units.insertBefore(Jimple.v().newAssignStmt(tokenLocal,
                    Jimple.v().newNewExpr(RefType.v(tokenClass))), insertPoint);
            units.insertBefore(Jimple.v().newInvokeStmt(
View Full Code Here

                    .getMethodByName("preinitialize");
            JimpleBody body = (JimpleBody) classMethod.getActiveBody();
            Stmt insertPoint = body.getFirstNonIdentityStmt();

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

            // Add code to the beginning of the preinitialize method that
            // initializes the attributes.
            //             ModelTransformer.initializeAttributesBefore(body, insertPoint,
            //                     model, body.getThisLocal(),
            //                     model, body.getThisLocal(),
            //                     modelClass);
            for (Iterator entities = model.deepEntityList().iterator(); entities
                    .hasNext();) {
                Entity entity = (Entity) entities.next();
                String fieldName = ModelTransformer.getFieldNameForEntity(
                        entity, model);
                SootField field = modelClass.getFieldByName(fieldName);
                String className = ModelTransformer.getInstanceClassName(
                        entity, options);
                SootClass theClass = Scene.v().loadClassAndSupport(className);
                SootMethod preinitializeMethod = SootUtilities
                        .searchForMethodByName(theClass, "preinitialize");
                Local actorLocal = Jimple.v().newLocal("actor",
                        RefType.v(theClass));
                body.getLocals().add(actorLocal);

                // Get the field.
                units.insertBefore(Jimple.v().newAssignStmt(
                        actorLocal,
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                field.makeRef())), insertPoint);
                units.insertBefore(Jimple.v().newInvokeStmt(
                        Jimple.v().newVirtualInvokeExpr(actorLocal,
                                preinitializeMethod.makeRef())), insertPoint);
            }

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

        {
            // populate the initialize method
            SootMethod classMethod = modelClass.getMethodByName("initialize");
            JimpleBody body = (JimpleBody) classMethod.getActiveBody();
            Stmt insertPoint = body.getFirstNonIdentityStmt();

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

            Local actorLocal = Jimple.v().newLocal("actor", actorType);
            body.getLocals().add(actorLocal);

            for (Iterator entities = model.deepEntityList().iterator(); entities
                    .hasNext();) {
                Entity entity = (Entity) entities.next();
                String fieldName = ModelTransformer.getFieldNameForEntity(
                        entity, model);
                SootField field = modelClass.getFieldByName(fieldName);
                String className = ModelTransformer.getInstanceClassName(
                        entity, options);
                SootClass theClass = Scene.v().loadClassAndSupport(className);
                SootMethod initializeMethod = SootUtilities
                        .searchForMethodByName(theClass, "initialize");

                // Set the field.
                units.insertBefore(Jimple.v().newAssignStmt(
                        actorLocal,
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                field.makeRef())), insertPoint);
                units.insertBefore(Jimple.v().newInvokeStmt(
                        Jimple.v().newVirtualInvokeExpr(actorLocal,
                                initializeMethod.makeRef())), insertPoint);
            }

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

        {
            // populate the prefire method
            SootMethod classMethod = modelClass.getMethodByName("prefire");
            JimpleBody body = (JimpleBody) classMethod.getActiveBody();
            Chain units = body.getUnits();
            Stmt insertPoint = (Stmt) units.getLast();

            Local thisLocal = body.getThisLocal();

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

            // Prefire the controller.
            Local actorLocal = Jimple.v().newLocal("actor", actorType);
            body.getLocals().add(actorLocal);

            String fieldName = ModelTransformer.getFieldNameForEntity(
                    controller, model);
            SootField field = modelClass.getFieldByName(fieldName);
            String className = ModelTransformer.getInstanceClassName(
                    controller, options);
            SootClass theClass = Scene.v().loadClassAndSupport(className);
            SootMethod actorPrefireMethod = SootUtilities
                    .searchForMethodByName(theClass, "prefire");

            units.insertBefore(
                    Jimple.v().newAssignStmt(
                            actorLocal,
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    field.makeRef())), insertPoint);
            units.insertBefore(Jimple.v().newAssignStmt(
                    prefireReturnsLocal,
                    Jimple.v().newVirtualInvokeExpr(actorLocal,
                            actorPrefireMethod.makeRef())), insertPoint);

            units.insertBefore(Jimple.v().newReturnStmt(prefireReturnsLocal),
                    insertPoint);

            LocalSplitter.v().transform(body, phaseName + ".lns");
            LocalNameStandardizer.v().transform(body, phaseName + ".lns");
            TypeResolver.resolve(body, Scene.v());
        }

        {
            // populate the fire method
            SootMethod classMethod = modelClass.getMethodByName("fire");
            JimpleBody body = (JimpleBody) classMethod.getActiveBody();
            Stmt insertPoint = body.getFirstNonIdentityStmt();

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

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

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

            // Transfer Inputs from input ports.
            for (Iterator ports = model.inputPortList().iterator(); ports
                    .hasNext();) {
                IOPort port = (IOPort) ports.next();
                int rate = 1;

                String fieldName = ModelTransformer.getFieldNameForPort(port,
                        model);
                SootField field = modelClass.getFieldByName(fieldName);

                // Get a reference to the port.
                Local portLocal = Jimple.v().newLocal("port",
                        PtolemyUtilities.ioportType);
                body.getLocals().add(portLocal);

                Local tempPortLocal = Jimple.v().newLocal("tempPort",
                        PtolemyUtilities.ioportType);
                body.getLocals().add(tempPortLocal);
                units.insertBefore(Jimple.v().newAssignStmt(
                        tempPortLocal,
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                field.makeRef())), insertPoint);
                units.insertBefore(Jimple.v().newAssignStmt(
                        portLocal,
                        Jimple.v().newCastExpr(tempPortLocal,
                                PtolemyUtilities.ioportType)), insertPoint);

                for (int i = 0; i < port.getWidth(); i++) {
                    // The list of initializer instructions.
                    List initializerList = new LinkedList();
                    initializerList.add(Jimple.v().newAssignStmt(indexLocal,
                            IntConstant.v(0)));

                    // The list of body instructions.
                    List bodyList = new LinkedList();

                    // Read
                    bodyList.add(Jimple.v().newAssignStmt(
                            tokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.getMethod.makeRef(),
                                    IntConstant.v(i))));

                    // Write
                    bodyList.add(Jimple.v().newInvokeStmt(
                            Jimple.v()
                                    .newVirtualInvokeExpr(
                                            portLocal,
                                            PtolemyUtilities.sendInsideMethod
                                                    .makeRef(),
                                            IntConstant.v(i), tokenLocal)));

                    // Increment the index.
                    bodyList.add(Jimple.v()
                            .newAssignStmt(
                                    indexLocal,
                                    Jimple.v().newAddExpr(indexLocal,
                                            IntConstant.v(1))));

                    Expr conditionalExpr = Jimple.v().newLtExpr(indexLocal,
                            IntConstant.v(rate));

                    SootUtilities.createForLoopBefore(body, insertPoint,
                            initializerList, bodyList, conditionalExpr);
                }
            }

            {
                // Fire the controller.
                Local actorLocal = Jimple.v().newLocal("actor", actorType);
                body.getLocals().add(actorLocal);

                String fieldName = ModelTransformer.getFieldNameForEntity(
                        controller, model);
                SootField field = modelClass.getFieldByName(fieldName);
                String className = ModelTransformer.getInstanceClassName(
                        controller, options);
                SootClass theClass = Scene.v().loadClassAndSupport(className);
                SootMethod actorFireMethod = SootUtilities
                        .searchForMethodByName(theClass, "fire");

                units.insertBefore(Jimple.v().newAssignStmt(
                        actorLocal,
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                field.makeRef())), insertPoint);
                units.insertBefore(Jimple.v().newInvokeStmt(
                        Jimple.v().newVirtualInvokeExpr(actorLocal,
                                actorFireMethod.makeRef())), insertPoint);
            }

            // Transfer outputs from output ports
            for (Iterator ports = model.outputPortList().iterator(); ports
                    .hasNext();) {
                IOPort port = (IOPort) ports.next();
                int rate = DFUtilities.getTokenProductionRate(port);

                String fieldName = ModelTransformer.getFieldNameForPort(port,
                        model);
                SootField field = modelClass.getFieldByName(fieldName);

                // Get a reference to the port.
                Local portLocal = Jimple.v().newLocal("port",
                        PtolemyUtilities.ioportType);
                body.getLocals().add(portLocal);

                Local tempPortLocal = Jimple.v().newLocal("tempPort",
                        PtolemyUtilities.ioportType);
                body.getLocals().add(tempPortLocal);
                units.insertBefore(Jimple.v().newAssignStmt(
                        tempPortLocal,
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                field.makeRef())), insertPoint);
                units.insertBefore(Jimple.v().newAssignStmt(
                        portLocal,
                        Jimple.v().newCastExpr(tempPortLocal,
                                PtolemyUtilities.ioportType)), insertPoint);

                for (int i = 0; i < port.getWidth(); i++) {
                    // The list of initializer instructions.
                    List initializerList = new LinkedList();
                    initializerList.add(Jimple.v().newAssignStmt(indexLocal,
                            IntConstant.v(0)));

                    // The list of body instructions.
                    List bodyList = new LinkedList();

                    // Read
                    bodyList.add(Jimple.v().newAssignStmt(
                            tokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.getInsideMethod.makeRef(),
                                    IntConstant.v(i))));

                    // Write
                    bodyList.add(Jimple.v().newInvokeStmt(
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.sendMethod.makeRef(),
                                    IntConstant.v(i), tokenLocal)));

                    // Increment the index.
                    bodyList.add(Jimple.v()
                            .newAssignStmt(
                                    indexLocal,
                                    Jimple.v().newAddExpr(indexLocal,
                                            IntConstant.v(1))));

                    Expr conditionalExpr = Jimple.v().newLtExpr(indexLocal,
                            IntConstant.v(rate));

                    SootUtilities.createForLoopBefore(body, insertPoint,
                            initializerList, bodyList, conditionalExpr);
                }
            }

            // Return.
            //            units.add(Jimple.v().newReturnVoidStmt());
            LocalSplitter.v().transform(body, phaseName + ".lns");
            LocalNameStandardizer.v().transform(body, phaseName + ".lns");
            TypeResolver.resolve(body, Scene.v());
        }

        {
            // populate the postfire method
            SootMethod classMethod = modelClass.getMethodByName("postfire");
            JimpleBody body = (JimpleBody) classMethod.getActiveBody();
            Stmt insertPoint = body.getFirstNonIdentityStmt();

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

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

            // Postfire the controller.
            Local actorLocal = Jimple.v().newLocal("actor", actorType);
            body.getLocals().add(actorLocal);

            String fieldName = ModelTransformer.getFieldNameForEntity(
                    controller, model);
            SootField field = modelClass.getFieldByName(fieldName);
            String className = ModelTransformer.getInstanceClassName(
                    controller, options);
            SootClass theClass = Scene.v().loadClassAndSupport(className);
            SootMethod actorPostfireMethod = SootUtilities
                    .searchForMethodByName(theClass, "postfire");

            units.insertBefore(
                    Jimple.v().newAssignStmt(
                            actorLocal,
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    field.makeRef())), insertPoint);
            units.insertBefore(Jimple.v().newAssignStmt(
                    postfireReturnsLocal,
                    Jimple.v().newVirtualInvokeExpr(actorLocal,
                            actorPostfireMethod.makeRef())), insertPoint);

            units.insertBefore(Jimple.v().newReturnStmt(postfireReturnsLocal),
                    insertPoint);
            LocalSplitter.v().transform(body, phaseName + ".lns");
            LocalNameStandardizer.v().transform(body, phaseName + ".lns");
            TypeResolver.resolve(body, Scene.v());
        }

        {
            // populate the wrapup method
            SootMethod classMethod = modelClass.getMethodByName("wrapup");
            JimpleBody body = (JimpleBody) classMethod.getActiveBody();
            Stmt insertPoint = body.getFirstNonIdentityStmt();

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

            Local actorLocal = Jimple.v().newLocal("actor", actorType);
            body.getLocals().add(actorLocal);

            for (Iterator entities = model.deepEntityList().iterator(); entities
                    .hasNext();) {
                Entity entity = (Entity) entities.next();
View Full Code Here

    private static Local _buildConstantTokenLocal(Body body, Unit insertPoint,
            String localName, SootClass tokenClass,
            SootMethod tokenConstructor, List constructorArgs) {
        RefType tokenType = RefType.v(tokenClass);
        Local tokenLocal = Jimple.v().newLocal(localName, tokenType);
        body.getLocals().add(tokenLocal);
        body.getUnits().insertBefore(
                Jimple.v().newAssignStmt(tokenLocal,
                        Jimple.v().newNewExpr(tokenType)), insertPoint);
        body.getUnits().insertBefore(
View Full Code Here

    private static Local _buildConstantTokenLocal(Body body, Unit insertPoint,
            String localName, SootClass tokenClass,
            SootMethod tokenConstructor, Value constructorArg) {
        RefType tokenType = RefType.v(tokenClass);
        Local tokenLocal = Jimple.v().newLocal(localName, tokenType);
        body.getLocals().add(tokenLocal);
        body.getUnits().insertBefore(
                Jimple.v().newAssignStmt(tokenLocal,
                        Jimple.v().newNewExpr(tokenType)), insertPoint);
        body.getUnits().insertBefore(
View Full Code Here

            ptolemy.data.type.Type type) {
        Chain units = body.getUnits();

        if (type instanceof ptolemy.data.type.BaseType
                || type instanceof ptolemy.data.type.MatrixType) {
            Local typeLocal = Jimple.v().newLocal("type_" + type.toString(),
                    RefType.v(baseTypeClass));
            body.getLocals().add(typeLocal);

            // This may look ugly, but wherever we insert type casts
            // it is more efficient and also much easier to optimize
            // during the translation process if we want to inline code.
            if (type.equals(ptolemy.data.type.BaseType.UNKNOWN)) {
                units.insertBefore(
                        Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        unknownTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.GENERAL)) {
                units.insertBefore(
                        Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        generalTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.BOOLEAN)) {
                units.insertBefore(
                        Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        booleanTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.BOOLEAN_MATRIX)) {
                units
                        .insertBefore(Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        booleanMatrixTypeField.makeRef())),
                                insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.COMPLEX)) {
                units.insertBefore(
                        Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        complexTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.COMPLEX_MATRIX)) {
                units
                        .insertBefore(Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        complexMatrixTypeField.makeRef())),
                                insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.DOUBLE)) {
                units.insertBefore(Jimple.v()
                        .newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        doubleTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.DOUBLE_MATRIX)) {
                units.insertBefore(Jimple.v().newAssignStmt(
                        typeLocal,
                        Jimple.v().newStaticFieldRef(
                                doubleMatrixTypeField.makeRef())), insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.FIX)) {
                units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                        Jimple.v().newStaticFieldRef(fixTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.FIX_MATRIX)) {
                units.insertBefore(Jimple.v().newAssignStmt(
                        typeLocal,
                        Jimple.v().newStaticFieldRef(
                                fixMatrixTypeField.makeRef())), insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.FLOAT)) {
                units
                        .insertBefore(Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        floatTypeField.makeRef())), insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.UNSIGNED_BYTE)) {
                units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                        Jimple.v().newStaticFieldRef(byteTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.INT)) {
                units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                        Jimple.v().newStaticFieldRef(intTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.INT_MATRIX)) {
                units.insertBefore(Jimple.v().newAssignStmt(
                        typeLocal,
                        Jimple.v().newStaticFieldRef(
                                intMatrixTypeField.makeRef())), insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.LONG)) {
                units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                        Jimple.v().newStaticFieldRef(longTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.LONG_MATRIX)) {
                units.insertBefore(Jimple.v().newAssignStmt(
                        typeLocal,
                        Jimple.v().newStaticFieldRef(
                                longMatrixTypeField.makeRef())), insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.OBJECT)) {
                units.insertBefore(Jimple.v()
                        .newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        objectTypeField.makeRef())),
                        insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.SHORT)) {
                units
                        .insertBefore(Jimple.v().newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        shortTypeField.makeRef())), insertPoint);
            } else if (type.equals(ptolemy.data.type.BaseType.STRING)) {
                units.insertBefore(Jimple.v()
                        .newAssignStmt(
                                typeLocal,
                                Jimple.v().newStaticFieldRef(
                                        stringTypeField.makeRef())),
                        insertPoint);
            } else {
                // Some base type that we didn't special case above.
                SootMethod typeConstructor = SootUtilities
                        .searchForMethodByName(baseTypeClass, "forName");
                units.insertBefore(Jimple.v().newAssignStmt(
                        typeLocal,
                        Jimple.v().newStaticInvokeExpr(
                                typeConstructor.makeRef(),
                                StringConstant.v(type.toString()))),
                        insertPoint);
            }

            return typeLocal;
        } else if (type instanceof ptolemy.data.type.ArrayType) {
            // recurse
            //SootMethod typeConstructor = SootUtilities.searchForMethodByName(
            //        arrayTypeClass, "<init>");
            // The array changes resulted in ArrayType having two
            // constructors: ArrayType(Type) and ArrayType(Type, int)
            SootMethod typeConstructor = arrayTypeClass
                    .getMethod("void <init>(ptolemy.data.type.Type)");

            Local elementTypeLocal = buildConstantTypeLocal(body, insertPoint,
                    ((ptolemy.data.type.ArrayType) type).getElementType());
            Local typeLocal = Jimple.v().newLocal(
                    "type_arrayOf" + elementTypeLocal.getName(),
                    RefType.v(arrayTypeClass));
            body.getLocals().add(typeLocal);
            units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                    Jimple.v().newNewExpr(RefType.v(arrayTypeClass))),
                    insertPoint);
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newSpecialInvokeExpr(typeLocal,
                            typeConstructor.makeRef(), elementTypeLocal)),
                    insertPoint);
            return typeLocal;
        } else if (type instanceof ptolemy.data.type.RecordType) {
            ptolemy.data.type.RecordType recordType = (ptolemy.data.type.RecordType) type;

            // recurse
            StringBuffer typeName = new StringBuffer("type_recordOf");

            // Create the new array of labels.
            Local labelArrayLocal = Jimple.v().newLocal("labelArray",
                    ArrayType.v(RefType.v("java.lang.String"), 1));
            body.getLocals().add(labelArrayLocal);
            units.insertBefore(Jimple.v().newAssignStmt(
                    labelArrayLocal,
                    Jimple.v().newNewArrayExpr(RefType.v("java.lang.String"),
                            IntConstant.v(recordType.labelSet().size()))),
                    insertPoint);

            // Create the new array of types.
            Local typeArrayLocal = Jimple.v().newLocal("typeArray",
                    ArrayType.v(RefType.v(typeClass), 1));
            body.getLocals().add(typeArrayLocal);
            units.insertBefore(Jimple.v().newAssignStmt(
                    typeArrayLocal,
                    Jimple.v().newNewArrayExpr(RefType.v(typeClass),
                            IntConstant.v(recordType.labelSet().size()))),
                    insertPoint);

            int count = 0;

            for (Iterator labels = recordType.labelSet().iterator(); labels
                    .hasNext(); count++) {
                String label = (String) labels.next();
                ptolemy.data.type.Type elementType = recordType.get(label);
                Local elementTypeLocal = buildConstantTypeLocal(body,
                        insertPoint, elementType);
                typeName.append("_" + label + "_" + elementTypeLocal.getName());

                // Store into the array of labels.
                units.insertBefore(
                        Jimple.v().newAssignStmt(
                                Jimple.v().newArrayRef(labelArrayLocal,
                                        IntConstant.v(count)),
                                StringConstant.v(label)), insertPoint);

                // Store into the array of types.
                units.insertBefore(Jimple.v().newAssignStmt(
                        Jimple.v().newArrayRef(typeArrayLocal,
                                IntConstant.v(count)), elementTypeLocal),
                        insertPoint);
            }

            // Create the new local and assign to local variable.
            Local typeLocal = Jimple.v().newLocal(typeName.toString(),
                    RefType.v(recordTypeClass));
            body.getLocals().add(typeLocal);
            units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                    Jimple.v().newNewExpr(RefType.v(recordTypeClass))),
                    insertPoint);

            // invoke the initializer.
            SootMethod typeConstructor = SootUtilities.searchForMethodByName(
                    recordTypeClass, "<init>");
            System.out.println("typeConstructor = " + typeConstructor);
            units.insertBefore(Jimple.v().newInvokeStmt(
                    Jimple.v().newSpecialInvokeExpr(typeLocal,
                            typeConstructor.makeRef(), labelArrayLocal,
                            typeArrayLocal)), insertPoint);
            return typeLocal;
        } else if (type instanceof ptolemy.data.type.FixType) {
            Local typeLocal = Jimple.v().newLocal("type_fix",
                    RefType.v(fixTypeClass));
            body.getLocals().add(typeLocal);
            units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                    Jimple.v().newStaticFieldRef(fixTypeField.makeRef())),
                    insertPoint);
            return typeLocal;
        } else if (type instanceof ptolemy.data.type.FunctionType) {
            ptolemy.data.type.FunctionType functionType = (ptolemy.data.type.FunctionType) type;

            // recurse
            String typeName = "type_function";

            // Create the new array of types.
            Local typeArrayLocal = Jimple.v().newLocal("typeArray",
                    ArrayType.v(RefType.v(typeClass), 1));
            body.getLocals().add(typeArrayLocal);
            units.insertBefore(Jimple.v().newAssignStmt(
                    typeArrayLocal,
                    Jimple.v().newNewArrayExpr(RefType.v(typeClass),
                            IntConstant.v(functionType.getArgCount()))),
                    insertPoint);

            for (int i = 0; i < functionType.getArgCount(); i++) {
                ptolemy.data.type.Type elementType = functionType.getArgType(i);
                Local elementTypeLocal = buildConstantTypeLocal(body,
                        insertPoint, elementType);

                // Store into the array of types.
                units.insertBefore(Jimple.v().newAssignStmt(
                        Jimple.v()
                                .newArrayRef(typeArrayLocal, IntConstant.v(i)),
                        elementTypeLocal), insertPoint);
            }

            Local returnTypeLocal = buildConstantTypeLocal(body, insertPoint,
                    functionType.getReturnType());

            // Create the new local and assign to local variable.
            Local typeLocal = Jimple.v().newLocal(typeName,
                    RefType.v(functionTypeClass));
            body.getLocals().add(typeLocal);
            units.insertBefore(Jimple.v().newAssignStmt(typeLocal,
                    Jimple.v().newNewExpr(RefType.v(functionTypeClass))),
                    insertPoint);
View Full Code Here

            SootClass theClass, SootMethod method, JimpleBody body,
            Object insertPoint) {
        // Make sure we have a local of type attribute to pass
        // to attributeChanged
        if (attributeLocal.getType() != attributeType) {
            Local oldAttributeLocal = attributeLocal;
            attributeLocal = Jimple.v().newLocal("attributeLocal",
                    attributeType);
            body.getLocals().add(attributeLocal);
            body.getUnits().insertBefore(
                    Jimple.v().newAssignStmt(
View Full Code Here

        // System.out.println("done loading support of " + className);
        RefType objectType = RefType.v(objectClass);

        // Create the new local with the given name.
        Local local = Jimple.v().newLocal(name, objectType);

        // Add the local to the body.
        body.getLocals().add(local);

        // Create the new local with the given name.
        Local attributeLocal = Jimple.v().newLocal(name, attributeType);

        // Add the local to the body.
        body.getLocals().add(attributeLocal);

        // Create the object.
View Full Code Here

        // Add this and read the parameters into locals
        body.insertIdentityStmts();
        constructor.setActiveBody(body);

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

        // get a list of the locals that reference the parameters of the
        // constructor.  What a nice hack.
        List parameterList = new ArrayList();
        parameterList.addAll(body.getLocals());
View Full Code Here

                            if (constructorExpr
                                    .getMethod()
                                    .getSignature()
                                    .equals(
                                            "<ptolemy.data.type.ArrayType: void <init>(ptolemy.data.type.Type)>")) {
                                Local arg1Local = (Local) constructorExpr
                                        .getArg(0);
                                ptolemy.data.type.Type elementType = getTypeValue(
                                        method, arg1Local, useStmt, localDefs,
                                        localUses);
                                return new ptolemy.data.type.ArrayType(
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.