Package soot

Examples of soot.SootField


        if (entity != null) {
            // Then we are dealing with a getPort call on one of the
            // classes we are generating.
            Port port = entity.getPort(name);
            SootField portField = (SootField) _portToFieldMap.get(port);

            if (portField != null) {
                return Jimple.v().newInstanceFieldRef(baseLocal,
                        portField.makeRef());
            } else {
                return NullConstant.v();
            }
        } else {
            // Walk back and get the definition of the field.
            DefinitionStmt definition = _getFieldDef(baseLocal, unit, localDefs);
            InstanceFieldRef fieldRef = (InstanceFieldRef) definition
                    .getRightOp();
            SootField baseField = fieldRef.getField();
            System.out.println("baseField = " + baseField);

            SootField portField = baseField.getDeclaringClass().getFieldByName(
                    baseField.getName() + "_" + name);
            return Jimple.v().newInstanceFieldRef(baseLocal,
                    portField.makeRef());
        }
    }
View Full Code Here


        for (Iterator ports = object.portList().iterator(); ports.hasNext();) {
            Port port = (Port) ports.next();

            String fieldName = ModelTransformer.getFieldNameForPort(port,
                    container);
            SootField field;

            if (!theClass.declaresFieldByName(fieldName)) {
                //                 throw new RuntimeException("Class " + theClass
                //                         + " does not declare field "
                //                         + fieldName + " for port "
                //                         + port.getFullName());
            }

            // retrieve the existing field.
            field = theClass.getFieldByName(fieldName);

            Type type = field.getType();

            if (!(type instanceof RefType)) {
                System.out.println("Class " + theClass
                        + " declares field for port " + port.getFullName()
                        + " but it has type " + type);
                continue;
            } else {
                SootClass fieldClass = ((RefType) type).getSootClass();

                if (!SootUtilities.derivesFrom(fieldClass,
                        PtolemyUtilities.componentPortClass)) {
                    System.out.println("Class " + theClass
                            + " declares field for port " + port.getFullName()
                            + " but it has type " + fieldClass.getName());
                    continue;
                }
            }

            // Make the field final and private.
            field.setModifiers((field.getModifiers() & Modifier.STATIC)
                    | Modifier.FINAL | Modifier.PUBLIC); // | Modifier.PRIVATE);

            field.addTag(new ValueTag(port));
            _portToFieldMap.put(port, field);

            // FIXME: call recursively
            // _getAttributeFields(theClass, container,
            //        attribute, attributeToFieldMap);
View Full Code Here

            // Assume that any method that is part of an interface that this
            // object implements, is reachable.
            for (Iterator fields = theClass.getFields().iterator(); fields
                    .hasNext();) {
                SootField field = (SootField) fields.next();
                field.setModifiers(field.getModifiers() & ~Modifier.FINAL);
            }
        }
    }
