Package ptolemy.codegen.kernel

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper$Channel


            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

        // is needed for each 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

                .processCode("$actorSymbol(currentConfiguration) = "));
        Iterator actors = container.deepEntityList().iterator();
        int actorNumber = 0;
        while (actors.hasNext()) {
            Actor actor = (Actor) actors.next();
            CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actor);
            int[][] rates = actorHelper.getRates();
            // From the following code one can find that the
            // configuration number of the first contained actor is
            // the "most significant" number and that of the last is
            // the "least significant".
            if (actorNumber < numberOfActors - 1) {
                if (rates != null) {
                    code.append(actorHelper
                            .processCode("$actorSymbol(currentConfiguration)")
                            + " * " + _divisors[actorNumber + 1] + " + ");
                } else {
                    code.append("0 + ");
                }
            } else {
                if (rates != null) {
                    code.append(actorHelper
                            .processCode("$actorSymbol(currentConfiguration);"
                                    + _eol));
                } else {
                    code.append("0;" + _eol);
                }
View Full Code Here

                // generate code for transition refinement
                Actor[] actors = transition.getRefinement();

                if (actors != null) {
                    for (int i = 0; i < actors.length; i++) {
                        CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[i]);
                        // fire the actor
                        if (inline) {
                            codeBuffer.append(helper.generateFireCode());
                            codeBuffer.append(helper
                                    .generateTypeConvertFireCode());
                        } else {
                            codeBuffer
                                    .append(generateName((NamedObj) actors[i])
                                            + "();" + _eol);
                        }
                    }
                }

                // generate code for commit action
                actions = transition.commitActionList().iterator();

                while (actions.hasNext()) {
                    AbstractActionsAttribute action = (AbstractActionsAttribute) actions
                            .next();
                    Iterator destinationNameList = action
                            .getDestinationNameList().iterator();
                    Iterator channelNumberList = action.getChannelNumberList()
                            .iterator();
                    Iterator parseTreeList = action.getParseTreeList()
                            .iterator();

                    while (destinationNameList.hasNext()) {
                        String destinationName = (String) destinationNameList
                                .next();
                        Integer channelNumber = (Integer) channelNumberList
                                .next();
                        ASTPtRootNode parseTree = (ASTPtRootNode) parseTreeList
                                .next();
                        NamedObj destination = action
                                .getDestination(destinationName);

                        int channel = -1;
                        if (channelNumber != null) {
                            channel = channelNumber.intValue();
                        }

                        codeBuffer.append(_getIndentPrefix(depth));

                        if (destination instanceof IOPort) {
                            if (channel >= 0) {
                                codeBuffer.append("$ref(" + destinationName
                                        + "#" + channel + ") = ");
                            } else { // broadcast

                                int width = ((IOPort) action
                                        .getDestination(destinationName))
                                        .getWidth();

                                for (int i = 0; i < width; i++) {
                                    codeBuffer.append("$ref(" + destinationName
                                            + "#" + i + ") = ");
                                }
                            }
                        } else if (destination instanceof Variable) {
                            codeBuffer
                                    .append(_codeGenerator
                                            .generateVariableName((Variable) destination)
                                            + " = ");
                        }

                        ParseTreeCodeGenerator parseTreeCodeGenerator = getParseTreeCodeGenerator();
                        parseTreeCodeGenerator.evaluateParseTree(parseTree,
                                _scope);
                        codeBuffer.append(parseTreeCodeGenerator
                                .generateFireCode());
                        codeBuffer.append(";" + _eol);
                    }
                }

                // generate code for updating current state
                State destinationState = transition.destinationState();
                _updateCurrentState(codeBuffer, destinationState, depth);

                // generate code for reinitialization if reset is
                // true.  we assume the value of reset itself cannot
                // be changed dynamically

                BooleanToken resetToken = (BooleanToken) transition.reset
                        .getToken();
                if (resetToken.booleanValue()) {
                    actors = destinationState.getRefinement();

                    if (actors != null) {
                        for (int i = 0; i < actors.length; ++i) {
                            ActorCodeGenerator helper = (ActorCodeGenerator) _getHelper((NamedObj) actors[i]);
                            codeBuffer.append(helper.generateInitializeCode());
                        }
                    }
                }

                // Generate code for updating configuration number of
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.