// get the caption for the loop's visual representation // the caption is an abbreviated form of the code // the caption appears in the upper-left corner of the loop public String getCaption() { String caption = ""; switch (type) { case LOOP_TYPE_REPETITIONS: if (!numWarmups.equals("0")) { caption += numWarmups + " " + Utility.wordForm(numWarmups, "warmups") + " + "; if (sync) caption += "sync + "; } caption += numReps + " " + Utility.wordForm(numReps, "reps"); return caption; case LOOP_TYPE_FOR_EACH: caption = sequenceName + " in "; for (int i = 0; i < sequences.size(); i++) { String sequence = (String) sequences.elementAt(i); if (i > 0) caption += ", "; caption += "{" + sequence + "}"; } return caption; case LOOP_TYPE_TIMED: return toCode(); default: assert false; return ""; } }
// returns the code for the header of the loop, not code for // the entire loop that it contains public String toCode() { String code; switch (type) { case LOOP_TYPE_REPETITIONS: code = "for " + numReps + " " + Utility.wordForm(numReps, "repetitions"); if (!numWarmups.equals("0")) { code += " plus " + numWarmups + " warmup " + Utility.wordForm(numWarmups, "repetitions"); if (sync) code += " and a synchronization"; } return code; case LOOP_TYPE_FOR_EACH: code = "for each " + sequenceName + " in "; for (int i = 0; i < sequences.size(); i++) { String sequence = (String) sequences.elementAt(i); if (i > 0) code += ", "; code += "{" + sequence + "}"; } return code; case LOOP_TYPE_TIMED: code = "for " + time + " " + Utility.wordForm(time, timeUnits); return code; default: assert false; return ""; } }
// generate the code corresponding to the compute aggregates public String toCodeComputeAggregates() { if (computeAggregatesGroup == null) return null; else return computeAggregatesGroup.toCodeSource() + " " + Utility.wordForm(computeAggregatesGroup.toCodeSource(), "computes") + " aggregates"; }