Ejemplo n.º 1
0
  /** Run all pending passes on <code>job</code>. */
  public boolean runAllPasses(Job job) {
    List pending = job.pendingPasses();

    // Run until there are no more passes.
    if (!pending.isEmpty()) {
      Pass lastPass = (Pass) pending.get(pending.size() - 1);
      return runToPass(job, lastPass);
    }

    return true;
  }
Ejemplo n.º 2
0
 /**
  * The confluence operator for <code>Initializer</code>s and <code>Constructor</code>s needs to be
  * a little special, as we are only concerned with non-exceptional flows in these cases. This
  * method ensures that a slightly different confluence is performed for these <code>Term</code>s,
  * otherwise <code>confluence(List, Term)</code> is called instead.
  */
 protected Item confluence(List items, List itemKeys, Term node, FlowGraph graph) {
   if (node instanceof Initializer || node instanceof ConstructorDecl) {
     List filtered = filterItemsNonException(items, itemKeys);
     if (filtered.isEmpty()) {
       return createInitDFI();
     } else if (filtered.size() == 1) {
       return (Item) filtered.get(0);
     } else {
       return confluence(filtered, node, graph);
     }
   }
   return confluence(items, node, graph);
 }
Ejemplo n.º 3
0
  /**
   * Insert the list of <code>newPasses</code> into <code>passes</code> immediately after the pass
   * named <code>id</code>.
   */
  public void afterPass(List passes, Pass.ID id, List newPasses) {
    for (ListIterator i = passes.listIterator(); i.hasNext(); ) {
      Pass p = (Pass) i.next();

      if (p.id() == id) {
        for (Iterator j = newPasses.iterator(); j.hasNext(); ) {
          i.add(j.next());
        }

        return;
      }
    }

    throw new InternalCompilerError("Pass " + id + " not found.");
  }
Ejemplo n.º 4
0
  /**
   * The confluence operator is essentially the union of all of the inItems. However, if two or more
   * of the initCount maps from the inItems each have a MinMaxInitCounts entry for the same
   * VarInstance, the conflict must be resolved, by using the minimum of all mins and the maximum of
   * all maxs.
   */
  public Item confluence(List inItems, Term node, FlowGraph graph) {
    // Resolve any conflicts pairwise.
    Iterator iter = inItems.iterator();
    Map m = null;
    while (iter.hasNext()) {
      Item itm = (Item) iter.next();
      if (itm == BOTTOM) continue;
      if (m == null) {
        m = new HashMap(((DataFlowItem) itm).initStatus);
      } else {
        Map n = ((DataFlowItem) itm).initStatus;
        for (Iterator iter2 = n.entrySet().iterator(); iter2.hasNext(); ) {
          Map.Entry entry = (Map.Entry) iter2.next();
          VarInstance v = (VarInstance) entry.getKey();
          MinMaxInitCount initCount1 = (MinMaxInitCount) m.get(v);
          MinMaxInitCount initCount2 = (MinMaxInitCount) entry.getValue();
          m.put(v, MinMaxInitCount.join(initCount1, initCount2));
        }
      }
    }

    if (m == null) return BOTTOM;

    return new DataFlowItem(m);
  }
Ejemplo n.º 5
0
  /**
   * Inform this <code>Job</code> that pass <code>p</code> has finished. If <code>okay</code> is
   * <code>true</code>, then the pass was completed successfully; if it is <code>false</code> the
   * pass was not completed successfully.
   *
   * <p>Pass <code>p</code> may be any pending pass.
   */
  public void finishPass(Pass p, boolean okay) {
    List passes = passes();

    status &= okay;

    for (int i = nextPass; i < passes.size(); i++) {
      Pass pass = (Pass) passes.get(i);

      if (pass == p) {
        nextPass = i + 1;
        return;
      }
    }

    throw new InternalCompilerError("Pass " + p + " was not a pending " + "pass.");
  }
Ejemplo n.º 6
0
  /** Flatten complex expressions within the AST */
  public Node leave(Node old, Node n, NodeVisitor v) {
    if (n == noFlatten) {
      noFlatten = null;
      return n;
    }

    if (n instanceof Block) {
      List l = (List) stack.removeFirst();
      return ((Block) n).statements(l);
    } else if (n instanceof Stmt && !(n instanceof LocalDecl)) {
      List l = (List) stack.getFirst();
      l.add(n);
      return n;
    } else if (n instanceof Expr
        && !(n instanceof Lit)
        && !(n instanceof Special)
        && !(n instanceof Local)) {

      Expr e = (Expr) n;

      if (e instanceof Assign) {
        return n;
      }

      // create a local temp, initialized to the value of the complex
      // expression

      String name = newID();
      LocalDecl def =
          nf.LocalDecl(
              e.position(), Flags.FINAL, nf.CanonicalTypeNode(e.position(), e.type()), name, e);
      def = def.localInstance(ts.localInstance(e.position(), Flags.FINAL, e.type(), name));

      List l = (List) stack.getFirst();
      l.add(def);

      // return the local temp instead of the complex expression
      Local use = nf.Local(e.position(), name);
      use = (Local) use.type(e.type());
      use = use.localInstance(ts.localInstance(e.position(), Flags.FINAL, e.type(), name));
      return use;
    }

    return n;
  }
