1 package edu.berkeley.fleet;
3 /** an instruction within a codebag, as specified in am10; this class is immutable */
4 public class Instruction extends Dispatchable {
6 public final PortReference source;
7 public final PortReference destination;
8 public final int count;
10 public final boolean trigger;
11 public final boolean dataIn;
12 public final boolean latch;
13 public final boolean dataOut;
14 public final boolean ack;
15 public final boolean recycle;
17 public Instruction(PortReference source,
18 PortReference destination,
25 this(source, destination, count, dataIn, latch, ack, trigger, dataOut, false);
27 public Instruction(PortReference source,
28 PortReference destination,
37 this.destination = destination;
42 this.trigger = trigger;
43 this.dataOut = dataOut;
44 this.recycle = recycle;
46 throw new RuntimeException("count field of an instruction must be >0");
49 public void dispatch(Fleet fleet) {
50 Port sourcePort = source.resolve(fleet);
51 if (!(sourcePort instanceof InstructionPort))
52 throw new RuntimeException(sourcePort + " is not an InstructionPort!");
53 ((InstructionPort)sourcePort).addInstruction(this);
56 public String toString() {
57 StringBuffer ret = new StringBuffer();
63 case Integer.MAX_VALUE: ret.append("[*] ");
64 default: ret.append("["+count+"] ");
66 if (trigger) { ret.append("wait"); more=true; }
67 if (dataIn && latch) { if (more) ret.append(", "); ret.append("take"); more = true; }
68 if (dataIn && !latch) { if (more) ret.append(", "); ret.append("discard"); more = true; }
69 if (dataOut && destination!=null) { if (more) ret.append(", "); ret.append("sendto "+destination); more = true; }
70 if (dataOut && destination==null) { if (more) ret.append(", "); ret.append("accept"); more = true; }
71 if (ack) { if (more) ret.append(", "); ret.append("ack "+destination); more = true; }
72 return ret.toString();