Package soot

Examples of soot.Value


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

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

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

                if (r.getBase().getType() instanceof RefType) {
                    RefType type = (RefType) r.getBase().getType();

                    // Inline calls to connections changed.
                    if (r.getMethod().equals(
                            PtolemyUtilities.connectionsChangedMethod)) {
                        // If we are calling connections changed on one of the classes
                        // we are generating code for, then inline it.
                        if (type.getSootClass().isApplicationClass()) {
                            SootMethod inlinee = null;

                            if (r instanceof VirtualInvokeExpr) {
                                // Now inline the resulting call.
                                List methodList = Scene
                                        .v()
                                        .getActiveHierarchy()
                                        .resolveAbstractDispatch(
                                                type.getSootClass(),
                                                PtolemyUtilities.connectionsChangedMethod);

                                if (methodList.size() == 1) {
                                    // Inline the method.
                                    inlinee = (SootMethod) methodList.get(0);
                                } else {
                                    String string = "Can't inline " + stmt
                                            + " in method " + method + "\n";

                                    for (int i = 0; i < methodList.size(); i++) {
                                        string += ("target = "
                                                + methodList.get(i) + "\n");
                                    }

                                    System.out.println(string);
                                }
                            } else if (r instanceof SpecialInvokeExpr) {
                                inlinee = Scene.v().getActiveHierarchy()
                                        .resolveSpecialDispatch(
                                                (SpecialInvokeExpr) r, method);
                            }

                            if (inlinee != null
                                    && !inlinee.getDeclaringClass()
                                            .isApplicationClass()) {
                                inlinee.getDeclaringClass().setLibraryClass();
                            }

                            inlinee.retrieveActiveBody();

                            if (debug) {
                                System.out
                                        .println("Inlining method call: " + r);
                            }

                            SiteInliner.inlineSite(inlinee, stmt, method);

                            doneSomething = true;
                        } else {
                            // FIXME: this is a bit of a hack, but
                            // for right now it seems to work.
                            // How many things that aren't
                            // the actors we are generating
                            // code for do we really care about here?
                            // Can we do this without having to create
                            // a class for the port too????
                            body.getUnits().remove(stmt);
                            doneSomething = true;
                        }
                    }

                    // Statically evaluate constant arguments.
                    Value[] argValues = new Value[r.getArgCount()];
                    int constantArgCount = 0;

                    for (Iterator args = r.getArgs().iterator(); args.hasNext();) {
                        Value arg = (Value) args.next();

                        //System.out.println("arg = " + arg);
                        if (Evaluator.isValueConstantValued(arg)) {
                            argValues[constantArgCount++] = Evaluator
                                    .getConstantValueOf(arg);
View Full Code Here


            Unit location, LocalDefs localDefs, LocalUses localUses) {
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = stmt.getRightOp();

            if (value instanceof Local) {
                return getPortValue(method, (Local) value, stmt, localDefs,
                        localUses);
            } else if (value instanceof CastExpr) {
View Full Code Here

                                    .snapshotIterator(); units.hasNext();) {
                                Stmt unit = (Stmt) units.next();

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

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

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

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

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

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

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

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

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

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

                            // If we're constructing one of our actor classes,
View Full Code Here

            for (Iterator boxes = unit.getUseBoxes().iterator(); boxes
                    .hasNext();) {
                ValueBox box = (ValueBox) boxes.next();

                // FIXME: This is currently way too simple.
                Value value = box.getValue();
                /*Type type = */value.getType();

                if (value instanceof NewExpr) {
                    // Fix kernel exceptions to be runtime exceptions.
                    NewExpr expr = (NewExpr) value;
                    SootClass exceptionClass = expr.getBaseType()
                            .getSootClass();

                    if (_isPtolemyException(exceptionClass)) {
                        expr.setBaseType(RefType
                                .v(PtolemyUtilities.runtimeExceptionClass));
                    }
                } else if (value instanceof CastExpr) {
                    CastExpr expr = (CastExpr) value;
                    Type castType = expr.getCastType();

                    if (castType instanceof RefType
                            && _isPtolemyException(((RefType) castType)
                                    .getSootClass())) {
                        expr.setCastType(RefType
                                .v(PtolemyUtilities.runtimeExceptionClass));
                    }
                } else if (value instanceof SpecialInvokeExpr) {
                    // Fix the exception constructors.
                    SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
                    SootClass exceptionClass = ((RefType) expr.getBase()
                            .getType()).getSootClass();

                    if (_isPtolemyException(exceptionClass)) {
                        Value foundArg = null;

                        for (Iterator args = expr.getArgs().iterator(); args
                                .hasNext();) {
                            Value arg = (Value) args.next();

                            if (arg.getType().equals(
                                    RefType.v(PtolemyUtilities.stringClass))) {
                                foundArg = arg;
                                break;
                            }
                        }
View Full Code Here

                Unit unit = (Unit) units.next();
                Iterator boxes = unit.getUseBoxes().iterator();

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

                    if (value instanceof SpecialInvokeExpr) {
                        SpecialInvokeExpr r = (SpecialInvokeExpr) value;

                        if (PtolemyUtilities.executableInterface
View Full Code Here

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

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

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

                    if (r.getMethod().getSubSignature().equals(_getDirectorSig)) {
                        // Replace calls to getDirector with
                        // null.  FIXME: we should be able to
                        // do better than this?
                        if (unit instanceof InvokeStmt) {
                            body.getUnits().remove(unit);
                        } else {
                            box.setValue(NullConstant.v());
                        }
                    } else if (r.getMethod().getSubSignature().equals(
                            _getAttributeSig)) {
                        if (unit instanceof InvokeStmt) {
                            body.getUnits().remove(unit);
                        } else {
                            // Replace calls to getAttribute(arg)
                            // when arg is a string that can be
                            // statically evaluated.
                            Value nameValue = r.getArg(0);

                            if (Evaluator.isValueConstantValued(nameValue)) {
                                StringConstant nameConstant = (StringConstant) Evaluator
                                        .getConstantValueOf(nameValue);
                                String name = nameConstant.value;
View Full Code Here

            LocalDefs localDefs) {
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = stmt.getRightOp();

            if (value instanceof CastExpr) {
                return _getFieldDef((Local) ((CastExpr) value).getOp(), stmt,
                        localDefs);
            } else if (value instanceof FieldRef) {
View Full Code Here

        for (Iterator relations = port.linkedRelationList().iterator(); relations
                .hasNext();) {
            TypedIORelation relation = (TypedIORelation) relations.next();

            for (int i = 0; i < relation.getWidth(); i++, channel++) {
                Value channelValue = IntConstant.v(channel);

                SootField arrayField = _modelClass
                        .getFieldByName(InlinePortTransformer
                                .getBufferFieldName(relation, i, port.getType()));

                // load the buffer array.
                body.getUnits().insertBefore(
                        Jimple.v().newAssignStmt(
                                bufferLocal,
                                Jimple.v().newStaticFieldRef(
                                        arrayField.makeRef())), stmt);

                // If we are calling with just a token, then send the token.
                if (expr.getArgCount() == 1) {
                    // Write to the buffer.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    Jimple.v().newArrayRef(bufferLocal,
                                            channelValue), expr.getArg(0)),
                            stmt);
                } else {
                    // We must send an array of tokens.
                    // Ignore all but the last value.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(returnArrayLocal,
                                    expr.getArg(0)), stmt);

                    Value argCount = expr.getArg(1);

                    // Get the value.
                    body.getUnits().insertBefore(
                            Jimple.v().newAssignStmt(
                                    returnLocal,
View Full Code Here

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

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

TOP

Related Classes of soot.Value

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.