View Full Code Here

                modelClass, model, options));
        System.out.println("Inlining director for " + model.getFullName());

        Type actorType = RefType.v(PtolemyUtilities.actorClass);

        SootField postfireReturnsField = new SootField("_postfireReturns",
                BooleanType.v(), Modifier.PRIVATE);
        modelClass.addField(postfireReturnsField);

        int iterationLimit = 0;
        SDFDirector director = (SDFDirector) model.getDirector();

        if (director != null) {
            Attribute attribute = director.getAttribute("iterations");

            if (attribute instanceof Variable) {
                IntToken token = (IntToken) ((Variable) attribute).getToken();
                iterationLimit = token.intValue();
            }
        }
        // Inline the director
        {
            // populate the preinitialize method
            SootMethod classMethod = modelClass
                    .getMethodByName("preinitialize");
            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);

            // Initialize the postfire flag.
            units.insertBefore(Jimple.v().newAssignStmt(postfireReturnsLocal,
                    IntConstant.v(1)), insertPoint);
            units.insertBefore(Jimple.v().newAssignStmt(
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            postfireReturnsField.makeRef()),
                    postfireReturnsLocal), insertPoint);

            // 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.insertBefore(Jimple.v().newReturnVoidStmt(),
            //                   insertPoint);
        }

        SootField iterationField = new SootField("_iteration", IntType.v());
        modelClass.addField(iterationField);

        {
            // 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();

            if (iterationLimit > 0) {
                units.insertBefore(Jimple.v().newAssignStmt(
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                iterationField.makeRef()), IntConstant.v(0)),
                        insertPoint);
            }

            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.insertBefore(Jimple.v().newReturnVoidStmt(),insertPoint);
        }
        // ModelTransformer does this.
        //         {
        //             // populate the prefire method
        //             SootMethod classMethod =
        //                 modelClass.getMethodByName("prefire");
        //             JimpleBody body = (JimpleBody)classMethod.getActiveBody();
        //             Stmt insertPoint = body.getFirstNonIdentityStmt();
        //             Chain units = body.getUnits();
        //             Local thisLocal = body.getThisLocal();
        //             Local prefireReturnsLocal =
        //                 Jimple.v().newLocal("preReturns", BooleanType.v());
        //             body.getLocals().add(prefireReturnsLocal);
        //             units.insertBefore(Jimple.v().newAssignStmt(prefireReturnsLocal,
        //                     IntConstant.v(1)),
        //                     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 actorLocal = Jimple.v().newLocal("actor", actorType);
            body.getLocals().add(actorLocal);

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

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

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

            // Update PortParameters.
            for (Iterator parameters = model.attributeList(PortParameter.class)
                    .iterator(); parameters.hasNext();) {
                PortParameter parameter = (PortParameter) parameters.next();
                String fieldName = ModelTransformer.getFieldNameForAttribute(
                        parameter, model);
                SootField field = modelClass.getFieldByName(fieldName);
                RefType fieldType = (RefType) field.getType();
                Local parameterLocal = Jimple.v().newLocal("parameter",
                        fieldType);
                SootClass fieldClass = fieldType.getSootClass();

                body.getLocals().add(parameterLocal);

                // Get a reference to the port parameter.
                units.insertBefore(Jimple.v().newAssignStmt(
                        parameterLocal,
                        Jimple.v().newInstanceFieldRef(thisLocal,
                                field.makeRef())), insertPoint);

                // Invoke the update() method.
                units
                        .insertBefore(
                                Jimple
                                        .v()
                                        .newInvokeStmt(
                                                Jimple
                                                        .v()
                                                        .newVirtualInvokeExpr(
                                                                parameterLocal,
                                                                fieldClass
                                                                        .getMethod(
                                                                                PtolemyUtilities.portParameterUpdateMethod
                                                                                        .getSubSignature())
                                                                        .makeRef())),
                                insertPoint);
            }

            // FIXME: This is the quiescent point where parameters
            // reconfigured as a result of port parameters should be
            // evaluated.
            // Transfer Inputs from input ports.
            for (Iterator ports = model.inputPortList().iterator(); ports
                    .hasNext();) {
                IOPort port = (IOPort) ports.next();

                if (port instanceof ParameterPort) {
                    continue;
                }

                int rate;
                rate = DFUtilities.getTokenConsumptionRate(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.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);
                }
            }

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

            units.insertBefore(Jimple.v().newAssignStmt(
                    postfireReturnsLocal,
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            postfireReturnsField.makeRef())), insertPoint);

            // Execute the schedule
            Iterator schedule = null;

            try {
                schedule = director.getScheduler().getSchedule()
                        .firingIterator();
            } catch (Exception ex) {
                throw new KernelRuntimeException(ex, "Failed to get schedule");
            }

            while (schedule.hasNext()) {
                Firing firing = (Firing) schedule.next();

                Entity entity = (Entity) firing.getActor();
                int firingCount = firing.getIterationCount();
                String fieldName = ModelTransformer.getFieldNameForEntity(
                        entity, model);
                SootField field = modelClass.getFieldByName(fieldName);
                String className = ModelTransformer.getInstanceClassName(
                        entity, options);
                SootClass theClass = Scene.v().loadClassAndSupport(className);
                SootMethod actorPrefireMethod = SootUtilities
                        .searchForMethodByName(theClass, "prefire");
                SootMethod actorFireMethod = SootUtilities
                        .searchForMethodByName(theClass, "fire");
                SootMethod actorPostfireMethod = SootUtilities
                        .searchForMethodByName(theClass, "postfire");

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

                // The threshold at which it is better to generate loops,
                // than to inline code.  A threshold of 2 means that loops will
                // always be used.
                // FIXME: This should be a command line option.
                int threshold = 2;

                if (firingCount < threshold) {
                    for (int i = 0; i < firingCount; i++) {
                        units.insertBefore(Jimple.v().newInvokeStmt(
                                Jimple.v().newVirtualInvokeExpr(actorLocal,
                                        actorPrefireMethod.makeRef())),
                                insertPoint);
                        units.insertBefore(Jimple.v().newInvokeStmt(
                                Jimple.v().newVirtualInvokeExpr(actorLocal,
                                        actorFireMethod.makeRef())),
                                insertPoint);
                        units.insertBefore(Jimple.v().newAssignStmt(
                                localPostfireReturnsLocal,
                                Jimple.v().newVirtualInvokeExpr(actorLocal,
                                        actorPostfireMethod.makeRef())),
                                insertPoint);
                        units.insertBefore(Jimple.v().newAssignStmt(
                                postfireReturnsLocal,
                                Jimple.v().newAndExpr(postfireReturnsLocal,
                                        localPostfireReturnsLocal)),
                                insertPoint);
                    }
                } else {
                    // 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();
                    bodyList.add(Jimple.v().newInvokeStmt(
                            Jimple.v().newVirtualInvokeExpr(actorLocal,
                                    actorPrefireMethod.makeRef())));
                    bodyList.add(Jimple.v().newInvokeStmt(
                            Jimple.v().newVirtualInvokeExpr(actorLocal,
                                    actorFireMethod.makeRef())));
                    bodyList.add(Jimple.v().newAssignStmt(
                            localPostfireReturnsLocal,
                            Jimple.v().newVirtualInvokeExpr(actorLocal,
                                    actorPostfireMethod.makeRef())));
                    bodyList.add(Jimple.v().newAssignStmt(
                            postfireReturnsLocal,
                            Jimple.v().newAndExpr(postfireReturnsLocal,
                                    localPostfireReturnsLocal)));

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

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

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

            // Transfer outputs from output ports
            for (Iterator ports = model.outputPortList().iterator(); ports
                    .hasNext();) {
                IOPort port = (IOPort) ports.next();
                int rate;
                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.getWidthInside(); 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.insertBefore(Jimple.v().newAssignStmt(
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            postfireReturnsField.makeRef()),
                    postfireReturnsLocal), insertPoint);

            //       units.insertBefore(Jimple.v().newReturnVoidStmt(),
            //              insertPoint);
            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);
            units.insertBefore(Jimple.v().newAssignStmt(
                    postfireReturnsLocal,
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            postfireReturnsField.makeRef())), insertPoint);

            // If we need to keep track of the number of iterations, then...
            if (iterationLimit > 0) {
                Local iterationLocal = null;
                iterationLocal = Jimple.v().newLocal("iteration", IntType.v());
                body.getLocals().add(iterationLocal);

                // Get the current number of iterations
                units.insertBefore(Jimple.v().newAssignStmt(
                        iterationLocal,
                        Jimple.v().newInstanceFieldRef(body.getThisLocal(),
                                iterationField.makeRef())), insertPoint);

                // Increment the number of iterations.
                units.insertBefore(Jimple.v()
                        .newAssignStmt(
                                iterationLocal,
                                Jimple.v().newAddExpr(iterationLocal,
                                        IntConstant.v(1))), insertPoint);

                // Save the current number of iterations
                units.insertBefore(Jimple.v().newAssignStmt(
                        Jimple.v().newInstanceFieldRef(body.getThisLocal(),
                                iterationField.makeRef()), iterationLocal),
                        insertPoint);

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

                // If the number of iterations is less than then
                // limit, then don't force postfire return to be
                // false.
                units.insertBefore(Jimple.v().newIfStmt(
                        Jimple.v().newLtExpr(iterationLocal,
                                IntConstant.v(iterationLimit)), endStmt),
                        insertPoint);
                units.insertBefore(Jimple.v().newAssignStmt(
                        postfireReturnsLocal, IntConstant.v(0)), // FALSE
                        insertPoint);
                units.insertBefore(endStmt, 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();
                String fieldName = ModelTransformer.getFieldNameForEntity(
                        entity, model);
                SootField field = modelClass.getFieldByName(fieldName);
                String className = ModelTransformer.getInstanceClassName(
                        entity, options);
                SootClass theClass = Scene.v().loadClassAndSupport(className);
                SootMethod wrapupMethod = SootUtilities.searchForMethodByName(
                        theClass, "wrapup");

                // 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,
                                wrapupMethod.makeRef())), insertPoint);
            }
