Package soot

Examples of soot.Value


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

        Value channelValue = expr.getArg(0);

        Value bufferSizeValue = _getBufferAndSize(body, stmt, port, port
                .getType(), channelValue, bufferLocal,
                _portToTypeNameToInsideBufferField, true);

        _getCorrectIndex(body, stmt, port, indexLocal, indexArrayLocal,
                channelValue, bufferSizeValue, _portToInsideIndexArrayField);

        // If we are calling with just a channel, then read the value.
        if (expr.getArgCount() == 1) {
            body.getUnits().insertAfter(
                    _createIndexUpdateInstructions(indexLocal, indexArrayLocal,
                            channelValue, bufferSizeValue), stmt);

            // 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, indexLocal));
            } 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 indexArrayLocal = Jimple.v().newLocal("indexArray",
                ArrayType.v(IntType.v(), 1));
        body.getLocals().add(indexArrayLocal);

        // The first argument is always the channel.
        Value channelValue = expr.getArg(0);

        // We have to repeat for all of the remote types.
        Set typeSet = _getConnectedTypeList(port);

        for (Iterator types = typeSet.iterator(); types.hasNext();) {
            ptolemy.data.type.Type type = (ptolemy.data.type.Type) types.next();
            Local typeLocal = null;

            if (_forceConversions || !port.getType().equals(type)) {
                typeLocal = PtolemyUtilities.buildConstantTypeLocal(body, stmt,
                        type);
            }

            Value bufferSizeValue = _getBufferAndSize(body, stmt, port, type,
                    channelValue, bufferLocal, _portToTypeNameToBufferField,
                    false);

            _getCorrectIndex(body, stmt, port, indexLocal, indexArrayLocal,
                    channelValue, bufferSizeValue, _portToIndexArrayField);

            // A local of type token
            Local tokenLocal = Jimple.v().newLocal("tokenLocal",
                    PtolemyUtilities.tokenType);
            body.getLocals().add(tokenLocal);

            // A local of the appropriate type to store in the
            // buffer.
            Local outputTokenLocal = Jimple.v().newLocal("outputTokenLocal",
                    PtolemyUtilities.getSootTypeForTokenType(type));
            body.getLocals().add(outputTokenLocal);

            // If we are calling with just a channel, then write the value.
            if (expr.getArgCount() == 2) {
                Local sendTokenLocal = (Local) expr.getArg(1);

                // Replace the put() with an array write.
                body.getUnits().insertBefore(
                        _createBufferStoreInstructions(bufferLocal, indexLocal,
                                sendTokenLocal, typeLocal, tokenLocal,
                                outputTokenLocal), stmt);

                // increment the position in the buffer.
                body.getUnits()
                        .insertBefore(
                                _createIndexUpdateInstructions(indexLocal,
                                        indexArrayLocal, channelValue,
                                        bufferSizeValue), stmt);
            } else {
                Local sendArrayLocal = (Local) expr.getArg(1);

                /*                Jimple.v().newLocal("sendArray",
                 ArrayType.v(PtolemyUtilities.tokenType, 1));
                 body.getLocals().add(sendArrayLocal);

                 // We must send an array of tokens.
                 body.getUnits().insertBefore(
                 Jimple.v().newAssignStmt(
                 sendArrayLocal,
                 expr.getArg(1)),
                 stmt);*/
                Value countValue = expr.getArg(2);

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

View Full Code Here

        Local indexArrayLocal = Jimple.v().newLocal("indexArray",
                ArrayType.v(IntType.v(), 1));
        body.getLocals().add(indexArrayLocal);

        // The first argument is always the channel.
        Value channelValue = expr.getArg(0);

        // We have to repeat for all of the remote types.
        Set typeSet = _getConnectedTypeListInside(port);

        for (Iterator types = typeSet.iterator(); types.hasNext();) {
            ptolemy.data.type.Type type = (ptolemy.data.type.Type) types.next();
            Local typeLocal = null;

            if (_forceConversions || !port.getType().equals(type)) {
                typeLocal = PtolemyUtilities.buildConstantTypeLocal(body, stmt,
                        type);
            }

            Value bufferSizeValue = _getBufferAndSize(body, stmt, port, type,
                    channelValue, bufferLocal,
                    _portToTypeNameToInsideBufferField, true);

            _getCorrectIndex(body, stmt, port, indexLocal, indexArrayLocal,
                    channelValue, bufferSizeValue, _portToInsideIndexArrayField);

            // A local of type token
            Local tokenLocal = Jimple.v().newLocal("tokenLocal",
                    PtolemyUtilities.tokenType);
            body.getLocals().add(tokenLocal);

            // A local of the appropriate type to store in the
            // buffer.
            Local outputTokenLocal = Jimple.v().newLocal("outputTokenLocal",
                    PtolemyUtilities.getSootTypeForTokenType(type));
            body.getLocals().add(outputTokenLocal);

            // If we are calling with just a channel, then write the value.
            if (expr.getArgCount() == 2) {
                Local sendTokenLocal = (Local) expr.getArg(1);

                // Replace the put() with an array write.
                body.getUnits().insertBefore(
                        _createBufferStoreInstructions(bufferLocal, indexLocal,
                                sendTokenLocal, typeLocal, tokenLocal,
                                outputTokenLocal), stmt);

                // increment the position in the buffer.
                body.getUnits()
                        .insertBefore(
                                _createIndexUpdateInstructions(indexLocal,
                                        indexArrayLocal, channelValue,
                                        bufferSizeValue), stmt);
            } else {
                Local sendArrayLocal = (Local) expr.getArg(1);

                /*                Jimple.v().newLocal("sendArray",
                 ArrayType.v(PtolemyUtilities.tokenType, 1));
                 body.getLocals().add(sendArrayLocal);

                 // We must send an array of tokens.
                 body.getUnits().insertBefore(
                 Jimple.v().newAssignStmt(
                 sendArrayLocal,
                 expr.getArg(1)),
                 stmt);*/
                Value countValue = expr.getArg(2);

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

View Full Code Here

    private Value _getBufferAndSize(JimpleBody body, Stmt stmt,
            TypedIOPort port, ptolemy.data.type.Type type, Value channelValue,
            Local bufferLocal, Map portToTypeNameToBufferField, boolean inside) {
        SootClass theClass = body.getMethod().getDeclaringClass();

        Value bufferSizeValue = null;

        // Now get the appropriate buffer
        if (Evaluator.isValueConstantValued(channelValue)) {
            // If we know the channel, then refer directly to the buffer in the
            // _model
View Full Code Here

            }

            for (Iterator boxes = unit.getDefBoxes().iterator(); boxes
                    .hasNext();) {
                ValueBox box = (ValueBox) boxes.next();
                Value value = box.getValue();

                if (value instanceof FieldRef) {
                    if (_debug) {
                        System.out
                                .println("SideEffectAnalysis: assigns to field");
                    }

                    out.addSideEffect(((FieldRef) value).getField());
                }

                if (value instanceof ArrayRef) {
                    if (_debug) {
                        System.out
                                .println("SideEffectAnalysis: assigns to array.");
                    }

                    // Escape analysis might help in this case.
                    out.setUnknownSideEffects();
                    return out;
                }
            }

            // Method calls that are in the invokeGraph
            // have already been checked.
            // However, it turns out that context classes
            // are not included in the
            // invokeGraph!  This checks to see if there
            // are any invocations of
            // methods that are not in the invoke graph.  Conservatively
            // assume that they have side effects.
            for (Iterator boxes = unit.getUseBoxes().iterator(); boxes
                    .hasNext();) {
                ValueBox box = (ValueBox) boxes.next();
                Value expr = box.getValue();

                if (expr instanceof InvokeExpr) {
                    SootMethod invokedMethod = ((InvokeExpr) expr).getMethod();

                    // It appears that soot does not automatically
View Full Code Here

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

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

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

                if (debug) {
                    System.out.println("invoking = " + r.getMethod());
                }

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

                    if (debug) {
                        System.out.println("baseType = " + type);
                    }

                    // Remove calls to validate().
                    if (r.getMethod().equals(PtolemyUtilities.validateMethod)) {
                        body.getUnits().remove(stmt);
                        continue;
                    } else {
                        // Inline calls to attribute changed that do
                        // not occur from within another
                        // attributeChanged method.
                        if (r.getMethod().getSubSignature().equals(
                                PtolemyUtilities.attributeChangedMethod
                                        .getSubSignature())) {
                            // If we are calling attribute 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) {
                                    inlinee = SootUtilities
                                            .resolveVirtualInvokationForInlining(
                                                    type.getSootClass(),
                                                    PtolemyUtilities.attributeChangedMethod);
                                } else if (r instanceof SpecialInvokeExpr) {
                                    inlinee = SootUtilities
                                            .resolveSpecialInvokationForInlining(
                                                    (SpecialInvokeExpr) r,
                                                    method);
                                }

                                if (inlinee.equals(method)) {
                                    System.out
                                            .println("Skipping inline at "
                                                    + r
                                                    + " because we can't inline methods into themselves.");
                                } else {
                                    if (debug) {
                                        System.out
                                                .println("Inlining method call: "
                                                        + r);
                                    }

                                    if (debug) {
                                        System.out.println("Inlinee = "
                                                + inlinee);
                                    }

                                    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 attribute too????
                                body.getUnits().remove(stmt);
                                doneSomething = true;
                            }
                        }
                    }

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

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

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

        //}
        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 getAttributeContainerRef(container, method,
                        (Local) value, stmt, localDefs, localUses, insertPoint);
            } else if (value instanceof CastExpr) {
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 getAttributeValue(method, (Local) value, stmt,
                        localDefs, localUses);
            } else if (value instanceof CastExpr) {
View Full Code Here

        SimpleLiveLocals liveLocals = new SimpleLiveLocals(unitGraph);

        for (Iterator units = body.getUnits().snapshotIterator(); units
                .hasNext();) {
            Unit unit = (Unit) units.next();
            Value useValue;

            // Find a method invocation that doesn't have a return
            // value, or whose return value is dead.
            if (unit instanceof DefinitionStmt) {
                DefinitionStmt stmt = (DefinitionStmt) unit;
                Value left = stmt.getLeftOp();

                // If this statement defines a local that is later used,
                // then we cannot remove it.
                if (liveLocals.getLiveLocalsAfter(stmt).contains(left)) {
                    continue;
View Full Code Here

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

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

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

                    if (PtolemyUtilities.executableInterface.declaresMethod(r
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.