Examples of CodeGeneratorHelper


Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

                        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

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

    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

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

        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

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

     * @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

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

                .deepEntityList().iterator();

        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            try {
                CodeGeneratorHelper helperObject = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
                helperObject.analyzeTypeConvert();
            } catch (Throwable throwable) {
                throw new IllegalActionException(actor, throwable,
                        "Failed to determine which ports need type conversion.");
            }
        }
View Full Code Here

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

        // Reset the offset for all of the contained actors' input ports.
        Iterator actors = ((ptolemy.actor.CompositeActor) getComponent())
                .deepEntityList().iterator();
        while (actors.hasNext()) {
            NamedObj actor = (NamedObj) actors.next();
            CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper(actor);
            String code = actorHelper.resetInputPortsOffset();
            if (code.length() > 0) {
                initializeCode.append(_eol
                        + _codeGenerator.comment(1, actor.getName()
                                + "'s input offset initialization"));
                initializeCode.append(code);
View Full Code Here

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

        Iterator actors = ((ptolemy.actor.CompositeActor) getComponent())
                .deepEntityList().iterator();

        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper helperObject = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            files.addAll(helperObject.getHeaderFiles());
        }

        // Get headers needed by the director helper.
        Director directorHelper = (Director) _getHelper(((ptolemy.actor.CompositeActor) getComponent())
                .getDirector());
View Full Code Here

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

        Iterator actors = ((ptolemy.actor.CompositeActor) getComponent())
                .deepEntityList().iterator();

        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper helperObject = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            includeDirectories.addAll(helperObject.getIncludeDirectories());
        }

        // Get include directories needed by the director helper.
        Director directorHelper = (Director) _getHelper(((ptolemy.actor.CompositeActor) getComponent())
                .getDirector());
View Full Code Here

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

        Iterator actors = ((ptolemy.actor.CompositeActor) getComponent())
                .deepEntityList().iterator();

        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper helperObject = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            libraries.addAll(helperObject.getLibraries());
        }

        // Get libraries needed by the director helper.
        Director directorHelper = (Director) _getHelper(((ptolemy.actor.CompositeActor) getComponent())
                .getDirector());
View Full Code Here

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper

        Iterator actors = ((ptolemy.actor.CompositeActor) getComponent())
                .deepEntityList().iterator();

        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper helperObject = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            sharedCode.addAll(helperObject.getSharedCode());
        }

        // Get shared code used by the director helper.
        Director directorHelper = (Director) _getHelper(((ptolemy.actor.CompositeActor) getComponent())
                .getDirector());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.