added fleet api classes
authoradam <adam@megacz.com>
Thu, 25 Jan 2007 13:58:53 +0000 (14:58 +0100)
committeradam <adam@megacz.com>
Thu, 25 Jan 2007 13:58:53 +0000 (14:58 +0100)
src/edu/berkeley/fleet/api/BenkoBox.java [new file with mode: 0644]
src/edu/berkeley/fleet/api/Fleet.java [new file with mode: 0644]
src/edu/berkeley/fleet/api/Instruction.java [new file with mode: 0644]
src/edu/berkeley/fleet/api/Ship.java [new file with mode: 0644]

diff --git a/src/edu/berkeley/fleet/api/BenkoBox.java b/src/edu/berkeley/fleet/api/BenkoBox.java
new file mode 100644 (file)
index 0000000..23ec414
--- /dev/null
@@ -0,0 +1,23 @@
+package edu.berkeley.fleet.api;
+
+public abstract class BenkoBox {
+
+    /** you should extend subclasses, not this class directly */
+    BenkoBox() { }
+
+    /** the descriptive name of this benkobox (relative to its ship) */
+    public abstract String getName();
+    
+    /** the maximum number of instructions we can put in the BenkoBox instruction fifo,
+     *  or Integer.MAX_VALUE if unbounded */
+    public abstract int getInstructionFifoLength();
+
+    public static abstract class Inbox extends BenkoBox {
+        public Inbox() { }
+    }
+
+    public static abstract class Outbox extends BenkoBox {
+        public Outbox() { }
+    }
+
+}            
diff --git a/src/edu/berkeley/fleet/api/Fleet.java b/src/edu/berkeley/fleet/api/Fleet.java
new file mode 100644 (file)
index 0000000..4c5432a
--- /dev/null
@@ -0,0 +1,16 @@
+package edu.berkeley.fleet.api;
+import java.io.*;
+import java.util.*;
+
+public abstract class Fleet implements Iterable<Ship> {
+
+    /** read a machine-formatted instruction from a file (into a Java object) */
+    public abstract Instruction readInstruction(DataInputStream is) throws IOException;
+
+    /** write a machine-formatted instruction to a file (from a Java object) */
+    public abstract void        writeInstruction(DataOutputStream os, Instruction instr) throws IOException;
+
+    /** ships must be returned in the same order every time -- ordering may be significant */
+    public abstract Iterator<Ship> iterator();
+
+}
\ No newline at end of file
diff --git a/src/edu/berkeley/fleet/api/Instruction.java b/src/edu/berkeley/fleet/api/Instruction.java
new file mode 100644 (file)
index 0000000..99e2c1b
--- /dev/null
@@ -0,0 +1,79 @@
+package edu.berkeley.fleet.api;
+
+public abstract class Instruction {
+
+    public static class Kill extends Instruction {
+
+        public final BenkoBox benkoBox;
+        public final int      count;
+        public Kill(BenkoBox benkoBox, int count) { this.benkoBox=benkoBox; this.count=count; }
+        public String toString() { return (count>1 ? "["+count+"] " : "") + "kill"; }
+
+    }
+
+    public static class Normal extends Instruction {
+
+        public final BenkoBox benkoBox;
+        public final BenkoBox dest;
+        public final int      count;
+
+        public final boolean  wait;
+        public final boolean  dataIn;
+        public final boolean  latch;
+        public final boolean  dataOut;
+        public final boolean  ack;
+        public final boolean  recycle;
+
+        public Normal(BenkoBox benkoBox,
+                      BenkoBox dest,
+                      int      count,
+                      boolean  dataIn,
+                      boolean  latch,
+                      boolean  ack,
+                      boolean  wait,
+                      boolean  dataOut,
+                      boolean  recycle) {
+            this.benkoBox = benkoBox;
+            this.dest = dest;
+            this.count = count;
+            this.dataIn = dataIn;
+            this.latch = latch;
+            this.ack = ack;
+            this.wait = wait;
+            this.dataOut = dataOut;
+            this.recycle = recycle;
+            if (count <= 0)
+                throw new RuntimeException("count field of an instruction must be >0");
+        }
+
+    }
+
+    public static class Literal extends Instruction {
+        public final BenkoBox dest;
+        protected Literal(BenkoBox dest) { this.dest = dest; }
+
+        public static class Absolute extends Literal {
+            public final long value;
+            public Absolute(BenkoBox dest, long value) { super(dest); this.value = value; }
+            public String toString() { return value + ": sendto " + dest; }
+        }
+
+        public static class Relative extends Literal {
+            /** value transmitted will be offset plus the address from which this instruction was loaded */
+            public final long offset;
+            public Relative(BenkoBox dest, long offset) { super(dest); this.offset = offset; }
+            // FIXME: not final form!
+            public String toString() { return "(relative "+offset+"): sendto " + dest; }
+        }
+
+        public static class CodeBagDescriptor extends Literal {
+            /** address of CBD, relative to address that this instruction was loaded from */
+            public final long offset;
+            public final long size;
+            public CodeBagDescriptor(BenkoBox dest, long offset, long size) {
+                super(dest); this.offset = offset; this.size = size; }
+            // FIXME: not final form!
+            public String toString() { return "(CBD "+offset+":"+size+"): sendto " + dest; }
+        }
+    }
+}
diff --git a/src/edu/berkeley/fleet/api/Ship.java b/src/edu/berkeley/fleet/api/Ship.java
new file mode 100644 (file)
index 0000000..d25083c
--- /dev/null
@@ -0,0 +1,13 @@
+package edu.berkeley.fleet.api;
+import java.io.*;
+import java.util.*;
+
+public abstract class Ship {
+
+    /** returns the type of the ship ("Fetch", "ALU", etc) */
+    public abstract String getType();
+    
+    /** return all benkoboxes which feed this ship; order is NOT significant */
+    public abstract Iterable<BenkoBox> getBenkoBoxes();
+
+}