Package ptolemy.codegen.kernel

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper$Channel


        }

        Iterator actors = container.deepEntityList().iterator();
        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            int[][] rates = actorHelper.getRates();
            // If a refinement has only one configuration, then there is no
            // need to use variables.
            if (!(actor instanceof Refinement && rates == null)) {
                Iterator inputPorts = actor.inputPortList().iterator();
                while (inputPorts.hasNext()) {
View Full Code Here


        // in each port for each configuration and then check if a
        // variable is needed for the offset. For now we always use
        // variables.

        StringBuffer code = new StringBuffer();
        CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper(port
                .getContainer());

        // When buffer size is no greater than 1, there is no need for
        // offset variable.
        if (actorHelper.getBufferSize(port) <= 1) {
            return code.toString();
        }

        int width = 0;
        if (port.isInput()) {
            width = port.getWidth();
        } else {
            width = port.getWidthInside();
        }
        for (int channel = 0; channel < width; channel++) {

            // Increase the buffer size of that channel to the power of two.
            int bufferSize = _ceilToPowerOfTwo(actorHelper.getBufferSize(port,
                    channel));
            actorHelper.setBufferSize(port, channel, bufferSize);

            StringBuffer channelReadOffset = new StringBuffer();
            StringBuffer channelWriteOffset = new StringBuffer();
            channelReadOffset.append(CodeGeneratorHelper.generateName(port));
            channelWriteOffset.append(CodeGeneratorHelper.generateName(port));

            if (width > 1) {
                channelReadOffset.append("_" + channel);
                channelWriteOffset.append("_" + channel);
            }

            channelReadOffset.append("_readOffset");
            channelWriteOffset.append("_writeOffset");

            String channelReadOffsetVariable = channelReadOffset.toString();
            String channelWriteOffsetVariable = channelWriteOffset.toString();

            code.append("static int " + channelReadOffsetVariable + " = "
                    + actorHelper.getReadOffset(port, channel) + ";" + _eol);
            code.append("static int " + channelWriteOffsetVariable + " = "
                    + actorHelper.getWriteOffset(port, channel) + ";" + _eol);

            // Now replace these concrete offsets with the variables.
            actorHelper.setReadOffset(port, channel, channelReadOffsetVariable);
            actorHelper.setWriteOffset(port, channel,
                    channelWriteOffsetVariable);
        }
        return code.toString();
    }
View Full Code Here

        CompositeActor container = (CompositeActor) director.getContainer();

        ptolemy.domains.fsm.kernel.FSMActor controller = director
                .getController();

        CodeGeneratorHelper refinementHelper = (CodeGeneratorHelper) _getHelper((NamedObj) refinement);

        CodeGeneratorHelper controllerHelper = (CodeGeneratorHelper) _getHelper(controller);

        CodeGeneratorHelper containerHelper = (CodeGeneratorHelper) _getHelper(container);

        List refinementPorts = ((Entity) refinement).portList();
        List controllerPorts = controller.portList();
        List containerPorts = container.portList();

        for (int i = 0; i < refinementPorts.size(); i++) {

            IOPort refinementPort = (IOPort) refinementPorts.get(i);
            IOPort controllerPort = (IOPort) controllerPorts.get(i);
            IOPort containerPort = (IOPort) containerPorts.get(i);

            // Update the corresponding controller port buffer size.
            // Notice that all channels have same buffer size.
            int oldSize = controllerHelper.getBufferSize(controllerPort, 0);
            if (oldSize < portRates[i]) {
                for (int j = 0; j < controllerPort.getWidth(); j++) {
                    controllerHelper.setBufferSize(controllerPort, j,
                            portRates[i]);
                }
            }

            if (refinementPort.isInput()) {
                // Update the input port buffer size of the refinement.
                oldSize = refinementHelper.getBufferSize(refinementPort, 0);
                if (oldSize < portRates[i]) {
                    for (int j = 0; j < refinementPort.getWidth(); j++) {
                        refinementHelper.setBufferSize(refinementPort, j,
                                portRates[i]);
                    }
                }
            } else {
                // Update the output port buffer size of the container actor.
                oldSize = containerHelper.getBufferSize(containerPort, 0);
                if (oldSize < portRates[i]) {
                    for (int j = 0; j < containerPort.getWidthInside(); j++) {
                        containerHelper.setBufferSize(containerPort, j,
                                portRates[i]);
                    }
                }
            }
        }
View Full Code Here

            Actor actor = firing.getActor();

            // FIXME: Before looking for a helper class, we should check to
            // see whether the actor contains a code generator attribute.
            // If it does, we should use that as the helper.
            CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);

            if (inline) {
                for (int i = 0; i < firing.getIterationCount(); i++) {

                    // generate fire code for the actor
                    code.append(helper.generateFireCode());
                    code.append(helper.generateTypeConvertFireCode());

                    // update buffer offset after firing each actor once
                    Iterator inputPorts = actor.inputPortList().iterator();
                    while (inputPorts.hasNext()) {
                        IOPort port = (IOPort) inputPorts.next();
View Full Code Here

        code.append(str_director);
        /////
       
        ptolemy.actor.CompositeActor container = (ptolemy.actor.CompositeActor) getComponent()
                .getContainer();
        CodeGeneratorHelper containerHelper = (CodeGeneratorHelper) _getHelper(container);

        // Generate code for creating external initial production.
        Iterator outputPorts = container.outputPortList().iterator();
        while (outputPorts.hasNext()) {
            IOPort outputPort = (IOPort) outputPorts.next();
            int rate = DFUtilities.getTokenInitProduction(outputPort);

            if (rate > 0) {
                for (int i = 0; i < outputPort.getWidthInside(); i++) {
                    if (i < outputPort.getWidth()) {
                        String name = outputPort.getName();

                        if (outputPort.isMultiport()) {
                            name = name + '#' + i;
                        }

                        for (int k = 0; k < rate; k++) {
                            code.append(CodeStream.indent(containerHelper
                                    .getReference(name + "," + k)));
                            code.append(" = ");
                            code.append(containerHelper.getReference("@" + name
                                    + "," + k));
                            code.append(";" + _eol);
                        }
                    }
                }
View Full Code Here

     */
    protected String _createDynamicOffsetVariables(IOPort port)
            throws IllegalActionException {
        StringBuffer code = new StringBuffer();

        CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(port
                .getContainer());

        int width;
        if (port.isInput()) {
            width = port.getWidth();
        } else {
            width = port.getWidthInside();
        }

        if (width != 0) {
            // Declare the read offset variable.
            String channelReadOffset = CodeGeneratorHelper.generateName(port);
            channelReadOffset += "_readOffset";

            // Now replace the concrete offset with the variable.
            for (int i = 0; i < width; i++) {
                helper
                        .setReadOffset(port, i, channelReadOffset + "[" + i
                                + "]");
            }
            channelReadOffset += "[" + width + "]";
            code.append("static int " + channelReadOffset + ";\n");

            // Declare the write offset variable.
            String channelWriteOffset = CodeGeneratorHelper.generateName(port);

            channelWriteOffset += "_writeOffset";

            // Now replace the concrete offset with the variable.
            for (int i = 0; i < width; i++) {
                helper.setWriteOffset(port, i, channelWriteOffset + "[" + i
                        + "]");
            }
            channelWriteOffset += "[" + width + "]";
            code.append("static int " + channelWriteOffset + ";\n");
        }
View Full Code Here

                        readTokens = DFUtilities.getRate(outputPort);
                        Iterator sourcePorts = outputPort
                                .insideSourcePortList().iterator();
                        label1: while (sourcePorts.hasNext()) {
                            IOPort sourcePort = (IOPort) sourcePorts.next();
                            CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(sourcePort
                                    .getContainer());
                            int width;
                            if (sourcePort.isInput()) {
                                width = sourcePort.getWidthInside();
                            } else {
                                width = sourcePort.getWidth();
                            }
                            for (int j = 0; j < width; j++) {
                                Iterator channels = helper.getSinkChannels(
                                        sourcePort, j).iterator();
                                while (channels.hasNext()) {
                                    Channel channel = (Channel) channels.next();
                                    if (channel.port == outputPort
                                            && channel.channelNumber == i) {
                                        writeTokens = DFUtilities
                                                .getRate(sourcePort);
                                        break label1;
                                    }
                                }
                            }
                        }
                    }
                    tempCode.append(_createOffsetVariablesIfNeeded(outputPort,
                            i, readTokens, writeTokens));
                }
            }
        }
        if (tempCode.length() > 0) {
            code.append("\n"
                    + _codeGenerator.comment(container.getName()
                            + "'s offset variables"));
            code.append(tempCode);
        }

        Iterator actors = container.deepEntityList().iterator();
        while (actors.hasNext()) {
            StringBuffer tempCode2 = new StringBuffer();
            Actor actor = (Actor) actors.next();
            Iterator inputPorts = actor.inputPortList().iterator();
            while (inputPorts.hasNext()) {
                IOPort inputPort = (IOPort) inputPorts.next();
                // If dynamic references are desired, conditionally pad buffers
                // and append the dynamic offset variables for input ports.
                if (dynamicReferencesAllowed) {
                    if (padBuffers) {
                        for (int i = 0; i < inputPort.getWidth(); i++) {
                            _padBuffer(inputPort, i);
                        }
                    }
                    tempCode2.append(_createDynamicOffsetVariables(inputPort));
                    // Otherwise, append the offset variables (padding is handled
                    // in _createOffsetVariablesIfNeeded()) for input ports.
                } else {
                    for (int i = 0; i < inputPort.getWidth(); i++) {
                        int readTokens = 0;
                        int writeTokens = 0;
                        // If each actor firing is inlined in the code,
                        // then read and write positions in the buffer
                        // must return to the previous values after one
                        // iteration of the container actor in order to
                        // avoid using read and write offset variables.
                        if (inline) {
                            Variable firings = (Variable) ((NamedObj) actor)
                                    .getAttribute("firingsPerIteration");
                            int firingsPerIteration = ((IntToken) firings
                                    .getToken()).intValue();
                            readTokens = DFUtilities.getRate(inputPort)
                                    * firingsPerIteration;
                            writeTokens = readTokens;

                            // If each actor firing is wrapped in a
                            // function, then read and write positions in
                            // the buffer must return to the previous
                            // values after one firing of this actor or
                            // one firing of the actor that produces
                            // tokens consumed by this actor in order to
                            // avoid using read and write offset
                            // variables.
                        } else {
                            readTokens = DFUtilities.getRate(inputPort);
                            Iterator sourcePorts = inputPort.sourcePortList()
                                    .iterator();
                            label2: while (sourcePorts.hasNext()) {
                                IOPort sourcePort = (IOPort) sourcePorts.next();
                                CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(sourcePort
                                        .getContainer());
                                int width;
                                if (sourcePort.isInput()) {
                                    width = sourcePort.getWidthInside();
                                } else {
                                    width = sourcePort.getWidth();
                                }
                                for (int j = 0; j < width; j++) {
                                    Iterator channels = helper.getSinkChannels(
                                            sourcePort, j).iterator();
                                    while (channels.hasNext()) {
                                        Channel channel = (Channel) channels
                                                .next();
                                        if (channel.port == inputPort
View Full Code Here

    protected String _createOffsetVariablesIfNeeded(IOPort port,
            int channelNumber, int readTokens, int writeTokens)
            throws IllegalActionException {
        StringBuffer code = new StringBuffer();

        CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(port
                .getContainer());
        boolean padBuffers = ((BooleanToken) _codeGenerator.padBuffers
                .getToken()).booleanValue();

        int bufferSize = helper.getBufferSize(port, channelNumber);

        // Increase the buffer size of that channel to the power of two.
        if (bufferSize > 0 && padBuffers) {
            bufferSize = _padBuffer(port, channelNumber);
        }

        if (bufferSize != 0
                && (readTokens % bufferSize != 0 || writeTokens % bufferSize != 0)) {
            int width;
            if (port.isInput()) {
                width = port.getWidth();
            } else {
                width = port.getWidthInside();
            }

            // We check again if the new bufferSize divides readTokens or
            // writeTokens. If yes, we could avoid using variable to represent
            // offset.
            if (readTokens % bufferSize != 0) {

                // Declare the read offset variable.
                StringBuffer channelReadOffset = new StringBuffer();
                channelReadOffset
                        .append(CodeGeneratorHelper.generateName(port));
                if (width > 1) {
                    channelReadOffset.append("_" + channelNumber);
                }
                channelReadOffset.append("_readOffset");
                String channelReadOffsetVariable = channelReadOffset.toString();
                //code.append("static int " + channelReadOffsetVariable + " = "
                //        + helper.getReadOffset(port, channelNumber) + ";\n");
                code.append("static int " + channelReadOffsetVariable + ";\n");
                // Now replace the concrete offset with the variable.
                helper.setReadOffset(port, channelNumber,
                        channelReadOffsetVariable);
            }

            if (writeTokens % bufferSize != 0) {

                // Declare the write offset variable.
                StringBuffer channelWriteOffset = new StringBuffer();
                channelWriteOffset.append(CodeGeneratorHelper
                        .generateName(port));
                if (width > 1) {
                    channelWriteOffset.append("_" + channelNumber);
                }
                channelWriteOffset.append("_writeOffset");
                String channelWriteOffsetVariable = channelWriteOffset
                        .toString();
                code.append("static int " + channelWriteOffsetVariable + ";\n");
                // Now replace the concrete offset with the variable.
                helper.setWriteOffset(port, channelNumber,
                        channelWriteOffsetVariable);
            }
        }
        return code.toString();
    }
View Full Code Here

        ptolemy.codegen.SystemC.actor.TypedCompositeActor containerHelper = (ptolemy.codegen.SystemC.actor.TypedCompositeActor) _getHelper(container);

        Iterator actors = container.deepEntityList().iterator();
        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            Iterator inputPorts = actor.inputPortList().iterator();
            while (inputPorts.hasNext()) {
                IOPort inputPort = (IOPort) inputPorts.next();
                for (int k = 0; k < inputPort.getWidth(); k++) {
                    int newCapacity = getBufferSize(inputPort, k);
                    int oldCapacity = actorHelper.getBufferSize(inputPort, k);
                    if (newCapacity > oldCapacity) {
                        actorHelper.setBufferSize(inputPort, k, newCapacity);
                    }
                }
            }
        }
View Full Code Here

     * @return The size of the new buffer.
     * @exception IllegalActionException If thrown when getting the port's helper.
     */
    private int _padBuffer(IOPort port, int channelNumber)
            throws IllegalActionException {
        CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(port
                .getContainer());

        int bufferSize = helper.getBufferSize(port, channelNumber);
        int newBufferSize = _ceilToPowerOfTwo(bufferSize);
        helper.setBufferSize(port, channelNumber, newBufferSize);

        return newBufferSize;
    }
View Full Code Here

TOP

Related Classes of ptolemy.codegen.kernel.CodeGeneratorHelper$Channel

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.