1 package edu.berkeley.fleet;
3 /** an instruction within a codebag, as specified in am10 */
4 public class Instruction extends Dispatchable {
6 public final PortReference source;
7 public final PortReference destination;
8 public final int count;
9 public final IgnoreCopyTake dataIn;
10 public final boolean ack;
11 public final boolean trigger;
12 public final boolean dataOut;
14 public static enum IgnoreCopyTake { IGNORE, COPY, TAKE };
16 public Instruction(PortReference source,
17 PortReference destination,
19 IgnoreCopyTake dataIn,
24 this.destination = destination;
28 this.trigger = trigger;
29 this.dataOut = dataOut;
31 throw new RuntimeException("count field of an instruction must be >0");
34 public void dispatch(Fleet fleet) {
35 Port sourcePort = source.resolve(fleet);
36 if (!(sourcePort instanceof InstructionPort))
37 throw new RuntimeException(sourcePort + " is not an InstructionPort!");
38 ((InstructionPort)sourcePort).addInstruction(this);
41 public String toString() {
42 StringBuffer ret = new StringBuffer();
43 if (trigger) ret.append("triggered ");
49 ret.append(dataOut ? "copy" : "wait");
52 ret.append(dataOut ? "move" : "discard");
55 if (ack) ret.append("+ack");
60 case 1: ret.append("->"); break;
61 case Integer.MAX_VALUE: ret.append("-[*]->"); break;
62 default: ret.append("-["+count+"]->"); break;
65 ret.append(destination);
66 return ret.toString();