Package ptolemy.codegen.kernel

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper$VariableScope


    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.c.actor.TypedCompositeActor containerHelper = (ptolemy.codegen.c.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

            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

            while (modifiedVariables.hasNext()) {
                // SetVariable needs this to be a Variable, not a Parameter.
                Variable variable = (Variable) modifiedVariables.next();

                NamedObj container = variable.getContainer();
                CodeGeneratorHelper containerHelper = (CodeGeneratorHelper) _getHelper(container);
                code.append(_INDENT1
                        + generateVariableName(variable)
                        + " = "
                        + containerHelper.getParameterValue(variable.getName(),
                                variable.getContainer()) + ";" + _eol);
            }
        }

        return code.toString();
View Full Code Here

            State state = (State) states.next();
            Actor[] actors = state.getRefinement();

            if (actors != null) {
                for (int i = 0; i < actors.length; i++) {
                    CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[i]);

                    // fire the actor
                    if (inline) {
                        code.append(actorHelper.generateFireCode());
                        code.append(actorHelper.generateTypeConvertFireCode());
                    } else {
                        code.append(CodeGeneratorHelper
                                .generateName((NamedObj) actors[i])
                                + "();" + _eol);
                    }

                    // update buffer offset after firing each actor once
                    int[][] rates = actorHelper.getRates();
                    Iterator ports = ((Entity) actors[i]).portList().iterator();
                    int portNumber = 0;
                    while (ports.hasNext()) {
                        IOPort port = (IOPort) ports.next();
                        if (rates != null) {
                            code.append("switch ("
                                    + actorHelper.processCode("$actorSymbol("
                                            + "currentConfiguration)") + ") {"
                                    + _eol);
                            for (int k = 0; k < rates.length; k++) {
                                code.append("case " + k + ":" + _eol);
                                if (rates[k] != null) {
View Full Code Here

            return directorHelper.generateMainLoop(
            /*CodeGenerator.containsCode(_postfireCode)*/);

        } else {
            // Generate JNI code.
            CodeGeneratorHelper compositeHelper = (CodeGeneratorHelper) _getHelper(model);
            return compositeHelper.generateFireCode();
        }
    }
View Full Code Here

            // modal controller is not used as a stand-alone actor.
            if (((ptolemy.domains.fsm.kernel.FSMDirector) _director)
                    .getController() == actor) {
                continue;
            }
            CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            code.append(actorHelper.generateFireFunctionCode());
        }
        return code.toString();
    }
View Full Code Here

                        break;
                    }
                    actorNumber++;
                }

                CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
                int[][] rates = helper.getRates();

                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 ports = ((Entity) actor).portList().iterator();
                        int j = 0; // j is the port number
                        while (ports.hasNext()) {
View Full Code Here

        // Initialize _divisors for later use and find the total number
        // of configurations for the container actor, which is the product
        // of the numbers of configurations of contained actors.
        for (int i = numberOfActors - 1; i >= 0; i--) {
            Actor actor = (Actor) actors.get(i);
            CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            int[][] rates = helper.getRates();
            _divisors[i] = numberOfConfigurationsOfContainer;
            if (rates != null) {
                numberOfConfigurationsOfContainer *= rates.length;
                _divisors[i] = numberOfConfigurationsOfContainer;
            }
        }

        // Set constrainBufferSizes to true so that buffer capacity
        // will be recorded while computing schedule.
        ((CachedSDFScheduler) director.getScheduler()).constrainBufferSizes
                .setExpression("true");

        _schedules = new Schedule[numberOfConfigurationsOfContainer];
        int[][] containerRates = new int[numberOfConfigurationsOfContainer][];
        int[] actorConfigurations = new int[numberOfActors];
        for (int configurationNumber = 0; configurationNumber < numberOfConfigurationsOfContainer; configurationNumber++) {

            // Find the configuration number of each contained actor
            // given the configuration number of the container actor.
            int remainder = configurationNumber;
            for (int j = 0; j < numberOfActors - 1; j++) {
                actorConfigurations[j] = remainder / _divisors[j + 1];
                remainder = remainder % _divisors[j + 1];
            }
            actorConfigurations[numberOfActors - 1] = remainder;

            // Set port rates of all actors for current configuration.
            int j = 0; // j is the actor number
            boolean isRateNull = false;
            Iterator actorsIterator = actors.iterator();
            while (actorsIterator.hasNext()) {
                Actor actor = (Actor) actorsIterator.next();
                CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
                int[][] rates = actorHelper.getRates();
                // If rates is null, then the current actor has only one
                // configuration and the port rates have already been set.
                if (rates != null) {
                    int[] portRates = rates[actorConfigurations[j]];
                    if (portRates == null) {
View Full Code Here

TOP

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

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.