View Full Code Here

                Local entityContainerLocal = getLocalReferenceForEntity(
                        entityContainer, sourceClass, local, body, unit,
                        options);
                String fieldName = ModelTransformer.getFieldNameForEntity(
                        entity, entityContainer);
                SootField field = entityContainerClass
                        .getFieldByName(fieldName);
                Local newLocal = Jimple.v().newLocal("container",
                        RefType.v(PtolemyUtilities.entityClass));
                body.getLocals().add(newLocal);
                body.getUnits()
                        .insertBefore(
                                Jimple.v().newAssignStmt(
                                        newLocal,
                                        Jimple.v().newInstanceFieldRef(
                                                entityContainerLocal,
                                                field.makeRef())), unit);
                return newLocal;
            } else {
                // Otherwise, the source class must be something up
                // the hierarchy.
                CompositeEntity container = (CompositeEntity) sourceEntity
                        .getContainer();
                SootClass containerClass = ModelTransformer
                        .getClassForActor(container);
                RefType type = RefType.v(containerClass);
                Local containerLocal = Jimple.v().newLocal("container", type);
                SootField field = sourceClass.getFieldByName(ModelTransformer
                        .getContainerFieldName());
                body.getLocals().add(containerLocal);
                body.getUnits().insertBefore(
                        Jimple.v().newAssignStmt(
                                containerLocal,
                                Jimple.v().newInstanceFieldRef(local,
                                        field.makeRef())), unit);
                return getLocalReferenceForEntity(entity, containerClass,
                        containerLocal, body, unit, options); // FIXME!
            }
        } else {
            // Then the source class must be a class for a settable attribute.
            NamedObj sourceObject = ModelTransformer
                    .getObjectForClass(sourceClass);
            Entity container = (Entity) sourceObject.getContainer();

            //             System.out.println("sourceObject = " + sourceObject);
            //             System.out.println("container = " + container);
            SootClass containerClass = ModelTransformer
                    .getClassForActor(container);
            RefType type = RefType.v(containerClass);
            Local containerLocal = Jimple.v().newLocal("container", type);
            SootField field = sourceClass.getFieldByName(ModelTransformer
                    .getContainerFieldName());
            body.getLocals().add(containerLocal);
            body.getUnits().insertBefore(
                    Jimple.v().newAssignStmt(
                            containerLocal,
                            Jimple.v().newInstanceFieldRef(local,
                                    field.makeRef())), unit);

            //   Local containerLocal = Jimple.v().newLocal("container",
            //                                 RefType.v(PtolemyUtilities.entityClass));
            //             body.getLocals().add(containerLocal);
            //             body.getUnits().insertBefore(
View Full Code Here

                        container.getClass().getName());
            }

            //           System.out.println("container = " + container);
            //             System.out.println("containerClass = " + containerClass);
            SootField field = new SootField(ModelTransformer
                    .getContainerFieldName(), RefType.v(containerClass),
                    Modifier.PUBLIC);

            theClass.addField(field);

            field.addTag(new ValueTag(container));

            ModelTransformer.addFieldForObject(field, container);

            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                if (method.getName().equals("<init>")) {
                    if (method.getParameterCount() == 2) {
                        // Assign to the container field.  Assume this
                        // is a container, name constructor.  Note
                        // that classes might have strange types for
                        // the first argument, so it is hard to just
                        // grab the right constructor.
                        JimpleBody body = (JimpleBody) method.getActiveBody();
                        Stmt insertPoint = (Stmt) body.getUnits().getLast();
                        body.getUnits()
                                .insertBefore(
                                        Jimple.v().newAssignStmt(
                                                Jimple.v().newInstanceFieldRef(
                                                        body.getThisLocal(),
                                                        field.makeRef()),
                                                body.getParameterLocal(0)),
                                        insertPoint);
                    } else {
                        // Assign null to the container field.
                        JimpleBody body = (JimpleBody) method.getActiveBody();
                        Stmt insertPoint = (Stmt) body.getUnits().getLast();
                        body.getUnits().insertBefore(
                                Jimple.v().newAssignStmt(
                                        Jimple.v().newInstanceFieldRef(
                                                body.getThisLocal(),
                                                field.makeRef()),
                                        NullConstant.v()), insertPoint);
                    }
                }
            }
        }
