示例#1
0
  /**
   * This static method creates the main function as described in the class comment. It first checks
   * that the filter has no inputs/outputs and does not declare any I/O rates Then it creates the
   * function and attaches it to the filter.
   *
   * @param top The single flatnode that contains the single filter of the app.
   * @param executionCounts The schedule for the stream graph as calculated by the scheduler.
   */
  public static void doit(FlatNode top, HashMap[] executionCounts) {
    assert top.contents instanceof SIRFilter : "Error top of graph is not filter";

    assert top.inputs == 0 && top.ways == 0 : "Error: Fused filter contains neighbors";

    SIRFilter filter = (SIRFilter) top.contents;

    assert filter.getPushInt() == 0 && filter.getPopInt() == 0 && filter.getPeekInt() == 0
        : "Error: fused filter declares non-zero I/O rate(s)";

    // make sure there are no push, pops or peeks...
    assert CheckForCommunication.check(filter) == false
        : "Error: Communication expression found in filter";

    //  assert !(filter instanceof SIRTwoStageFilter) :
    //    "Error: Fused filter is a two stage";

    ExecutionCode exeCode = new ExecutionCode();

    // check to see if the schedule is valid and
    // set the number of times the filter fires in the init
    // stage (weird)
    exeCode.checkSchedule(executionCounts, filter);

    // create the main function of the C code that will call
    // the filter
    JBlock block = exeCode.mainFunction(filter);

    // create the method and add it to the filter
    JMethodDeclaration mainFunct =
        new JMethodDeclaration(
            null,
            at.dms.kjc.Constants.ACC_PUBLIC,
            CStdType.Void,
            Names.main,
            JFormalParameter.EMPTY,
            CClassType.EMPTY,
            block,
            null,
            null);
    // make the main the new work function
    filter.setWork(mainFunct);
  }
示例#2
0
  /**
   * Set init and work functions to be for an identity filter with the given pop / push rate.
   *
   * @param rate push and pop rates
   * @param t input and output type
   */
  public void makeIdentityFilter(JExpression rate, CType t) {
    assert rate != null : "Constructing SIRIdentity with null rate";

    this.setInputType(t);
    this.setOutputType(t);

    this.setPush(rate); // set rates
    this.setPop(rate);
    this.setPeek(rate); // some parts of compiler expect peek rate >= pop rate, so set it.

    // work function

    JVariableDefinition tmp =
        new JVariableDefinition(
            null,
            0,
            this.getInputType(),
            at.dms.kjc.sir.lowering.ThreeAddressCode.nextTemp(),
            null);
    JVariableDeclarationStatement declarePopExpr = new JVariableDeclarationStatement(tmp);
    JLocalVariableExpression referencePoppedValue = new JLocalVariableExpression(tmp);
    JStatement popIt =
        new JExpressionStatement(
            new JAssignmentExpression(
                referencePoppedValue, new SIRPopExpression(this.getInputType())));

    JStatement work1body[];
    if (rate instanceof JIntLiteral && ((JIntLiteral) rate).intValue() == 1) {
      work1body =
          new JStatement[] {
            declarePopExpr,
            popIt,
            new JExpressionStatement(
                null, new SIRPushExpression(referencePoppedValue, this.getInputType()), null)
          };

    } else {
      JStatement pushPop =
          new JBlock(
              new JStatement[] {
                declarePopExpr,
                popIt,
                new JExpressionStatement(
                    null, new SIRPushExpression(referencePoppedValue, this.getInputType()), null)
              });
      JVariableDefinition induction =
          new JVariableDefinition(null, 0, CStdType.Integer, "i", new JIntLiteral(0));
      JRelationalExpression cond =
          new JRelationalExpression(
              null, Constants.OPE_LT, new JLocalVariableExpression(null, induction), rate);

      JExpressionStatement increment =
          new JExpressionStatement(
              null,
              new JCompoundAssignmentExpression(
                  null,
                  Constants.OPE_PLUS,
                  new JLocalVariableExpression(null, induction),
                  new JIntLiteral(1)),
              null);
      work1body =
          new JStatement[] {
            new JForStatement(
                null,
                new JVariableDeclarationStatement(null, induction, null),
                cond,
                increment,
                pushPop,
                new JavaStyleComment[] {
                  new JavaStyleComment("IncreaseFilterMult", true, false, false)
                })
          };
    }

    JBlock work1block =
        new JBlock(/* tokref   */ null, /* body     */ work1body, /* comments */ null);

    JMethodDeclaration workfn =
        new JMethodDeclaration(
            /* tokref     */ null,
            /* modifiers  */ at.dms.kjc.Constants.ACC_PUBLIC,
            /* returntype */ CStdType.Void,
            /* identifier */ "work",
            /* parameters */ JFormalParameter.EMPTY,
            /* exceptions */ CClassType.EMPTY,
            /* body       */ work1block,
            /* javadoc    */ null,
            /* comments   */ null);
    setWork(workfn);

    // init function
    JBlock initblock =
        new JBlock(/* tokref   */ null, /* body     */ new JStatement[0], /* comments */ null);
    setInit(SIRStream.makeEmptyInit());
  }