overhaul of interpreter, update ships to match; "make test" works now
[fleet.git] / src / edu / berkeley / fleet / interpreter / Interpreter.java
index 752ac72..0461167 100644 (file)
@@ -9,14 +9,14 @@ import edu.berkeley.fleet.two.*;
 import edu.berkeley.fleet.assembler.*;
 import edu.berkeley.fleet.util.*;
 
-public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynamicShips {
+public class Interpreter extends FleetTwoFleet {
 
     /** used to allocate serial numbers; see InterpreterDestination for further detail */
     int maxAllocatedDestinationSerialNumber = 0;
 
     private InterpreterShip debugShip = null;
     private BlockingQueue<BitVector> debugStream = new LinkedBlockingQueue<BitVector>();
-    private HashMap<String,InterpreterShip> ships = new HashMap<String,InterpreterShip>();
+    private LinkedHashMap<String,InterpreterShip> ships = new LinkedHashMap<String,InterpreterShip>();
     public Iterator<Ship> iterator() { return (Iterator<Ship>)(Object)ships.values().iterator(); }
     public Ship getShip(String type, int ordinal) {
         for(Ship s : this)
@@ -27,7 +27,40 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
     }
 
     /** do not use this; it is going to go away */
-    public Interpreter() {
+    public Interpreter() { this(true); }
+    public Interpreter(boolean logging) {
+        this(new String[] {
+                "Debug",
+                "Memory",
+                "Memory",
+                "Memory",
+                "Alu",
+                "Alu",
+                "Alu",
+                "Alu",
+                "Alu",
+                "Alu",
+                "Alu",
+                "Fifo",
+                "Fifo",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Counter",
+                "Lut3",
+                "CarrySaveAdder",
+                "Rotator",
+            }, logging);
     }
 
     public Interpreter(String[] ships, boolean logging) {
@@ -46,8 +79,7 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
         new Packet((InterpreterPath)path, new BitVector(getWordWidth()).set(il), false).send();
     }
 
-    /** do not use this; it is going to go away */
-    public Ship createShip(String shipType, String shipname) {
+    private Ship createShip(String shipType, String shipname) {
         try {
             if (ships.get(shipname)!=null) return ships.get(shipname);
             Class c = Class.forName("edu.berkeley.fleet.interpreter."+shipType);
@@ -148,9 +180,15 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
         private Instruction[] instructions;
         public void flush() { }
         public void sendWord(Destination d, BitVector word) {
-            throw new RuntimeException("not implemented");
+            InterpreterPath path = (InterpreterPath)debugShip.getDock("in").getPath(d, new BitVector(1));
+            ((InterpreterDestination)d).
+                addDataFromFabric(new Packet(path, word, false));
+        }
+        public void sendToken(Destination d) {
+            InterpreterPath path = (InterpreterPath)debugShip.getDock("in").getPath(d, new BitVector(1));
+            ((InterpreterDestination)d).
+                addDataFromFabric(new Packet(path, new BitVector(getWordWidth()), true));
         }
-        public void sendToken(Destination d) { throw new RuntimeException("not implemented"); }
         public InterpreterProcess(Instruction[] instructions) {
             this.instructions = instructions;
             for(Instruction i : instructions)