Ejemplo n.º 7
0
  /** Write the statement to an output file. */
  public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
    w.write("for (");
    w.begin(0);

    if (inits != null) {
      boolean first = true;
      for (Iterator i = inits.iterator(); i.hasNext(); ) {
        ForInit s = (ForInit) i.next();
        printForInit(s, w, tr, first);
        first = false;

        if (i.hasNext()) {
          w.write(",");
          w.allowBreak(2, " ");
        }
      }
    }

    w.write(";");
    w.allowBreak(0);

    if (cond != null) {
      printBlock(cond, w, tr);
    }

    w.write(";");
    w.allowBreak(0);

    if (iters != null) {
      for (Iterator i = iters.iterator(); i.hasNext(); ) {
        ForUpdate s = (ForUpdate) i.next();
        printForUpdate(s, w, tr);

        if (i.hasNext()) {
          w.write(",");
          w.allowBreak(2, " ");
        }
      }
    }

    w.end();
    w.write(")");

    printSubStmt(body, w, tr);
  }
Ejemplo n.º 8
0
  /**
   * Insert the list of <code>newPasses</code> into <code>passes</code> immediately before the pass
   * named <code>id</code>.
   */
  public void beforePass(List passes, Pass.ID id, List newPasses) {
    for (ListIterator i = passes.listIterator(); i.hasNext(); ) {
      Pass p = (Pass) i.next();

      if (p.id() == id) {
        // Backup one position.
        i.previous();

        for (Iterator j = newPasses.iterator(); j.hasNext(); ) {
          i.add(j.next());
        }

        return;
      }
    }

    throw new InternalCompilerError("Pass " + id + " not found.");
  }
Ejemplo n.º 9
0
  /**
   * Replace the pass named <code>id</code> in <code>passes</code> with the list of <code>newPasses
   * </code>.
   */
  public void replacePass(List passes, Pass.ID id, List newPasses) {
    for (ListIterator i = passes.listIterator(); i.hasNext(); ) {
      Pass p = (Pass) i.next();

      if (p.id() == id) {
        if (p instanceof BarrierPass) {
          throw new InternalCompilerError("Cannot replace a barrier pass.");
        }

        i.remove();

        for (Iterator j = newPasses.iterator(); j.hasNext(); ) {
          i.add(j.next());
        }

        return;
      }
    }

    throw new InternalCompilerError("Pass " + id + " not found.");
  }
Ejemplo n.º 10
0
  /**
   * Get the sub-list of passes for the job between passes <code>begin</code> and <code>end</code>,
   * inclusive.
   */
  public List passes(Job job, Pass.ID begin, Pass.ID end) {
    List l = passes(job);
    Pass p = null;

    Iterator i = l.iterator();

    while (i.hasNext()) {
      p = (Pass) i.next();
      if (begin == p.id()) break;
      if (!(p instanceof BarrierPass)) i.remove();
    }

    while (p.id() != end && i.hasNext()) {
      p = (Pass) i.next();
    }

    while (i.hasNext()) {
      p = (Pass) i.next();
      i.remove();
    }

    return l;
  }
Ejemplo n.º 11
0
 public String signature() {
   StringBuffer signature = new StringBuffer();
   // no trailing ; for base type before the type args
   signature.append("L" + ((Named) baseType).fullName().replaceAll("\\.", "/") + "<");
   for (Iterator it = typeArguments.iterator(); it.hasNext(); ) {
     SignatureType next = (SignatureType) it.next();
     signature.append(next.signature());
     if (it.hasNext()) {
       signature.append(",");
     }
   }
   signature.append(">;");
   return signature.toString();
 }