View Full Code Here

                                    ModelTransformer.getContainerFieldName())
                                    .makeRef());
        } else {
            DefinitionStmt stmt = _getFieldDef(baseLocal, unit, localDefs);
            FieldRef ref = (FieldRef) stmt.getRightOp();
            SootField field = ref.getField();
            Entity entity = ModelTransformer.getEntityForField(field);
            Entity container = (Entity) entity.getContainer();
            return getLocalReferenceForEntity(container, sourceClass, body
                    .getThisLocal(), body, unit, _options);
        }
View Full Code Here

            // classes we are generating.
            entity = ((CompositeEntity) object).getEntity(name);
        } else {
            DefinitionStmt stmt = _getFieldDef(baseLocal, unit, localDefs);
            FieldRef ref = (FieldRef) stmt.getRightOp();
            SootField field = ref.getField();
            CompositeEntity container = (CompositeEntity) ModelTransformer
                    .getEntityForField(field);
            entity = container.getEntity(name);
        }
View Full Code Here

        SootUtilities.assertFinalField(mainClass, mainClass
                .getFieldByName("_test"), IntConstant.v(0));

        // We know that we have exactly one model, so create it.
        // The final field for the model.
        SootField modelField = new SootField("_CGmodel", RefType.v(modelClass),
                Modifier.PRIVATE); // | Modifier.FINAL);
        mainClass.addField(modelField);

        // initialize the field by creating a model
        // in all the <init> methods.
        for (Iterator methods = mainClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();

            // ignore things that aren't initializers.
            if (!method.getName().equals("<init>")) {
                continue;
            }

            //  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);
            }
View Full Code Here

  public void calculateStaticFieldSize(){
    m_staticFieldSize = 0;
    determineFieldTypes();
    for(OpenCLField field : m_allUsedInstanceFields){
      SootField soot_field = field.getSootField();
      if(soot_field.isStatic() == false)
        continue;
      OpenCLType type = new OpenCLType(soot_field.getType());
      m_staticFieldSize += type.getSize();
    }
  }
View Full Code Here

TOP

Related Classes of soot.SootField

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.