Package ptolemy.codegen.kernel

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper$VariableScope


        // 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$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.