Exemplo n.º 1
0
  /**
   * Generate code for all the actors associated with the given FSMDirector.
   *
   * @return String containing the actor code.
   * @exception IllegalActionException If throw while accessing the model.
   */
  private String _generateActorCode() throws IllegalActionException {
    StringBuffer code = new StringBuffer();
    ptolemy.domains.fsm.kernel.FSMDirector director =
        (ptolemy.domains.fsm.kernel.FSMDirector) getComponent();
    ptolemy.domains.fsm.kernel.FSMActor controller = director.getController();
    // int depth = 1;

    // Iterator states = controller.entityList().iterator();
    Iterator states = controller.deepEntityList().iterator();
    // int stateCount = 0;
    // depth++;

    while (states.hasNext()) {
      // code.append(_getIndentPrefix(depth));
      // code.append("case " + stateCount + ":" + _eol);
      // stateCount++;

      // depth++;

      State state = (State) states.next();
      Actor[] actors = state.getRefinement();
      Set<Actor> actorsSet = new HashSet();
      ;
      if (actors != null) {
        for (int i = 0; i < actors.length; i++) {
          actorsSet.add(actors[i]);
        }
      }

      if (actors != null) {
        // for (int i = 0; i < actors.length; i++) {
        Iterator actorIterator = actorsSet.iterator();
        Actor actors2;
        while (actorIterator.hasNext()) {
          actors2 = (Actor) actorIterator.next();
          CodeGeneratorHelper actorHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actors2);
          if (actors2.getDirector().getFullName().contains("Giotto") == false) {
            // code.append("void "+_getActorName(actors2)+"(){");
            code.append(
                actorHelper
                    .generateFireFunctionCode()); // this was there initially and it works with SDF
            code.append(actorHelper.generateTypeConvertFireCode());
            // code.append(_eol+"}"+_eol);
          } else {
            code.append(_eol + "//modal model contains giotto director" + _eol);
          }
        }
      }
    }

    return code.toString();
  }
Exemplo n.º 2
0
 protected String getInfo(String name, List<String> parameters) throws IllegalActionException {
   ptolemy.domains.fsm.kernel.FSMActor fa = (ptolemy.domains.fsm.kernel.FSMActor) getComponent();
   if (name.equals("initState")) {
     return fa.getInitialState().getName();
   }
   if (name.equals("transitions")) {
     ArrayList transitions = new ArrayList();
     for (State s : (List<State>) fa.entityList(State.class)) {
       transitions.addAll(s.outgoingPort.linkedRelationList());
     }
     return new ListTerm<Transition>("emptyTransitionSet", " ;" + _eol, transitions) {
       public String item(Transition t) throws IllegalActionException {
         return ((RTMaudeAdaptor) _getHelper(t)).generateTermCode();
       }
     }.generateCode();
   }
   return super.getInfo(name, parameters);
 }
Exemplo n.º 3
0
  /**
   * Return the worst case execution time (WCET) seen by this director.
   *
   * @return The Worst Case Execution Time (WCET).
   * @exception IllegalActionException If there is a problem determining the WCET or a problem
   *     accessing the model.
   */
  public double getWCET() throws IllegalActionException {
    ptolemy.domains.fsm.kernel.FSMDirector director =
        (ptolemy.domains.fsm.kernel.FSMDirector) getComponent();
    ptolemy.domains.fsm.kernel.FSMActor controller = director.getController();
    // int depth = 1;

    Iterator states = controller.deepEntityList().iterator();
    // int stateCount = 0;
    // depth++;
    double largestWCET = 0.0;

    while (states.hasNext()) {

      // stateCount++;

      // depth++;

      State state = (State) states.next();
      Actor[] actors = state.getRefinement();
      Set<Actor> actorsSet = new HashSet();
      ;
      if (actors != null) {
        for (int i = 0; i < actors.length; i++) {
          actorsSet.add(actors[i]);
        }
      }
      for (Actor actor : actorsSet) {
        ptolemy.codegen.actor.Director df = new ptolemy.codegen.actor.Director(actor.getDirector());
        double localWCET = df.getWCET();
        if (localWCET > largestWCET) {
          largestWCET = localWCET;
        }
      }
    }
    if (_debugging) {
      _debug("fsm director has wcet of " + largestWCET);
    }
    return largestWCET;
  }
