added fleet api classes
[fleet.git] / src / edu / berkeley / fleet / api / Instruction.java
1 package edu.berkeley.fleet.api;
2
3 public abstract class Instruction {
4
5     public static class Kill extends Instruction {
6
7         public final BenkoBox benkoBox;
8         public final int      count;
9         public Kill(BenkoBox benkoBox, int count) { this.benkoBox=benkoBox; this.count=count; }
10         public String toString() { return (count>1 ? "["+count+"] " : "") + "kill"; }
11
12     }
13
14     public static class Normal extends Instruction {
15
16         public final BenkoBox benkoBox;
17         public final BenkoBox dest;
18         public final int      count;
19
20         public final boolean  wait;
21         public final boolean  dataIn;
22         public final boolean  latch;
23         public final boolean  dataOut;
24         public final boolean  ack;
25         public final boolean  recycle;
26
27         public Normal(BenkoBox benkoBox,
28                       BenkoBox dest,
29                       int      count,
30                       boolean  dataIn,
31                       boolean  latch,
32                       boolean  ack,
33                       boolean  wait,
34                       boolean  dataOut,
35                       boolean  recycle) {
36             this.benkoBox = benkoBox;
37             this.dest = dest;
38             this.count = count;
39             this.dataIn = dataIn;
40             this.latch = latch;
41             this.ack = ack;
42             this.wait = wait;
43             this.dataOut = dataOut;
44             this.recycle = recycle;
45             if (count <= 0)
46                 throw new RuntimeException("count field of an instruction must be >0");
47         }
48
49     }
50
51     public static class Literal extends Instruction {
52         public final BenkoBox dest;
53         protected Literal(BenkoBox dest) { this.dest = dest; }
54
55         public static class Absolute extends Literal {
56             public final long value;
57             public Absolute(BenkoBox dest, long value) { super(dest); this.value = value; }
58             public String toString() { return value + ": sendto " + dest; }
59         }
60
61         public static class Relative extends Literal {
62             /** value transmitted will be offset plus the address from which this instruction was loaded */
63             public final long offset;
64             public Relative(BenkoBox dest, long offset) { super(dest); this.offset = offset; }
65             // FIXME: not final form!
66             public String toString() { return "(relative "+offset+"): sendto " + dest; }
67         }
68
69         public static class CodeBagDescriptor extends Literal {
70             /** address of CBD, relative to address that this instruction was loaded from */
71             public final long offset;
72             public final long size;
73             public CodeBagDescriptor(BenkoBox dest, long offset, long size) {
74                 super(dest); this.offset = offset; this.size = size; }
75             // FIXME: not final form!
76             public String toString() { return "(CBD "+offset+":"+size+"): sendto " + dest; }
77         }
78     }
79 }