コード例 #1
0
ファイル: ArrayCopy.java プロジェクト: navicella/streamit
 // Only handles rectangle multi dim arrays now
 public static void acceptInit(JMethodDeclaration init, Hashtable constants) {
   JBlock body = init.getBody();
   JFormalParameter[] params = init.getParameters();
   for (int i = params.length - 1; i >= 0; i--) {
     LinkedList<JIntLiteral> dims = new LinkedList<JIntLiteral>();
     Object val = constants.get(params[i]);
     Object temp = val;
     while (temp instanceof Object[]) {
       dims.add(new JIntLiteral(((Object[]) temp).length));
       temp = ((Object[]) temp)[0];
     }
     if (dims.size() > 0) {
       dumpAssign(val, body, new JLocalVariableExpression(null, params[i]));
       body.addStatementFirst(
           new JExpressionStatement(
               null,
               new JAssignmentExpression(
                   null,
                   new JLocalVariableExpression(null, params[i]),
                   new JNewArrayExpression(
                       null, params[i].getType(), dims.toArray(new JExpression[0]), null)),
               null));
     }
   }
 }
コード例 #2
0
ファイル: ExecutionCode.java プロジェクト: daib/streamit
  /**
   * generate the code for the steady state loop. Inline the work function inside of an infinite
   * while loop.
   *
   * @param filter The single fused filter of the application.
   * @return A JStatement that is a while loop with the work function inlined.
   */
  JStatement generateSteadyStateLoop(SIRFilter filter) {

    JBlock block = new JBlock(null, new JStatement[0], null);

    JBlock workBlock = (JBlock) ObjectDeepCloner.deepCopy(filter.getWork().getBody());

    // add the cloned work function to the block
    block.addStatement(workBlock);

    // return the infinite loop
    return new JWhileStatement(null, new JBooleanLiteral(null, true), block, null);
  }
コード例 #3
0
ファイル: ExecutionCode.java プロジェクト: daib/streamit
  /**
   * Construct the main function.
   *
   * @param filter The single SIRFilter of the application.
   * @return A JBlock with the statements of the main function.
   */
  private JBlock mainFunction(SIRFilter filter) {

    JBlock statements = new JBlock(null, new JStatement[0], null);

    // create the params list, for some reason
    // calling toArray() on the list breaks a later pass
    List paramList = filter.getParams();
    JExpression[] paramArray;
    if (paramList == null || paramList.size() == 0) paramArray = new JExpression[0];
    else paramArray = (JExpression[]) paramList.toArray(new JExpression[0]);

    // add the call to the init function
    statements.addStatement(
        new JExpressionStatement(
            null,
            new JMethodCallExpression(
                null, new JThisExpression(null), filter.getInit().getName(), paramArray),
            null));

    // add the call to the pre(init)work function if this filter
    // is a two stage..
    if (filter instanceof SIRTwoStageFilter) {
      SIRTwoStageFilter two = (SIRTwoStageFilter) filter;
      statements.addStatement(
          new JExpressionStatement(
              null,
              new JMethodCallExpression(
                  null, new JThisExpression(null), two.getInitWork().getName(), new JExpression[0]),
              null));
    }

    // add the call to the work function
    statements.addStatement(generateSteadyStateLoop(filter));

    return statements;
  }
コード例 #4
0
ファイル: ArrayCopy.java プロジェクト: navicella/streamit
 private static void dumpAssign(Object array, JBlock body, JExpression prefix) {
   if (array instanceof JExpression) {
     if (((JExpression) array).isConstant())
       body.addStatementFirst(
           new JExpressionStatement(
               null, new JAssignmentExpression(null, prefix, (JExpression) array), null));
   } else if (array instanceof Object[]) {
     for (int i = ((Object[]) array).length - 1; i >= 0; i--)
       dumpAssign(
           ((Object[]) array)[i],
           body,
           new JArrayAccessExpression(null, prefix, new JIntLiteral(i)));
   } else {
     System.err.println("WARNING: Non Array input to dumpAssign" + array);
   }
 }