Break Fpga.java into separate subclasses for ML509.Large, ML509.Small, and Bee2
[fleet.git] / src / edu / berkeley / fleet / fpga / Fpga.java
index f73e9b1..26bbc8f 100644 (file)
@@ -16,7 +16,7 @@ import static edu.berkeley.fleet.fpga.verilog.Verilog.*;
 import edu.berkeley.fleet.two.PercolatedPort;
 
 
-public class Fpga extends FleetTwoFleet {
+public abstract class Fpga extends FleetTwoFleet {
 
     public  Module top;
     Ship debugShip;
@@ -33,7 +33,7 @@ public class Fpga extends FleetTwoFleet {
     }
 
     public static void main(String[] s) throws Exception { 
-        new Fpga(new Module("main")).top.dump(s[0]);
+        ((Fpga)Fleet.getDefaultImpl()).top.dump(s[0]);
         PrintWriter pw;
 
         pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(s[0]+"/timescale.v")));
@@ -64,7 +64,7 @@ public class Fpga extends FleetTwoFleet {
     // Setup //////////////////////////////////////////////////////////////////////////////
 
     Ship createShip(String type) throws IOException {
-        ShipDescription sd = new ShipDescription(type, new BufferedReader(new InputStreamReader(new FileInputStream("ships/"+type+".ship"))));
+        ShipDescription sd = new ShipDescription(this, type, new BufferedReader(new InputStreamReader(new FileInputStream("ships/"+type+".ship"))));
         int count = 0;
         for(Ship ship : ships.values()) if (ship.getType().equals(type)) count++;
         String name = type+count;
@@ -73,54 +73,12 @@ public class Fpga extends FleetTwoFleet {
         return ship;
     }
 
-    public Fpga() throws Exception { this(new Module("main")); }
-    public Fpga(Module top) throws Exception {
-        this.top = top;
-        debugShip = createShip("Debug");
-
-        boolean small = true;
-        //boolean small = false;
-
-        if (small) {
-            for(int i=0; i<2; i++) createShip("Alu");
-            for(int i=0; i<1; i++) createShip("Memory");
-            for(int i=0; i<2; i++) createShip("Fifo");
-            createShip("Counter");
-            createShip("CarrySaveAdder");
-            createShip("Rotator");
-            createShip("Lut3");
-            createShip("Timer");
-            createShip("DDR2");
-            createShip("Dvi");
-            createShip("ZBT");
-
-        } else {
-
-            for(int i=0; i<3; i++)  createShip("Memory");
-            for(int i=0; i<3; i++)  createShip("Alu");
-            for(int i=0; i<2; i++)  createShip("Fifo");
-            for(int i=0; i<11; i++) createShip("Counter");
-
-            /*
-            for(int i=0; i<3; i++)  createShip("Memory");
-            for(int i=0; i<3; i++)  createShip("Alu");
-            for(int i=0; i<2; i++)  createShip("Fifo");
-            for(int i=0; i<14; i++) createShip("Counter");
-
-            // "really big" configuration: 138 docks
-            for(int i=0; i<4; i++)  createShip("Alu");
-            */
-
-            //createShip("CarrySaveAdder");
-            //createShip("Rotator");
-            //createShip("Lut3");
-
-            createShip("Timer");
-            createShip("DDR2");
-            createShip("Dvi");
-            createShip("ZBT");
-        }
+    protected Fpga() throws IOException {
+        this.top = new Module("main");
+        this.debugShip = createShip("Debug");
+    }
 
+    protected void init() throws IOException {
         // for FifoShip
         new Module.InstantiatedModule(top, new FifoModule(8, WIDTH_WORD));
 
@@ -142,6 +100,7 @@ public class Fpga extends FleetTwoFleet {
                 final Module.SourcePort sp = sp0;
                 sources.add(new FabricElement.AbstractFabricElement() {
                         private FabricElement upstream;
+                        public int      getPathLength(FpgaDestination dest) { return upstream.getPathLength(dest); }
                         public FpgaPath getPath(FpgaDestination dest, BitVector signal) { return upstream.getPath(dest, signal); }
                         public void addOutput(FabricElement out, Module.Port outPort) {
                             this.upstream = out;
@@ -176,6 +135,7 @@ public class Fpga extends FleetTwoFleet {
     public void expand(ShipDescription sd) {
         try {
             if (sd.getSection("fpga")==null) return;
+            if (getShip(sd.getName(),0)==null) return;  // no ships of this type
             String filename = sd.getName().toLowerCase();
 
             if (sd.getSection("ucf") != null) {