Ejemplo n.º 12
0
  /** Type check the statement. */
  public Node typeCheck(TypeChecker tc) throws SemanticException {
    TypeSystem ts = tc.typeSystem();

    // Check that all initializers have the same type.
    // This should be enforced by the parser, but check again here,
    // just to be sure.
    Type t = null;

    for (Iterator i = inits.iterator(); i.hasNext(); ) {
      ForInit s = (ForInit) i.next();

      if (s instanceof LocalDecl) {
        LocalDecl d = (LocalDecl) s;
        Type dt = d.type().type();
        if (t == null) {
          t = dt;
        } else if (!t.equals(dt)) {
          throw new InternalCompilerError(
              "Local variable "
                  + "declarations in a for loop initializer must all "
                  + "be the same type, in this case "
                  + t
                  + ", not "
                  + dt
                  + ".",
              d.position());
        }
      }
    }

    if (cond != null && !ts.isImplicitCastValid(cond.type(), ts.Boolean())) {
      throw new SemanticException(
          "The condition of a for statement must have boolean type.", cond.position());
    }

    return this;
  }
Ejemplo n.º 13
0
 public Type convertToInferred(List typeVars, List inferredTypes) {
   List newBounds = new ArrayList();
   for (Iterator it = typeArguments().iterator(); it.hasNext(); ) {
     Type next = (Type) it.next();
     if (next instanceof IntersectionType) {
       newBounds.add(inferredTypes.get(typeVars.indexOf(next)));
     } else if (next instanceof ParameterizedType) {
       newBounds.add(((ParameterizedType) next).convertToInferred(typeVars, inferredTypes));
     }
     /*else if (next instanceof AnySubType){
         newBounds.add(((AnySubType)next).convertToInferred(typeVars, inferredTypes));
     }*/
     else {
       newBounds.add(next);
     }
   }
   ParameterizedType converted = ((JL5TypeSystem) typeSystem()).parameterizedType(this.baseType());
   converted.typeArguments(newBounds);
   return converted;
 }
Ejemplo n.º 14
0
  /**
   * Before running <code>Pass pass</code> on <code>SourceJob job</code> make sure that all
   * appropriate scheduling invariants are satisfied, to ensure that all passes of other jobs that
   * <code>job</code> depends on will have already been done.
   */
  protected void enforceInvariants(Job job, Pass pass) throws CyclicDependencyException {
    SourceJob srcJob = job.sourceJob();
    if (srcJob == null) {
      return;
    }

    BarrierPass lastBarrier = srcJob.lastBarrier();
    if (lastBarrier != null) {
      // make sure that _all_ dependent jobs have completed at least up to
      // the last barrier (not just children).
      //
      // Ideally the invariant should be that only the source jobs that
      // job _depends on_ should be brought up to the last barrier.
      // This is work to be done in the future...
      List allDependentSrcs = new ArrayList(srcJob.dependencies());
      Iterator i = allDependentSrcs.iterator();
      while (i.hasNext()) {
        Source s = (Source) i.next();
        Object o = jobs.get(s);
        if (o == COMPLETED_JOB) continue;
        if (o == null) {
          throw new InternalCompilerError("Unknown source " + s);
        }
        SourceJob sj = (SourceJob) o;
        if (sj.pending(lastBarrier.id())) {
          // Make the job run up to the last barrier.
          // We ignore the return result, since even if the job
          // fails, we will keep on going and see
          // how far we get...
          if (Report.should_report(Report.frontend, 3)) {
            Report.report(3, "Running " + sj + " to " + lastBarrier.id() + " for " + srcJob);
          }
          runToPass(sj, lastBarrier.id());
        }
      }
    }

    if (pass instanceof GlobalBarrierPass) {
      // need to make sure that _all_ jobs have completed just up to
      // this global barrier.

      // If we hit a cyclic dependency, ignore it and run the other
      // jobs up to that pass.  Then try again to run the cyclic
      // pass.  If we hit the cycle again for the same job, stop.
      LinkedList barrierWorklist = new LinkedList(jobs.values());

      while (!barrierWorklist.isEmpty()) {
        Object o = barrierWorklist.removeFirst();
        if (o == COMPLETED_JOB) continue;
        SourceJob sj = (SourceJob) o;
        if (sj.completed(pass.id()) || sj.nextPass() == sj.passByID(pass.id())) {
          // the source job has either done this global pass
          // (which is possible if the job was loaded late in the
          // game), or is right up to the global barrier.
          continue;
        }

        // Make the job run up to just before the global barrier.
        // We ignore the return result, since even if the job
        // fails, we will keep on going and see
        // how far we get...
        Pass beforeGlobal = sj.getPreviousTo(pass.id());
        if (Report.should_report(Report.frontend, 3)) {
          Report.report(3, "Running " + sj + " to " + beforeGlobal.id() + " for " + srcJob);
        }

        // Don't use runToPass, since that catches the
        // CyclicDependencyException that we should report
        // back to the caller.
        while (!sj.pendingPasses().isEmpty()) {
          Pass p = (Pass) sj.pendingPasses().get(0);

          runPass(sj, p);

          if (p == beforeGlobal) {
            break;
          }
        }
      }
    }
  }