示例#1
0
  /**
   * Generate the preinitialize code. Declare temporary variables.
   *
   * @return The preinitialize code.
   * @exception IllegalActionException If the code stream encounters an error in processing the
   *     specified code block(s).
   */
  public String generatePreinitializeCode() throws IllegalActionException {
    // Automatically append the "preinitBlock" by default.
    super.generatePreinitializeCode();

    ptolemy.actor.lib.NonStrictTest actor = (ptolemy.actor.lib.NonStrictTest) getComponent();

    if (actor.input.getWidth() > 1) {
      ArrayList args = new ArrayList();
      args.add(Integer.valueOf(0));
      for (int i = 0; i < actor.input.getWidth(); i++) {
        args.set(0, Integer.valueOf(i));
        _codeStream.appendCodeBlock("TokenPreinitBlock", args);
      }
    }

    for (int i = 0; i < actor.input.getWidth(); i++) {
      if (!isPrimitive(actor.input.getType())) {
        // One of the channels is not primitive, so we will
        // later call TokenBlock($channel), so we define
        // toleranceToken for our use.
        _codeStream.appendCodeBlock("toleranceTokenPreinitBlock");
        break;
      }
    }

    return processCode(_codeStream.toString());
  }
示例#2
0
  /**
   * Generate fire code. The method reads in <code>fireBlock</code> from ElementsToArray.c, replaces
   * macros with their values and returns the processed code block.
   *
   * @return The generated code.
   * @exception IllegalActionException If the code stream encounters an error in processing the
   *     specified code block(s).
   */
  public String generateFireCode() throws IllegalActionException {
    super.generateFireCode();
    ptolemy.actor.lib.ElementsToArray actor = (ptolemy.actor.lib.ElementsToArray) getComponent();

    ArrayList args = new ArrayList();
    args.add(new Integer(0));

    for (int i = 0; i < actor.input.getWidth(); i++) {
      args.set(0, new Integer(i));
      _codeStream.appendCodeBlock("fillArray", args);
    }
    _codeStream.appendCodeBlock("sendOutput");
    return processCode(_codeStream.toString());
  }
示例#3
0
  /**
   * Generate the initialize code. Declare the variable state.
   *
   * @return The initialize code.
   * @exception IllegalActionException
   */
  public String generateInitializeCode() throws IllegalActionException {
    super.generateInitializeCode();

    ptolemy.actor.lib.NonStrictTest actor = (ptolemy.actor.lib.NonStrictTest) getComponent();
    for (int i = 0; i < actor.input.getWidth(); i++) {
      if (!isPrimitive(actor.input.getType())) {
        // One of the channels is not primitive, so we will
        // later call TokenBlock($channel), so we define
        // toleranceToken for our use.
        _codeStream.appendCodeBlock("toleranceTokenInitBlock");
        break;
      }
    }
    return processCode(_codeStream.toString());
  }
示例#4
0
  /**
   * Generate fire code. Read the <code>fireBlock</code> from Comparator.c, replace macros with
   * their values and return the processed code block.
   *
   * @return The processed code string.
   * @exception IllegalActionException If the code stream encounters an error in processing the
   *     specified code block(s).
   */
  protected String _generateFireCode() throws IllegalActionException {
    super._generateFireCode();
    ptolemy.actor.lib.logic.Comparator actor = (ptolemy.actor.lib.logic.Comparator) getComponent();

    String comparison = actor.comparison.getExpression();

    if (comparison.equals(">")) {
      _codeStream.appendCodeBlock("GTBlock");
    } else if (comparison.equals(">=")) {
      _codeStream.appendCodeBlock("GEBlock");
    } else if (comparison.equals("<")) {
      _codeStream.appendCodeBlock("LTBlock");
    } else if (comparison.equals("<=")) {
      _codeStream.appendCodeBlock("LEBlock");
    } else if (comparison.equals("==")) {
      _codeStream.appendCodeBlock("EQBlock");
    }
    return processCode(_codeStream.toString());
  }
示例#5
0
文件: Equals.java 项目: blickly/ptii
  /**
   * Generate fire code. Read the <code>fireBlock</code> from Equals.c, replace macros with their
   * values and return the processed code block.
   *
   * @return The processed code string.
   * @exception IllegalActionException If the code stream encounters an error in processing the
   *     specified code block(s).
   */
  protected String _generateFireCode() throws IllegalActionException {
    super._generateFireCode();
    ptolemy.actor.lib.logic.Equals actor = (ptolemy.actor.lib.logic.Equals) getComponent();

    String type = "";
    type = codeGenType(actor.input.getType());
    if (!isPrimitive(type)) {
      type = "Token";
    }

    _codeStream.appendCodeBlock("fireBlockOpen");
    ArrayList args = new ArrayList();
    args.add(Integer.valueOf(0));
    args.add(Integer.valueOf(1));
    for (int i = 0; i < actor.input.getWidth() - 1; i++) {
      args.set(0, Integer.valueOf(i));
      args.set(1, Integer.valueOf(i + 1));
      _codeStream.appendCodeBlock(type + "EqualsBlock", args);
    }
    return processCode(_codeStream.toString());
  }
示例#6
0
  /**
   * Generate fire code. The method reads in <code>fireBlock</code> from Test.c, replaces macros
   * with their values and returns the processed code block.
   *
   * @return The generated code.
   * @exception IllegalActionException If the code stream encounters an error in processing the
   *     specified code block(s).
   */
  protected String _generateFireCode() throws IllegalActionException {
    super._generateFireCode();

    ptolemy.actor.lib.NonStrictTest actor = (ptolemy.actor.lib.NonStrictTest) getComponent();

    ArrayList args = new ArrayList();
    args.add(Integer.valueOf(0));
    String multiChannel = "";
    Type inputType = actor.input.getType();
    String inputTypeString = "";
    String blockName = "Block";

    if (actor.input.getWidth() > 1) {
      // If we have multiple inputs, use different blocks
      multiChannel = "MultiChannel";
    }

    inputTypeString = codeGenType(inputType);
    if (isPrimitive(inputType)) {
      blockName = inputTypeString + blockName;
    } else {
      if (multiChannel.length() == 0 && (actor.input.getType() instanceof ArrayType)) {
        blockName = "Array" + blockName;
      } else {
        blockName = "Token" + blockName;
      }
      args.add(inputTypeString);
    }

    for (int i = 0; i < actor.input.getWidth(); i++) {
      args.set(0, Integer.valueOf(i));

      _codeStream.appendCodeBlock(blockName + multiChannel, args);
    }
    return processCode(_codeStream.toString());
  }