Exemplo n.º 4
0
  /**
   * Generate code for the firing of refinements.
   *
   * @param code The string buffer that the generated code is appended to.
   * @exception IllegalActionException If the helper associated with an actor throws it while
   *     generating fire code for the actor.
   */
  protected void _generateRefinementCode(StringBuffer code) throws IllegalActionException {

    ptolemy.domains.fsm.kernel.FSMDirector director =
        (ptolemy.domains.fsm.kernel.FSMDirector) getComponent();
    ptolemy.domains.fsm.kernel.FSMActor controller = director.getController();
    FSMActor controllerHelper = (FSMActor) _getHelper(controller);

    int depth = 1;
    code.append(_getIndentPrefix(depth));
    code.append(
        "switch (" + controllerHelper.processCode("$actorSymbol(currentState)") + ") {" + _eol);

    Iterator states = controller.entityList().iterator();
    int stateCount = 0;
    depth++;

    while (states.hasNext()) {
      code.append(_getIndentPrefix(depth));
      code.append("case " + stateCount + ":" + _eol);
      stateCount++;

      depth++;

      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
          // code.append(actorHelper.generateFireCode());
          code.append(_getActorName(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) {
                  int rate = rates[k][portNumber];
                  if (port.isInput()) {
                    _updatePortOffset(port, code, rate);
                  } else {
                    _updateConnectedPortsOffset(port, code, rate);
                  }
                  code.append("break;" + _eol);
                }
              }
              code.append("}" + _eol);
            } else {
              int rate = DFUtilities.getRate(port);
              if (port.isInput()) {
                _updatePortOffset(port, code, rate);
              } else {
                _updateConnectedPortsOffset(port, code, rate);
              }
            }
            portNumber++;
          }
        }
      }

      code.append(_getIndentPrefix(depth));
      code.append("break;" + _eol); // end of case statement
      depth--;
    }

    depth--;
    code.append(_getIndentPrefix(depth));
    code.append("}" + _eol); // end of switch statement
  }
Exemplo n.º 5
0
  /**
   * Generate mode code for the FSM. Notice the refinements share same inputs and outputs. Here, the
   * mode, state and refinement have same meaning.
   *
   * @param fsm The FSM generated mode code from.
   * @param inputPorts The inputs of fsm model.
   * @param outputPorts The outputs of fsm model.
   * @return The fsm submode code.
   */
  private String _fsmModeCode(FSMActor fsm, String inputPorts, String outputPorts)
      throws IllegalActionException {
    String subModeCode = "";
    String transitionString = "";

    transitionString +=
        ("  trans from default to "
            + fsm.getInitialState().getName()
            + _endLine
            + "  when ( true ) do { } "
            + _endLine);

    ListIterator stateIterator = fsm.entityList().listIterator();

    while (stateIterator.hasNext()) {
      State st = (State) stateIterator.next();

      if (st.getRefinement() != null) {
        Actor[] refinements = st.getRefinement();
        CompositeActor refinement = (CompositeActor) refinements[0];
        String stParameters = _agentParameters(refinement, false);
        String typedStParameters = _agentParameters(refinement, true);
        String flowString = "";
        String invariantString = "";

        _modeCode +=
            ("  mode "
                + st.getName()
                + " = "
                + st.getName()
                + "Mode"
                + " ( "
                + stParameters
                + " );"
                + _endLine);

        flowString = _graphToText(refinement);

        ListIterator assertions = _assertions(refinement).listIterator();

        while (assertions.hasNext()) {
          Assertion assertion = (Assertion) assertions.next();

          if (invariantString.length() == 0) {
            invariantString = "inv { " + assertion.assertion.getExpression();
          } else {
            invariantString += (" ; " + assertion.assertion.getExpression());
          }

          invariantString += " } ";
        }

        subModeCode +=
            ("mode "
                + st.getName()
                + "Mode "
                + "( "
                + typedStParameters
                + " )"
                + _endLine
                + "{"
                + _endLine
                + "  "
                + outputPorts
                + _endLine
                + "  "
                + inputPorts
                + _endLine
                + "  "
                + flowString
                + _endLine
                + "  "
                + invariantString
                + _endLine
                + "}"
                + _endLine);

        LinkedList transitionList = new LinkedList();
        transitionList.addAll(st.preemptiveTransitionList());
        transitionList.addAll(st.nonpreemptiveTransitionList());

        ListIterator transitionItr = transitionList.listIterator();

        while (transitionItr.hasNext()) {
          Transition tr = (Transition) transitionItr.next();
          State newState = tr.destinationState();
          String guardString = tr.getGuardExpression();
          transitionString +=
              ("  trans from "
                  + st.getName()
                  + " to "
                  + newState.getName()
                  + _endLine
                  + "  when ( "
                  + guardString
                  + ") "
                  + _endLine
                  + "  do {}"
                  + _endLine);
        }
      }
    }

    _modeCode += (transitionString + _endLine);

    return subModeCode;
  }